diff options
| author | 3gg <3gg@shellblade.net> | 2025-12-27 12:03:39 -0800 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2025-12-27 12:03:39 -0800 |
| commit | 5a079a2d114f96d4847d1ee305d5b7c16eeec50e (patch) | |
| tree | 8926ab44f168acf787d8e19608857b3af0f82758 /contrib/SDL-3.2.8/src/video/cocoa/SDL_cocoaopengles.m | |
Initial commit
Diffstat (limited to 'contrib/SDL-3.2.8/src/video/cocoa/SDL_cocoaopengles.m')
| -rw-r--r-- | contrib/SDL-3.2.8/src/video/cocoa/SDL_cocoaopengles.m | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/video/cocoa/SDL_cocoaopengles.m b/contrib/SDL-3.2.8/src/video/cocoa/SDL_cocoaopengles.m new file mode 100644 index 0000000..053ddc9 --- /dev/null +++ b/contrib/SDL-3.2.8/src/video/cocoa/SDL_cocoaopengles.m | |||
| @@ -0,0 +1,156 @@ | |||
| 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_COCOA) && defined(SDL_VIDEO_OPENGL_EGL) | ||
| 24 | |||
| 25 | #include "SDL_cocoavideo.h" | ||
| 26 | #include "SDL_cocoaopengles.h" | ||
| 27 | #include "SDL_cocoaopengl.h" | ||
| 28 | |||
| 29 | // EGL implementation of SDL OpenGL support | ||
| 30 | |||
| 31 | bool Cocoa_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) | ||
| 32 | { | ||
| 33 | // If the profile requested is not GL ES, switch over to WIN_GL functions | ||
| 34 | if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) { | ||
| 35 | #ifdef SDL_VIDEO_OPENGL_CGL | ||
| 36 | Cocoa_GLES_UnloadLibrary(_this); | ||
| 37 | _this->GL_LoadLibrary = Cocoa_GL_LoadLibrary; | ||
| 38 | _this->GL_GetProcAddress = Cocoa_GL_GetProcAddress; | ||
| 39 | _this->GL_UnloadLibrary = Cocoa_GL_UnloadLibrary; | ||
| 40 | _this->GL_CreateContext = Cocoa_GL_CreateContext; | ||
| 41 | _this->GL_MakeCurrent = Cocoa_GL_MakeCurrent; | ||
| 42 | _this->GL_SetSwapInterval = Cocoa_GL_SetSwapInterval; | ||
| 43 | _this->GL_GetSwapInterval = Cocoa_GL_GetSwapInterval; | ||
| 44 | _this->GL_SwapWindow = Cocoa_GL_SwapWindow; | ||
| 45 | _this->GL_DestroyContext = Cocoa_GL_DestroyContext; | ||
| 46 | _this->GL_GetEGLSurface = NULL; | ||
| 47 | return Cocoa_GL_LoadLibrary(_this, path); | ||
| 48 | #else | ||
| 49 | return SDL_SetError("SDL not configured with OpenGL/CGL support"); | ||
| 50 | #endif | ||
| 51 | } | ||
| 52 | |||
| 53 | if (_this->egl_data == NULL) { | ||
| 54 | return SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, _this->gl_config.egl_platform); | ||
| 55 | } | ||
| 56 | |||
| 57 | return true; | ||
| 58 | } | ||
| 59 | |||
| 60 | SDL_GLContext Cocoa_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) | ||
| 61 | { | ||
| 62 | @autoreleasepool { | ||
| 63 | SDL_GLContext context; | ||
| 64 | SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->internal; | ||
| 65 | |||
| 66 | #ifdef SDL_VIDEO_OPENGL_CGL | ||
| 67 | if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) { | ||
| 68 | // Switch to CGL based functions | ||
| 69 | Cocoa_GLES_UnloadLibrary(_this); | ||
| 70 | _this->GL_LoadLibrary = Cocoa_GL_LoadLibrary; | ||
| 71 | _this->GL_GetProcAddress = Cocoa_GL_GetProcAddress; | ||
| 72 | _this->GL_UnloadLibrary = Cocoa_GL_UnloadLibrary; | ||
| 73 | _this->GL_CreateContext = Cocoa_GL_CreateContext; | ||
| 74 | _this->GL_MakeCurrent = Cocoa_GL_MakeCurrent; | ||
| 75 | _this->GL_SetSwapInterval = Cocoa_GL_SetSwapInterval; | ||
| 76 | _this->GL_GetSwapInterval = Cocoa_GL_GetSwapInterval; | ||
| 77 | _this->GL_SwapWindow = Cocoa_GL_SwapWindow; | ||
| 78 | _this->GL_DestroyContext = Cocoa_GL_DestroyContext; | ||
| 79 | _this->GL_GetEGLSurface = NULL; | ||
| 80 | |||
| 81 | if (!Cocoa_GL_LoadLibrary(_this, NULL)) { | ||
| 82 | return NULL; | ||
| 83 | } | ||
| 84 | |||
| 85 | return Cocoa_GL_CreateContext(_this, window); | ||
| 86 | } | ||
| 87 | #endif | ||
| 88 | |||
| 89 | context = SDL_EGL_CreateContext(_this, data.egl_surface); | ||
| 90 | return context; | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 | bool Cocoa_GLES_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context) | ||
| 95 | { | ||
| 96 | @autoreleasepool { | ||
| 97 | SDL_EGL_DestroyContext(_this, context); | ||
| 98 | } | ||
| 99 | return true; | ||
| 100 | } | ||
| 101 | |||
| 102 | bool Cocoa_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) | ||
| 103 | { | ||
| 104 | @autoreleasepool { | ||
| 105 | return SDL_EGL_SwapBuffers(_this, ((__bridge SDL_CocoaWindowData *)window->internal).egl_surface); | ||
| 106 | } | ||
| 107 | } | ||
| 108 | |||
| 109 | bool Cocoa_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) | ||
| 110 | { | ||
| 111 | @autoreleasepool { | ||
| 112 | return SDL_EGL_MakeCurrent(_this, window ? ((__bridge SDL_CocoaWindowData *)window->internal).egl_surface : EGL_NO_SURFACE, context); | ||
| 113 | } | ||
| 114 | } | ||
| 115 | |||
| 116 | bool Cocoa_GLES_SetupWindow(SDL_VideoDevice *_this, SDL_Window *window) | ||
| 117 | { | ||
| 118 | @autoreleasepool { | ||
| 119 | NSView *v; | ||
| 120 | // The current context is lost in here; save it and reset it. | ||
| 121 | SDL_CocoaWindowData *windowdata = (__bridge SDL_CocoaWindowData *)window->internal; | ||
| 122 | SDL_Window *current_win = SDL_GL_GetCurrentWindow(); | ||
| 123 | SDL_GLContext current_ctx = SDL_GL_GetCurrentContext(); | ||
| 124 | |||
| 125 | if (_this->egl_data == NULL) { | ||
| 126 | // !!! FIXME: commenting out this assertion is (I think) incorrect; figure out why driver_loaded is wrong for ANGLE instead. --ryan. | ||
| 127 | #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. | ||
| 128 | SDL_assert(!_this->gl_config.driver_loaded); | ||
| 129 | #endif | ||
| 130 | if (!SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, _this->gl_config.egl_platform)) { | ||
| 131 | SDL_EGL_UnloadLibrary(_this); | ||
| 132 | return false; | ||
| 133 | } | ||
| 134 | _this->gl_config.driver_loaded = 1; | ||
| 135 | } | ||
| 136 | |||
| 137 | // Create the GLES window surface | ||
| 138 | v = windowdata.nswindow.contentView; | ||
| 139 | windowdata.egl_surface = SDL_EGL_CreateSurface(_this, window, (__bridge NativeWindowType)[v layer]); | ||
| 140 | |||
| 141 | if (windowdata.egl_surface == EGL_NO_SURFACE) { | ||
| 142 | return SDL_SetError("Could not create GLES window surface"); | ||
| 143 | } | ||
| 144 | |||
| 145 | return Cocoa_GLES_MakeCurrent(_this, current_win, current_ctx); | ||
| 146 | } | ||
| 147 | } | ||
| 148 | |||
| 149 | SDL_EGLSurface Cocoa_GLES_GetEGLSurface(SDL_VideoDevice *_this, SDL_Window *window) | ||
| 150 | { | ||
| 151 | @autoreleasepool { | ||
| 152 | return ((__bridge SDL_CocoaWindowData *)window->internal).egl_surface; | ||
| 153 | } | ||
| 154 | } | ||
| 155 | |||
| 156 | #endif // SDL_VIDEO_DRIVER_COCOA && SDL_VIDEO_OPENGL_EGL | ||
