Commit 559c5253 authored by Robert Menzel's avatar Robert Menzel
Browse files

added debug label support and tests for object label names

parent d18b216c
...@@ -12,6 +12,19 @@ ...@@ -12,6 +12,19 @@
namespace ACGL{ namespace ACGL{
namespace OpenGL{ namespace OpenGL{
/*
* Pushes the message onto the debug message stack from KHR_debug
* and pops it when the scope ends (== this object gets destroyed).
*
* Will be visible in debuggers.
*/
class GLDebugAnnotation
{
public:
GLDebugAnnotation( const char *_message );
~GLDebugAnnotation();
};
//! converts a KHR debug source enum to a human readable string //! converts a KHR debug source enum to a human readable string
const char *debugSourceName( GLenum _source ); const char *debugSourceName( GLenum _source );
......
...@@ -129,6 +129,7 @@ ...@@ -129,6 +129,7 @@
// prevents QT from redefining the debug functions // prevents QT from redefining the debug functions
#define GL_ARB_debug_output #define GL_ARB_debug_output
#define GL_KHR_debug #define GL_KHR_debug
#define ACGL_OPENGL_DEBUGGER_SUPPORT
#endif #endif
void CHECKGLERROR(); void CHECKGLERROR();
......
...@@ -72,9 +72,9 @@ public: ...@@ -72,9 +72,9 @@ public:
protected: protected:
// could get reactivated if needed, might get removed later (thus protected): // could get reactivated if needed, might get removed later (thus protected):
bool setFromFileNoImportParsing(const std::string& _filename); //bool setFromFileNoImportParsing(const std::string& _filename);
bool compile () const; bool compile() const;
// get a log and a bool whether the log contains an error (or just a warning), not done // get a log and a bool whether the log contains an error (or just a warning), not done
// automatically by compile() but called by all public source setting functions: // automatically by compile() but called by all public source setting functions:
void getCompileLog( std::string &_log, bool &_wasErrorLog ) const; void getCompileLog( std::string &_log, bool &_wasErrorLog ) const;
......
...@@ -220,8 +220,6 @@ inline bool openGLErrorOccuredDummy() { return false; } ...@@ -220,8 +220,6 @@ inline bool openGLErrorOccuredDummy() { return false; }
# define openGLRareErrorOccured() ACGL::OpenGL::openGLErrorOccuredDummy() # define openGLRareErrorOccured() ACGL::OpenGL::openGLErrorOccuredDummy()
#endif #endif
} // OpenGL } // OpenGL
} // ACGL } // ACGL
......
...@@ -32,6 +32,9 @@ SharedTexture2D loadTexture2D(const std::string& _filename, ColorSpace _colorSpa ...@@ -32,6 +32,9 @@ SharedTexture2D loadTexture2D(const std::string& _filename, ColorSpace _colorSpa
SharedTexture2D texture = SharedTexture2D( new Texture2D(data->getRecommendedInternalFormat()) ); SharedTexture2D texture = SharedTexture2D( new Texture2D(data->getRecommendedInternalFormat()) );
texture->setImageData( data ); texture->setImageData( data );
texture->generateMipmaps(); // calculates all remaining mipmap levels texture->generateMipmaps(); // calculates all remaining mipmap levels
#ifdef ACGL_OPENGL_DEBUGGER_SUPPORT
glObjectLabel( GL_TEXTURE, texture->getObjectName(), -1, _filename.c_str() );
#endif
return texture; return texture;
} else { } else {
ACGL::Utils::error() << "can't create Texture from file " << _filename << " creating small empty texture instead." << std::endl; ACGL::Utils::error() << "can't create Texture from file " << _filename << " creating small empty texture instead." << std::endl;
......
...@@ -91,6 +91,9 @@ SharedTexture2D loadTexture2DFromDDS(const std::string& _filename, ColorSpace _c ...@@ -91,6 +91,9 @@ SharedTexture2D loadTexture2DFromDDS(const std::string& _filename, ColorSpace _c
ACGL::Utils::error() << "could not open " << _filename << std::endl; ACGL::Utils::error() << "could not open " << _filename << std::endl;
} }
#ifdef ACGL_OPENGL_DEBUGGER_SUPPORT
glObjectLabel( GL_TEXTURE, texture->getObjectName(), -1, _filename.c_str() );
#endif
return texture; return texture;
} }
......
...@@ -68,6 +68,9 @@ SharedVertexArrayObject loadVertexArrayObject(const std::string& _filename, bool ...@@ -68,6 +68,9 @@ SharedVertexArrayObject loadVertexArrayObject(const std::string& _filename, bool
saveVertexArrayObjectToVAO(vao, _filename + ".vao"); saveVertexArrayObjectToVAO(vao, _filename + ".vao");
} }
#ifdef ACGL_OPENGL_DEBUGGER_SUPPORT
glObjectLabel( GL_VERTEX_ARRAY, vao->getObjectName(), -1, _filename.c_str() );
#endif
return vao; return vao;
} }
......
...@@ -17,6 +17,22 @@ using namespace ACGL::Utils; ...@@ -17,6 +17,22 @@ using namespace ACGL::Utils;
namespace ACGL{ namespace ACGL{
namespace OpenGL{ namespace OpenGL{
#ifdef ACGL_OPENGL_DEBUGGER_SUPPORT
GLDebugAnnotation::GLDebugAnnotation( const char *_message )
{
GLuint messageID = 0;
glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, messageID, -1, _message );
}
GLDebugAnnotation::~GLDebugAnnotation()
{
glPopDebugGroup();
}
#else
GLDebugAnnotation::GLDebugAnnotation( const char *_message ){}
GLDebugAnnotation::~GLDebugAnnotation(){}
#endif
const char *debugSourceName( GLenum _source ) const char *debugSourceName( GLenum _source )
{ {
if (_source == GL_DEBUG_SOURCE_API) return "API"; if (_source == GL_DEBUG_SOURCE_API) return "API";
...@@ -25,7 +41,7 @@ const char *debugSourceName( GLenum _source ) ...@@ -25,7 +41,7 @@ const char *debugSourceName( GLenum _source )
if (_source == GL_DEBUG_SOURCE_THIRD_PARTY) return "Third Party"; if (_source == GL_DEBUG_SOURCE_THIRD_PARTY) return "Third Party";
if (_source == GL_DEBUG_SOURCE_APPLICATION) return "Application"; if (_source == GL_DEBUG_SOURCE_APPLICATION) return "Application";
if (_source == GL_DEBUG_SOURCE_OTHER) return "Unknown"; if (_source == GL_DEBUG_SOURCE_OTHER) return "Unknown";
return "Unknown"; return "Unknown Source";
} }
const char *debugTypeName( GLenum _type ) const char *debugTypeName( GLenum _type )
...@@ -37,7 +53,9 @@ const char *debugTypeName( GLenum _type ) ...@@ -37,7 +53,9 @@ const char *debugTypeName( GLenum _type )
if (_type == GL_DEBUG_TYPE_PERFORMANCE) return "Performance Issue"; if (_type == GL_DEBUG_TYPE_PERFORMANCE) return "Performance Issue";
if (_type == GL_DEBUG_TYPE_MARKER) return "Marker"; if (_type == GL_DEBUG_TYPE_MARKER) return "Marker";
if (_type == GL_DEBUG_TYPE_OTHER) return "Issue"; if (_type == GL_DEBUG_TYPE_OTHER) return "Issue";
return "Issue"; if (_type == GL_DEBUG_TYPE_POP_GROUP) return "Debug group pop";
if (_type == GL_DEBUG_TYPE_PUSH_GROUP) return "Debug group push";
return "Unknown Type";
} }
const char *debugSeverityName( GLenum _type ) const char *debugSeverityName( GLenum _type )
...@@ -46,7 +64,7 @@ const char *debugSeverityName( GLenum _type ) ...@@ -46,7 +64,7 @@ const char *debugSeverityName( GLenum _type )
if (_type == GL_DEBUG_SEVERITY_MEDIUM) return "medium"; if (_type == GL_DEBUG_SEVERITY_MEDIUM) return "medium";
if (_type == GL_DEBUG_SEVERITY_HIGH) return "high"; if (_type == GL_DEBUG_SEVERITY_HIGH) return "high";
if (_type == GL_DEBUG_SEVERITY_NOTIFICATION) return "notification"; if (_type == GL_DEBUG_SEVERITY_NOTIFICATION) return "notification";
return "unknown"; return "Unknown Severity";
} }
void ACGLRegisterDefaultDebugCallback() void ACGLRegisterDefaultDebugCallback()
...@@ -73,14 +91,14 @@ void APIENTRY ACGL_KHR_default_debug_callback( GLenum _source, GLenum _type, GLu ...@@ -73,14 +91,14 @@ void APIENTRY ACGL_KHR_default_debug_callback( GLenum _source, GLenum _type, GLu
// be printed first... // be printed first...
if (_type == GL_DEBUG_TYPE_ERROR) { if (_type == GL_DEBUG_TYPE_ERROR) {
error() << "<" << _id << "> severity: " << debugSeverityName(_severity) << " source: " << debugSourceName(_source) << ": " << _message << endl; error() << "<" << _id << "> severity: " << debugSeverityName(_severity) << " source: " << debugSourceName(_source) << ": " << _message << endl;
} else if (_type == GL_DEBUG_TYPE_POP_GROUP || _type == GL_DEBUG_TYPE_PUSH_GROUP) {
// push and pop groups are ignored because they are intended for a debugger
} else { } else {
debug() << "<" << _id << "> severity: " << debugSeverityName(_severity) << " source: " << debugSourceName(_source) << ": " << _message << endl; debug() << "<" << _id << "> severity: " << debugSeverityName(_severity) << " source: " << debugSourceName(_source) << ": " << _message << endl;
} }
// delete all errors to not create another error log for the same problem: // delete all errors to not create another error log for the same problem:
int tries(100); while ( glGetError() != GL_NO_ERROR ) {}
while ( glGetError() != GL_NO_ERROR && --tries > 0 ) {}
} }
} // OpenGL } // OpenGL
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
using namespace ACGL::Utils; using namespace ACGL::Utils;
using namespace ACGL::OpenGL; using namespace ACGL::OpenGL;
/*
bool Shader::setFromFileNoImportParsing(const std::string& _filename) bool Shader::setFromFileNoImportParsing(const std::string& _filename)
{ {
std::string line = ""; std::string line = "";
...@@ -51,7 +51,7 @@ bool Shader::setFromFileNoImportParsing(const std::string& _filename) ...@@ -51,7 +51,7 @@ bool Shader::setFromFileNoImportParsing(const std::string& _filename)
} }
} }
return !compileErrors; // return true iff there were no errors return !compileErrors; // return true iff there were no errors
} }*/
bool Shader::setFromFile(SharedShaderParser const& _sp) bool Shader::setFromFile(SharedShaderParser const& _sp)
{ {
...@@ -69,6 +69,11 @@ bool Shader::setFromFile(SharedShaderParser const& _sp) ...@@ -69,6 +69,11 @@ bool Shader::setFromFile(SharedShaderParser const& _sp)
} }
} }
} }
#ifdef ACGL_OPENGL_DEBUGGER_SUPPORT
glObjectLabel( GL_SHADER, mObjectName, -1, _sp->getSources()[0].c_str() );
#endif
return !compileErrors; // return true iff there were no errors return !compileErrors; // return true iff there were no errors
} }
......
...@@ -291,7 +291,6 @@ GLenum openGLError_( const char *_fileName, const unsigned long _lineNumber ) ...@@ -291,7 +291,6 @@ GLenum openGLError_( const char *_fileName, const unsigned long _lineNumber )
return lastError; // returns the last real error (in case there was at least one!) return lastError; // returns the last real error (in case there was at least one!)
} }
} // OpenGL } // OpenGL
} // ACGL } // ACGL
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