Commit 2e395b19 authored by Sylvain Thery's avatar Sylvain Thery

better shader error logging

parent fc8ce785
......@@ -126,6 +126,16 @@ protected:
static std::vector<std::string> m_pathes;
/**
* @brief log compile error
* @param handle handle of shader
* @param nameSrc name of shader
* @param src source of shader
* @return true if ok false if not
*/
bool logError(GLuint handle, const std::string& nameSrc, const char *src);
/**
* load vertex shader
* @param vertex_shader_source src text shader
......
......@@ -273,11 +273,35 @@ bool GLSLShader::loadGeometryShader(const std::string& filename )
return flag;
}
bool GLSLShader::loadVertexShaderSourceString( const char *vertex_shader_source )
bool GLSLShader::logError(GLuint handle, const std::string& nameSrc, const char *src)
{
// int status;
char *info_log;
char *info_log;
info_log = getInfoLog( handle );
if (info_log!=NULL)
{
CGoGNerr << "============================================================================" << CGoGNendl;
CGoGNerr << "Error in " << nameSrc << CGoGNendl;
CGoGNerr << "----------------------------------------------------------------------------" << CGoGNendl;
char line[256];
int ln=1;
std::stringstream ss(src);
do
{
ss.getline(line,256);
std::cout << ln++ << ": "<< line<< std::endl;
}while (!ss.eof());
CGoGNerr << "----------------------------------------------------------------------------" << CGoGNendl;
CGoGNerr << info_log;
CGoGNerr << "============================================================================" << CGoGNendl;
delete [] info_log;
return false;
}
return true;
}
bool GLSLShader::loadVertexShaderSourceString( const char *vertex_shader_source )
{
if (*m_vertex_shader_object==0)
{
glDeleteShader(*m_vertex_shader_object);
......@@ -309,26 +333,8 @@ bool GLSLShader::loadVertexShaderSourceString( const char *vertex_shader_source
/*** compile shader object ***/
glCompileShader( *m_vertex_shader_object );
// glGetProgramiv( *m_vertex_shader_object, GL_OBJECT_COMPILE_STATUS_ARB, &status );
// if( !status )
// {
// CGoGNerr << "ERROR - GLshader::loadVertexShader() - error occured while compiling shader " << m_nameVS<< CGoGNendl;
// info_log = getInfoLog( *m_vertex_shader_object );
// CGoGNerr << info_log << CGoGNendl;
// delete [] info_log;
// glDeleteShader( *m_vertex_shader_object );
// *m_vertex_shader_object = 0;
// return false;
// }
info_log = getInfoLog( *m_vertex_shader_object );
if (info_log!=NULL)
if (!logError(*m_vertex_shader_object, m_nameVS, vertex_shader_source))
{
CGoGNerr << "ERROR - GLshader::loadVertexShader() - error occured while compiling shader " << m_nameVS<< CGoGNendl;
CGoGNerr << vertex_shader_source << CGoGNendl;
CGoGNerr << "----------------------------------------------------------------------------" << CGoGNendl;
delete [] info_log;
glDeleteShader( *m_vertex_shader_object );
*m_vertex_shader_object = 0;
return false;
......@@ -340,9 +346,6 @@ bool GLSLShader::loadVertexShaderSourceString( const char *vertex_shader_source
bool GLSLShader::loadFragmentShaderSourceString( const char *fragment_shader_source )
{
// int status;
char *info_log;
if (*m_fragment_shader_object==0)
{
glDeleteShader(*m_fragment_shader_object);
......@@ -374,40 +377,20 @@ bool GLSLShader::loadFragmentShaderSourceString( const char *fragment_shader_sou
/*** compile shader object ***/
glCompileShader( *m_fragment_shader_object );
// glGetProgramiv( *m_fragment_shader_object, GL_OBJECT_COMPILE_STATUS_ARB, &status );
// if( !status )
// {
// CGoGNerr << "ERROR - GLshader::loadFragmentShader() - error occured while compiling shader " << m_nameFS << CGoGNendl;
// info_log = getInfoLog( *m_fragment_shader_object );
// CGoGNerr << info_log << CGoGNendl;
// delete [] info_log;
// glDeleteShader( *m_fragment_shader_object );
// *m_fragment_shader_object = 0;
// return false;
// }
info_log = getInfoLog( *m_vertex_shader_object );
if (info_log!=NULL)
if (!logError(*m_fragment_shader_object, m_nameFS, fragment_shader_source))
{
CGoGNerr << "ERROR - GLshader::loadFragmentShader() - error occured while compiling shader " << m_nameFS<< CGoGNendl;
CGoGNerr << fragment_shader_source << CGoGNendl;
CGoGNerr << "----------------------------------------------------------------------------" << CGoGNendl;
delete [] info_log;
glDeleteShader( *m_fragment_shader_object );
*m_fragment_shader_object = 0;
return false;
}
/*** termination ***/
return true;
}
bool GLSLShader::loadGeometryShaderSourceString( const char *geom_shader_source )
{
// int status;
char *info_log;
if (*m_geom_shader_object==0)
{
glDeleteShader(*m_geom_shader_object);
......@@ -438,30 +421,14 @@ bool GLSLShader::loadGeometryShaderSourceString( const char *geom_shader_source
/*** compile shader object ***/
glCompileShader( *m_geom_shader_object );
// glGetProgramiv( *m_geom_shader_object, GL_OBJECT_COMPILE_STATUS_ARB, &status );
// if( !status )
// {
// CGoGNerr << "ERROR - GLshader::loadGeometryShader() - error occured while compiling shader "<< m_nameGS << CGoGNendl;
// info_log = getInfoLog( *m_geom_shader_object );
// CGoGNerr << info_log << CGoGNendl;
// delete [] info_log;
// glDeleteShader( *m_geom_shader_object );
// *m_geom_shader_object = 0;
// return false;
// }
info_log = getInfoLog( *m_geom_shader_object );
if (info_log!=NULL)
if (!logError(*m_geom_shader_object, m_nameGS, geom_shader_source))
{
CGoGNerr << "ERROR - GLshader::loadGeometryShader() - error occured while compiling shader " << m_nameGS<< CGoGNendl;
CGoGNerr << info_log << CGoGNendl;
delete [] info_log;
glDeleteShader( *m_geom_shader_object );
*m_geom_shader_object = 0;
return false;
}
/*** termination ***/
return true;
}
......
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