Created
July 10, 2016 06:00
-
-
Save Barakat/7657dd9cba21cb1f1430fde83bd85898 to your computer and use it in GitHub Desktop.
An implementation of glDebugMessageCallbackARB callback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <gl/glew.h> | |
#include <string> | |
void GLAPIENTRY DebugMessageCallback(GLenum source, | |
GLenum type, | |
GLuint id, | |
GLenum severity, | |
GLsizei length, | |
const GLchar* message, | |
const void* userParam) | |
{ | |
// Convert enums into a humen readable text | |
// See: https://www.opengl.org/registry/specs/ARB/debug_output.txt | |
const char* sourceText = "Unknown"; | |
switch (source) | |
{ | |
case GL_DEBUG_SOURCE_API_ARB: | |
// The GL | |
sourceText = "API"; | |
break; | |
// The GLSL shader compiler or compilers for other extension - provided languages | |
case GL_DEBUG_SOURCE_SHADER_COMPILER_ARB: | |
sourceText = "Shader compiler"; | |
break; | |
// The window system, such as WGL or GLX | |
case GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB: | |
sourceText = "Window system"; | |
break; | |
// External debuggers or third-party middleware libraries | |
case GL_DEBUG_SOURCE_THIRD_PARTY_ARB: | |
sourceText = "Third party"; | |
break; | |
// The application | |
case GL_DEBUG_SOURCE_APPLICATION_ARB: | |
sourceText = "Application"; | |
break; | |
// Sources that do not fit to any of the ones listed above | |
case GL_DEBUG_SOURCE_OTHER_ARB: | |
sourceText = "Other"; | |
break; | |
} | |
const char* typeText = "Unknown"; | |
switch (type) | |
{ | |
// Events that generated an error | |
case GL_DEBUG_TYPE_ERROR_ARB: | |
typeText = "Error"; | |
break; | |
// Behavior that has been marked for deprecation | |
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB: | |
typeText = "Deprecated behavior"; | |
break; | |
// Behavior that is undefined according to the specification | |
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB: | |
typeText = "Undefined behavior"; | |
break; | |
// Implementation-dependent performance warnings | |
case GL_DEBUG_TYPE_PERFORMANCE_ARB: | |
typeText = "Performance"; | |
break; | |
// Use of extensions or shaders in a way that is highly vendor - specific | |
case GL_DEBUG_TYPE_PORTABILITY_ARB: | |
typeText = "Portability"; | |
break; | |
// Types of events that do not fit any of the ones listed above | |
case GL_DEBUG_TYPE_OTHER_ARB: | |
typeText = "Other"; | |
break; | |
} | |
const char* severityText = "Unknown"; | |
switch (severity) | |
{ | |
// Any GL error; dangerous undefined behavior; any GLSL or ARB shader compiler and linker errors; | |
case GL_DEBUG_SEVERITY_HIGH_ARB: | |
severityText = "High"; | |
break; | |
// Severe performance warnings; GLSL or other shader compiler and linker warnings; use of currently deprecated behavior | |
case GL_DEBUG_SEVERITY_MEDIUM_ARB: | |
severityText = "Medium"; | |
break; | |
// Performance warnings from redundant state changes; trivial undefined behavior | |
case GL_DEBUG_SEVERITY_LOW_ARB: | |
severityText = "Low"; | |
break; | |
} | |
// Unused params | |
(void)id; | |
(void)length; | |
(void)userParam; | |
// Replace LogDebug with your logging function | |
LogDebug(SDL_LOG_CATEGORY_VIDEO, "[OpenGL:source='%s', type='%s', severity='%s'] %s", | |
sourceText, | |
typeText, | |
severityText, | |
message); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment