From c608cf6222937ec339b2002a26f72a7abb773ebc Mon Sep 17 00:00:00 2001 From: Steven Noonan Date: Thu, 25 Aug 2022 20:29:41 -0700 Subject: [PATCH] egl: implement SDL_GL_EGL_PLATFORM attribute This implements a new SDL_GL_EGL_PLATFORM attribute to set the "platform" argument for SDL_EGL_LoadLibrary on Windows, macOS, and Linux. I've limited it to those three operating systems because that's what I've been able to test against. --- include/SDL_video.h | 3 ++- src/video/SDL_sysvideo.h | 1 + src/video/SDL_video.c | 11 +++++++++++ src/video/cocoa/SDL_cocoaopengles.m | 4 ++-- src/video/windows/SDL_windowsopengles.c | 4 ++-- src/video/x11/SDL_x11opengles.c | 2 +- 6 files changed, 19 insertions(+), 6 deletions(-) diff --git a/include/SDL_video.h b/include/SDL_video.h index 79d572fcc..8e9ed8da2 100644 --- a/include/SDL_video.h +++ b/include/SDL_video.h @@ -249,7 +249,8 @@ typedef enum SDL_GL_CONTEXT_RELEASE_BEHAVIOR, SDL_GL_CONTEXT_RESET_NOTIFICATION, SDL_GL_CONTEXT_NO_ERROR, - SDL_GL_FLOATBUFFERS + SDL_GL_FLOATBUFFERS, + SDL_GL_EGL_PLATFORM } SDL_GLattr; typedef enum diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index 4bc1f111f..20340da60 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -391,6 +391,7 @@ struct SDL_VideoDevice int framebuffer_srgb_capable; int no_error; int retained_backing; + int egl_platform; int driver_loaded; char driver_path[256]; void *dll_handle; diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 0bb5f0e9c..6f5d46855 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -3673,6 +3673,8 @@ SDL_GL_ResetAttributes() _this->gl_config.reset_notification = SDL_GL_CONTEXT_RESET_NO_NOTIFICATION; _this->gl_config.share_with_current_context = 0; + + _this->gl_config.egl_platform = 0; } int @@ -3789,6 +3791,9 @@ SDL_GL_SetAttribute(SDL_GLattr attr, int value) case SDL_GL_CONTEXT_NO_ERROR: _this->gl_config.no_error = value; break; + case SDL_GL_EGL_PLATFORM: + _this->gl_config.egl_platform = value; + break; default: retval = SDL_SetError("Unknown OpenGL attribute"); break; @@ -3998,6 +4003,12 @@ SDL_GL_GetAttribute(SDL_GLattr attr, int *value) *value = _this->gl_config.no_error; return 0; } + case SDL_GL_EGL_PLATFORM: + { + *value = _this->gl_config.egl_platform; + return 0; + } + break; default: return SDL_SetError("Unknown OpenGL attribute"); } diff --git a/src/video/cocoa/SDL_cocoaopengles.m b/src/video/cocoa/SDL_cocoaopengles.m index bdf2e9a08..04561b281 100644 --- a/src/video/cocoa/SDL_cocoaopengles.m +++ b/src/video/cocoa/SDL_cocoaopengles.m @@ -51,7 +51,7 @@ Cocoa_GLES_LoadLibrary(_THIS, const char *path) } if (_this->egl_data == NULL) { - return SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, 0); + return SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, _this->gl_config.egl_platform); } return 0; @@ -127,7 +127,7 @@ Cocoa_GLES_SetupWindow(_THIS, SDL_Window * window) #if 0 /* When hint SDL_HINT_OPENGL_ES_DRIVER is set to "1" (e.g. for ANGLE support), _this->gl_config.driver_loaded can be 1, while the below lines function. */ SDL_assert(!_this->gl_config.driver_loaded); #endif - if (SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, 0) < 0) { + if (SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, _this->gl_config.egl_platform) < 0) { SDL_EGL_UnloadLibrary(_this); return -1; } diff --git a/src/video/windows/SDL_windowsopengles.c b/src/video/windows/SDL_windowsopengles.c index 1e2a4f620..49cebd62d 100644 --- a/src/video/windows/SDL_windowsopengles.c +++ b/src/video/windows/SDL_windowsopengles.c @@ -52,7 +52,7 @@ WIN_GLES_LoadLibrary(_THIS, const char *path) { } if (_this->egl_data == NULL) { - return SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, 0); + return SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, _this->gl_config.egl_platform); } return 0; @@ -113,7 +113,7 @@ WIN_GLES_SetupWindow(_THIS, SDL_Window * window) #if 0 /* When hint SDL_HINT_OPENGL_ES_DRIVER is set to "1" (e.g. for ANGLE support), _this->gl_config.driver_loaded can be 1, while the below lines function. */ SDL_assert(!_this->gl_config.driver_loaded); #endif - if (SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, 0) < 0) { + if (SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, _this->gl_config.egl_platform) < 0) { SDL_EGL_UnloadLibrary(_this); return -1; } diff --git a/src/video/x11/SDL_x11opengles.c b/src/video/x11/SDL_x11opengles.c index 7641a6cc6..43d7a7d89 100644 --- a/src/video/x11/SDL_x11opengles.c +++ b/src/video/x11/SDL_x11opengles.c @@ -55,7 +55,7 @@ X11_GLES_LoadLibrary(_THIS, const char *path) #endif } - return SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType) data->display, 0); + return SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType) data->display, _this->gl_config.egl_platform); } XVisualInfo *