diff --git a/src/engine/renderer/gl_shader.cpp b/src/engine/renderer/gl_shader.cpp index e665442d43..9b7bfa1570 100644 --- a/src/engine/renderer/gl_shader.cpp +++ b/src/engine/renderer/gl_shader.cpp @@ -28,7 +28,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // We currently write GLBinaryHeader to a file and memcpy all over it. // Make sure it's a pod, so we don't put a std::string in it or something // and try to memcpy over that or binary write an std::string to a file. -static_assert(std::is_pod::value, "Value must be a pod while code in this cpp file reads and writes this object to file as binary."); +static_assert(IsPod, "Value must be a pod while code in this cpp file reads and writes this object to file as binary."); // set via command line args only since this allows arbitrary code execution static Cvar::Cvar shaderpath( diff --git a/src/engine/renderer/gl_shader.h b/src/engine/renderer/gl_shader.h index a6ed7b14b9..0719d6b1a6 100644 --- a/src/engine/renderer/gl_shader.h +++ b/src/engine/renderer/gl_shader.h @@ -83,6 +83,89 @@ struct GLHeader { } }; +struct ShaderEntry { + std::string name; + uint32_t macro; + GLuint type; + + bool operator==( const ShaderEntry& other ) const { + return name == other.name && macro == other.macro && type == other.type; + } + + bool operator!=( const ShaderEntry& other ) const { + return !( *this == other ); + } +}; + +struct ShaderDescriptor { + std::string name; + + std::string macros; + uint32_t macro; + + GLenum type; + bool main = false; + + GLuint id = 0; + + std::string shaderSource; +}; + +static const uint32_t MAX_SHADER_PROGRAM_SHADERS = 16; + +struct ShaderProgramDescriptor { + GLuint id = 0; + + bool hasMain = false; + GLuint type; + + uint32_t macro = 0; + + GLuint shaders[MAX_SHADER_PROGRAM_SHADERS] {}; + ShaderEntry shaderNames[MAX_SHADER_PROGRAM_SHADERS] {}; + std::string mainShader; + uint32_t shaderCount = 0; + + GLint* uniformLocations; + GLuint* uniformBlockIndexes = nullptr; + byte* uniformFirewall; + + uint32_t checkSum; + + void AttachShader( ShaderDescriptor* descriptor ) { + if ( shaderCount == MAX_SHADER_PROGRAM_SHADERS ) { + Log::Warn( "Tried to attach too many shaders to program: skipping shader %s %s", descriptor->name, descriptor->macros ); + return; + } + + if ( !shaderCount ) { + type = descriptor->type; + } else if ( type != descriptor->type ) { + type = 0; + } + + if ( descriptor->main ) { + if ( hasMain && mainShader != descriptor->name ) { + Log::Warn( "More than one shader specified as main, current: %s, new: %s, using current", + mainShader, descriptor->name ); + } else { + mainShader = descriptor->name; + hasMain = true; + } + } + + shaders[shaderCount] = descriptor->id; + + shaderNames[shaderCount].name = descriptor->name; + shaderNames[shaderCount].macro = descriptor->macro; + shaderNames[shaderCount].type = descriptor->type; + + macro |= descriptor->macro; + + shaderCount++; + }; +}; + class GLShader { friend class GLShaderManager; public: @@ -229,89 +312,6 @@ class GLShader { void WriteUniformsToBuffer( uint32_t* buffer ); }; -struct ShaderEntry { - std::string name; - uint32_t macro; - GLuint type; - - bool operator==( const ShaderEntry& other ) const { - return name == other.name && macro == other.macro && type == other.type; - } - - bool operator!=( const ShaderEntry& other ) const { - return !( *this == other ); - } -}; - -struct ShaderDescriptor { - std::string name; - - std::string macros; - uint32_t macro; - - GLenum type; - bool main = false; - - GLuint id = 0; - - std::string shaderSource; -}; - -static const uint32_t MAX_SHADER_PROGRAM_SHADERS = 16; - -struct ShaderProgramDescriptor { - GLuint id = 0; - - bool hasMain = false; - GLuint type; - - uint32_t macro = 0; - - GLuint shaders[MAX_SHADER_PROGRAM_SHADERS] {}; - ShaderEntry shaderNames[MAX_SHADER_PROGRAM_SHADERS] {}; - std::string mainShader; - uint32_t shaderCount = 0; - - GLint* uniformLocations; - GLuint* uniformBlockIndexes = nullptr; - byte* uniformFirewall; - - uint32_t checkSum; - - void AttachShader( ShaderDescriptor* descriptor ) { - if ( shaderCount == MAX_SHADER_PROGRAM_SHADERS ) { - Log::Warn( "Tried to attach too many shaders to program: skipping shader %s %s", descriptor->name, descriptor->macros ); - return; - } - - if ( !shaderCount ) { - type = descriptor->type; - } else if ( type != descriptor->type ) { - type = 0; - } - - if ( descriptor->main ) { - if ( hasMain && mainShader != descriptor->name ) { - Log::Warn( "More than one shader specified as main, current: %s, new: %s, using current", - mainShader, descriptor->name ); - } else { - mainShader = descriptor->name; - hasMain = true; - } - } - - shaders[shaderCount] = descriptor->id; - - shaderNames[shaderCount].name = descriptor->name; - shaderNames[shaderCount].macro = descriptor->macro; - shaderNames[shaderCount].type = descriptor->type; - - macro |= descriptor->macro; - - shaderCount++; - }; -}; - class GLUniform { public: const std::string _name;