libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.39k stars 1.74k forks source link

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

Open DynamoFox opened 1 month ago

DynamoFox commented 1 month ago

Hello.

Suppose:

Now, with commit https://github.com/libsdl-org/SDL/commit/bd2f1e9ea635b232d5aa39fb9f0326b1f134b99e (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:

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 https://github.com/libsdl-org/SDL/issues/8812#issuecomment-1885337310, 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 commented 1 month ago

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 commented 1 month ago

(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 commented 1 month ago

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 commented 1 month ago

Many apps/games don't even need glew like it is used (with glewInit), see: https://github.com/nigels-com/glew/pull/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.