From a6c0052f39eaf7e14ed2e351ba57b31052794640 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Tue, 3 Feb 2026 13:25:54 -0500
Subject: [PATCH] srgb: Readd WGL/GLX extension checks when asking for
sRGB-capable framebuffers.
Reference Issue #14898.
---
src/video/windows/SDL_windowsopengl.c | 20 ++++++++++++++------
src/video/windows/SDL_windowsopengl.h | 1 +
src/video/x11/SDL_x11opengl.c | 9 ++++++++-
src/video/x11/SDL_x11opengl.h | 1 +
4 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/src/video/windows/SDL_windowsopengl.c b/src/video/windows/SDL_windowsopengl.c
index dd8eb9e011eb1..4423a0a036809 100644
--- a/src/video/windows/SDL_windowsopengl.c
+++ b/src/video/windows/SDL_windowsopengl.c
@@ -512,6 +512,13 @@ void WIN_GL_InitExtensions(SDL_VideoDevice *_this)
_this->gl_data->HAS_WGL_ARB_create_context_no_error = true;
}
+ // Check for WGL_ARB_framebuffer_sRGB
+ if (HasExtension("WGL_ARB_framebuffer_sRGB", extensions)) {
+ _this->gl_data->HAS_WGL_ARB_framebuffer_sRGB = true;
+ } else if (HasExtension("WGL_EXT_framebuffer_sRGB", extensions)) { // same thing.
+ _this->gl_data->HAS_WGL_ARB_framebuffer_sRGB = true;
+ }
+
/* Check for WGL_ARB_pixel_format_float */
_this->gl_data->HAS_WGL_ARB_pixel_format_float =
HasExtension("WGL_ARB_pixel_format_float", extensions);
@@ -532,9 +539,6 @@ static int WIN_GL_ChoosePixelFormatARB(SDL_VideoDevice *_this, int *iAttribs, fl
int pixel_format = 0;
unsigned int matching;
- int qAttrib = WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB;
- int srgb = 0;
-
hwnd =
CreateWindow(SDL_Appname, SDL_Appname, (WS_POPUP | WS_DISABLED), 0, 0,
10, 10, NULL, NULL, SDL_Instance, NULL);
@@ -556,7 +560,11 @@ static int WIN_GL_ChoosePixelFormatARB(SDL_VideoDevice *_this, int *iAttribs, fl
&matching);
// Check whether we actually got an SRGB capable buffer
- _this->gl_data->wglGetPixelFormatAttribivARB(hdc, pixel_format, 0, 1, &qAttrib, &srgb);
+ int srgb = 0;
+ if (_this->gl_data->HAS_WGL_ARB_framebuffer_sRGB) {
+ int qAttrib = WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB;
+ _this->gl_data->wglGetPixelFormatAttribivARB(hdc, pixel_format, 0, 1, &qAttrib, &srgb);
+ }
_this->gl_config.framebuffer_srgb_capable = srgb;
}
@@ -651,9 +659,9 @@ static bool WIN_GL_SetupWindowInternal(SDL_VideoDevice *_this, SDL_Window *windo
*iAttr++ = WGL_TYPE_RGBA_FLOAT_ARB;
}
- if (_this->gl_config.framebuffer_srgb_capable) {
+ if (_this->gl_data->HAS_WGL_ARB_framebuffer_sRGB && _this->gl_config.framebuffer_srgb_capable) {
*iAttr++ = WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB;
- *iAttr++ = _this->gl_config.framebuffer_srgb_capable;
+ *iAttr++ = GL_TRUE;
}
/* We always choose either FULL or NO accel on Windows, because of flaky
diff --git a/src/video/windows/SDL_windowsopengl.h b/src/video/windows/SDL_windowsopengl.h
index 1711514ce246c..a6ea01544165d 100644
--- a/src/video/windows/SDL_windowsopengl.h
+++ b/src/video/windows/SDL_windowsopengl.h
@@ -66,6 +66,7 @@ struct SDL_GLDriverData
bool HAS_WGL_ARB_create_context_no_error;
bool HAS_WGL_ARB_pixel_format_float;
bool HAS_WGL_EXT_create_context_es2_profile;
+ bool HAS_WGL_ARB_framebuffer_sRGB;
/* 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 7d843ab67672e..906a3eeae2104 100644
--- a/src/video/x11/SDL_x11opengl.c
+++ b/src/video/x11/SDL_x11opengl.c
@@ -466,6 +466,13 @@ static void X11_GL_InitExtensions(SDL_VideoDevice *_this)
_this->gl_data->HAS_GLX_ARB_create_context_no_error = true;
}
+ // Check for GLX_ARB_framebuffer_sRGB
+ if (HasExtension("GLX_ARB_framebuffer_sRGB", extensions)) {
+ _this->gl_data->HAS_GLX_ARB_framebuffer_sRGB = true;
+ } else if (HasExtension("GLX_EXT_framebuffer_sRGB", extensions)) { // same thing.
+ _this->gl_data->HAS_GLX_ARB_framebuffer_sRGB = true;
+ }
+
if (context) {
_this->gl_data->glXMakeCurrent(display, None, NULL);
_this->gl_data->glXDestroyContext(display, context);
@@ -576,7 +583,7 @@ static int X11_GL_GetAttributes(SDL_VideoDevice *_this, Display *display, int sc
attribs[i++] = GLX_RGBA_FLOAT_TYPE_ARB;
}
- if (_this->gl_config.framebuffer_srgb_capable) {
+ if (_this->gl_data->HAS_GLX_ARB_framebuffer_sRGB && _this->gl_config.framebuffer_srgb_capable) {
attribs[i++] = GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB;
attribs[i++] = True; // always needed, for_FBConfig or not!
}
diff --git a/src/video/x11/SDL_x11opengl.h b/src/video/x11/SDL_x11opengl.h
index 1694a32bd3cae..5a405683d0641 100644
--- a/src/video/x11/SDL_x11opengl.h
+++ b/src/video/x11/SDL_x11opengl.h
@@ -47,6 +47,7 @@ struct SDL_GLDriverData
bool HAS_GLX_ARB_context_flush_control;
bool HAS_GLX_ARB_create_context_robustness;
bool HAS_GLX_ARB_create_context_no_error;
+ bool HAS_GLX_ARB_framebuffer_sRGB;
/* Max version of OpenGL ES context that can be created if the
implementation supports GLX_EXT_create_context_es2_profile.