From 61261e59bc22bbab9922628560f6ba9f0216b4c9 Mon Sep 17 00:00:00 2001 From: Dawid Gan Date: Tue, 16 Jan 2018 21:29:32 +0100 Subject: [PATCH] EGL: Request sRGB framebuffer in correct place. The EGL_GL_COLORSPACE_KHR is an attribute for eglCreate*Surface. As written in EGL_KHR_gl_colorspace documentation: Accepted as an attribute name by eglCreateWindowSurface, eglCreatePbufferSurface and eglCreatePixmapSurface EGL_GL_COLORSPACE_KHR 0x309D (...) --- src/video/SDL_egl.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c index 521b47445e5d1..7308c15e61457 100644 --- a/src/video/SDL_egl.c +++ b/src/video/SDL_egl.c @@ -519,18 +519,6 @@ SDL_EGL_ChooseConfig(_THIS) attribs[i++] = _this->gl_config.multisamplesamples; } - 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")) { - attribs[i++] = EGL_GL_COLORSPACE_KHR; - attribs[i++] = EGL_GL_COLORSPACE_SRGB_KHR; - } else -#endif - { - return SDL_SetError("EGL implementation does not support sRGB system framebuffers"); - } - } - attribs[i++] = EGL_RENDERABLE_TYPE; if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) { #ifdef EGL_KHR_create_context @@ -799,6 +787,10 @@ SDL_EGL_DeleteContext(_THIS, SDL_GLContext context) EGLSurface * SDL_EGL_CreateSurface(_THIS, NativeWindowType nw) { + /* max 2 values plus terminator. */ + EGLint attribs[3]; + int attr = 0; + EGLSurface * surface; if (SDL_EGL_ChooseConfig(_this) != 0) { @@ -818,11 +810,25 @@ SDL_EGL_CreateSurface(_THIS, NativeWindowType nw) ANativeWindow_setBuffersGeometry(nw, 0, 0, format); } #endif + 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")) { + attribs[attr++] = EGL_GL_COLORSPACE_KHR; + attribs[attr++] = EGL_GL_COLORSPACE_SRGB_KHR; + } else +#endif + { + SDL_SetError("EGL implementation does not support sRGB system framebuffers"); + return EGL_NO_SURFACE; + } + } + + attribs[attr++] = EGL_NONE; surface = _this->egl_data->eglCreateWindowSurface( _this->egl_data->egl_display, _this->egl_data->egl_config, - nw, NULL); + nw, &attribs[0]); if (surface == EGL_NO_SURFACE) { SDL_EGL_SetError("unable to create an EGL window surface", "eglCreateWindowSurface"); }