97 lines
2.1 KiB
C++
97 lines
2.1 KiB
C++
|
#pragma once
|
||
|
#ifndef REAL_BUILD
|
||
|
# include "externals.hh"
|
||
|
#endif
|
||
|
|
||
|
|
||
|
// Uniform types
|
||
|
enum class E_UniformType {
|
||
|
F1 , F2 , F3 , F4 ,
|
||
|
I1 , I2 , I3 , I4 ,
|
||
|
SAMPLER2D
|
||
|
};
|
||
|
|
||
|
// Categories
|
||
|
enum class E_UniformCategory {
|
||
|
FLOAT , INT ,
|
||
|
SAMPLER2D ,
|
||
|
__COUNT__
|
||
|
};
|
||
|
|
||
|
// Category from type
|
||
|
E_UniformCategory GetUniformCategory(
|
||
|
__rd__ const E_UniformType type );
|
||
|
// Element count from type
|
||
|
uint32_t GetElementCount(
|
||
|
__rd__ const E_UniformType type );
|
||
|
// Is some category a vector type?
|
||
|
bool IsVectorCategory(
|
||
|
__rd__ const E_UniformCategory category );
|
||
|
|
||
|
|
||
|
// Uniform declarations
|
||
|
struct T_UniformDeclaration
|
||
|
{
|
||
|
std::string name;
|
||
|
bool global;
|
||
|
E_UniformType type;
|
||
|
|
||
|
std::string source;
|
||
|
uint32_t line;
|
||
|
};
|
||
|
|
||
|
using T_UniformDeclarations = std::unordered_map< std::string , T_UniformDeclaration >;
|
||
|
|
||
|
|
||
|
// Packed uniforms
|
||
|
struct T_PackedUniforms
|
||
|
{
|
||
|
uint32_t elements = 0;
|
||
|
std::map< std::string , uint32_t > positions;
|
||
|
};
|
||
|
|
||
|
T_PackedUniforms PackUniforms(
|
||
|
__rd__ T_UniformDeclarations const& declarations ,
|
||
|
__rd__ const E_UniformCategory category );
|
||
|
|
||
|
|
||
|
// A set of uniforms, meant for use with a buffer or directly
|
||
|
struct T_UniformSet
|
||
|
{
|
||
|
static constexpr uint32_t Invalid = 0xffffffff;
|
||
|
|
||
|
T_UniformSet( );
|
||
|
explicit T_UniformSet(
|
||
|
__rw__ T_UniformDeclarations uniforms );
|
||
|
|
||
|
DEF_MOVE( T_UniformSet );
|
||
|
NO_COPY( T_UniformSet );
|
||
|
|
||
|
// ---------------------------------------------------------------------
|
||
|
|
||
|
T_UniformDeclarations const& declarations( ) const noexcept
|
||
|
{ return declarations_; }
|
||
|
|
||
|
uint32_t vectorElements( ) const noexcept
|
||
|
{ return vectorElements_; }
|
||
|
uint32_t opaqueElements( ) const noexcept
|
||
|
{ return opaqueElements_; }
|
||
|
|
||
|
uint32_t inCategory(
|
||
|
__rd__ const E_UniformCategory category ) const noexcept
|
||
|
{
|
||
|
assert( category != E_UniformCategory::__COUNT__ );
|
||
|
return packed_[ int( category ) ].elements;
|
||
|
}
|
||
|
|
||
|
// Return the position of the specified uniform in its category.
|
||
|
// If the uniform doesn't exist, this will return Invalid.
|
||
|
uint32_t position(
|
||
|
__rd__ std::string const& uniform ) const;
|
||
|
|
||
|
private:
|
||
|
T_UniformDeclarations declarations_;
|
||
|
uint32_t vectorElements_ , opaqueElements_;
|
||
|
T_PackedUniforms packed_[ int( E_UniformCategory::__COUNT__ ) ];
|
||
|
};
|