opengl: added SDL_HINT_OPENGL_FORCE_SRGB_CAPABLE.

Reference Issue #14898.

(cherry picked from commit 632c83b722)
This commit is contained in:
Ryan C. Gordon
2026-02-04 13:47:10 -05:00
parent 7f3d51b690
commit fc5862b0dd
5 changed files with 83 additions and 13 deletions

View File

@@ -38,6 +38,7 @@
#include "SDL_sysvideo.h"
#include "SDL_egl_c.h"
#include "../SDL_hints_c.h"
#ifdef EGL_KHR_create_context
// EGL_OPENGL_ES3_BIT_KHR was added in version 13 of the extension.
@@ -1270,18 +1271,22 @@ EGLSurface SDL_EGL_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, Nat
ANativeWindow_setBuffersGeometry(nw, 0, 0, format_wanted);
#endif
if (_this->gl_config.framebuffer_srgb_capable >= 0) {
#ifdef EGL_KHR_gl_colorspace
if (SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_KHR_gl_colorspace")) {
if (SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_KHR_gl_colorspace")) {
const char *srgbhint = SDL_GetHint(SDL_HINT_OPENGL_FORCE_SRGB_CAPABLE);
if (srgbhint && *srgbhint) {
if (SDL_strcmp(srgbhint, "skip") == 0) {
// don't set an attribute at all.
} else {
attribs[attr++] = EGL_GL_COLORSPACE_KHR;
attribs[attr++] = SDL_GetStringBoolean(srgbhint, false) ? EGL_GL_COLORSPACE_SRGB_KHR : EGL_GL_COLORSPACE_LINEAR_KHR;
}
} else if (_this->gl_config.framebuffer_srgb_capable >= 0) { // default behavior without the hint.
attribs[attr++] = EGL_GL_COLORSPACE_KHR;
attribs[attr++] = _this->gl_config.framebuffer_srgb_capable ? EGL_GL_COLORSPACE_SRGB_KHR : EGL_GL_COLORSPACE_LINEAR_KHR;
} else
#endif
if (_this->gl_config.framebuffer_srgb_capable > 0) {
SDL_SetError("EGL implementation does not support sRGB system framebuffers");
return EGL_NO_SURFACE;
}
}
#endif
int opaque_ext_idx = -1;

View File

@@ -31,6 +31,7 @@
#include "../../events/SDL_keyboard_c.h"
#include "../../events/SDL_mouse_c.h"
#include "../../power/uikit/SDL_syspower.h"
#include "../../SDL_hints_c.h"
#include <dlfcn.h>
@interface SDLEAGLContext : EAGLContext
@@ -153,6 +154,12 @@ SDL_GLContext UIKit_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window)
return NULL;
}
int srgb = _this->gl_config.framebuffer_srgb_capable;
const char *srgbhint = SDL_GetHint(SDL_HINT_OPENGL_FORCE_SRGB_CAPABLE);
if (srgbhint && *srgbhint) {
srgb = SDL_GetStringBoolean(srgbhint, false) ? 1 : 0; // there is no "skip" here, since initWithFrame expects it, so we'll treat it as false.
}
// construct our view, passing in SDL's OpenGL configuration data
view = [[SDL_uikitopenglview alloc] initWithFrame:frame
scale:scale
@@ -163,7 +170,7 @@ SDL_GLContext UIKit_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window)
aBits:_this->gl_config.alpha_size
depthBits:_this->gl_config.depth_size
stencilBits:_this->gl_config.stencil_size
sRGB:_this->gl_config.framebuffer_srgb_capable
sRGB:srgb
multisamples:samples
context:context];

View File

@@ -24,6 +24,7 @@
#include "SDL_windowsvideo.h"
#include "SDL_windowsopengles.h"
#include "../../SDL_hints_c.h"
// WGL implementation of SDL OpenGL support
@@ -660,8 +661,18 @@ static bool WIN_GL_SetupWindowInternal(SDL_VideoDevice *_this, SDL_Window *windo
}
if (_this->gl_data->HAS_WGL_ARB_framebuffer_sRGB) {
*iAttr++ = WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB;
*iAttr++ = (_this->gl_config.framebuffer_srgb_capable > 0) ? GL_TRUE : GL_FALSE;
const char *srgbhint = SDL_GetHint(SDL_HINT_OPENGL_FORCE_SRGB_CAPABLE);
if (srgbhint && *srgbhint) {
if (SDL_strcmp(srgbhint, "skip") == 0) {
// don't set an attribute at all.
} else {
*iAttr++ = WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB;
*iAttr++ = SDL_GetStringBoolean(srgbhint, false) ? GL_TRUE : GL_FALSE;
}
} else if (_this->gl_config.framebuffer_srgb_capable) { // default behavior without the hint.
*iAttr++ = WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB;
*iAttr++ = GL_TRUE;
}
}
/* We always choose either FULL or NO accel on Windows, because of flaky

View File

@@ -25,6 +25,7 @@
#include "SDL_x11video.h"
#include "SDL_x11xsync.h"
#include "../../SDL_hints_c.h"
// GLX implementation of SDL OpenGL support
@@ -583,9 +584,19 @@ 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 >= 0) && _this->gl_data->HAS_GLX_ARB_framebuffer_sRGB) {
attribs[i++] = GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB;
attribs[i++] = _this->gl_config.framebuffer_srgb_capable ? True : False; // always needed, for_FBConfig or not!
if (_this->gl_data->HAS_GLX_ARB_framebuffer_sRGB) {
const char *srgbhint = SDL_GetHint(SDL_HINT_OPENGL_FORCE_SRGB_CAPABLE);
if (srgbhint && *srgbhint) {
if (SDL_strcmp(srgbhint, "skip") == 0) {
// don't set an attribute at all.
} else {
attribs[i++] = GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB;
attribs[i++] = SDL_GetStringBoolean(srgbhint, false) ? True : False; // always needed, for_FBConfig or not!
}
} else if (_this->gl_config.framebuffer_srgb_capable) { // default behavior without the hint.
attribs[i++] = GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB;
attribs[i++] = True; // always needed, for_FBConfig or not!
}
}
if (_this->gl_config.accelerated >= 0 &&