diff --git a/include/SDL_hints.h b/include/SDL_hints.h index fcc04e901..04e92e163 100644 --- a/include/SDL_hints.h +++ b/include/SDL_hints.h @@ -244,6 +244,17 @@ extern "C" { */ #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 * diff --git a/src/video/x11/SDL_x11opengl.c b/src/video/x11/SDL_x11opengl.c index 02364c245..8747ff2db 100644 --- a/src/video/x11/SDL_x11opengl.c +++ b/src/video/x11/SDL_x11opengl.c @@ -238,7 +238,8 @@ X11_GL_LoadLibrary(_THIS, const char *path) /* If we need a GL ES context and there's no * 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) ) { #if SDL_VIDEO_OPENGL_EGL X11_GL_UnloadLibrary(_this); @@ -649,8 +650,13 @@ SDL_bool X11_GL_UseEGL(_THIS) { 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) || _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 diff --git a/src/video/x11/SDL_x11opengles.c b/src/video/x11/SDL_x11opengles.c index 5c4890e1c..d3bdaa648 100644 --- a/src/video/x11/SDL_x11opengles.c +++ b/src/video/x11/SDL_x11opengles.c @@ -22,6 +22,7 @@ #if SDL_VIDEO_DRIVER_X11 && SDL_VIDEO_OPENGL_EGL +#include "SDL_hints.h" #include "SDL_x11video.h" #include "SDL_x11opengles.h" #include "SDL_x11opengl.h" @@ -34,7 +35,8 @@ X11_GLES_LoadLibrary(_THIS, const char *path) SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; /* 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 X11_GLES_UnloadLibrary(_this); _this->GL_LoadLibrary = X11_GL_LoadLibrary; diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c index 059b05d95..76cce5831 100644 --- a/src/video/x11/SDL_x11video.c +++ b/src/video/x11/SDL_x11video.c @@ -27,6 +27,7 @@ #include "SDL_video.h" #include "SDL_mouse.h" #include "SDL_timer.h" +#include "SDL_hints.h" #include "../SDL_sysvideo.h" #include "../SDL_pixels_c.h" @@ -276,16 +277,23 @@ X11_CreateDevice(int devindex) device->GL_GetSwapInterval = X11_GL_GetSwapInterval; device->GL_SwapWindow = X11_GL_SwapWindow; device->GL_DeleteContext = X11_GL_DeleteContext; -#elif SDL_VIDEO_OPENGL_EGL - device->GL_LoadLibrary = X11_GLES_LoadLibrary; - device->GL_GetProcAddress = X11_GLES_GetProcAddress; - device->GL_UnloadLibrary = X11_GLES_UnloadLibrary; - device->GL_CreateContext = X11_GLES_CreateContext; - 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; +#endif +#if SDL_VIDEO_OPENGL_EGL +#if SDL_VIDEO_OPENGL_GLX + if (SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_FORCE_EGL, SDL_FALSE)) { +#endif + device->GL_LoadLibrary = X11_GLES_LoadLibrary; + device->GL_GetProcAddress = X11_GLES_GetProcAddress; + device->GL_UnloadLibrary = X11_GLES_UnloadLibrary; + device->GL_CreateContext = X11_GLES_CreateContext; + 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 device->SetClipboardText = X11_SetClipboardText; diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c index d5b7fd04f..554da0661 100644 --- a/src/video/x11/SDL_x11window.c +++ b/src/video/x11/SDL_x11window.c @@ -418,7 +418,8 @@ X11_CreateWindow(_THIS, SDL_Window * window) XVisualInfo *vinfo = NULL; #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 && ( !_this->gl_data || X11_GL_UseEGL(_this) ) #endif @@ -628,9 +629,10 @@ X11_CreateWindow(_THIS, SDL_Window * window) } 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) && - _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 && ( !_this->gl_data || X11_GL_UseEGL(_this) ) #endif