Commit a47ebb95 authored by Robert Menzel's avatar Robert Menzel

started redirecting all OpenGL debugging calls to a debug callback

parent b70f0ed0
/***********************************************************************
* Copyright 2013 Computer Graphics Group RWTH Aachen University. *
* All rights reserved. *
* Distributed under the terms of the MIT License (see LICENSE.TXT). *
**********************************************************************/
#pragma once
#include <ACGL/ACGL.hh>
#include <ACGL/OpenGL/GL.hh>
#if (ACGL_OPENGL_VERSION < 43)
#define ACGL_EMULATE_KHR_DEBUG
#endif
namespace ACGL{
namespace OpenGL{
//! will just call the gl version unless ACGL_EMULATE_KHR_DEBUG is defined
void acglDebugMessageInsert(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const char* buf);
//! will just call the gl version unless ACGL_EMULATE_KHR_DEBUG is defined
void acglDebugMessageCallback(GLDEBUGPROC callback, const void* userParam);
//! converts a KHR debug source enum to a human readable string
const char *debugSourceName( GLenum _source );
//! converts a KHR debug type enum to a human readable string
const char *debugTypeName( GLenum _type );
//! converts a KHR debug severity enum to a human readable string
const char *debugSeverityName( GLenum _type );
//! tries to register the default debug callback:
void ACGLRegisterDefaultDebugCallback();
//! default debug callback
void ACGL_KHR_default_debug_callback( GLenum _source, GLenum _type, GLuint _id, GLenum _severity, GLsizei _length, const GLchar *_message, const void *_userParam);
} // OpenGL
} // ACGL
...@@ -98,6 +98,17 @@ inline bool ACGL_ARB_debug_output() { ...@@ -98,6 +98,17 @@ inline bool ACGL_ARB_debug_output() {
#endif #endif
} }
// KHR debug (core in OpenGL 4.3) this tests only the extension!
inline bool ACGL_KHR_debug() {
#ifdef ACGL_EXTENSION_LOADER_GLLOADGEN
return (ogl_ext_KHR_debug != ogl_LOAD_FAILED);
#elif ACGL_EXTENSION_LOADER_GLEW
return GLEW_KHR_debug;
#else
return false;
#endif
}
} // OpenGL } // OpenGL
} // ACGL } // ACGL
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <ACGL/ACGL.hh> #include <ACGL/ACGL.hh>
#include <ACGL/OpenGL/GL.hh> #include <ACGL/OpenGL/GL.hh>
#include <ACGL/OpenGL/Tools.hh> #include <ACGL/OpenGL/Tools.hh>
#include <ACGL/OpenGL/Debug.hh>
#include <ACGL/OpenGL/Objects/VertexArrayObject.hh> #include <ACGL/OpenGL/Objects/VertexArrayObject.hh>
namespace ACGL namespace ACGL
...@@ -77,6 +78,10 @@ bool init() ...@@ -77,6 +78,10 @@ bool init()
// gets runtime limits to be used internally: // gets runtime limits to be used internally:
OpenGL::initRuntimeDependentLimits(); OpenGL::initRuntimeDependentLimits();
// if possible, register debug callback:
OpenGL::ACGLRegisterDefaultDebugCallback();
return true; return true;
} }
......
/***********************************************************************
* Copyright 2011-2012 Computer Graphics Group RWTH Aachen University. *
* All rights reserved. *
* Distributed under the terms of the MIT License (see LICENSE.TXT). *
**********************************************************************/
#include <ACGL/ACGL.hh>
#include <ACGL/OpenGL/Debug.hh>
#include <ACGL/OpenGL/Tools.hh>
#include <ACGL/OpenGL/glloaders/extensions.hh>
using namespace std;
using namespace ACGL::Utils;
namespace ACGL{
namespace OpenGL{
#ifdef ACGL_EMULATE_KHR_DEBUG
GLDEBUGPROC currentDebugCallback = NULL;
const void *currentDebugUserData = NULL;
void acglDebugMessageInsert(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const char* buf)
{
currentDebugCallback( source, type, id, severity, length, buf, currentDebugUserData );
}
void acglDebugMessageCallback(GLDEBUGPROC callback, const void* userParam)
{
currentDebugCallback = callback;
currentDebugUserData = userParam;
}
#else
void acglDebugMessageInsert(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const char* buf)
{
glDebugMessageInsert( source, type, id, severity, length, buf);
}
void acglDebugMessageCallback(GLDEBUGPROC callback, const void* userParam)
{
glEnable( GL_DEBUG_OUTPUT_SYNCHRONOUS );
glDebugMessageCallback( callback, userParam);
}
#endif
const char *debugSourceName( GLenum _source )
{
if (_source == GL_DEBUG_SOURCE_API) return "API";
if (_source == GL_DEBUG_SOURCE_WINDOW_SYSTEM) return "Window System";
if (_source == GL_DEBUG_SOURCE_SHADER_COMPILER) return "Shader Compiler";
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 "Other";
return "unknown";
}
const char *debugTypeName( GLenum _type )
{
if (_type == GL_DEBUG_TYPE_ERROR) return "Error";
if (_type == GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR) return "Deprecated Behavior";
if (_type == GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR) return "Undefined Behavior";
if (_type == GL_DEBUG_TYPE_PORTABILITY) return "Portability";
if (_type == GL_DEBUG_TYPE_PERFORMANCE) return "Performance";
if (_type == GL_DEBUG_TYPE_OTHER) return "Other";
if (_type == GL_DEBUG_TYPE_MARKER) return "Marker";
return "unknown";
}
const char *debugSeverityName( GLenum _type )
{
if (_type == GL_DEBUG_SEVERITY_LOW) return "low";
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";
}
void ACGLRegisterDefaultDebugCallback()
{
#ifndef ACGL_EMULATE_KHR_DEBUG
if (getOpenGLVersionNumber() >= 43 || ACGL_KHR_debug()) {
GLint v;
glGetIntegerv( GL_CONTEXT_FLAGS, &v );
if ((v & GL_CONTEXT_FLAG_DEBUG_BIT) != 0) {
debug() << "context was created with debug capabilities" << endl;
} else {
debug() << "context was created WITHOUT debug capabilities - registering a debug callback is possible but might not result in getting called even if errors occur!" << endl;
}
acglDebugMessageCallback( ACGL_KHR_default_debug_callback, NULL );
}
#else
// the emulation works with every GL version:
debug() << "using emulated debug capabilities - might not catch everything!" << endl;
acglDebugMessageCallback( ACGL_KHR_default_debug_callback, NULL );
#endif
}
//! place a brakepoint in here to find the source of a problem!
void ACGL_KHR_default_debug_callback( GLenum _source, GLenum _type, GLuint _id, GLenum _severity, GLsizei _length, const GLchar *_message, const void *_userParam)
{
debug() << "<" << _id << "> " << debugSeverityName(_severity) << ": " << debugSourceName(_source) << " " << debugTypeName(_type) << " " << _message << endl;
// delete all errors to not create another error log for the same problem:
while ( glGetError() != GL_NO_ERROR ) {}
}
} // OpenGL
} // ACGL
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
#include <ACGL/OpenGL/Tools.hh> #include <ACGL/OpenGL/Tools.hh>
#include <ACGL/Utils/FileHelpers.hh> #include <ACGL/Utils/FileHelpers.hh>
#include <ACGL/OpenGL/glloaders/extensions.hh> #include <ACGL/OpenGL/glloaders/extensions.hh>
#include <ACGL/OpenGL/Debug.hh>
#include <sstream>
using namespace std;
namespace ACGL{ namespace ACGL{
namespace OpenGL{ namespace OpenGL{
...@@ -184,7 +187,12 @@ GLenum openGLError_( const char *_fileName, const unsigned long _lineNumber ) ...@@ -184,7 +187,12 @@ GLenum openGLError_( const char *_fileName, const unsigned long _lineNumber )
// OpenGL does not forbit the implementation to stack up more than one error code // OpenGL does not forbit the implementation to stack up more than one error code
// so we have to check those in a loop: // so we have to check those in a loop:
while ( currentError != GL_NO_ERROR ) { while ( currentError != GL_NO_ERROR ) {
ACGL::Utils::error() << "GL error in file " << _fileName << ":" << _lineNumber << " - " << acglErrorString( currentError ) << std::endl; //ACGL::Utils::error() << "GL error in file " << _fileName << ":" << _lineNumber << " - " << acglErrorString( currentError ) << std::endl;
stringstream sstream (stringstream::in | stringstream::out);
sstream << acglErrorString( currentError ) << " in file " << _fileName << ":" << _lineNumber;
acglDebugMessageInsert( GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, currentError, GL_DEBUG_SEVERITY_HIGH, -1, sstream.str().c_str() );
lastError = currentError; lastError = currentError;
currentError = glGetError(); currentError = glGetError();
} }
......
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