Skip to content

Commit

Permalink
Finally implemented remaining part of the LoadShader for gl renderer.
Browse files Browse the repository at this point in the history
  • Loading branch information
hogsy committed Dec 7, 2023
1 parent 3f309c2 commit 8ef8058
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions engine/client/renderer/ref_gl/gl_shader_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,10 @@ bool chr::renderer::gl::ShaderProgram::LoadShaderStage( const std::string &path,
}

GLenum glStage;
assert( stage < Stage::MAX_STAGES );
if ( stage == Stage::STAGE_PIXEL )
{
glStage = GL_VERTEX_SHADER;
}
else if ( stage == Stage::STAGE_VERTEX )
{
glStage = GL_FRAGMENT_SHADER;
}
else if ( stage == Stage::STAGE_VERTEX )
glStage = GL_VERTEX_SHADER;
else
{
Com_Printf( "Unsupported shader stage: %u\n", stage );
Expand All @@ -46,7 +41,7 @@ bool chr::renderer::gl::ShaderProgram::LoadShaderStage( const std::string &path,
}

char *buffer;
int length = FS_LoadFile( path.c_str(), ( void **) &buffer );
int length = FS_LoadFile( path.c_str(), ( void ** ) &buffer );
if ( length == -1 )
{
Com_Printf( "Failed to open shader: %s\n", path.c_str() );
Expand All @@ -55,7 +50,29 @@ bool chr::renderer::gl::ShaderProgram::LoadShaderStage( const std::string &path,
return false;
}

return false;
XGL_CALL( glShaderSource( glStages[ stage ], 1, &buffer, &length ) );
XGL_CALL( glCompileShader( glStages[ stage ] ) );

FS_FreeFile( buffer );

GLint compileStatus;
XGL_CALL( glGetShaderiv( glStages[ stage ], GL_COMPILE_STATUS, &compileStatus ) );
if ( compileStatus == GL_FALSE )
{
GLint maxLength;
XGL_CALL( glGetShaderiv( glStages[ stage ], GL_INFO_LOG_LENGTH, &maxLength ) );

std::vector< GLchar > infoLog( maxLength );
XGL_CALL( glGetShaderInfoLog( glStages[ stage ], maxLength, &maxLength, &infoLog[ 0 ] ) );

Com_Printf( "Failed to compile shader: %s\n%s\n", path.c_str(), &infoLog[ 0 ] );

XGL_CALL( glDeleteShader( glStages[ stage ] ) );

return false;
}

return true;
}

void chr::renderer::gl::ShaderProgram::Enable()
Expand Down

0 comments on commit 8ef8058

Please sign in to comment.