Game Development Reference
In-Depth Information
The CheckStatus() function performs error checks and logs a speciied error message
on failure:
if ( !CheckStatus( Shader, GL_COMPILE_STATUS,
"Failed to compile shader:" ) )
{
LGL3->glDeleteShader( Shader );
return OldShaderID;
}
if ( OldShaderID ) LGL3->glDeleteShader( OldShaderID );
return Shader;
OldShaderID retains the previous compiled shader. It is used to allow the editing of shaders
on-the-ly on a PC and prevents loading of invalid shaders. After the vertex and fragment
shaders have compiled, a shader program should be linked:
bool clGLSLShaderProgram::RelinkShaderProgram()
{
GLuint ProgramID = LGL3->glCreateProgram();
FVertexShaderID = AttachShaderID( GL_VERTEX_SHADER,
FVertexShader, FVertexShaderID );
if ( FVertexShaderID ) LGL3->glAttachShader( ProgramID,
FVertexShaderID );
FFragmentShaderID = AttachShaderID( GL_FRAGMENT_SHADER,
FFragmentShader, FFragmentShaderID );
if ( FFragmentShaderID ) LGL3->glAttachShader( ProgramID,
FFragmentShaderID );
BindDefaultLocations( ProgramID );
LGL3->glLinkProgram( ProgramID );
The same should also be done to the shader program. Replace the old program only if the
program was linked successfully:
if ( !CheckStatus( ProgramID, GL_LINK_STATUS,
"Failed to link program\n" ) )
{
LOGI( "Error during shader program relinking\n" );
return false;
}
LGL3->glDeleteProgram( FProgramID );
FProgramID = ProgramID;
RebindAllUniforms();
return true;
}
We have to bind the default locations of different attributes that we will use throughout
our renderer:
 
Search WWH ::




Custom Search