Game Development Reference
In-Depth Information
void clGLSLShaderProgram::BindDefaultLocations( GLuint ID )
{
The meaning of the L_VS_ identiiers is explained in the recipe Manipulating geometry :
LGL3->glBindAttribLocation( ID, L_VS_VERTEX, "in_Vertex" );
LGL3->glBindAttribLocation( ID, L_VS_TEXCOORD,"in_TexCoord" );
LGL3->glBindAttribLocation( ID, L_VS_NORMAL, "in_Normal" );
LGL3->glBindAttribLocation( ID, L_VS_COLORS, "in_Color" );
LGL3->glBindFragDataLocation( ID, 0, "out_FragColor" );
LGL3->glUniform1i(
LGL3->glGetUniformLocation( ID, "Texture0" ), 0 );
}
The shader program can now be used for rendering.
There's moreā€¦
During rendering, we can specify the location of additional uniforms by name and ask the
underlying OpenGL API to bind uniforms by name. However, it is more convenient to do it
in our own code, since we can omit the redundant OpenGL state change calls. The following
is the listing of the RebindAllUniforms() method that will get locations of all the active
uniforms of a shader program and save them for the further use:
void clGLSLShaderProgram::RebindAllUniforms()
{
Bind();
FUniforms.clear();
GLint ActiveUniforms;
char Buff[256];
LGL3->glGetProgramiv( FProgramID,
GL_ACTIVE_UNIFORMS, &ActiveUniforms );
for ( int i = 0; i != ActiveUniforms; ++i )
{
GLsizei Length;
GLint Size;
GLenum Type;
LGL3->glGetActiveUniform( FProgramID, i,
sizeof( Buff ), &Length, &Size, &Type, Buff );
std::string Name( Buff, Length );
sUniform Uniform( Name );
Uniform.FLocation = LGL3->glGetUniformLocation(
FProgramID, Name.c_str() );
FUniforms.push_back( Uniform );
}
}
 
Search WWH ::




Custom Search