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

[Question - SDL2] Opt-out of "forcing X11" mech with GLEW&Co? #10385

Open
DynamoFox opened this issue Jul 26, 2024 · 4 comments
Open

[Question - SDL2] Opt-out of "forcing X11" mech with GLEW&Co? #10385

DynamoFox opened this issue Jul 26, 2024 · 4 comments
Assignees
Milestone

Comments

@DynamoFox
Copy link

DynamoFox commented Jul 26, 2024

Hello.

Suppose:

  • I have a game that supports the Vulkan and OpenGL API and that makes use of GLEW for the latter
  • The machine the game happens to be running on is Wayland-only (no XWayland available)
  • The game is smart enough to figure out that if it's running on Wayland it must not try to use OpenGL w/ GLEW
  • The game will link against GLEW regardless of it being used

Now, with commit bd2f1e9 (discussed in #8812), if I understand correctly, if we run the game on this Wayland-only system the video driver will be arbitrarily set to x11 regardless of the fact that:

  • The x11 isn't available at runtime on the machine
  • The game could actually have used the Vulkan API

In practice, this behavior results in the game failing to load complaining that "x11 isn't available" unless further action is taken by the developer or the enduser.

The matter can be generalized if we acknowledge that, as @smcv mentioned here #8812 (comment), on certain conditions the GLX flavour of GLEW actually works enough on Wayland and that a developer may actually want to use OpenGL regardless.

Now the question becomes, what is the intended way to opt-out of this "quirks" mechanism?
I suppose one must now do SDL_SetHint(SDL_HINT_VIDEODRIVER, "x11,wayland"), because this way the condition to trigger the new 'quirks' mech wouldn't trigger.

Can anybody confirm that that is the proper solution to the case? Is this intended?

CC: @slouken (as the author of the aforementioned commit)

Thank you :3

@icculus
Copy link
Collaborator

icculus commented Jul 26, 2024

The game is smart enough to figure out that if it's running on Wayland it must not try to use OpenGL w/ GLEW

The quickest fix is to set the environment variable SDL_VIDEODRIVER=wayland (or call SDL_SetHint(SDL_HINT_VIDEODRIVER, "wayland") before calling SDL_Init. SDL only does this quirk checking if the user or app didn't request a specific backend.

(If it's figuring out it's on Wayland by what backend SDL is choosing, we have a bigger problem and should probably have a separate hint to disable this check.)

@icculus
Copy link
Collaborator

icculus commented Jul 26, 2024

(Also, while we should make this work, my heretical opinion is no one should be using GLEW at all, since you can easily query the extensions and entry points you need through SDL without having this weird X11 dependency, but that's just my opinion.)

@smcv
Copy link
Contributor

smcv commented Jul 26, 2024

The quickest fix is to set the environment variable SDL_VIDEODRIVER=wayland (or call SDL_SetHint(SDL_HINT_VIDEODRIVER, "wayland") before calling SDL_Init. SDL only does this quirk checking if the user or app didn't request a specific backend.

If the game supports both Wayland and X11 equally well, and doesn't know ahead of time whether its users are going to be running it on a Wayland-only, X11-only or Wayland-and-Xwayland system, would SDL_SetHint(SDL_HINT_VIDEODRIVER, "x11,wayland") also work as an "official" way to disable the quirk, forcing SDL to try X11 and then Wayland in that order? (making SDL2's default behaviour explicit)

my heretical opinion is no one should be using GLEW at all

I don't think that's actually heretical, and I would tend to agree - but the motivation for #8812 was that there are already games that blindly assume X11 and will crash if it isn't used, and if SDL2 is going to meet its "safe to upgrade, no regressions" goal, then it needs to avoid breaking those games' assumptions, even if the assumptions are wrong.

Unfortunately there's no amount of "this is a bad pattern, don't use it in new code" that will fix pre-existing binaries!

@Jupeyy
Copy link
Contributor

Jupeyy commented Jul 26, 2024

Many apps/games don't even need glew like it is used (with glewInit), see:
nigels-com/glew#216
Which allows OpenGL extensions to be loaded but not all plattform specific extensions (egl extensions or whatever), which SDL does anyway.

Sadly the glew maintainer never released a version with that patch merged, so for example ddnet could never use glewContextInit, except when building glew from source. With glewContextInit wayland would run with any glew without any hacks.

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

No branches or pull requests

4 participants