Skip to content

SDL3 EGL: try GLES API when desktop GL bind fails (Mali / gl4es)#2484

Draft
Zetarancio wants to merge 1 commit intoROCKNIX:nextfrom
Zetarancio:sdl3-egl-gles-fallback-mali
Draft

SDL3 EGL: try GLES API when desktop GL bind fails (Mali / gl4es)#2484
Zetarancio wants to merge 1 commit intoROCKNIX:nextfrom
Zetarancio:sdl3-egl-gles-fallback-mali

Conversation

@Zetarancio
Copy link
Copy Markdown

After this #2345 on GLES-only stacks, eglBindAPI can fail while GLES remains valid. SDL3 EGL path currently treats a failed desktop-GL bind as fatal and returned NULL, which breaks apps that request an OpenGL window through the legacy stack (e.g. SDL 1.2 → box86 → SDL2-compat → SDL3 with SDL_OPENGL). With this if binding EGL_OPENGL_API fails, SDL retries EGL_OPENGL_ES_API before failing and allows GL-on-GLES layers to work.

The prior hard failurre on eglBindAPI is ok on desktop GL drivers, but on embedded Mali builds that only expose the GLES EGL API, the first bind fails. Wayland/SDL renderer fallback paths do not apply to raw SDL_GL_CreateContext / legacy OpenGL window creation.

If eglBindAPI(EGL_OPENGL_API) fails, call eglBindAPI(EGL_OPENGL_ES_API) and continue when that succeeds.
If both fail, set a single clear error: Could not bind EGL API (tried GL and GLES).

Verified with a PortMaster title using box86 + gl4es on an RK3566 device where only the Mali GLES path is available: check the logs.
Devices using native desktop GL (e.g. Mesa/Panfrost) are unaffected when EGL_OPENGL_API binds successfully on the first try and SHOULD BE unaffected when the first bind fails and then a retry is run.
log-postpatch.txt
log-panfrost.txt
log-prepatch.txt

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.
@Zetarancio Zetarancio marked this pull request as draft March 27, 2026 23:55
@sunshineinabox
Copy link
Copy Markdown
Contributor

There is already a built in mechanism for it to fall back to GLES if GL fails tho

@Zetarancio
Copy link
Copy Markdown
Author

There is already a built in mechanism for it to fall back to GLES if GL fails tho

I saw it but it does not work for direct calls. Yet my patch is bad because it fixes direct calls but breaks portmaster app and other apps too. We need a better approach.

@sunshineinabox
Copy link
Copy Markdown
Contributor

Yea I think this was my original intention just having full SDL2 package for things that aren't quiet there yet on sdl2-compat

@Zetarancio
Copy link
Copy Markdown
Author

Yea I think this was my original intention just having full SDL2 package for things that aren't quiet there yet on sdl2-compat

Something like this might work? No? aenertia@2beb321

@sunshineinabox
Copy link
Copy Markdown
Contributor

yup it would

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants