From b7b1f7843d2717b646e78578ddb07ab6cac91147 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Thu, 11 Jun 2026 13:42:56 -0400
Subject: [PATCH] EGL: Always pass the platform type when available
Always pass the EGL platform type for Wayland and X11, or the driver could potentially select the wrong backend if certain envvars are misconfigured.
(cherry picked from commit 34af24276f0c5777aa253fa5a73e6e3636922496)
---
src/video/kmsdrm/SDL_kmsdrmopengles.c | 6 +++---
src/video/kmsdrm/SDL_kmsdrmvideo.c | 8 ++++----
src/video/wayland/SDL_waylandopengles.c | 7 +++++++
src/video/x11/SDL_x11opengles.c | 7 +++++++
4 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/src/video/kmsdrm/SDL_kmsdrmopengles.c b/src/video/kmsdrm/SDL_kmsdrmopengles.c
index bab95e3c3701b..c02563c7323b0 100644
--- a/src/video/kmsdrm/SDL_kmsdrmopengles.c
+++ b/src/video/kmsdrm/SDL_kmsdrmopengles.c
@@ -30,8 +30,8 @@
#define VOID2U64(x) ((uint64_t)(size_t)(x))
-#ifndef EGL_PLATFORM_GBM_MESA
-#define EGL_PLATFORM_GBM_MESA 0x31D7
+#ifndef EGL_PLATFORM_GBM_KHR
+#define EGL_PLATFORM_GBM_KHR 0x31D7
#endif
#ifndef EGL_SYNC_NATIVE_FENCE_ANDROID
@@ -70,7 +70,7 @@ bool KMSDRM_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path)
call order in SDL_CreateWindow(). */
#if 0
NativeDisplayType display = (NativeDisplayType)_this->internal->gbm_dev;
- return SDL_EGL_LoadLibrary(_this, path, display, EGL_PLATFORM_GBM_MESA);
+ return SDL_EGL_LoadLibrary(_this, path, display, EGL_PLATFORM_GBM_KHR);
#endif
return true;
}
diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c
index 276f0d494e89f..d6d505732189b 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvideo.c
+++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c
@@ -74,8 +74,8 @@ static char kmsdrm_dri_cardpath[32];
#define DRM_FORMAT_MOD_LINEAR fourcc_mod_code(NONE, 0)
#endif
-#ifndef EGL_PLATFORM_GBM_MESA
-#define EGL_PLATFORM_GBM_MESA 0x31D7
+#ifndef EGL_PLATFORM_GBM_KHR
+#define EGL_PLATFORM_GBM_KHR 0x31D7
#endif
static int get_driindex(void)
@@ -2135,12 +2135,12 @@ bool KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propert
before we call KMSDRM_GBMInit(), causing all GLES programs to fail. */
if (!_this->egl_data) {
egl_display = (NativeDisplayType)_this->internal->gbm_dev;
- if (!SDL_EGL_LoadLibrary(_this, NULL, egl_display, EGL_PLATFORM_GBM_MESA)) {
+ if (!SDL_EGL_LoadLibrary(_this, NULL, egl_display, EGL_PLATFORM_GBM_KHR)) {
// Try again with OpenGL ES 2.0
_this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
_this->gl_config.major_version = 2;
_this->gl_config.minor_version = 0;
- if (!SDL_EGL_LoadLibrary(_this, NULL, egl_display, EGL_PLATFORM_GBM_MESA)) {
+ if (!SDL_EGL_LoadLibrary(_this, NULL, egl_display, EGL_PLATFORM_GBM_KHR)) {
return SDL_SetError("Can't load EGL/GL library on window creation.");
}
}
diff --git a/src/video/wayland/SDL_waylandopengles.c b/src/video/wayland/SDL_waylandopengles.c
index 26335bf10b480..49124d72ff68d 100644
--- a/src/video/wayland/SDL_waylandopengles.c
+++ b/src/video/wayland/SDL_waylandopengles.c
@@ -32,6 +32,10 @@
#include "xdg-shell-client-protocol.h"
+#ifndef EGL_PLATFORM_WAYLAND_KHR
+#define EGL_PLATFORM_WAYLAND_KHR 0x31D8
+#endif
+
// EGL implementation of SDL OpenGL ES support
bool Wayland_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path)
@@ -39,6 +43,9 @@ bool Wayland_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path)
bool result;
SDL_VideoData *data = _this->internal;
+ if (!_this->gl_config.egl_platform) {
+ _this->gl_config.egl_platform = EGL_PLATFORM_WAYLAND_KHR;
+ }
result = SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType)data->display, _this->gl_config.egl_platform);
Wayland_PumpEvents(_this);
diff --git a/src/video/x11/SDL_x11opengles.c b/src/video/x11/SDL_x11opengles.c
index 147576d29bdaa..1522da467223f 100644
--- a/src/video/x11/SDL_x11opengles.c
+++ b/src/video/x11/SDL_x11opengles.c
@@ -27,6 +27,10 @@
#include "SDL_x11opengl.h"
#include "SDL_x11xsync.h"
+#ifndef EGL_PLATFORM_X11_KHR
+#define EGL_PLATFORM_X11_KHR 0x31D5
+#endif
+
// EGL implementation of SDL OpenGL support
bool X11_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path)
@@ -53,6 +57,9 @@ bool X11_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path)
#endif
}
+ if (!_this->gl_config.egl_platform) {
+ _this->gl_config.egl_platform = EGL_PLATFORM_X11_KHR;
+ }
return SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType)data->display, _this->gl_config.egl_platform);
}