From 667e4e9020ac552a65926d24605978469d5c943a Mon Sep 17 00:00:00 2001
From: Cameron Gutman <[EMAIL REDACTED]>
Date: Fri, 5 Dec 2025 21:25:55 -0600
Subject: [PATCH] egl: Fix X11 EGL window creation on Nvidia
This is a port of 808a3f5 to SDL2.
Fixes #13094
(cherry picked from commit 3146374e4a38753da84bb1652b6b9d6119bbe268)
---
src/video/SDL_egl.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c
index 50f7082f489b0..190a8119f92bc 100644
--- a/src/video/SDL_egl.c
+++ b/src/video/SDL_egl.c
@@ -1186,6 +1186,7 @@ EGLSurface *SDL_EGL_CreateSurface(_THIS, NativeWindowType nw)
/* max 2 key+value pairs, plus terminator. */
EGLint attribs[5];
int attr = 0;
+ int opaque_ext_idx = -1;
EGLSurface *surface;
@@ -1220,6 +1221,7 @@ EGLSurface *SDL_EGL_CreateSurface(_THIS, NativeWindowType nw)
#ifdef EGL_EXT_present_opaque
if (SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_EXT_present_opaque")) {
const SDL_bool allow_transparent = SDL_GetHintBoolean(SDL_HINT_VIDEO_EGL_ALLOW_TRANSPARENCY, SDL_FALSE);
+ opaque_ext_idx = attr;
attribs[attr++] = EGL_PRESENT_OPAQUE_EXT;
attribs[attr++] = allow_transparent ? EGL_FALSE : EGL_TRUE;
}
@@ -1231,6 +1233,16 @@ EGLSurface *SDL_EGL_CreateSurface(_THIS, NativeWindowType nw)
_this->egl_data->egl_display,
_this->egl_data->egl_config,
nw, &attribs[0]);
+ if (surface == EGL_NO_SURFACE) {
+ /* we had a report of Nvidia drivers that report EGL_BAD_ATTRIBUTE if you try to
+ * use EGL_PRESENT_OPAQUE_EXT, even when EGL_EXT_present_opaque is reported as available.
+ * If we used it, try a second time without this attribute. */
+ if ((_this->egl_data->eglGetError() == EGL_BAD_ATTRIBUTE) && (opaque_ext_idx >= 0)) {
+ SDL_memmove(&attribs[opaque_ext_idx], &attribs[opaque_ext_idx + 2], sizeof (attribs[0]) * ((attr - opaque_ext_idx) - 2));
+ surface = _this->egl_data->eglCreateWindowSurface(_this->egl_data->egl_display, _this->egl_data->egl_config, nw, &attribs[0]);
+ }
+ }
+
if (surface == EGL_NO_SURFACE) {
SDL_EGL_SetError("unable to create an EGL window surface", "eglCreateWindowSurface");
}
1 Like