X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=laserbrain_demo;a=blobdiff_plain;f=src%2Fopengl.c;fp=src%2Fopengl.c;h=9fe7ea3f7a817c04a9aba0dd2c1b77328af3c375;hp=0000000000000000000000000000000000000000;hb=215f16e2f26cc2acc79255bab06f13452ec06ae5;hpb=827f01e0ede01a7dd640c8055f1a169cb85e32f9 diff --git a/src/opengl.c b/src/opengl.c new file mode 100644 index 0000000..9fe7ea3 --- /dev/null +++ b/src/opengl.c @@ -0,0 +1,104 @@ +#include "opengl.h" +#include "logger.h" + +static void gldebug_logger(unsigned int src, unsigned int type, unsigned int id, + unsigned int severity, int len, const char *msg, const void *cls); +static const char *gldebug_srcstr(unsigned int src); +static const char *gldebug_typestr(unsigned int type); +static const char *gldebug_sevstr(unsigned int sev); + +struct GLCaps glcaps; + +int init_opengl(void) +{ + glewInit(); + + glcaps.debug = GLEW_ARB_debug_output; + +#ifndef NDEBUG + if(glcaps.debug) { + info_log("Installing OpenGL debug callback\n"); + glDebugMessageCallback(gldebug_logger, 0); + } +#endif + + return 0; +} + + +static void gldebug_logger(unsigned int src, unsigned int type, unsigned int id, + unsigned int severity, int len, const char *msg, const void *cls) +{ + static const char *fmt = "[GLDEBUG] (%s) %s: %s\n"; + switch(type) { + case GL_DEBUG_TYPE_ERROR: + error_log(fmt, gldebug_srcstr(src), gldebug_typestr(type), msg); + break; + + case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: + case GL_DEBUG_TYPE_PORTABILITY: + case GL_DEBUG_TYPE_PERFORMANCE: + warning_log(fmt, gldebug_srcstr(src), gldebug_typestr(type), msg); + break; + + default: + debug_log(fmt, gldebug_srcstr(src), gldebug_typestr(type), msg); + } +} + +static const char *gldebug_srcstr(unsigned int src) +{ + switch(src) { + case GL_DEBUG_SOURCE_API: + return "api"; + case GL_DEBUG_SOURCE_WINDOW_SYSTEM: + return "wsys"; + case GL_DEBUG_SOURCE_SHADER_COMPILER: + return "sdrc"; + case GL_DEBUG_SOURCE_THIRD_PARTY: + return "3rdparty"; + case GL_DEBUG_SOURCE_APPLICATION: + return "app"; + case GL_DEBUG_SOURCE_OTHER: + return "other"; + default: + break; + } + return "unknown"; +} + +static const char *gldebug_typestr(unsigned int type) +{ + switch(type) { + case GL_DEBUG_TYPE_ERROR: + return "error"; + case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: + return "deprecated"; + case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: + return "undefined behavior"; + case GL_DEBUG_TYPE_PORTABILITY: + return "portability warning"; + case GL_DEBUG_TYPE_PERFORMANCE: + return "performance warning"; + case GL_DEBUG_TYPE_OTHER: + return "other"; + default: + break; + } + return "unknown"; +} + +static const char *gldebug_sevstr(unsigned int sev) +{ + switch(sev) { + case GL_DEBUG_SEVERITY_HIGH: + return "high"; + case GL_DEBUG_SEVERITY_MEDIUM: + return "medium"; + case GL_DEBUG_SEVERITY_LOW: + return "low"; + default: + break; + } + return "unknown"; +}