Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDL2] Set EGL surface for foreign X11 windows #10645

Open
wants to merge 1 commit into
base: SDL2
Choose a base branch
from

Conversation

CasualPokePlayer
Copy link

Ensures the EGL surface is set for foreign X11 windows.

Description

Moves the EGL surface creation code over to SetupWindowData so it works for foreign X11 windows too.

Also slightly changes up the cleanup code for SetupWindowData, to avoid copy pasting.

Existing Issue(s)

#10611

Also slightly changes up the cleanup code for SetupWindowData, to avoid copy pasting.

See libsdl-org#10611
@slouken
Copy link
Collaborator

slouken commented Aug 31, 2024

Thanks for the patch! What’s the use case for this?

@CasualPokePlayer
Copy link
Author

CasualPokePlayer commented Aug 31, 2024

My use case is with the BizHawk project, which uses SDL2 for OpenGL functionality. A WinForms handle is wrapped using SDL_CreateWindowFrom, and SDL_HINT_VIDEO_FOREIGN_WINDOW_OPENGL is set so this foreign window can use SDL's OpenGL API.

On Mono, this WinForms handle will just be an X11 window id. As such, SDL would normally end up using GLX for OpenGL. However, this seems to end up being problematic in one very dumb case: Nvidia proprietary drivers under XWayland, which end up always getting a BadMatch error once glXMakeCurrent is called (done at the end of context creation by SDL, so SDL's GL context creation function ends up reporting a failure).

This error is even stranger as cursory googling indicates this typically happens with Nvidia's proprietary drivers if you request a pixel format with alpha present, and one without alpha works fine. However, BizHawk already does specify 0 alpha bits, so I would assume this is just some other driver bug. Also of course, this error is XWayland specific, it does not occur under a pure X11 DE.

I have found out I can end up working around this bug by simply using EGL rather than GLX. While I can easily do this with SDL2 at a glance with SDL_HINT_VIDEO_X11_FORCE_EGL, it simply doesn't work due to the foreign window usage, as the EGL surface ends up only created with SDL created windows. With this patch, foreign X11 windows can use EGL, and I've had users affected by the driver bug report BizHawk working fine applying this workaround.

CasualPokePlayer added a commit to TASEmulators/BizHawk that referenced this pull request Sep 4, 2024
includes libsdl-org/SDL#10645 (waiting on merge)
CasualPokePlayer referenced this pull request in TASEmulators/BizHawk Sep 9, 2024
should fix Nvidia proprietary driver issues on XWayland
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