src/render/opengl/SDL_render_gl.c
changeset 7198 2928be835dbd
parent 7197 126f8f345bfb
child 7239 04dda95ba22c
equal deleted inserted replaced
7197:126f8f345bfb 7198:2928be835dbd
    99 
    99 
   100 typedef struct
   100 typedef struct
   101 {
   101 {
   102     SDL_GLContext context;
   102     SDL_GLContext context;
   103 
   103 
       
   104     SDL_bool debug_enabled;
   104     SDL_bool GL_ARB_debug_output_supported;
   105     SDL_bool GL_ARB_debug_output_supported;
   105     int errors;
   106     int errors;
   106     char **error_messages;
   107     char **error_messages;
   107     GLDEBUGPROCARB next_error_callback;
   108     GLDEBUGPROCARB next_error_callback;
   108     GLvoid *next_error_userparam;
   109     GLvoid *next_error_userparam;
   180 SDL_FORCE_INLINE void
   181 SDL_FORCE_INLINE void
   181 GL_ClearErrors(SDL_Renderer *renderer)
   182 GL_ClearErrors(SDL_Renderer *renderer)
   182 {
   183 {
   183     GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
   184     GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
   184 
   185 
       
   186     if (!data->debug_enabled)
       
   187     {
       
   188         return;
       
   189     }
   185     if (data->GL_ARB_debug_output_supported) {
   190     if (data->GL_ARB_debug_output_supported) {
   186         if (data->errors) {
   191         if (data->errors) {
   187             int i;
   192             int i;
   188             for (i = 0; i < data->errors; ++i) {
   193             for (i = 0; i < data->errors; ++i) {
   189                 SDL_free(data->error_messages[i]);
   194                 SDL_free(data->error_messages[i]);
   204 GL_CheckAllErrors (const char *prefix, SDL_Renderer *renderer, const char *file, int line, const char *function)
   209 GL_CheckAllErrors (const char *prefix, SDL_Renderer *renderer, const char *file, int line, const char *function)
   205 {
   210 {
   206     GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
   211     GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
   207     int ret = 0;
   212     int ret = 0;
   208 
   213 
       
   214     if (!data->debug_enabled)
       
   215     {
       
   216         return 0;
       
   217     }
   209     if (data->GL_ARB_debug_output_supported) {
   218     if (data->GL_ARB_debug_output_supported) {
   210         if (data->errors) {
   219         if (data->errors) {
   211             int i;
   220             int i;
   212             for (i = 0; i < data->errors; ++i) {
   221             for (i = 0; i < data->errors; ++i) {
   213                 SDL_SetError("%s: %s (%d): %s %s", prefix, file, line, function, data->error_messages[i]);
   222                 SDL_SetError("%s: %s (%d): %s %s", prefix, file, line, function, data->error_messages[i]);
   442     if (SDL_GL_GetSwapInterval() > 0) {
   451     if (SDL_GL_GetSwapInterval() > 0) {
   443         renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
   452         renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
   444     }
   453     }
   445 
   454 
   446     /* Check for debug output support */
   455     /* Check for debug output support */
   447     if (SDL_GL_ExtensionSupported("GL_ARB_debug_output")) {
   456     if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_FLAGS, &value) == 0 &&
       
   457         (value & SDL_GL_CONTEXT_DEBUG_FLAG)) {
       
   458         data->debug_enabled = SDL_TRUE;
       
   459     }
       
   460     if (data->debug_enabled && SDL_GL_ExtensionSupported("GL_ARB_debug_output")) {
   448         PFNGLDEBUGMESSAGECALLBACKARBPROC glDebugMessageCallbackARBFunc = (PFNGLDEBUGMESSAGECALLBACKARBPROC) SDL_GL_GetProcAddress("glDebugMessageCallbackARB");
   461         PFNGLDEBUGMESSAGECALLBACKARBPROC glDebugMessageCallbackARBFunc = (PFNGLDEBUGMESSAGECALLBACKARBPROC) SDL_GL_GetProcAddress("glDebugMessageCallbackARB");
   449 
   462 
   450         data->GL_ARB_debug_output_supported = SDL_TRUE;
   463         data->GL_ARB_debug_output_supported = SDL_TRUE;
   451         data->glGetPointerv(GL_DEBUG_CALLBACK_FUNCTION_ARB, (GLvoid **)&data->next_error_callback);
   464         data->glGetPointerv(GL_DEBUG_CALLBACK_FUNCTION_ARB, (GLvoid **)&data->next_error_callback);
   452         data->glGetPointerv(GL_DEBUG_CALLBACK_USER_PARAM_ARB, &data->next_error_userparam);
   465         data->glGetPointerv(GL_DEBUG_CALLBACK_USER_PARAM_ARB, &data->next_error_userparam);
   453         glDebugMessageCallbackARBFunc(GL_HandleDebugMessage, renderer);
   466         glDebugMessageCallbackARBFunc(GL_HandleDebugMessage, renderer);
       
   467 
       
   468         /* Make sure our callback is called when errors actually happen */
       
   469         data->glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
   454     }
   470     }
   455 
   471 
   456     if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle")
   472     if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle")
   457         || SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
   473         || SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
   458         data->GL_ARB_texture_rectangle_supported = SDL_TRUE;
   474         data->GL_ARB_texture_rectangle_supported = SDL_TRUE;