It turns out that GL_ARB_debug_output is really only useful on debug contexts, so for consistency and performance we'll only check and report errors on debug contexts.
authorSam Lantinga <slouken@libsdl.org>
Mon, 20 May 2013 12:01:31 -0700
changeset 7198 2928be835dbd
parent 7197 126f8f345bfb
child 7199 6d4cad3fb837
It turns out that GL_ARB_debug_output is really only useful on debug contexts, so for consistency and performance we'll only check and report errors on debug contexts. I added a --gldebug command line option for the test programs to easily test this, and we may want a hint as well to enable OpenGL error checking.
src/render/opengl/SDL_render_gl.c
--- a/src/render/opengl/SDL_render_gl.c	Sun May 19 22:57:01 2013 -0700
+++ b/src/render/opengl/SDL_render_gl.c	Mon May 20 12:01:31 2013 -0700
@@ -101,6 +101,7 @@
 {
     SDL_GLContext context;
 
+    SDL_bool debug_enabled;
     SDL_bool GL_ARB_debug_output_supported;
     int errors;
     char **error_messages;
@@ -182,6 +183,10 @@
 {
     GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
 
+    if (!data->debug_enabled)
+    {
+        return;
+    }
     if (data->GL_ARB_debug_output_supported) {
         if (data->errors) {
             int i;
@@ -206,6 +211,10 @@
     GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
     int ret = 0;
 
+    if (!data->debug_enabled)
+    {
+        return 0;
+    }
     if (data->GL_ARB_debug_output_supported) {
         if (data->errors) {
             int i;
@@ -444,13 +453,20 @@
     }
 
     /* Check for debug output support */
-    if (SDL_GL_ExtensionSupported("GL_ARB_debug_output")) {
+    if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_FLAGS, &value) == 0 &&
+        (value & SDL_GL_CONTEXT_DEBUG_FLAG)) {
+        data->debug_enabled = SDL_TRUE;
+    }
+    if (data->debug_enabled && SDL_GL_ExtensionSupported("GL_ARB_debug_output")) {
         PFNGLDEBUGMESSAGECALLBACKARBPROC glDebugMessageCallbackARBFunc = (PFNGLDEBUGMESSAGECALLBACKARBPROC) SDL_GL_GetProcAddress("glDebugMessageCallbackARB");
 
         data->GL_ARB_debug_output_supported = SDL_TRUE;
         data->glGetPointerv(GL_DEBUG_CALLBACK_FUNCTION_ARB, (GLvoid **)&data->next_error_callback);
         data->glGetPointerv(GL_DEBUG_CALLBACK_USER_PARAM_ARB, &data->next_error_userparam);
         glDebugMessageCallbackARBFunc(GL_HandleDebugMessage, renderer);
+
+        /* Make sure our callback is called when errors actually happen */
+        data->glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
     }
 
     if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle")