From 685890a22992d41b29631486c75ce3199e1d6fba Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Thu, 24 Aug 2017 22:57:42 -0400 Subject: [PATCH] Fix KHR_no_error support --- src/video/SDL_egl.c | 25 +++++++++++++------------ src/video/windows/SDL_windowsopengl.c | 20 +++++++++++++------- src/video/windows/SDL_windowsopengl.h | 1 + src/video/x11/SDL_x11opengl.c | 20 +++++++++++++------- src/video/x11/SDL_x11opengl.h | 1 + 5 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c index 6241c49b03a34..1e0aacf20cf1c 100644 --- a/src/video/SDL_egl.c +++ b/src/video/SDL_egl.c @@ -463,18 +463,6 @@ SDL_EGL_ChooseConfig(_THIS) attribs[i++] = _this->gl_config.multisamplesamples; } - if (_this->gl_config.no_error) { -#ifdef GL_KHR_no_error - if (SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "GL_KHR_no_error")) { - attribs[i++] = EGL_CONTEXT_OPENGL_NO_ERROR_KHR; - attribs[i++] = _this->gl_config.no_error; - } else -#endif - { - return SDL_SetError("EGL implementation does not support no_error contexts"); - } - } - if (_this->gl_config.framebuffer_srgb_capable) { #ifdef EGL_KHR_gl_colorspace if (SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_KHR_gl_colorspace")) { @@ -618,6 +606,19 @@ SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface) } } + if (_this->gl_config.no_error) { +#ifdef EGL_KHR_create_context_no_error + if (SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_KHR_create_context_no_error")) { + attribs[attr++] = EGL_CONTEXT_OPENGL_NO_ERROR_KHR; + attribs[attr++] = _this->gl_config.no_error; + } else +#endif + { + SDL_SetError("EGL implementation does not support no_error contexts"); + return NULL; + } + } + attribs[attr++] = EGL_NONE; /* Bind the API */ diff --git a/src/video/windows/SDL_windowsopengl.c b/src/video/windows/SDL_windowsopengl.c index a46c4e4530224..9398ded661bea 100644 --- a/src/video/windows/SDL_windowsopengl.c +++ b/src/video/windows/SDL_windowsopengl.c @@ -468,6 +468,11 @@ WIN_GL_InitExtensions(_THIS) _this->gl_data->HAS_WGL_ARB_create_context_robustness = SDL_TRUE; } + /* Check for WGL_ARB_create_context_no_error */ + if (HasExtension("WGL_ARB_create_context_no_error", extensions)) { + _this->gl_data->HAS_WGL_ARB_create_context_no_error = SDL_TRUE; + } + _this->gl_data->wglMakeCurrent(hdc, NULL); _this->gl_data->wglDeleteContext(hglrc); ReleaseDC(hwnd, hdc); @@ -598,11 +603,6 @@ WIN_GL_SetupWindowInternal(_THIS, SDL_Window * window) *iAttr++ = _this->gl_config.framebuffer_srgb_capable; } - if (_this->gl_config.no_error) { - *iAttr++ = WGL_CONTEXT_OPENGL_NO_ERROR_ARB; - *iAttr++ = _this->gl_config.no_error; - } - /* We always choose either FULL or NO accel on Windows, because of flaky drivers. If the app didn't specify, we use FULL, because that's probably what they wanted (and if you didn't care and got FULL, that's @@ -728,8 +728,8 @@ WIN_GL_CreateContext(_THIS, SDL_Window * window) SDL_SetError("GL 3.x is not supported"); context = temp_context; } else { - /* max 12 attributes plus terminator */ - int attribs[13] = { + /* max 14 attributes plus terminator */ + int attribs[15] = { WGL_CONTEXT_MAJOR_VERSION_ARB, _this->gl_config.major_version, WGL_CONTEXT_MINOR_VERSION_ARB, _this->gl_config.minor_version, 0 @@ -764,6 +764,12 @@ WIN_GL_CreateContext(_THIS, SDL_Window * window) WGL_NO_RESET_NOTIFICATION_ARB; } + /* only set if wgl extension is available */ + if (_this->gl_data->HAS_WGL_ARB_create_context_no_error) { + attribs[iattr++] = WGL_CONTEXT_OPENGL_NO_ERROR_ARB; + attribs[iattr++] = _this->gl_config.no_error; + } + attribs[iattr++] = 0; /* Create the GL 3.x context */ diff --git a/src/video/windows/SDL_windowsopengl.h b/src/video/windows/SDL_windowsopengl.h index 87e4689ff5357..1d9fa239b9804 100644 --- a/src/video/windows/SDL_windowsopengl.h +++ b/src/video/windows/SDL_windowsopengl.h @@ -31,6 +31,7 @@ struct SDL_GLDriverData SDL_bool HAS_WGL_EXT_swap_control_tear; SDL_bool HAS_WGL_ARB_context_flush_control; SDL_bool HAS_WGL_ARB_create_context_robustness; + SDL_bool HAS_WGL_ARB_create_context_no_error; /* Max version of OpenGL ES context that can be created if the implementation supports WGL_EXT_create_context_es2_profile. diff --git a/src/video/x11/SDL_x11opengl.c b/src/video/x11/SDL_x11opengl.c index 37267edaec09a..9bbcb05dbcf6e 100644 --- a/src/video/x11/SDL_x11opengl.c +++ b/src/video/x11/SDL_x11opengl.c @@ -406,6 +406,11 @@ X11_GL_InitExtensions(_THIS) if (HasExtension("GLX_ARB_create_context_robustness", extensions)) { _this->gl_data->HAS_GLX_ARB_create_context_robustness = SDL_TRUE; } + + /* Check for GLX_ARB_create_context_no_error */ + if (HasExtension("GLX_ARB_create_context_no_error", extensions)) { + _this->gl_data->HAS_GLX_ARB_create_context_no_error = SDL_TRUE; + } } /* glXChooseVisual and glXChooseFBConfig have some small differences in @@ -501,11 +506,6 @@ X11_GL_GetAttributes(_THIS, Display * display, int screen, int * attribs, int si attribs[i++] = True; /* always needed, for_FBConfig or not! */ } - if (_this->gl_config.no_error) { - attribs[i++] = GLX_CONTEXT_OPENGL_NO_ERROR_ARB; - attribs[i++] = _this->gl_config.no_error; - } - if (_this->gl_config.accelerated >= 0 && _this->gl_data->HAS_GLX_EXT_visual_rating) { attribs[i++] = GLX_VISUAL_CAVEAT_EXT; @@ -638,8 +638,8 @@ X11_GL_CreateContext(_THIS, SDL_Window * window) context = _this->gl_data->glXCreateContext(display, vinfo, share_context, True); } else { - /* max 12 attributes plus terminator */ - int attribs[13] = { + /* max 14 attributes plus terminator */ + int attribs[15] = { GLX_CONTEXT_MAJOR_VERSION_ARB, _this->gl_config.major_version, GLX_CONTEXT_MINOR_VERSION_ARB, @@ -678,6 +678,12 @@ X11_GL_CreateContext(_THIS, SDL_Window * window) GLX_NO_RESET_NOTIFICATION_ARB; } + /* only set if glx extension is available */ + if( _this->gl_data->HAS_GLX_ARB_create_context_no_error ) { + attribs[iattr++] = GLX_CONTEXT_OPENGL_NO_ERROR_ARB; + attribs[iattr++] = _this->gl_config.no_error; + } + attribs[iattr++] = 0; /* Get a pointer to the context creation function for GL 3.0 */ diff --git a/src/video/x11/SDL_x11opengl.h b/src/video/x11/SDL_x11opengl.h index dd3c7e503f3e8..8e0b0f3b8569c 100644 --- a/src/video/x11/SDL_x11opengl.h +++ b/src/video/x11/SDL_x11opengl.h @@ -36,6 +36,7 @@ struct SDL_GLDriverData SDL_bool HAS_GLX_EXT_swap_control_tear; SDL_bool HAS_GLX_ARB_context_flush_control; SDL_bool HAS_GLX_ARB_create_context_robustness; + SDL_bool HAS_GLX_ARB_create_context_no_error; /* Max version of OpenGL ES context that can be created if the implementation supports GLX_EXT_create_context_es2_profile.