Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions Xcode/SDL/SDL.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Xcode/SDL/third-party/frameworks/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.framework
7 changes: 7 additions & 0 deletions Xcode/SDL/third-party/frameworks/README.md
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.
3 changes: 3 additions & 0 deletions include/SDL_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,9 @@
/* Enable Metal support */
#undef SDL_VIDEO_METAL

/* Enable MetalANGLE support */
#undef SDL_VIDEO_METALANGLE

/* Enable system power support */
#undef SDL_POWER_LINUX
#undef SDL_POWER_WINDOWS
Expand Down
2 changes: 1 addition & 1 deletion src/video/SDL_sysvideo.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ struct SDL_VideoDevice
struct SDL_EGL_VideoData *egl_data;
#endif

#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 || SDL_VIDEO_METALANGLE
Copy link
Copy Markdown
Contributor

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 how SDL_VIDEO_OPENGL_EGL is 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.

Copy link
Copy Markdown
Contributor Author

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_METALANGLE if it looks nice.

struct SDL_PrivateGLESData *gles_data;
#endif

Expand Down
22 changes: 15 additions & 7 deletions src/video/SDL_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Copy link
Copy Markdown
Contributor

@slime73 slime73 Apr 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these headers needed here if the code is changed to keep SDL_VIDEO_OPENGL_ES2 defined instead of making it mutually exclusive with the metal-angle backend?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be merged inside the SDL_opengles2.h file, with a #if SDL_VIDEO_OPENGL_METALANGLE #else ...

#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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/video/uikit/SDL_uikitevents.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "SDL_uikitvideo.h"
#include "SDL_uikitevents.h"
#include "SDL_uikitopengles.h"
#include "SDL_uikitmetalangle.h"

#import <Foundation/Foundation.h>

Expand Down Expand Up @@ -72,7 +73,7 @@ touch events to get processed (which is important to get certain
} while(result == kCFRunLoopRunHandledSource);

/* See the comment in the function definition. */
#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 || SDL_VIDEO_METALANGLE
UIKit_GL_RestoreCurrentContext();
#endif
}
Expand Down
44 changes: 44 additions & 0 deletions src/video/uikit/SDL_uikitmetalangle.h
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,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 SDL_uikitopengles etc. with a couple #ifdefs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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 src/video/uikit/SDL_uikitmetalangleview.m is going to be definitely cleaner into a separate file.

I will try to merge the two implementations when changing SDL_VIDEO_METALANGLE to SDL_VIDEO_OPENGL_METALANGLE unless it makes sense to have both on the same file.

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: */
Loading