Skip to content

Instantly share code, notes, and snippets.

@qookei
Created January 24, 2020 14:30
Show Gist options
  • Save qookei/76586d33238f0fa918c499dc7fb5ed04 to your computer and use it in GitHub Desktop.
Save qookei/76586d33238f0fa918c499dc7fb5ed04 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <epoxy/gl.h> // replace with proper include
void gl_debug_callback(GLenum source, GLenum type, GLuint id,
GLenum severity, GLsizei length,
const char *message, const void *) {
const char *sev = "";
switch (severity) {
case GL_DEBUG_SEVERITY_HIGH: sev = "\e[91m"; break;
case GL_DEBUG_SEVERITY_MEDIUM: sev = "\e[93m"; break;
case GL_DEBUG_SEVERITY_LOW: sev = "\e[92m"; break;
case GL_DEBUG_SEVERITY_NOTIFICATION: sev = "\e[34m"; break;
}
const char *src = "?";
switch (source) {
case GL_DEBUG_SOURCE_API: src = "API"; break;
case GL_DEBUG_SOURCE_WINDOW_SYSTEM: src = "window system"; break;
case GL_DEBUG_SOURCE_SHADER_COMPILER: src = "shader compiler"; break;
case GL_DEBUG_SOURCE_THIRD_PARTY: src = "third party"; break;
case GL_DEBUG_SOURCE_APPLICATION: src = "app"; break;
case GL_DEBUG_SOURCE_OTHER: src = "other"; break;
}
const char *type_str = "?";
switch (type) {
case GL_DEBUG_TYPE_ERROR: type_str = "error"; break;
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: type_str = "deprecated behavior"; break;
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: type_str = "undefined behavior"; break;
case GL_DEBUG_TYPE_PORTABILITY: type_str = "portability"; break;
case GL_DEBUG_TYPE_MARKER: type_str = "marker"; break;
case GL_DEBUG_TYPE_PUSH_GROUP: type_str = "push group"; break;
case GL_DEBUG_TYPE_POP_GROUP: type_str = "pop group"; break;
case GL_DEBUG_TYPE_OTHER: type_str = "other"; break;
}
fprintf(stderr, "debug:%s type: %s, source: %s, message: \"%.*s\"\e[0m\n", sev, type_str, src, length, message);
}
int init_debug() {
glEnable(GL_DEBUG_OUTPUT);
#ifndef NDEBUG
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); // disable if in release
#endif
glDebugMessageCallback(gl_debug_callback, nullptr);
// this disables messages printed for successfully compiled shaders
glDebugMessageControl(GL_DEBUG_SOURCE_SHADER_COMPILER, GL_DEBUG_TYPE_OTHER, GL_DEBUG_SEVERITY_NOTIFICATION, 0, nullptr, GL_FALSE);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment