| Summary: | Use EGL for X11? | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Ryan C. Gordon <icculus> |
| Component: | video | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | keyj-sdl, sylvain.becker |
| Version: | HG 2.0 | ||
| Hardware: | All | ||
| OS: | Linux | ||
| Attachments: |
patch
patch patch v2 patch_v3 |
||
|
Description
Ryan C. Gordon
2019-10-18 16:48:42 UTC
Not sure, but we have SDL_x11opengles.c that uses EGL. /* If we need a GL ES context and there's no * GLX_EXT_create_context_es2_profile extension, switch over to X11_GLES functions */ This can be forced with: SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); SDL_SetHint(SDL_HINT_OPENGL_ES_DRIVER, "1"); To be precise, this is about *desktop OpenGL* on X11. For OpenGL ES, EGL is already used (as it's the only way to get an OpenGL ES context), as Sylvain noted above. To shine some light on why this is needed: In 99% of all cases, using GLX on X11 is fine, even though it's effectively deprecated in favor of EGL [1]. However, there's at least one use case that *requires* the OpenGL context being created with EGL instead of GLX, and that's DRM_PRIME interoperability: The function glEGLImageTargetTexture2DOES simply doesn't work with GLX. (Currently, Mesa actually crashes when trying that.) Some example code: https://gist.github.com/kajott/d1b29c613be30893c855621edd1f212e Runs on Intel and open-source AMD drivers just fine (others unconfirmed), but with #define USE_EGL 0 (i.e. forcing it to GLX), it crashes. The same happens when using SDL for window and context creation. The good news is that most of the pieces for EGL support on X11 are already in place: SDL_egl.c is pretty complete (and used for desktop OpenGL on Wayland, for example), and SDL_x11opengl.c has the aforementioned OpenGL-ES-on-EGL support. However, when it comes to desktop OpenGL, it's hardcoded to fall back to GLX. I'm not advocating to make EGL the default for desktop OpenGL on X11; don't fix what ain't broken. But something like an SDL_HINT_VIDEO_X11_FORCE_EGL would be very appreciated to make use cases like the above work with SDL. [1] source: Eric Anholt, major Linux graphics stack developer, 7 years ago already - see last paragraph of https://www.phoronix.com/scan.php?page=news_item&px=MTE3MTI Created attachment 4019 [details]
patch
Here's a patch for the Hint.
It can either work like this or maybe just miss a lot of things !
Created attachment 4020 [details]
patch
I just rename extension of the file.
Ok, please ignore, it's missing probably more things :) Created attachment 4021 [details]
patch v2
Maybe this new version would be better
Created attachment 4186 [details]
patch_v3
Here's another patch. Verified to work with core, compatibility and ES2 profiles, both with GLX and EGL.
It's basically the same at Sylvain's v2 patch, but now really all GLS-vs-EGL decision points are addressed, and the logic to select the GL method implementations in SDL_x11video.c is a little more DRY now.
Looks good, thanks! https://hg.libsdl.org/SDL/rev/c0c6f54d2dce |