From c7b8b85469dd85c570737fd6d708844d4b8423d5 Mon Sep 17 00:00:00 2001 From: Zetarancio Date: Sat, 28 Mar 2026 00:20:45 +0100 Subject: [PATCH] SDL3: fall back to GLES EGL API when desktop GL bind fails GLES-only stacks (e.g. libmali on RK3566) cannot satisfy eglBindAPI(EGL_OPENGL_API). The previous patch returned NULL from SDL_EGL_CreateContext, which broke SDL 1.2 titles under box86 that route through SDL2-compat: SDL_SetVideoMode(..., SDL_OPENGL) never got a context (gl4es still provides GL-on-GLES at the libGL layer). If binding EGL_OPENGL_API fails, retry with EGL_OPENGL_ES_API before giving up. Only error out if both bindings fail. Fixes PortMaster / gl4es ports that regressed after the SDL2-compat + SDL3 transition on Mali-class devices. --- ...08-egl-check-eglBindAPI-return-value.patch | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/projects/ROCKNIX/packages/graphics/SDL3/patches/0008-egl-check-eglBindAPI-return-value.patch b/projects/ROCKNIX/packages/graphics/SDL3/patches/0008-egl-check-eglBindAPI-return-value.patch index cf06296df67..76fadcd7372 100644 --- a/projects/ROCKNIX/packages/graphics/SDL3/patches/0008-egl-check-eglBindAPI-return-value.patch +++ b/projects/ROCKNIX/packages/graphics/SDL3/patches/0008-egl-check-eglBindAPI-return-value.patch @@ -1,29 +1,34 @@ -Subject: [PATCH] video: egl: check eglBindAPI return value +Subject: [PATCH] video: egl: fall back to GLES when desktop GL eglBindAPI fails -eglBindAPI(EGL_OPENGL_API) can fail on GLES-only drivers (e.g. libmali) -that do not support desktop OpenGL. Without checking the return value, -SDL proceeds to create what it thinks is a desktop GL context (but is -actually GLES), then crashes when calling desktop GL functions on it. +eglBindAPI(EGL_OPENGL_API) fails on GLES-only drivers (e.g. libmali) +that do not support desktop OpenGL. Rather than returning NULL (which +breaks SDL 1.2 ports using gl4es through box86 → SDL2-compat → SDL3), +fall back to EGL_OPENGL_ES_API so the context can still be created. -Check the return value and fail early so the renderer fallback logic can -try the next backend (opengles2). +gl4es translates desktop GL calls into GLES internally, so an ES EGL +context is correct on these devices. --- - src/video/SDL_egl.c | 5 ++++- - 1 file changed, 4 insertions(+), 1 deletion(-) + src/video/SDL_egl.c | 9 ++++++++- + 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c --- a/src/video/SDL_egl.c +++ b/src/video/SDL_egl.c -@@ -746,7 +746,10 @@ +@@ -746,7 +746,15 @@ } else { _this->egl_data->apitype = EGL_OPENGL_API; } - _this->egl_data->eglBindAPI(_this->egl_data->apitype); + if (!_this->egl_data->eglBindAPI(_this->egl_data->apitype)) { -+ SDL_SetError("Could not bind EGL API"); -+ return NULL; ++ /* GLES-only driver (e.g. libmali): desktop GL unavailable. ++ * Fall back to GLES so gl4es / ES-native apps still work. */ ++ _this->egl_data->apitype = EGL_OPENGL_ES_API; ++ if (!_this->egl_data->eglBindAPI(_this->egl_data->apitype)) { ++ SDL_SetError("Could not bind EGL API (tried GL and GLES)"); ++ return NULL; ++ } + } - + egl_context = _this->egl_data->eglCreateContext(_this->egl_data->egl_display, _this->egl_data->egl_config,