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

added debug label support and tests for object label names

parent d18b216c
......@@ -12,6 +12,19 @@
namespace ACGL{
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
const char *debugSourceName( GLenum _source );
......
......@@ -129,6 +129,7 @@
// prevents QT from redefining the debug functions
#define GL_ARB_debug_output
#define GL_KHR_debug
#define ACGL_OPENGL_DEBUGGER_SUPPORT
#endif
void CHECKGLERROR();
......
......@@ -72,9 +72,9 @@ public:
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
// automatically by compile() but called by all public source setting functions:
void getCompileLog( std::string &_log, bool &_wasErrorLog ) const;
......
......@@ -220,8 +220,6 @@ inline bool openGLErrorOccuredDummy() { return false; }
# define openGLRareErrorOccured() ACGL::OpenGL::openGLErrorOccuredDummy()
#endif
} // OpenGL
} // ACGL
......
......@@ -32,6 +32,9 @@ SharedTexture2D loadTexture2D(const std::string& _filename, ColorSpace _colorSpa
SharedTexture2D texture = SharedTexture2D( new Texture2D(data->getRecommendedInternalFormat()) );
texture->setImageData( data );
texture->generateMipmaps(); // calculates all remaining mipmap levels
#ifdef ACGL_OPENGL_DEBUGGER_SUPPORT
glObjectLabel( GL_TEXTURE, texture->getObjectName(), -1, _filename.c_str() );
#endif
return texture;
} else {
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
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;
}
......
......@@ -68,6 +68,9 @@ SharedVertexArrayObject loadVertexArrayObject(const std::string& _filename, bool
saveVertexArrayObjectToVAO(vao, _filename + ".vao");
}
#ifdef ACGL_OPENGL_DEBUGGER_SUPPORT
glObjectLabel( GL_VERTEX_ARRAY, vao->getObjectName(), -1, _filename.c_str() );
#endif
return vao;
}
......
......@@ -17,6 +17,22 @@ using namespace ACGL::Utils;
namespace ACGL{
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 )
{
if (_source == GL_DEBUG_SOURCE_API) return "API";
......@@ -25,7 +41,7 @@ const char *debugSourceName( GLenum _source )
if (_source == GL_DEBUG_SOURCE_THIRD_PARTY) return "Third Party";
if (_source == GL_DEBUG_SOURCE_APPLICATION) return "Application";
if (_source == GL_DEBUG_SOURCE_OTHER) return "Unknown";
return "Unknown";
return "Unknown Source";
}
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_MARKER) return "Marker";
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 )
......@@ -46,7 +64,7 @@ const char *debugSeverityName( GLenum _type )
if (_type == GL_DEBUG_SEVERITY_MEDIUM) return "medium";
if (_type == GL_DEBUG_SEVERITY_HIGH) return "high";
if (_type == GL_DEBUG_SEVERITY_NOTIFICATION) return "notification";
return "unknown";
return "Unknown Severity";
}
void ACGLRegisterDefaultDebugCallback()
......@@ -73,14 +91,14 @@ void APIENTRY ACGL_KHR_default_debug_callback( GLenum _source, GLenum _type, GLu
// be printed first...
if (_type == GL_DEBUG_TYPE_ERROR) {
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 {
debug() << "<" << _id << "> severity: " << debugSeverityName(_severity) << " source: " << debugSourceName(_source) << ": " << _message << endl;
}
// delete all errors to not create another error log for the same problem:
int tries(100);
while ( glGetError() != GL_NO_ERROR && --tries > 0 ) {}
while ( glGetError() != GL_NO_ERROR ) {}
}
} // OpenGL
......
......@@ -15,7 +15,7 @@
using namespace ACGL::Utils;
using namespace ACGL::OpenGL;
/*
bool Shader::setFromFileNoImportParsing(const std::string& _filename)
{
std::string line = "";
......@@ -51,7 +51,7 @@ bool Shader::setFromFileNoImportParsing(const std::string& _filename)
}
}
return !compileErrors; // return true iff there were no errors
}
}*/
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
}
......
......@@ -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!)
}
} // OpenGL
} // 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