diff --git a/include/SDL_hints.h b/include/SDL_hints.h index ce2225440f..2175cf11f3 100644 --- a/include/SDL_hints.h +++ b/include/SDL_hints.h @@ -1802,6 +1802,18 @@ extern "C" { */ #define SDL_HINT_VIDEO_WIN_D3DCOMPILER "SDL_VIDEO_WIN_D3DCOMPILER" +/** + * \brief A variable controlling whether the OpenGL context should be created + * with EGL by default + * + * This variable can be set to the following values: + * "0" - Use platform-specific GL context creation API (GLX, WGL, CGL, etc) + * "1" - Use EGL + * + * By default SDL will use the platform-specific GL context API when both are present. + */ +#define SDL_HINT_VIDEO_FORCE_EGL "SDL_VIDEO_FORCE_EGL" + /** * \brief A variable controlling whether X11 should use GLX or EGL by default * @@ -1810,6 +1822,9 @@ extern "C" { * "1" - Use EGL * * By default SDL will use GLX when both are present. + * + * \deprecated Use the platform-agnostic SDL_HINT_VIDEO_FORCE_EGL hint instead. + * */ #define SDL_HINT_VIDEO_X11_FORCE_EGL "SDL_VIDEO_X11_FORCE_EGL" diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c index 28d02b132c..a0e78b2bac 100644 --- a/src/video/SDL_egl.c +++ b/src/video/SDL_egl.c @@ -506,7 +506,7 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa * Khronos doc: "EGL_BAD_DISPLAY is generated if display is not an EGL display connection, unless display is EGL_NO_DISPLAY and name is EGL_EXTENSIONS." * Therefore SDL_EGL_GetVersion() shouldn't work with uninitialized display. * - it actually doesn't work on Android that has 1.5 egl client - * - it works on desktop X11 (using SDL_VIDEO_X11_FORCE_EGL=1) */ + * - it works on desktop X11 (using SDL_VIDEO_FORCE_EGL=1) */ SDL_EGL_GetVersion(_this); if (_this->egl_data->egl_version_major == 1 && _this->egl_data->egl_version_minor == 5) { diff --git a/src/video/cocoa/SDL_cocoavideo.m b/src/video/cocoa/SDL_cocoavideo.m index 6c3d44efae..d957184339 100644 --- a/src/video/cocoa/SDL_cocoavideo.m +++ b/src/video/cocoa/SDL_cocoavideo.m @@ -139,16 +139,23 @@ Cocoa_CreateDevice(void) device->GL_GetSwapInterval = Cocoa_GL_GetSwapInterval; device->GL_SwapWindow = Cocoa_GL_SwapWindow; device->GL_DeleteContext = Cocoa_GL_DeleteContext; -#elif SDL_VIDEO_OPENGL_EGL - device->GL_LoadLibrary = Cocoa_GLES_LoadLibrary; - device->GL_GetProcAddress = Cocoa_GLES_GetProcAddress; - device->GL_UnloadLibrary = Cocoa_GLES_UnloadLibrary; - device->GL_CreateContext = Cocoa_GLES_CreateContext; - device->GL_MakeCurrent = Cocoa_GLES_MakeCurrent; - device->GL_SetSwapInterval = Cocoa_GLES_SetSwapInterval; - device->GL_GetSwapInterval = Cocoa_GLES_GetSwapInterval; - device->GL_SwapWindow = Cocoa_GLES_SwapWindow; - device->GL_DeleteContext = Cocoa_GLES_DeleteContext; +#endif +#if SDL_VIDEO_OPENGL_EGL +#if SDL_VIDEO_OPENGL_CGL + if (SDL_GetHintBoolean(SDL_HINT_VIDEO_FORCE_EGL, SDL_FALSE)) { +#endif + device->GL_LoadLibrary = Cocoa_GLES_LoadLibrary; + device->GL_GetProcAddress = Cocoa_GLES_GetProcAddress; + device->GL_UnloadLibrary = Cocoa_GLES_UnloadLibrary; + device->GL_CreateContext = Cocoa_GLES_CreateContext; + device->GL_MakeCurrent = Cocoa_GLES_MakeCurrent; + device->GL_SetSwapInterval = Cocoa_GLES_SetSwapInterval; + device->GL_GetSwapInterval = Cocoa_GLES_GetSwapInterval; + device->GL_SwapWindow = Cocoa_GLES_SwapWindow; + device->GL_DeleteContext = Cocoa_GLES_DeleteContext; +#if SDL_VIDEO_OPENGL_CGL + } +#endif #endif #if SDL_VIDEO_VULKAN diff --git a/src/video/windows/SDL_windowsvideo.c b/src/video/windows/SDL_windowsvideo.c index 0dc107bdf2..bdf887bdb9 100644 --- a/src/video/windows/SDL_windowsvideo.c +++ b/src/video/windows/SDL_windowsvideo.c @@ -226,17 +226,24 @@ WIN_CreateDevice(void) device->GL_GetSwapInterval = WIN_GL_GetSwapInterval; device->GL_SwapWindow = WIN_GL_SwapWindow; device->GL_DeleteContext = WIN_GL_DeleteContext; -#elif SDL_VIDEO_OPENGL_EGL - /* Use EGL based functions */ - device->GL_LoadLibrary = WIN_GLES_LoadLibrary; - device->GL_GetProcAddress = WIN_GLES_GetProcAddress; - device->GL_UnloadLibrary = WIN_GLES_UnloadLibrary; - device->GL_CreateContext = WIN_GLES_CreateContext; - device->GL_MakeCurrent = WIN_GLES_MakeCurrent; - device->GL_SetSwapInterval = WIN_GLES_SetSwapInterval; - device->GL_GetSwapInterval = WIN_GLES_GetSwapInterval; - device->GL_SwapWindow = WIN_GLES_SwapWindow; - device->GL_DeleteContext = WIN_GLES_DeleteContext; +#endif +#if SDL_VIDEO_OPENGL_EGL +#if SDL_VIDEO_OPENGL_WGL + if (SDL_GetHintBoolean(SDL_HINT_VIDEO_FORCE_EGL, SDL_FALSE)) { +#endif + /* Use EGL based functions */ + device->GL_LoadLibrary = WIN_GLES_LoadLibrary; + device->GL_GetProcAddress = WIN_GLES_GetProcAddress; + device->GL_UnloadLibrary = WIN_GLES_UnloadLibrary; + device->GL_CreateContext = WIN_GLES_CreateContext; + device->GL_MakeCurrent = WIN_GLES_MakeCurrent; + device->GL_SetSwapInterval = WIN_GLES_SetSwapInterval; + device->GL_GetSwapInterval = WIN_GLES_GetSwapInterval; + device->GL_SwapWindow = WIN_GLES_SwapWindow; + device->GL_DeleteContext = WIN_GLES_DeleteContext; +#if SDL_VIDEO_OPENGL_WGL + } +#endif #endif #if SDL_VIDEO_VULKAN device->Vulkan_LoadLibrary = WIN_Vulkan_LoadLibrary; diff --git a/src/video/x11/SDL_x11opengl.c b/src/video/x11/SDL_x11opengl.c index 60b2203cdf..8c728ea970 100644 --- a/src/video/x11/SDL_x11opengl.c +++ b/src/video/x11/SDL_x11opengl.c @@ -253,6 +253,7 @@ X11_GL_LoadLibrary(_THIS, const char *path) * GLX_EXT_create_context_es2_profile extension, switch over to X11_GLES functions */ if (((_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) || + SDL_GetHintBoolean(SDL_HINT_VIDEO_FORCE_EGL, SDL_FALSE) || SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_FORCE_EGL, SDL_FALSE)) && X11_GL_UseEGL(_this) ) { #if SDL_VIDEO_OPENGL_EGL @@ -691,7 +692,8 @@ SDL_bool X11_GL_UseEGL(_THIS) { SDL_assert(_this->gl_data != NULL); - if (SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_FORCE_EGL, SDL_FALSE)) + if (SDL_GetHintBoolean(SDL_HINT_VIDEO_FORCE_EGL, SDL_FALSE) || + SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_FORCE_EGL, SDL_FALSE)) { /* use of EGL has been requested, even for desktop GL */ return SDL_TRUE; diff --git a/src/video/x11/SDL_x11opengles.c b/src/video/x11/SDL_x11opengles.c index e1ec4e4d2a..7641a6cc64 100644 --- a/src/video/x11/SDL_x11opengles.c +++ b/src/video/x11/SDL_x11opengles.c @@ -36,6 +36,7 @@ X11_GLES_LoadLibrary(_THIS, const char *path) /* 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) && + !SDL_GetHintBoolean(SDL_HINT_VIDEO_FORCE_EGL, SDL_FALSE) && !SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_FORCE_EGL, SDL_FALSE)) { #if SDL_VIDEO_OPENGL_GLX X11_GLES_UnloadLibrary(_this); diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c index 2e5e190bd0..569e995f3d 100644 --- a/src/video/x11/SDL_x11video.c +++ b/src/video/x11/SDL_x11video.c @@ -282,7 +282,8 @@ X11_CreateDevice(void) #endif #if SDL_VIDEO_OPENGL_EGL #if SDL_VIDEO_OPENGL_GLX - if (SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_FORCE_EGL, SDL_FALSE)) { + if (SDL_GetHintBoolean(SDL_HINT_VIDEO_FORCE_EGL, SDL_FALSE) || + SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_FORCE_EGL, SDL_FALSE)) { #endif device->GL_LoadLibrary = X11_GLES_LoadLibrary; device->GL_GetProcAddress = X11_GLES_GetProcAddress; diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c index 9b007e79d7..8e08be753f 100644 --- a/src/video/x11/SDL_x11window.c +++ b/src/video/x11/SDL_x11window.c @@ -429,6 +429,7 @@ X11_CreateWindow(_THIS, SDL_Window * window) #if SDL_VIDEO_OPENGL_EGL if (((_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) || + SDL_GetHintBoolean(SDL_HINT_VIDEO_FORCE_EGL, SDL_FALSE) || SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_FORCE_EGL, SDL_FALSE)) #if SDL_VIDEO_OPENGL_GLX && ( !_this->gl_data || X11_GL_UseEGL(_this) )