Skip to content

Minor gl_shader fixes #1743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/engine/renderer/gl_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<GLBinaryHeader>::value, "Value must be a pod while code in this cpp file reads and writes this object to file as binary.");
static_assert(IsPod<GLBinaryHeader>, "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<std::string> shaderpath(
Expand Down
166 changes: 83 additions & 83 deletions src/engine/renderer/gl_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down