Skip to content

Commit ff54372

Browse files
Akaricchiicculus
authored andcommitted
Fix SDL_HINT_OPENGL_ES_DRIVER interaction with SDL_HINT_OPENGL_LIBRARY for x11 and windows
If SDL_HINT_OPENGL_ES_DRIVER is enabled and a GLES context is requested, don't try to load the WGL/GLX library. Doing so may fail, because SDL_HINT_OPENGL_LIBRARY may have been set to a custom libGLESv2 (e.g. ANGLE). This effectively restores the SDL2 behavior. Other video drivers shouldn't be affected, because they always use EGL for GLES. Incidentally, this patch also fixes a missing GL_GetEGLSurface callback in the X11 fallback path.
1 parent 62af66f commit ff54372

File tree

2 files changed

+53
-28
lines changed

2 files changed

+53
-28
lines changed

src/video/windows/SDL_windowsopengl.c

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,35 @@ typedef HGLRC(APIENTRYP PFNWGLCREATECONTEXTATTRIBSARBPROC)(HDC hDC,
106106
#define SetPixelFormat _this->gl_data->wglSetPixelFormat
107107
#endif
108108

109+
static bool WIN_GL_LoadLibrary_EGLFallback(SDL_VideoDevice *_this, const char *path)
110+
{
111+
#ifdef SDL_VIDEO_OPENGL_EGL
112+
WIN_GL_UnloadLibrary(_this);
113+
_this->GL_LoadLibrary = WIN_GLES_LoadLibrary;
114+
_this->GL_GetProcAddress = WIN_GLES_GetProcAddress;
115+
_this->GL_UnloadLibrary = WIN_GLES_UnloadLibrary;
116+
_this->GL_CreateContext = WIN_GLES_CreateContext;
117+
_this->GL_MakeCurrent = WIN_GLES_MakeCurrent;
118+
_this->GL_SetSwapInterval = WIN_GLES_SetSwapInterval;
119+
_this->GL_GetSwapInterval = WIN_GLES_GetSwapInterval;
120+
_this->GL_SwapWindow = WIN_GLES_SwapWindow;
121+
_this->GL_DestroyContext = WIN_GLES_DestroyContext;
122+
_this->GL_GetEGLSurface = WIN_GLES_GetEGLSurface;
123+
return WIN_GLES_LoadLibrary(_this, path);
124+
#else
125+
return SDL_SetError("SDL not configured with EGL support");
126+
#endif
127+
}
128+
109129
bool WIN_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path)
110130
{
111131
void *handle;
112132

133+
if ((_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) &&
134+
SDL_GetHintBoolean(SDL_HINT_OPENGL_ES_DRIVER, false)) {
135+
return WIN_GL_LoadLibrary_EGLFallback(_this, path);
136+
}
137+
113138
if (path == NULL) {
114139
path = SDL_GetHint(SDL_HINT_OPENGL_LIBRARY);
115140
}
@@ -740,19 +765,8 @@ SDL_GLContext WIN_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window)
740765
if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES && WIN_GL_UseEGL(_this)) {
741766
#ifdef SDL_VIDEO_OPENGL_EGL
742767
// Switch to EGL based functions
743-
WIN_GL_UnloadLibrary(_this);
744-
_this->GL_LoadLibrary = WIN_GLES_LoadLibrary;
745-
_this->GL_GetProcAddress = WIN_GLES_GetProcAddress;
746-
_this->GL_UnloadLibrary = WIN_GLES_UnloadLibrary;
747-
_this->GL_CreateContext = WIN_GLES_CreateContext;
748-
_this->GL_MakeCurrent = WIN_GLES_MakeCurrent;
749-
_this->GL_SetSwapInterval = WIN_GLES_SetSwapInterval;
750-
_this->GL_GetSwapInterval = WIN_GLES_GetSwapInterval;
751-
_this->GL_SwapWindow = WIN_GLES_SwapWindow;
752-
_this->GL_DestroyContext = WIN_GLES_DestroyContext;
753-
_this->GL_GetEGLSurface = WIN_GLES_GetEGLSurface;
754-
755-
if (!WIN_GLES_LoadLibrary(_this, NULL)) {
768+
769+
if (!WIN_GL_LoadLibrary_EGLFallback(_this, NULL)) {
756770
return NULL;
757771
}
758772

src/video/x11/SDL_x11opengl.c

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,26 @@ typedef GLXContext (*PFNGLXCREATECONTEXTATTRIBSARBPROC)(Display *dpy,
163163

164164
static void X11_GL_InitExtensions(SDL_VideoDevice *_this);
165165

166+
static bool X11_GL_LoadLibrary_EGLFallback(SDL_VideoDevice *_this, const char *path)
167+
{
168+
#ifdef SDL_VIDEO_OPENGL_EGL
169+
X11_GL_UnloadLibrary(_this);
170+
_this->GL_LoadLibrary = X11_GLES_LoadLibrary;
171+
_this->GL_GetProcAddress = X11_GLES_GetProcAddress;
172+
_this->GL_UnloadLibrary = X11_GLES_UnloadLibrary;
173+
_this->GL_CreateContext = X11_GLES_CreateContext;
174+
_this->GL_MakeCurrent = X11_GLES_MakeCurrent;
175+
_this->GL_SetSwapInterval = X11_GLES_SetSwapInterval;
176+
_this->GL_GetSwapInterval = X11_GLES_GetSwapInterval;
177+
_this->GL_SwapWindow = X11_GLES_SwapWindow;
178+
_this->GL_DestroyContext = X11_GLES_DestroyContext;
179+
_this->GL_GetEGLSurface = X11_GLES_GetEGLSurface;
180+
return X11_GLES_LoadLibrary(_this, path);
181+
#else
182+
return SDL_SetError("SDL not configured with EGL support");
183+
#endif
184+
}
185+
166186
bool X11_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path)
167187
{
168188
Display *display;
@@ -172,6 +192,11 @@ bool X11_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path)
172192
return SDL_SetError("OpenGL context already created");
173193
}
174194

195+
if ((_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) &&
196+
SDL_GetHintBoolean(SDL_HINT_OPENGL_ES_DRIVER, false)) {
197+
return X11_GL_LoadLibrary_EGLFallback(_this, path);
198+
}
199+
175200
// Load the OpenGL library
176201
if (path == NULL) {
177202
path = SDL_GetHint(SDL_HINT_OPENGL_LIBRARY);
@@ -254,21 +279,7 @@ bool X11_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path)
254279
if (((_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) ||
255280
SDL_GetHintBoolean(SDL_HINT_VIDEO_FORCE_EGL, false)) &&
256281
X11_GL_UseEGL(_this)) {
257-
#ifdef SDL_VIDEO_OPENGL_EGL
258-
X11_GL_UnloadLibrary(_this);
259-
_this->GL_LoadLibrary = X11_GLES_LoadLibrary;
260-
_this->GL_GetProcAddress = X11_GLES_GetProcAddress;
261-
_this->GL_UnloadLibrary = X11_GLES_UnloadLibrary;
262-
_this->GL_CreateContext = X11_GLES_CreateContext;
263-
_this->GL_MakeCurrent = X11_GLES_MakeCurrent;
264-
_this->GL_SetSwapInterval = X11_GLES_SetSwapInterval;
265-
_this->GL_GetSwapInterval = X11_GLES_GetSwapInterval;
266-
_this->GL_SwapWindow = X11_GLES_SwapWindow;
267-
_this->GL_DestroyContext = X11_GLES_DestroyContext;
268-
return X11_GLES_LoadLibrary(_this, NULL);
269-
#else
270-
return SDL_SetError("SDL not configured with EGL support");
271-
#endif
282+
return X11_GL_LoadLibrary_EGLFallback(_this, NULL);
272283
}
273284

274285
return true;

0 commit comments

Comments
 (0)