mirror of https://github.com/encounter/SDL.git
Fixed bug 4833 - Use EGL for X11?
Martin Fiedler 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
This commit is contained in:
parent
67f4478867
commit
4b585e75d9
|
@ -244,6 +244,17 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
#define SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR "SDL_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR"
|
#define SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR "SDL_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief A variable controlling whether X11 should use GLX or EGL by default
|
||||||
|
*
|
||||||
|
* This variable can be set to the following values:
|
||||||
|
* "0" - Use GLX
|
||||||
|
* "1" - Use EGL
|
||||||
|
*
|
||||||
|
* By default SDL will use GLX when both are present.
|
||||||
|
*/
|
||||||
|
#define SDL_HINT_VIDEO_X11_FORCE_EGL "SDL_VIDEO_X11_FORCE_EGL"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief A variable controlling whether the window frame and title bar are interactive when the cursor is hidden
|
* \brief A variable controlling whether the window frame and title bar are interactive when the cursor is hidden
|
||||||
*
|
*
|
||||||
|
|
|
@ -238,7 +238,8 @@ X11_GL_LoadLibrary(_THIS, const char *path)
|
||||||
/* If we need a GL ES context and there's no
|
/* If we need a GL ES context and there's no
|
||||||
* GLX_EXT_create_context_es2_profile extension, switch over to X11_GLES functions
|
* GLX_EXT_create_context_es2_profile extension, switch over to X11_GLES functions
|
||||||
*/
|
*/
|
||||||
if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES &&
|
if (((_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) ||
|
||||||
|
SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_FORCE_EGL, SDL_FALSE)) &&
|
||||||
X11_GL_UseEGL(_this) ) {
|
X11_GL_UseEGL(_this) ) {
|
||||||
#if SDL_VIDEO_OPENGL_EGL
|
#if SDL_VIDEO_OPENGL_EGL
|
||||||
X11_GL_UnloadLibrary(_this);
|
X11_GL_UnloadLibrary(_this);
|
||||||
|
@ -649,8 +650,13 @@ SDL_bool
|
||||||
X11_GL_UseEGL(_THIS)
|
X11_GL_UseEGL(_THIS)
|
||||||
{
|
{
|
||||||
SDL_assert(_this->gl_data != NULL);
|
SDL_assert(_this->gl_data != NULL);
|
||||||
SDL_assert(_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES);
|
if (SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_FORCE_EGL, SDL_FALSE))
|
||||||
|
{
|
||||||
|
/* use of EGL has been requested, even for desktop GL */
|
||||||
|
return SDL_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_assert(_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES);
|
||||||
return (SDL_GetHintBoolean(SDL_HINT_OPENGL_ES_DRIVER, SDL_FALSE)
|
return (SDL_GetHintBoolean(SDL_HINT_OPENGL_ES_DRIVER, SDL_FALSE)
|
||||||
|| _this->gl_config.major_version == 1 /* No GLX extension for OpenGL ES 1.x profiles. */
|
|| _this->gl_config.major_version == 1 /* No GLX extension for OpenGL ES 1.x profiles. */
|
||||||
|| _this->gl_config.major_version > _this->gl_data->es_profile_max_supported_version.major
|
|| _this->gl_config.major_version > _this->gl_data->es_profile_max_supported_version.major
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#if SDL_VIDEO_DRIVER_X11 && SDL_VIDEO_OPENGL_EGL
|
#if SDL_VIDEO_DRIVER_X11 && SDL_VIDEO_OPENGL_EGL
|
||||||
|
|
||||||
|
#include "SDL_hints.h"
|
||||||
#include "SDL_x11video.h"
|
#include "SDL_x11video.h"
|
||||||
#include "SDL_x11opengles.h"
|
#include "SDL_x11opengles.h"
|
||||||
#include "SDL_x11opengl.h"
|
#include "SDL_x11opengl.h"
|
||||||
|
@ -34,7 +35,8 @@ X11_GLES_LoadLibrary(_THIS, const char *path)
|
||||||
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
||||||
|
|
||||||
/* If the profile requested is not GL ES, switch over to X11_GL functions */
|
/* If the profile requested is not GL ES, switch over to X11_GL functions */
|
||||||
if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
|
if ((_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) &&
|
||||||
|
!SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_FORCE_EGL, SDL_FALSE)) {
|
||||||
#if SDL_VIDEO_OPENGL_GLX
|
#if SDL_VIDEO_OPENGL_GLX
|
||||||
X11_GLES_UnloadLibrary(_this);
|
X11_GLES_UnloadLibrary(_this);
|
||||||
_this->GL_LoadLibrary = X11_GL_LoadLibrary;
|
_this->GL_LoadLibrary = X11_GL_LoadLibrary;
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "SDL_video.h"
|
#include "SDL_video.h"
|
||||||
#include "SDL_mouse.h"
|
#include "SDL_mouse.h"
|
||||||
#include "SDL_timer.h"
|
#include "SDL_timer.h"
|
||||||
|
#include "SDL_hints.h"
|
||||||
#include "../SDL_sysvideo.h"
|
#include "../SDL_sysvideo.h"
|
||||||
#include "../SDL_pixels_c.h"
|
#include "../SDL_pixels_c.h"
|
||||||
|
|
||||||
|
@ -276,16 +277,23 @@ X11_CreateDevice(int devindex)
|
||||||
device->GL_GetSwapInterval = X11_GL_GetSwapInterval;
|
device->GL_GetSwapInterval = X11_GL_GetSwapInterval;
|
||||||
device->GL_SwapWindow = X11_GL_SwapWindow;
|
device->GL_SwapWindow = X11_GL_SwapWindow;
|
||||||
device->GL_DeleteContext = X11_GL_DeleteContext;
|
device->GL_DeleteContext = X11_GL_DeleteContext;
|
||||||
#elif SDL_VIDEO_OPENGL_EGL
|
#endif
|
||||||
device->GL_LoadLibrary = X11_GLES_LoadLibrary;
|
#if SDL_VIDEO_OPENGL_EGL
|
||||||
device->GL_GetProcAddress = X11_GLES_GetProcAddress;
|
#if SDL_VIDEO_OPENGL_GLX
|
||||||
device->GL_UnloadLibrary = X11_GLES_UnloadLibrary;
|
if (SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_FORCE_EGL, SDL_FALSE)) {
|
||||||
device->GL_CreateContext = X11_GLES_CreateContext;
|
#endif
|
||||||
device->GL_MakeCurrent = X11_GLES_MakeCurrent;
|
device->GL_LoadLibrary = X11_GLES_LoadLibrary;
|
||||||
device->GL_SetSwapInterval = X11_GLES_SetSwapInterval;
|
device->GL_GetProcAddress = X11_GLES_GetProcAddress;
|
||||||
device->GL_GetSwapInterval = X11_GLES_GetSwapInterval;
|
device->GL_UnloadLibrary = X11_GLES_UnloadLibrary;
|
||||||
device->GL_SwapWindow = X11_GLES_SwapWindow;
|
device->GL_CreateContext = X11_GLES_CreateContext;
|
||||||
device->GL_DeleteContext = X11_GLES_DeleteContext;
|
device->GL_MakeCurrent = X11_GLES_MakeCurrent;
|
||||||
|
device->GL_SetSwapInterval = X11_GLES_SetSwapInterval;
|
||||||
|
device->GL_GetSwapInterval = X11_GLES_GetSwapInterval;
|
||||||
|
device->GL_SwapWindow = X11_GLES_SwapWindow;
|
||||||
|
device->GL_DeleteContext = X11_GLES_DeleteContext;
|
||||||
|
#if SDL_VIDEO_OPENGL_GLX
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
device->SetClipboardText = X11_SetClipboardText;
|
device->SetClipboardText = X11_SetClipboardText;
|
||||||
|
|
|
@ -418,7 +418,8 @@ X11_CreateWindow(_THIS, SDL_Window * window)
|
||||||
XVisualInfo *vinfo = NULL;
|
XVisualInfo *vinfo = NULL;
|
||||||
|
|
||||||
#if SDL_VIDEO_OPENGL_EGL
|
#if SDL_VIDEO_OPENGL_EGL
|
||||||
if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES
|
if (((_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) ||
|
||||||
|
SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_FORCE_EGL, SDL_FALSE))
|
||||||
#if SDL_VIDEO_OPENGL_GLX
|
#if SDL_VIDEO_OPENGL_GLX
|
||||||
&& ( !_this->gl_data || X11_GL_UseEGL(_this) )
|
&& ( !_this->gl_data || X11_GL_UseEGL(_this) )
|
||||||
#endif
|
#endif
|
||||||
|
@ -628,9 +629,10 @@ X11_CreateWindow(_THIS, SDL_Window * window)
|
||||||
}
|
}
|
||||||
windowdata = (SDL_WindowData *) window->driverdata;
|
windowdata = (SDL_WindowData *) window->driverdata;
|
||||||
|
|
||||||
#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
|
#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 || SDL_VIDEO_OPENGL_EGL
|
||||||
if ((window->flags & SDL_WINDOW_OPENGL) &&
|
if ((window->flags & SDL_WINDOW_OPENGL) &&
|
||||||
_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES
|
((_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) ||
|
||||||
|
SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_FORCE_EGL, SDL_FALSE))
|
||||||
#if SDL_VIDEO_OPENGL_GLX
|
#if SDL_VIDEO_OPENGL_GLX
|
||||||
&& ( !_this->gl_data || X11_GL_UseEGL(_this) )
|
&& ( !_this->gl_data || X11_GL_UseEGL(_this) )
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue