Commit ad5d10a8 authored by Maciej Suminski's avatar Maciej Suminski

Display linking errors in debug mode for shaders. Added SHADER::GetAttribute()...

Display linking errors in debug mode for shaders. Added SHADER::GetAttribute() function for getting shaders attribute location.
parent e8acd291
...@@ -168,23 +168,30 @@ void SHADER::ConfigureGeometryShader( GLuint maxVertices, GLuint geometryInputTy ...@@ -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 ) ...@@ -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() );
}
...@@ -80,8 +80,9 @@ public: ...@@ -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: ...@@ -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:
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment