From 8f9dd75ead7e0f023b7dd7a38d17cea9b936b600 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Fri, 13 Feb 2026 14:14:40 -0500
Subject: [PATCH] video: Only set GL_FRAMEBUFFER_SRGB state if the hint
requests it.
Reference Issue #14898.
(cherry picked from commit ead67481c0a40a3e8e1898419b67a4ec9838f3d3)
---
include/SDL3/SDL_hints.h | 4 ++++
src/video/SDL_video.c | 27 ++++++++++++++-------------
2 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/include/SDL3/SDL_hints.h b/include/SDL3/SDL_hints.h
index 9e4041cad71d8..6ded6b91f40f8 100644
--- a/include/SDL3/SDL_hints.h
+++ b/include/SDL3/SDL_hints.h
@@ -3025,6 +3025,10 @@ extern "C" {
* Note that some platforms cannot make this request at all, and on all
* platforms this request can be denied by the operating system.
*
+ * In addition to attempting to obtain the type of sRGB-capable OpenGL context
+ * requested by this hint, SDL will try to force the state of
+ * GL_FRAMEBUFFER_SRGB on the new context, if appropriate.
+ *
* The variable can be set to the following values:
*
* - "0": Force a request for an OpenGL context that is _not_ sRGB-capable.
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 93c7b05fbc438..df3d3f0ed88f6 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -5411,10 +5411,10 @@ SDL_GLContext SDL_GL_CreateContext(SDL_Window *window)
}
#if defined(SDL_VIDEO_OPENGL) || defined(SDL_VIDEO_OPENGL_ES) || defined(SDL_VIDEO_OPENGL_ES2)
- bool srgb_requested = (_this->gl_config.framebuffer_srgb_capable > 0);
+ int srgb_requested = -1;
const char *srgbhint = SDL_GetHint(SDL_HINT_OPENGL_FORCE_SRGB_CAPABLE);
if (srgbhint && *srgbhint) {
- srgb_requested = SDL_GetStringBoolean(srgbhint, false);
+ srgb_requested = SDL_GetStringBoolean(srgbhint, false) ? 1 : 0;
}
#endif
@@ -5430,21 +5430,22 @@ SDL_GLContext SDL_GL_CreateContext(SDL_Window *window)
}
#if defined(SDL_VIDEO_OPENGL) || defined(SDL_VIDEO_OPENGL_ES) || defined(SDL_VIDEO_OPENGL_ES2)
- // try to force the window framebuffer to the requested sRGB state.
- PFNGLENABLEPROC glToggleFunc = (PFNGLENABLEPROC) SDL_GL_GetProcAddress(srgb_requested ? "glEnable" : "glDisable");
- PFNGLGETSTRINGPROC glGetStringFunc = (PFNGLGETSTRINGPROC)SDL_GL_GetProcAddress("glGetString");
- if (glToggleFunc && glGetStringFunc) {
- bool supported = isAtLeastGL3((const char *)glGetStringFunc(GL_VERSION)); // no extensions needed in OpenGL 3+ or GLES 3+.
- if (!supported) {
+ if (srgb_requested != -1) {
+ PFNGLENABLEPROC glToggleFunc = (PFNGLENABLEPROC) SDL_GL_GetProcAddress(srgb_requested ? "glEnable" : "glDisable");
+ PFNGLGETSTRINGPROC glGetStringFunc = (PFNGLGETSTRINGPROC)SDL_GL_GetProcAddress("glGetString");
+ if (glToggleFunc && glGetStringFunc) {
+ bool supported = false;
if (_this->gl_config.profile_mask & SDL_GL_CONTEXT_PROFILE_ES) {
- supported = SDL_GL_ExtensionSupported("GL_EXT_sRGB_write_control");
+ supported = SDL_GL_ExtensionSupported("GL_EXT_sRGB_write_control"); // GL_FRAMEBUFFER_SRGB is not core in any GLES version at the moment.
} else {
- supported = SDL_GL_ExtensionSupported("GL_EXT_framebuffer_sRGB") || SDL_GL_ExtensionSupported("GL_ARB_framebuffer_sRGB");
+ supported = isAtLeastGL3((const char *)glGetStringFunc(GL_VERSION)) || // no extensions needed in OpenGL 3+.
+ SDL_GL_ExtensionSupported("GL_EXT_framebuffer_sRGB") ||
+ SDL_GL_ExtensionSupported("GL_ARB_framebuffer_sRGB");
}
- }
- if (supported) {
- glToggleFunc(GL_FRAMEBUFFER_SRGB);
+ if (supported) {
+ glToggleFunc(GL_FRAMEBUFFER_SRGB);
+ }
}
}
#endif