Created
May 19, 2014 05:20
-
-
Save golightlyb/e957880186f55b862330 to your computer and use it in GitHub Desktop.
DebugMessageCallbackARB arguments are garbled by some drivers. This is a limited safer version that will try to safely print /something/ useful
This file contains 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
// DebugMessageCallbackARB arguments are garbled by some drivers. This is a limited safer version that will try to safely print /something/ useful | |
void FormatDebugOutputARB | |
( | |
int d0, // accepts buggy parameters in any order | |
int d1, | |
int d2, | |
int d3 | |
) | |
{ | |
char s0[64]; memset(s0, '\0', 64); | |
char s1[64]; memset(s1, '\0', 64); | |
char s2[64]; memset(s2, '\0', 64); | |
char s3[64]; memset(s3, '\0', 64); | |
int d[4] = {d0, d1, d2, d3}; | |
char *s[4] = {s0, s1, s2, s3}; | |
for (unsigned int i = 0; i < 4; i++) | |
{ | |
int id = d[i]; | |
char *dest = s[i]; | |
sprintf(dest, "[0x%x/%d: ", id, id); | |
# define CASE(v, x) case v: strcat(dest, x); break; | |
switch (id) | |
{ | |
CASE(0x0500, "GL_INVALID_ENUM]"); | |
CASE(0x0501, "GL_INVALID_VALUE]"); | |
CASE(0x0502, "GL_INVALID_OPERATION]"); | |
CASE(0x0503, "GL_STACK_OVERFLOW]"); | |
CASE(0x0504, "GL_STACK_UNDERFLOW]"); | |
CASE(0x0505, "GL_OUT_OF_MEMORY]"); | |
CASE(0x0506, "GL_INVALID_FRAMEBUFFER_OPERATION]"); | |
#ifdef GL_TABLE_TOO_LARGE // deprecated | |
CASE(0x8031, "GL_TABLE_TOO_LARGE]"); | |
#endif | |
CASE(0x9146, "GL_DEBUG_SEVERITY_HIGH_ARB]"); | |
CASE(0x9147, "GL_DEBUG_SEVERITY_MEDIUM_ARB]"); | |
CASE(0x9148, "GL_DEBUG_SEVERITY_LOW_ARB]"); | |
default: | |
strcat(dest, "UNKOWN]"); | |
} | |
} | |
fprintf(stderr, "OpenGL Debug Info: %s, %s, %s, %s\n", s0, s1, s2, s3); | |
} | |
GLvoid APIENTRY DebugMessageCallbackARB | |
( | |
GLenum source, | |
GLenum type, | |
GLuint id, | |
GLenum severity, | |
GLsizei length, | |
const GLchar *message, | |
GLvoid *userParam | |
) | |
{ | |
/* BUG - the following are completely garbled */ | |
UNUSED(userParam); | |
UNUSED(length); | |
UNUSED(message); | |
FormatDebugOutputARB((int) source, (int) type, (int) id, (int) severity); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Feel free to use without credit; public domain, etc