From ad5d10a8ba891c0c79c2ecffdb33851aaaf93357 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 3 Jun 2013 10:54:24 +0200 Subject: [PATCH] Display linking errors in debug mode for shaders. Added SHADER::GetAttribute() function for getting shaders attribute location. --- common/gal/opengl/shader.cpp | 27 ++++++++++++++++++++------- include/gal/opengl/shader.h | 11 ++++++++++- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/common/gal/opengl/shader.cpp b/common/gal/opengl/shader.cpp index e38fbe1995..6cbd84850d 100644 --- a/common/gal/opengl/shader.cpp +++ b/common/gal/opengl/shader.cpp @@ -168,23 +168,30 @@ void SHADER::ConfigureGeometryShader( GLuint maxVertices, GLuint geometryInputTy } -void SHADER::Link() +bool SHADER::Link() { // Shader linking glLinkProgram( programNumber ); ProgramInfo( programNumber ); // Check the Link state - GLint linkStatus = 0; - glGetObjectParameterivARB( programNumber, GL_OBJECT_LINK_STATUS_ARB, &linkStatus ); + glGetObjectParameterivARB( programNumber, GL_OBJECT_LINK_STATUS_ARB, (GLint*) &isShaderLinked ); - if( !linkStatus ) +#ifdef __WXDEBUG__ + if( !isShaderLinked ) { - wxLogError( wxString::FromUTF8( "Can't link the shaders!" ) ); - exit( 1 ); + int maxLength; + 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 ); } + + +int SHADER::GetAttribute( std::string aAttributeName ) +{ + return glGetAttribLocation( programNumber, aAttributeName.c_str() ); +} diff --git a/include/gal/opengl/shader.h b/include/gal/opengl/shader.h index 97852c27d4..71fa03109f 100644 --- a/include/gal/opengl/shader.h +++ b/include/gal/opengl/shader.h @@ -80,8 +80,9 @@ public: /** * Link the shaders. + * @return true in case of success, false otherwise. */ - void Link(); + bool Link(); /** * Use the shader. @@ -122,6 +123,14 @@ public: */ 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: /**