6 static void GLAPIENTRY gldebug_logger(GLenum src, GLenum type, GLuint id, GLenum severity,
7 GLsizei len, const char *msg, const void *cls);
9 static const char *gldebug_srcstr(unsigned int src);
10 static const char *gldebug_typestr(unsigned int type);
18 glcaps.debug = GLEW_ARB_debug_output;
22 info_log("Installing OpenGL debug callback\n");
23 glDebugMessageCallbackARB(gldebug_logger, 0);
30 void dump_gl_texture(unsigned int tex, const char *fname)
34 unsigned char *pixels;
36 glBindTexture(GL_TEXTURE_2D, tex);
37 glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
38 glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
40 if(!(pixels = malloc(width * height * 3))) {
43 glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);
45 if(!(fp = fopen(fname, "wb"))) {
49 fprintf(fp, "P6\n%d %d\n255\n", width, height);
50 for(i=0; i<width * height * 3; i++) {
58 static void GLAPIENTRY gldebug_logger(GLenum src, GLenum type, GLuint id, GLenum severity,
59 GLsizei len, const char *msg, const void *cls)
61 static const char *fmt = "[GLDEBUG] (%s) %s: %s\n";
63 case GL_DEBUG_TYPE_ERROR:
64 error_log(fmt, gldebug_srcstr(src), gldebug_typestr(type), msg);
67 case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
68 case GL_DEBUG_TYPE_PORTABILITY:
69 case GL_DEBUG_TYPE_PERFORMANCE:
70 warning_log(fmt, gldebug_srcstr(src), gldebug_typestr(type), msg);
74 debug_log(fmt, gldebug_srcstr(src), gldebug_typestr(type), msg);
78 static const char *gldebug_srcstr(unsigned int src)
81 case GL_DEBUG_SOURCE_API:
83 case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
85 case GL_DEBUG_SOURCE_SHADER_COMPILER:
87 case GL_DEBUG_SOURCE_THIRD_PARTY:
89 case GL_DEBUG_SOURCE_APPLICATION:
91 case GL_DEBUG_SOURCE_OTHER:
99 static const char *gldebug_typestr(unsigned int type)
102 case GL_DEBUG_TYPE_ERROR:
104 case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
106 case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
107 return "undefined behavior";
108 case GL_DEBUG_TYPE_PORTABILITY:
109 return "portability warning";
110 case GL_DEBUG_TYPE_PERFORMANCE:
111 return "performance warning";
112 case GL_DEBUG_TYPE_OTHER: