opengl: Add support for [GLX|WGL]_ARB_create_context_robustness.
authorRyan C. Gordon <icculus@icculus.org>
Sat, 19 Aug 2017 15:02:03 -0400
changeset 11332e3797888c6f1
parent 11331 1e231cf0a347
child 11333 3f0b31578620
opengl: Add support for [GLX|WGL]_ARB_create_context_robustness.

This patch was originally written by Marc Di Luzio for glX and enhanced by
Maximilian Malek for WGL, etc. Thanks to both of you!

Fixes Bugzilla #3643.
Fixes Bugzilla #3735.
include/SDL_video.h
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/windows/SDL_windowsopengl.c
src/video/windows/SDL_windowsopengl.h
src/video/x11/SDL_x11opengl.c
src/video/x11/SDL_x11opengl.h
     1.1 --- a/include/SDL_video.h	Sat Aug 19 11:15:58 2017 -0700
     1.2 +++ b/include/SDL_video.h	Sat Aug 19 15:02:03 2017 -0400
     1.3 @@ -201,7 +201,8 @@
     1.4      SDL_GL_CONTEXT_PROFILE_MASK,
     1.5      SDL_GL_SHARE_WITH_CURRENT_CONTEXT,
     1.6      SDL_GL_FRAMEBUFFER_SRGB_CAPABLE,
     1.7 -    SDL_GL_CONTEXT_RELEASE_BEHAVIOR
     1.8 +    SDL_GL_CONTEXT_RELEASE_BEHAVIOR,
     1.9 +    SDL_GL_CONTEXT_RESET_NOTIFICATION
    1.10  } SDL_GLattr;
    1.11  
    1.12  typedef enum
    1.13 @@ -225,6 +226,12 @@
    1.14      SDL_GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH  = 0x0001
    1.15  } SDL_GLcontextReleaseFlag;
    1.16  
    1.17 +typedef enum
    1.18 +{
    1.19 +    SDL_GL_CONTEXT_RESET_NO_NOTIFICATION = 0x0000,
    1.20 +    SDL_GL_CONTEXT_RESET_LOSE_CONTEXT    = 0x0001
    1.21 +} SDL_GLContextResetNotification;
    1.22 +
    1.23  
    1.24  /* Function prototypes */
    1.25  
     2.1 --- a/src/video/SDL_sysvideo.h	Sat Aug 19 11:15:58 2017 -0700
     2.2 +++ b/src/video/SDL_sysvideo.h	Sat Aug 19 15:02:03 2017 -0400
     2.3 @@ -329,6 +329,7 @@
     2.4          int profile_mask;
     2.5          int share_with_current_context;
     2.6          int release_behavior;
     2.7 +        int reset_notification;
     2.8          int framebuffer_srgb_capable;
     2.9          int retained_backing;
    2.10          int driver_loaded;
     3.1 --- a/src/video/SDL_video.c	Sat Aug 19 11:15:58 2017 -0700
     3.2 +++ b/src/video/SDL_video.c	Sat Aug 19 15:02:03 2017 -0400
     3.3 @@ -2990,6 +2990,7 @@
     3.4      _this->gl_config.flags = 0;
     3.5      _this->gl_config.framebuffer_srgb_capable = 0;
     3.6      _this->gl_config.release_behavior = SDL_GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH;
     3.7 +    _this->gl_config.reset_notification = SDL_GL_CONTEXT_RESET_NO_NOTIFICATION;
     3.8  
     3.9      _this->gl_config.share_with_current_context = 0;
    3.10  }
    3.11 @@ -3099,6 +3100,9 @@
    3.12      case SDL_GL_CONTEXT_RELEASE_BEHAVIOR:
    3.13          _this->gl_config.release_behavior = value;
    3.14          break;
    3.15 +    case SDL_GL_CONTEXT_RESET_NOTIFICATION:
    3.16 +        _this->gl_config.reset_notification = value;
    3.17 +        break;
    3.18      default:
    3.19          retval = SDL_SetError("Unknown OpenGL attribute");
    3.20          break;
     4.1 --- a/src/video/windows/SDL_windowsopengl.c	Sat Aug 19 11:15:58 2017 -0700
     4.2 +++ b/src/video/windows/SDL_windowsopengl.c	Sat Aug 19 15:02:03 2017 -0400
     4.3 @@ -453,11 +453,16 @@
     4.4          );
     4.5      }
     4.6  
     4.7 -    /* Check for GLX_ARB_context_flush_control */
     4.8 +    /* Check for WGL_ARB_context_flush_control */
     4.9      if (HasExtension("WGL_ARB_context_flush_control", extensions)) {
    4.10          _this->gl_data->HAS_WGL_ARB_context_flush_control = SDL_TRUE;
    4.11      }
    4.12  
    4.13 +    /* Check for WGL_ARB_create_context_robustness */
    4.14 +    if (HasExtension("WGL_ARB_create_context_robustness", extensions)) {
    4.15 +        _this->gl_data->HAS_WGL_ARB_create_context_robustness = SDL_TRUE;
    4.16 +    }
    4.17 +
    4.18      _this->gl_data->wglMakeCurrent(hdc, NULL);
    4.19      _this->gl_data->wglDeleteContext(hglrc);
    4.20      ReleaseDC(hwnd, hdc);
    4.21 @@ -713,8 +718,8 @@
    4.22              SDL_SetError("GL 3.x is not supported");
    4.23              context = temp_context;
    4.24          } else {
    4.25 -        /* max 10 attributes plus terminator */
    4.26 -            int attribs[11] = {
    4.27 +        /* max 12 attributes plus terminator */
    4.28 +            int attribs[13] = {
    4.29                  WGL_CONTEXT_MAJOR_VERSION_ARB, _this->gl_config.major_version,
    4.30                  WGL_CONTEXT_MINOR_VERSION_ARB, _this->gl_config.minor_version,
    4.31                  0
    4.32 @@ -741,6 +746,14 @@
    4.33                                      WGL_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB;
    4.34              }
    4.35  
    4.36 +            /* only set if wgl extension is available */
    4.37 +            if (_this->gl_data->HAS_WGL_ARB_create_context_robustness) {
    4.38 +                attribs[iattr++] = WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB;
    4.39 +                attribs[iattr++] = _this->gl_config.reset_notification ?
    4.40 +                                    WGL_LOSE_CONTEXT_ON_RESET_ARB :
    4.41 +                                    WGL_NO_RESET_NOTIFICATION_ARB;
    4.42 +            }
    4.43 +
    4.44              attribs[iattr++] = 0;
    4.45  
    4.46              /* Create the GL 3.x context */
     5.1 --- a/src/video/windows/SDL_windowsopengl.h	Sat Aug 19 11:15:58 2017 -0700
     5.2 +++ b/src/video/windows/SDL_windowsopengl.h	Sat Aug 19 15:02:03 2017 -0400
     5.3 @@ -30,6 +30,7 @@
     5.4      SDL_bool HAS_WGL_ARB_pixel_format;
     5.5      SDL_bool HAS_WGL_EXT_swap_control_tear;
     5.6      SDL_bool HAS_WGL_ARB_context_flush_control;
     5.7 +    SDL_bool HAS_WGL_ARB_create_context_robustness;
     5.8  
     5.9  	/* Max version of OpenGL ES context that can be created if the
    5.10  	   implementation supports WGL_EXT_create_context_es2_profile.
     6.1 --- a/src/video/x11/SDL_x11opengl.c	Sat Aug 19 11:15:58 2017 -0700
     6.2 +++ b/src/video/x11/SDL_x11opengl.c	Sat Aug 19 15:02:03 2017 -0400
     6.3 @@ -394,6 +394,11 @@
     6.4      if (HasExtension("GLX_ARB_context_flush_control", extensions)) {
     6.5          _this->gl_data->HAS_GLX_ARB_context_flush_control = SDL_TRUE;
     6.6      }
     6.7 +
     6.8 +    /* Check for GLX_ARB_create_context_robustness */
     6.9 +    if (HasExtension("GLX_ARB_create_context_robustness", extensions)) {
    6.10 +        _this->gl_data->HAS_GLX_ARB_create_context_robustness = SDL_TRUE;
    6.11 +    }
    6.12  }
    6.13  
    6.14  /* glXChooseVisual and glXChooseFBConfig have some small differences in
    6.15 @@ -621,8 +626,8 @@
    6.16              context =
    6.17                  _this->gl_data->glXCreateContext(display, vinfo, share_context, True);
    6.18          } else {
    6.19 -            /* max 10 attributes plus terminator */
    6.20 -            int attribs[11] = {
    6.21 +            /* max 12 attributes plus terminator */
    6.22 +            int attribs[13] = {
    6.23                  GLX_CONTEXT_MAJOR_VERSION_ARB,
    6.24                  _this->gl_config.major_version,
    6.25                  GLX_CONTEXT_MINOR_VERSION_ARB,
    6.26 @@ -652,6 +657,15 @@
    6.27                      GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB;
    6.28              }
    6.29  
    6.30 +            /* only set if glx extension is available */
    6.31 +            if( _this->gl_data->HAS_GLX_ARB_create_context_robustness ) {
    6.32 +                attribs[iattr++] = GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB;
    6.33 +                attribs[iattr++] =
    6.34 +                    _this->gl_config.reset_notification ?
    6.35 +                    GLX_LOSE_CONTEXT_ON_RESET_ARB :
    6.36 +                    GLX_NO_RESET_NOTIFICATION_ARB;
    6.37 +            }
    6.38 +
    6.39              attribs[iattr++] = 0;
    6.40  
    6.41              /* Get a pointer to the context creation function for GL 3.0 */
     7.1 --- a/src/video/x11/SDL_x11opengl.h	Sat Aug 19 11:15:58 2017 -0700
     7.2 +++ b/src/video/x11/SDL_x11opengl.h	Sat Aug 19 15:02:03 2017 -0400
     7.3 @@ -35,6 +35,7 @@
     7.4      SDL_bool HAS_GLX_EXT_visual_info;
     7.5      SDL_bool HAS_GLX_EXT_swap_control_tear;
     7.6      SDL_bool HAS_GLX_ARB_context_flush_control;
     7.7 +    SDL_bool HAS_GLX_ARB_create_context_robustness;
     7.8  
     7.9  	/* Max version of OpenGL ES context that can be created if the
    7.10  	   implementation supports GLX_EXT_create_context_es2_profile.