SDL: EGL: Ensure the platform extensions exist before using them

From 819f6ae75b9e7cfde0d898d1af427af295db8344 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Thu, 11 Jun 2026 13:16:03 -0400
Subject: [PATCH] EGL: Ensure the platform extensions exist before using them

The EXT and KHR variants use the same constant values, but the EXT versions are available a bit further back.
---
 src/video/wayland/SDL_waylandopengles.c | 9 +++++++--
 src/video/x11/SDL_x11opengles.c         | 8 ++++++--
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/video/wayland/SDL_waylandopengles.c b/src/video/wayland/SDL_waylandopengles.c
index e0af9253c9790..3c373ef79b9c6 100644
--- a/src/video/wayland/SDL_waylandopengles.c
+++ b/src/video/wayland/SDL_waylandopengles.c
@@ -37,10 +37,15 @@
 
 int Wayland_GLES_LoadLibrary(_THIS, const char *path)
 {
-    int ret;
     SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
+    int ret;
+#ifdef EGL_EXT_platform_wayland
+    const EGLenum platform = EGL_PLATFORM_WAYLAND_EXT;
+#else
+    const EGLenum platform = 0;
+#endif
 
-    ret = SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType) data->display, EGL_PLATFORM_WAYLAND_KHR);
+    ret = SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType) data->display, platform);
 
     Wayland_PumpEvents(_this);
     WAYLAND_wl_display_flush(data->display);
diff --git a/src/video/x11/SDL_x11opengles.c b/src/video/x11/SDL_x11opengles.c
index 92f9976f8fdab..aaef9d0903318 100644
--- a/src/video/x11/SDL_x11opengles.c
+++ b/src/video/x11/SDL_x11opengles.c
@@ -32,6 +32,11 @@
 int X11_GLES_LoadLibrary(_THIS, const char *path)
 {
     SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
+#ifdef EGL_EXT_platform_x11
+    const EGLenum platform = EGL_PLATFORM_X11_EXT;
+#else
+    const EGLenum platform = 0;
+#endif
 
     /* If the profile requested is not GL ES, switch over to X11_GL functions  */
     if ((_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) &&
@@ -53,8 +58,7 @@ int X11_GLES_LoadLibrary(_THIS, const char *path)
 #endif
     }
 
-    return SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType) data->display,
-                               EGL_PLATFORM_X11_KHR);
+    return SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType) data->display, platform);
 }
 
 XVisualInfo *X11_GLES_GetVisual(_THIS, Display *display, int screen)