Display linking errors in debug mode for shaders. Added SHADER::GetAttribute() function for getting shaders attribute location.

This commit is contained in:
Maciej Suminski 2013-06-03 10:54:24 +02:00
parent e8acd2919b
commit ad5d10a8ba
2 changed files with 30 additions and 8 deletions

View File

@ -168,23 +168,30 @@ void SHADER::ConfigureGeometryShader( GLuint maxVertices, GLuint geometryInputTy
} }
void SHADER::Link() bool SHADER::Link()
{ {
// Shader linking // Shader linking
glLinkProgram( programNumber ); glLinkProgram( programNumber );
ProgramInfo( programNumber ); ProgramInfo( programNumber );
// Check the Link state // Check the Link state
GLint linkStatus = 0; glGetObjectParameterivARB( programNumber, GL_OBJECT_LINK_STATUS_ARB, (GLint*) &isShaderLinked );
glGetObjectParameterivARB( programNumber, GL_OBJECT_LINK_STATUS_ARB, &linkStatus );
if( !linkStatus ) #ifdef __WXDEBUG__
if( !isShaderLinked )
{ {
wxLogError( wxString::FromUTF8( "Can't link the shaders!" ) ); int maxLength;
exit( 1 ); glGetProgramiv( programNumber, GL_INFO_LOG_LENGTH, &maxLength );
maxLength = maxLength + 1;
char *linkInfoLog = new char[maxLength];
glGetProgramInfoLog( programNumber, maxLength, &maxLength, linkInfoLog );
std::cerr << "Shader linking error:" << std::endl;
std::cerr << linkInfoLog;
delete[] linkInfoLog;
} }
#endif /* __WXDEBUG__ */
isShaderLinked = true; return isShaderLinked;
} }
@ -215,3 +222,9 @@ void SHADER::SetParameter( int parameterNumber, float value )
{ {
glUniform1f( parameterLocation[parameterNumber], value ); glUniform1f( parameterLocation[parameterNumber], value );
} }
int SHADER::GetAttribute( std::string aAttributeName )
{
return glGetAttribLocation( programNumber, aAttributeName.c_str() );
}

View File

@ -80,8 +80,9 @@ public:
/** /**
* Link the shaders. * Link the shaders.
* @return true in case of success, false otherwise.
*/ */
void Link(); bool Link();
/** /**
* Use the shader. * Use the shader.
@ -122,6 +123,14 @@ public:
*/ */
void SetParameter( int aParameterNumber, float aValue ); void SetParameter( int aParameterNumber, float aValue );
/**
* @brief Gets an attribute location.
*
* @param aAttributeName is the name of the attribute.
* @return the location.
*/
int GetAttribute( std::string aAttributeName );
private: private:
/** /**