Fix KHR_no_error support
authorEthan Lee <flibitijibibo@flibitijibibo.com>
Thu, 24 Aug 2017 22:57:42 -0400
changeset 113477f254d0b7842
parent 11346 4d2bf1b340cd
child 11348 6e1d0d1e2a5b
Fix KHR_no_error support
src/video/SDL_egl.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/src/video/SDL_egl.c	Thu Aug 24 21:30:53 2017 -0400
     1.2 +++ b/src/video/SDL_egl.c	Thu Aug 24 22:57:42 2017 -0400
     1.3 @@ -463,18 +463,6 @@
     1.4          attribs[i++] = _this->gl_config.multisamplesamples;
     1.5      }
     1.6  
     1.7 -    if (_this->gl_config.no_error) {
     1.8 -#ifdef GL_KHR_no_error
     1.9 -        if (SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "GL_KHR_no_error")) {
    1.10 -            attribs[i++] = EGL_CONTEXT_OPENGL_NO_ERROR_KHR;
    1.11 -            attribs[i++] = _this->gl_config.no_error;
    1.12 -        } else
    1.13 -#endif
    1.14 -        {
    1.15 -            return SDL_SetError("EGL implementation does not support no_error contexts");
    1.16 -        }
    1.17 -    }
    1.18 -
    1.19      if (_this->gl_config.framebuffer_srgb_capable) {
    1.20  #ifdef EGL_KHR_gl_colorspace
    1.21          if (SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_KHR_gl_colorspace")) {
    1.22 @@ -618,6 +606,19 @@
    1.23          }
    1.24      }
    1.25  
    1.26 +    if (_this->gl_config.no_error) {
    1.27 +#ifdef EGL_KHR_create_context_no_error
    1.28 +        if (SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_KHR_create_context_no_error")) {
    1.29 +            attribs[attr++] = EGL_CONTEXT_OPENGL_NO_ERROR_KHR;
    1.30 +            attribs[attr++] = _this->gl_config.no_error;
    1.31 +        } else
    1.32 +#endif
    1.33 +        {
    1.34 +            SDL_SetError("EGL implementation does not support no_error contexts");
    1.35 +            return NULL;
    1.36 +        }
    1.37 +    }
    1.38 +
    1.39      attribs[attr++] = EGL_NONE;
    1.40  
    1.41      /* Bind the API */
     2.1 --- a/src/video/windows/SDL_windowsopengl.c	Thu Aug 24 21:30:53 2017 -0400
     2.2 +++ b/src/video/windows/SDL_windowsopengl.c	Thu Aug 24 22:57:42 2017 -0400
     2.3 @@ -468,6 +468,11 @@
     2.4          _this->gl_data->HAS_WGL_ARB_create_context_robustness = SDL_TRUE;
     2.5      }
     2.6  
     2.7 +    /* Check for WGL_ARB_create_context_no_error */
     2.8 +    if (HasExtension("WGL_ARB_create_context_no_error", extensions)) {
     2.9 +        _this->gl_data->HAS_WGL_ARB_create_context_no_error = SDL_TRUE;
    2.10 +    }
    2.11 +
    2.12      _this->gl_data->wglMakeCurrent(hdc, NULL);
    2.13      _this->gl_data->wglDeleteContext(hglrc);
    2.14      ReleaseDC(hwnd, hdc);
    2.15 @@ -598,11 +603,6 @@
    2.16          *iAttr++ = _this->gl_config.framebuffer_srgb_capable;
    2.17      }
    2.18  
    2.19 -    if (_this->gl_config.no_error) {
    2.20 -        *iAttr++ = WGL_CONTEXT_OPENGL_NO_ERROR_ARB;
    2.21 -        *iAttr++ = _this->gl_config.no_error;
    2.22 -    }
    2.23 -
    2.24      /* We always choose either FULL or NO accel on Windows, because of flaky
    2.25         drivers. If the app didn't specify, we use FULL, because that's
    2.26         probably what they wanted (and if you didn't care and got FULL, that's
    2.27 @@ -728,8 +728,8 @@
    2.28              SDL_SetError("GL 3.x is not supported");
    2.29              context = temp_context;
    2.30          } else {
    2.31 -        /* max 12 attributes plus terminator */
    2.32 -            int attribs[13] = {
    2.33 +        /* max 14 attributes plus terminator */
    2.34 +            int attribs[15] = {
    2.35                  WGL_CONTEXT_MAJOR_VERSION_ARB, _this->gl_config.major_version,
    2.36                  WGL_CONTEXT_MINOR_VERSION_ARB, _this->gl_config.minor_version,
    2.37                  0
    2.38 @@ -764,6 +764,12 @@
    2.39                                      WGL_NO_RESET_NOTIFICATION_ARB;
    2.40              }
    2.41  
    2.42 +            /* only set if wgl extension is available */
    2.43 +            if (_this->gl_data->HAS_WGL_ARB_create_context_no_error) {
    2.44 +                attribs[iattr++] = WGL_CONTEXT_OPENGL_NO_ERROR_ARB;
    2.45 +                attribs[iattr++] = _this->gl_config.no_error;
    2.46 +            }
    2.47 +
    2.48              attribs[iattr++] = 0;
    2.49  
    2.50              /* Create the GL 3.x context */
     3.1 --- a/src/video/windows/SDL_windowsopengl.h	Thu Aug 24 21:30:53 2017 -0400
     3.2 +++ b/src/video/windows/SDL_windowsopengl.h	Thu Aug 24 22:57:42 2017 -0400
     3.3 @@ -31,6 +31,7 @@
     3.4      SDL_bool HAS_WGL_EXT_swap_control_tear;
     3.5      SDL_bool HAS_WGL_ARB_context_flush_control;
     3.6      SDL_bool HAS_WGL_ARB_create_context_robustness;
     3.7 +    SDL_bool HAS_WGL_ARB_create_context_no_error;
     3.8  
     3.9  	/* Max version of OpenGL ES context that can be created if the
    3.10  	   implementation supports WGL_EXT_create_context_es2_profile.
     4.1 --- a/src/video/x11/SDL_x11opengl.c	Thu Aug 24 21:30:53 2017 -0400
     4.2 +++ b/src/video/x11/SDL_x11opengl.c	Thu Aug 24 22:57:42 2017 -0400
     4.3 @@ -406,6 +406,11 @@
     4.4      if (HasExtension("GLX_ARB_create_context_robustness", extensions)) {
     4.5          _this->gl_data->HAS_GLX_ARB_create_context_robustness = SDL_TRUE;
     4.6      }
     4.7 +
     4.8 +    /* Check for GLX_ARB_create_context_no_error */
     4.9 +    if (HasExtension("GLX_ARB_create_context_no_error", extensions)) {
    4.10 +        _this->gl_data->HAS_GLX_ARB_create_context_no_error = SDL_TRUE;
    4.11 +    }
    4.12  }
    4.13  
    4.14  /* glXChooseVisual and glXChooseFBConfig have some small differences in
    4.15 @@ -501,11 +506,6 @@
    4.16          attribs[i++] = True;  /* always needed, for_FBConfig or not! */
    4.17      }
    4.18  
    4.19 -    if (_this->gl_config.no_error) {
    4.20 -        attribs[i++] = GLX_CONTEXT_OPENGL_NO_ERROR_ARB;
    4.21 -        attribs[i++] = _this->gl_config.no_error;
    4.22 -    }
    4.23 -
    4.24      if (_this->gl_config.accelerated >= 0 &&
    4.25          _this->gl_data->HAS_GLX_EXT_visual_rating) {
    4.26          attribs[i++] = GLX_VISUAL_CAVEAT_EXT;
    4.27 @@ -638,8 +638,8 @@
    4.28              context =
    4.29                  _this->gl_data->glXCreateContext(display, vinfo, share_context, True);
    4.30          } else {
    4.31 -            /* max 12 attributes plus terminator */
    4.32 -            int attribs[13] = {
    4.33 +            /* max 14 attributes plus terminator */
    4.34 +            int attribs[15] = {
    4.35                  GLX_CONTEXT_MAJOR_VERSION_ARB,
    4.36                  _this->gl_config.major_version,
    4.37                  GLX_CONTEXT_MINOR_VERSION_ARB,
    4.38 @@ -678,6 +678,12 @@
    4.39                      GLX_NO_RESET_NOTIFICATION_ARB;
    4.40              }
    4.41  
    4.42 +            /* only set if glx extension is available */
    4.43 +            if( _this->gl_data->HAS_GLX_ARB_create_context_no_error ) {
    4.44 +                attribs[iattr++] = GLX_CONTEXT_OPENGL_NO_ERROR_ARB;
    4.45 +                attribs[iattr++] = _this->gl_config.no_error;
    4.46 +            }
    4.47 +
    4.48              attribs[iattr++] = 0;
    4.49  
    4.50              /* Get a pointer to the context creation function for GL 3.0 */
     5.1 --- a/src/video/x11/SDL_x11opengl.h	Thu Aug 24 21:30:53 2017 -0400
     5.2 +++ b/src/video/x11/SDL_x11opengl.h	Thu Aug 24 22:57:42 2017 -0400
     5.3 @@ -36,6 +36,7 @@
     5.4      SDL_bool HAS_GLX_EXT_swap_control_tear;
     5.5      SDL_bool HAS_GLX_ARB_context_flush_control;
     5.6      SDL_bool HAS_GLX_ARB_create_context_robustness;
     5.7 +    SDL_bool HAS_GLX_ARB_create_context_no_error;
     5.8  
     5.9  	/* Max version of OpenGL ES context that can be created if the
    5.10  	   implementation supports GLX_EXT_create_context_es2_profile.