diff options
Diffstat (limited to 'contrib/SDL-3.2.8/src/video/windows/SDL_windowsopengles.c')
| -rw-r--r-- | contrib/SDL-3.2.8/src/video/windows/SDL_windowsopengles.c | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/video/windows/SDL_windowsopengles.c b/contrib/SDL-3.2.8/src/video/windows/SDL_windowsopengles.c new file mode 100644 index 0000000..46f8ea3 --- /dev/null +++ b/contrib/SDL-3.2.8/src/video/windows/SDL_windowsopengles.c | |||
| @@ -0,0 +1,142 @@ | |||
| 1 | /* | ||
| 2 | Simple DirectMedia Layer | ||
| 3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> | ||
| 4 | |||
| 5 | This software is provided 'as-is', without any express or implied | ||
| 6 | warranty. In no event will the authors be held liable for any damages | ||
| 7 | arising from the use of this software. | ||
| 8 | |||
| 9 | Permission is granted to anyone to use this software for any purpose, | ||
| 10 | including commercial applications, and to alter it and redistribute it | ||
| 11 | freely, subject to the following restrictions: | ||
| 12 | |||
| 13 | 1. The origin of this software must not be misrepresented; you must not | ||
| 14 | claim that you wrote the original software. If you use this software | ||
| 15 | in a product, an acknowledgment in the product documentation would be | ||
| 16 | appreciated but is not required. | ||
| 17 | 2. Altered source versions must be plainly marked as such, and must not be | ||
| 18 | misrepresented as being the original software. | ||
| 19 | 3. This notice may not be removed or altered from any source distribution. | ||
| 20 | */ | ||
| 21 | #include "SDL_internal.h" | ||
| 22 | |||
| 23 | #if defined(SDL_VIDEO_DRIVER_WINDOWS) && defined(SDL_VIDEO_OPENGL_EGL) && !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) | ||
| 24 | |||
| 25 | #include "SDL_windowsvideo.h" | ||
| 26 | #include "SDL_windowsopengles.h" | ||
| 27 | #include "SDL_windowsopengl.h" | ||
| 28 | #include "SDL_windowswindow.h" | ||
| 29 | |||
| 30 | // EGL implementation of SDL OpenGL support | ||
| 31 | |||
| 32 | bool WIN_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) | ||
| 33 | { | ||
| 34 | |||
| 35 | // If the profile requested is not GL ES, switch over to WIN_GL functions | ||
| 36 | if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES && | ||
| 37 | !SDL_GetHintBoolean(SDL_HINT_VIDEO_FORCE_EGL, false)) { | ||
| 38 | #ifdef SDL_VIDEO_OPENGL_WGL | ||
| 39 | WIN_GLES_UnloadLibrary(_this); | ||
| 40 | _this->GL_LoadLibrary = WIN_GL_LoadLibrary; | ||
| 41 | _this->GL_GetProcAddress = WIN_GL_GetProcAddress; | ||
| 42 | _this->GL_UnloadLibrary = WIN_GL_UnloadLibrary; | ||
| 43 | _this->GL_CreateContext = WIN_GL_CreateContext; | ||
| 44 | _this->GL_MakeCurrent = WIN_GL_MakeCurrent; | ||
| 45 | _this->GL_SetSwapInterval = WIN_GL_SetSwapInterval; | ||
| 46 | _this->GL_GetSwapInterval = WIN_GL_GetSwapInterval; | ||
| 47 | _this->GL_SwapWindow = WIN_GL_SwapWindow; | ||
| 48 | _this->GL_DestroyContext = WIN_GL_DestroyContext; | ||
| 49 | _this->GL_GetEGLSurface = NULL; | ||
| 50 | return WIN_GL_LoadLibrary(_this, path); | ||
| 51 | #else | ||
| 52 | return SDL_SetError("SDL not configured with OpenGL/WGL support"); | ||
| 53 | #endif | ||
| 54 | } | ||
| 55 | |||
| 56 | if (!_this->egl_data) { | ||
| 57 | return SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, _this->gl_config.egl_platform); | ||
| 58 | } | ||
| 59 | |||
| 60 | return true; | ||
| 61 | } | ||
| 62 | |||
| 63 | SDL_GLContext WIN_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) | ||
| 64 | { | ||
| 65 | SDL_GLContext context; | ||
| 66 | SDL_WindowData *data = window->internal; | ||
| 67 | |||
| 68 | #ifdef SDL_VIDEO_OPENGL_WGL | ||
| 69 | if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES && | ||
| 70 | !SDL_GetHintBoolean(SDL_HINT_VIDEO_FORCE_EGL, false)) { | ||
| 71 | // Switch to WGL based functions | ||
| 72 | WIN_GLES_UnloadLibrary(_this); | ||
| 73 | _this->GL_LoadLibrary = WIN_GL_LoadLibrary; | ||
| 74 | _this->GL_GetProcAddress = WIN_GL_GetProcAddress; | ||
| 75 | _this->GL_UnloadLibrary = WIN_GL_UnloadLibrary; | ||
| 76 | _this->GL_CreateContext = WIN_GL_CreateContext; | ||
| 77 | _this->GL_MakeCurrent = WIN_GL_MakeCurrent; | ||
| 78 | _this->GL_SetSwapInterval = WIN_GL_SetSwapInterval; | ||
| 79 | _this->GL_GetSwapInterval = WIN_GL_GetSwapInterval; | ||
| 80 | _this->GL_SwapWindow = WIN_GL_SwapWindow; | ||
| 81 | _this->GL_DestroyContext = WIN_GL_DestroyContext; | ||
| 82 | _this->GL_GetEGLSurface = NULL; | ||
| 83 | |||
| 84 | if (!WIN_GL_LoadLibrary(_this, NULL)) { | ||
| 85 | return NULL; | ||
| 86 | } | ||
| 87 | |||
| 88 | return WIN_GL_CreateContext(_this, window); | ||
| 89 | } | ||
| 90 | #endif | ||
| 91 | |||
| 92 | context = SDL_EGL_CreateContext(_this, data->egl_surface); | ||
| 93 | return context; | ||
| 94 | } | ||
| 95 | |||
| 96 | bool WIN_GLES_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context) | ||
| 97 | { | ||
| 98 | return SDL_EGL_DestroyContext(_this, context); | ||
| 99 | } | ||
| 100 | |||
| 101 | /* *INDENT-OFF* */ // clang-format off | ||
| 102 | SDL_EGL_SwapWindow_impl(WIN) | ||
| 103 | SDL_EGL_MakeCurrent_impl(WIN) | ||
| 104 | /* *INDENT-ON* */ // clang-format on | ||
| 105 | |||
| 106 | bool WIN_GLES_SetupWindow(SDL_VideoDevice *_this, SDL_Window *window) | ||
| 107 | { | ||
| 108 | // The current context is lost in here; save it and reset it. | ||
| 109 | SDL_WindowData *windowdata = window->internal; | ||
| 110 | SDL_Window *current_win = SDL_GL_GetCurrentWindow(); | ||
| 111 | SDL_GLContext current_ctx = SDL_GL_GetCurrentContext(); | ||
| 112 | |||
| 113 | if (!_this->egl_data) { | ||
| 114 | // !!! FIXME: commenting out this assertion is (I think) incorrect; figure out why driver_loaded is wrong for ANGLE instead. --ryan. | ||
| 115 | #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. | ||
| 116 | SDL_assert(!_this->gl_config.driver_loaded); | ||
| 117 | #endif | ||
| 118 | if (!SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, _this->gl_config.egl_platform)) { | ||
| 119 | SDL_EGL_UnloadLibrary(_this); | ||
| 120 | return false; | ||
| 121 | } | ||
| 122 | _this->gl_config.driver_loaded = 1; | ||
| 123 | } | ||
| 124 | |||
| 125 | // Create the GLES window surface | ||
| 126 | windowdata->egl_surface = SDL_EGL_CreateSurface(_this, window, (NativeWindowType)windowdata->hwnd); | ||
| 127 | |||
| 128 | if (windowdata->egl_surface == EGL_NO_SURFACE) { | ||
| 129 | return SDL_SetError("Could not create GLES window surface"); | ||
| 130 | } | ||
| 131 | |||
| 132 | return WIN_GLES_MakeCurrent(_this, current_win, current_ctx); | ||
| 133 | } | ||
| 134 | |||
| 135 | EGLSurface WIN_GLES_GetEGLSurface(SDL_VideoDevice *_this, SDL_Window *window) | ||
| 136 | { | ||
| 137 | SDL_WindowData *windowdata = window->internal; | ||
| 138 | |||
| 139 | return windowdata->egl_surface; | ||
| 140 | } | ||
| 141 | |||
| 142 | #endif // SDL_VIDEO_DRIVER_WINDOWS && SDL_VIDEO_OPENGL_EGL | ||
