More debug information in case of failure compilation of shaders.
This commit is contained in:
parent
5eb38ec232
commit
335bf72060
|
@ -359,8 +359,16 @@ void OPENGL_GAL::BeginDrawing()
|
|||
// Compile the shaders
|
||||
if( !isShaderInitialized && isUseShader )
|
||||
{
|
||||
shader.AddSource( shaderPath + std::string( "/shader.vert" ), SHADER_TYPE_VERTEX );
|
||||
shader.AddSource( shaderPath + std::string( "/shader.frag" ), SHADER_TYPE_FRAGMENT );
|
||||
if( !shader.AddSource( shaderPath + std::string( "/shader.vert" ), SHADER_TYPE_VERTEX ) )
|
||||
{
|
||||
wxLogFatalError( wxT( "Cannot compile vertex shader!" ) );
|
||||
}
|
||||
|
||||
if( !shader.AddSource( shaderPath + std::string( "/shader.frag" ), SHADER_TYPE_FRAGMENT ) )
|
||||
{
|
||||
wxLogFatalError( wxT( "Cannot compile fragment shader!" ) );
|
||||
}
|
||||
|
||||
if( !shader.Link() )
|
||||
{
|
||||
wxLogFatalError( wxT( "Cannot link the shaders!" ) );
|
||||
|
|
|
@ -83,6 +83,27 @@ void SHADER::ProgramInfo( GLuint aProgram )
|
|||
}
|
||||
|
||||
|
||||
void SHADER::ShaderInfo( GLuint aShader )
|
||||
{
|
||||
GLint glInfoLogLength = 0;
|
||||
GLint writtenChars = 0;
|
||||
|
||||
// Get the length of the info string
|
||||
glGetShaderiv( aShader, GL_INFO_LOG_LENGTH, &glInfoLogLength );
|
||||
|
||||
// Print the information
|
||||
if( glInfoLogLength > 2 )
|
||||
{
|
||||
GLchar* glInfoLog = new GLchar[glInfoLogLength];
|
||||
glGetShaderInfoLog( aShader, glInfoLogLength, &writtenChars, glInfoLog );
|
||||
|
||||
wxLogInfo( wxString::FromUTF8( (char*) glInfoLog ) );
|
||||
|
||||
delete glInfoLog;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string SHADER::ReadSource( std::string aShaderSourceName )
|
||||
{
|
||||
// Open the shader source for reading
|
||||
|
@ -109,7 +130,7 @@ std::string SHADER::ReadSource( std::string aShaderSourceName )
|
|||
}
|
||||
|
||||
|
||||
void SHADER::AddSource( const std::string& aShaderSourceName, ShaderType aShaderType )
|
||||
bool SHADER::AddSource( const std::string& aShaderSourceName, ShaderType aShaderType )
|
||||
{
|
||||
if( isShaderLinked )
|
||||
{
|
||||
|
@ -144,6 +165,17 @@ void SHADER::AddSource( const std::string& aShaderSourceName, ShaderType aShader
|
|||
|
||||
// Compile and attach shader to the program
|
||||
glCompileShader( shaderNumber );
|
||||
GLint status;
|
||||
glGetShaderiv( shaderNumber, GL_COMPILE_STATUS, &status );
|
||||
if( status != GL_TRUE )
|
||||
{
|
||||
wxLogError( wxT( "Shader compilation error" ) );
|
||||
|
||||
ShaderInfo( shaderNumber );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
glAttachShader( programNumber, shaderNumber );
|
||||
ProgramInfo( programNumber );
|
||||
|
||||
|
@ -157,6 +189,8 @@ void SHADER::AddSource( const std::string& aShaderSourceName, ShaderType aShader
|
|||
|
||||
// Delete the allocated char array
|
||||
delete[] source;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ public:
|
|||
* @param aShaderSourceName is the shader source file name.
|
||||
* @param aShaderType is the type of the shader.
|
||||
*/
|
||||
void AddSource( const std::string& aShaderSourceName, ShaderType aShaderType );
|
||||
bool AddSource( const std::string& aShaderSourceName, ShaderType aShaderType );
|
||||
|
||||
/**
|
||||
* @brief Link the shaders.
|
||||
|
@ -159,6 +159,13 @@ private:
|
|||
*/
|
||||
void ProgramInfo( GLuint aProgram );
|
||||
|
||||
/**
|
||||
* @brief Get the shader information.
|
||||
*
|
||||
* @param aShader is the shader number.
|
||||
*/
|
||||
void ShaderInfo( GLuint aShader );
|
||||
|
||||
/**
|
||||
* @brief Read the shader source file
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue