-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add support for MetalANGLE on UIKit (OpenGL ES to Metal API translation layer) #4333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| *.framework |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Why this folder is here? | ||
|
|
||
| SDL Xcode project is using this folder for managing third-party components (like external Frameworks) that are needed during the build phase. | ||
|
|
||
| ### Usage: | ||
|
|
||
| If you're building **SDL** with **MetalANGLE** support, just copy + paste your `MetalANGLE.framework` here. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,14 @@ | |
| #include "SDL_opengles2.h" | ||
| #endif /* SDL_VIDEO_OPENGL_ES2 && !SDL_VIDEO_OPENGL */ | ||
|
|
||
| #if SDL_VIDEO_METALANGLE | ||
| #include <MetalANGLE/GLES2/gl2.h> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these headers needed here if the code is changed to keep
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be merged inside the |
||
| #include <MetalANGLE/GLES2/gl2ext.h> | ||
| #ifndef APIENTRY | ||
| #define APIENTRY GL_APIENTRY | ||
| #endif | ||
| #endif /* SDL_VIDEO_METALANGLE */ | ||
|
|
||
| #if !SDL_VIDEO_OPENGL | ||
| #ifndef GL_CONTEXT_RELEASE_BEHAVIOR_KHR | ||
| #define GL_CONTEXT_RELEASE_BEHAVIOR_KHR 0x82FB | ||
|
|
@@ -247,7 +255,7 @@ ShouldUseTextureFramebuffer() | |
| } | ||
| return hasAcceleratedOpenGL; | ||
| } | ||
| #elif SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 | ||
| #elif SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 || SDL_VIDEO_METALANGLE | ||
| /* Let's be optimistic about this! */ | ||
| return SDL_TRUE; | ||
| #else | ||
|
|
@@ -3158,7 +3166,7 @@ SDL_GL_UnloadLibrary(void) | |
| } | ||
| } | ||
|
|
||
| #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 | ||
| #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 || SDL_VIDEO_METALANGLE | ||
| static SDL_INLINE SDL_bool | ||
| isAtLeastGL3(const char *verstr) | ||
| { | ||
|
|
@@ -3169,7 +3177,7 @@ isAtLeastGL3(const char *verstr) | |
| SDL_bool | ||
| SDL_GL_ExtensionSupported(const char *extension) | ||
| { | ||
| #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 | ||
| #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 || SDL_VIDEO_METALANGLE | ||
| const GLubyte *(APIENTRY * glGetStringFunc) (GLenum); | ||
| const char *extensions; | ||
| const char *start; | ||
|
|
@@ -3261,7 +3269,7 @@ SDL_GL_DeduceMaxSupportedESProfile(int* major, int* minor) | |
| { | ||
| /* THIS REQUIRES AN EXISTING GL CONTEXT THAT HAS BEEN MADE CURRENT. */ | ||
| /* Please refer to https://bugzilla.libsdl.org/show_bug.cgi?id=3725 for discussion. */ | ||
| #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 | ||
| #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 || SDL_VIDEO_METALANGLE | ||
| /* XXX This is fragile; it will break in the event of release of | ||
| * new versions of OpenGL ES. | ||
| */ | ||
|
|
@@ -3310,7 +3318,7 @@ SDL_GL_ResetAttributes() | |
| _this->gl_config.major_version = 2; | ||
| _this->gl_config.minor_version = 1; | ||
| _this->gl_config.profile_mask = 0; | ||
| #elif SDL_VIDEO_OPENGL_ES2 | ||
| #elif SDL_VIDEO_OPENGL_ES2 || SDL_VIDEO_METALANGLE | ||
| _this->gl_config.major_version = 2; | ||
| _this->gl_config.minor_version = 0; | ||
| _this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES; | ||
|
|
@@ -3338,7 +3346,7 @@ SDL_GL_ResetAttributes() | |
| int | ||
| SDL_GL_SetAttribute(SDL_GLattr attr, int value) | ||
| { | ||
| #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 | ||
| #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 || SDL_VIDEO_METALANGLE | ||
| int retval; | ||
|
|
||
| if (!_this) { | ||
|
|
@@ -3459,7 +3467,7 @@ SDL_GL_SetAttribute(SDL_GLattr attr, int value) | |
| int | ||
| SDL_GL_GetAttribute(SDL_GLattr attr, int *value) | ||
| { | ||
| #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 | ||
| #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 || SDL_VIDEO_METALANGLE | ||
| GLenum (APIENTRY *glGetErrorFunc) (void); | ||
| GLenum attrib = 0; | ||
| GLenum error = 0; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| Simple DirectMedia Layer | ||
| Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org> | ||
|
|
||
| This software is provided 'as-is', without any express or implied | ||
| warranty. In no event will the authors be held liable for any damages | ||
| arising from the use of this software. | ||
|
|
||
| Permission is granted to anyone to use this software for any purpose, | ||
| including commercial applications, and to alter it and redistribute it | ||
| freely, subject to the following restrictions: | ||
|
|
||
| 1. The origin of this software must not be misrepresented; you must not | ||
| claim that you wrote the original software. If you use this software | ||
| in a product, an acknowledgment in the product documentation would be | ||
| appreciated but is not required. | ||
| 2. Altered source versions must be plainly marked as such, and must not be | ||
| misrepresented as being the original software. | ||
| 3. This notice may not be removed or altered from any source distribution. | ||
| */ | ||
| #ifndef SDL_uikitmetalangle_ | ||
| #define SDL_uikitmetalangle_ | ||
|
|
||
| #if SDL_VIDEO_METALANGLE | ||
|
|
||
| #include "../SDL_sysvideo.h" | ||
|
|
||
| extern int UIKit_GL_MakeCurrent(_THIS, SDL_Window * window, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These files have a lot of duplicate code. I wonder if it might be cleaner to merge it all into
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uhm, there's a lot of duplicated code (especially for the header files), but, instead I will try to merge the two implementations when changing |
||
| SDL_GLContext context); | ||
| extern void UIKit_GL_GetDrawableSize(_THIS, SDL_Window * window, | ||
| int * w, int * h); | ||
| extern int UIKit_GL_SwapWindow(_THIS, SDL_Window * window); | ||
| extern SDL_GLContext UIKit_GL_CreateContext(_THIS, SDL_Window * window); | ||
| extern void UIKit_GL_DeleteContext(_THIS, SDL_GLContext context); | ||
| extern void *UIKit_GL_GetProcAddress(_THIS, const char *proc); | ||
| extern int UIKit_GL_LoadLibrary(_THIS, const char *path); | ||
|
|
||
| extern void UIKit_GL_RestoreCurrentContext(void); | ||
|
|
||
| #endif SDL_VIDEO_METALANGLE | ||
|
|
||
| #endif /* SDL_uikitmetalangle_ */ | ||
|
|
||
| /* vi: set ts=4 sw=4 expandtab: */ | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a better approach would be to do a similar thing to the
EGL,CGL,GLX, etc. opengl context backend defines (you can see some examples by looking at howSDL_VIDEO_OPENGL_EGLis used) – I don't think code here needs to care whether metal-ANGLE is used to create the OpenGL ES context, since it's just an implementation of the OpenGL ES API.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, and it makes sense.
I'm going for a
SDL_VIDEO_OPENGL_METALANGLEif it looks nice.