mirror of
https://github.com/love2d/love.git
synced 2026-08-18 03:34:23 +02:00
iOS: fix compile errors when SDL3 is used
This commit is contained in:
+31
-1
@@ -35,9 +35,16 @@ using namespace love::apple;
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#if __has_include(<SDL3/SDL_events.h>)
|
||||||
|
#include <SDL3/SDL_events.h>
|
||||||
|
#include <SDL3/SDL_video.h>
|
||||||
|
#include <SDL3/SDL_version.h>
|
||||||
|
#else
|
||||||
#include <SDL_events.h>
|
#include <SDL_events.h>
|
||||||
#include <SDL_video.h>
|
#include <SDL_video.h>
|
||||||
#include <SDL_syswm.h>
|
#include <SDL_syswm.h>
|
||||||
|
#include <SDL_version.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
static NSArray *getLovesInDocuments();
|
static NSArray *getLovesInDocuments();
|
||||||
static bool deleteFileInDocuments(NSString *filename);
|
static bool deleteFileInDocuments(NSString *filename);
|
||||||
@@ -167,14 +174,27 @@ static bool deleteFileInDocuments(NSString *filename)
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dropFileEventFilter(void *userdata, SDL_Event *event)
|
#if SDL_VERSION_ATLEAST(3, 0, 0)
|
||||||
|
static bool
|
||||||
|
#else
|
||||||
|
static int
|
||||||
|
#endif
|
||||||
|
dropFileEventFilter(void *userdata, SDL_Event *event)
|
||||||
{
|
{
|
||||||
@autoreleasepool
|
@autoreleasepool
|
||||||
{
|
{
|
||||||
|
#if SDL_VERSION_ATLEAST(3, 0, 0)
|
||||||
|
if (event->type != SDL_EVENT_DROP_FILE)
|
||||||
|
#else
|
||||||
if (event->type != SDL_DROPFILE)
|
if (event->type != SDL_DROPFILE)
|
||||||
|
#endif
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
#if SDL_VERSION_ATLEAST(3, 0, 0)
|
||||||
|
NSString *fname = @(event->drop.data);
|
||||||
|
#else
|
||||||
NSString *fname = @(event->drop.file);
|
NSString *fname = @(event->drop.file);
|
||||||
|
#endif
|
||||||
NSFileManager *fmanager = [NSFileManager defaultManager];
|
NSFileManager *fmanager = [NSFileManager defaultManager];
|
||||||
|
|
||||||
if ([fmanager fileExistsAtPath:fname] && [fname.pathExtension isEqual:@"love"])
|
if ([fmanager fileExistsAtPath:fname] && [fname.pathExtension isEqual:@"love"])
|
||||||
@@ -195,7 +215,9 @@ static int dropFileEventFilter(void *userdata, SDL_Event *event)
|
|||||||
vc.gameList = [[NSMutableArray alloc] initWithArray:games copyItems:YES];
|
vc.gameList = [[NSMutableArray alloc] initWithArray:games copyItems:YES];
|
||||||
[vc.tableView reloadData];
|
[vc.tableView reloadData];
|
||||||
|
|
||||||
|
#if !SDL_VERSION_ATLEAST(3, 0, 0)
|
||||||
SDL_free(event->drop.file);
|
SDL_free(event->drop.file);
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -434,11 +456,19 @@ Rect getSafeArea(SDL_Window *window)
|
|||||||
Rect rect = {};
|
Rect rect = {};
|
||||||
SDL_GetWindowSize(window, &rect.w, &rect.h);
|
SDL_GetWindowSize(window, &rect.w, &rect.h);
|
||||||
|
|
||||||
|
#if SDL_VERSION_ATLEAST(3, 0, 0)
|
||||||
|
SDL_PropertiesID props = SDL_GetWindowProperties(window);
|
||||||
|
UIWindow *window = (__bridge UIWindow *) SDL_GetPointerProperty(props, SDL_PROP_WINDOW_UIKIT_WINDOW_POINTER, nullptr);
|
||||||
|
if (window != nil)
|
||||||
|
{
|
||||||
|
UIView *view = window.rootViewController.view;
|
||||||
|
#else
|
||||||
SDL_SysWMinfo info = {};
|
SDL_SysWMinfo info = {};
|
||||||
SDL_VERSION(&info.version);
|
SDL_VERSION(&info.version);
|
||||||
if (SDL_GetWindowWMInfo(window, &info))
|
if (SDL_GetWindowWMInfo(window, &info))
|
||||||
{
|
{
|
||||||
UIView *view = info.info.uikit.window.rootViewController.view;
|
UIView *view = info.info.uikit.window.rootViewController.view;
|
||||||
|
#endif
|
||||||
if (@available(iOS 11.0, tvOS 11.0, *))
|
if (@available(iOS 11.0, tvOS 11.0, *))
|
||||||
{
|
{
|
||||||
UIEdgeInsets insets = view.safeAreaInsets;
|
UIEdgeInsets insets = view.safeAreaInsets;
|
||||||
|
|||||||
@@ -45,7 +45,13 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
#ifdef LOVE_IOS
|
#ifdef LOVE_IOS
|
||||||
|
#if __has_include(<SDL3/SDL_video.h>)
|
||||||
|
#include <SDL3/SDL_video.h>
|
||||||
|
#include <SDL3/SDL_version.h>
|
||||||
|
#else
|
||||||
#include <SDL_syswm.h>
|
#include <SDL_syswm.h>
|
||||||
|
#include <SDL_version.h>
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace love
|
namespace love
|
||||||
@@ -282,6 +288,14 @@ GLuint Graphics::getSystemBackbufferFBO() const
|
|||||||
{
|
{
|
||||||
#ifdef LOVE_IOS
|
#ifdef LOVE_IOS
|
||||||
// Hack: iOS uses a custom FBO.
|
// Hack: iOS uses a custom FBO.
|
||||||
|
#if SDL_VERSION_ATLEAST(3, 0, 0)
|
||||||
|
SDL_PropertiesID props = SDL_GetWindowProperties(SDL_GL_GetCurrentWindow());
|
||||||
|
GLuint resolveframebuffer = (GLuint)SDL_GetNumberProperty(props, SDL_PROP_WINDOW_UIKIT_OPENGL_RESOLVE_FRAMEBUFFER_NUMBER, 0);
|
||||||
|
if (resolveframebuffer != 0)
|
||||||
|
return resolveframebuffer;
|
||||||
|
else
|
||||||
|
return (GLuint)SDL_GetNumberProperty(props, SDL_PROP_WINDOW_UIKIT_OPENGL_FRAMEBUFFER_NUMBER, 0);
|
||||||
|
#else
|
||||||
SDL_SysWMinfo info = {};
|
SDL_SysWMinfo info = {};
|
||||||
SDL_VERSION(&info.version);
|
SDL_VERSION(&info.version);
|
||||||
SDL_GetWindowWMInfo(SDL_GL_GetCurrentWindow(), &info);
|
SDL_GetWindowWMInfo(SDL_GL_GetCurrentWindow(), &info);
|
||||||
@@ -290,6 +304,7 @@ GLuint Graphics::getSystemBackbufferFBO() const
|
|||||||
return info.info.uikit.resolveFramebuffer;
|
return info.info.uikit.resolveFramebuffer;
|
||||||
else
|
else
|
||||||
return info.info.uikit.framebuffer;
|
return info.info.uikit.framebuffer;
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
@@ -1291,10 +1306,16 @@ void Graphics::present(void *screenshotCallbackData)
|
|||||||
|
|
||||||
#ifdef LOVE_IOS
|
#ifdef LOVE_IOS
|
||||||
// Hack: SDL's color renderbuffer must be bound when swapBuffers is called.
|
// Hack: SDL's color renderbuffer must be bound when swapBuffers is called.
|
||||||
|
#if SDL_VERSION_ATLEAST(3, 0, 0)
|
||||||
|
SDL_PropertiesID props = SDL_GetWindowProperties(SDL_GL_GetCurrentWindow());
|
||||||
|
GLuint colorbuffer = (GLuint)SDL_GetNumberProperty(props, SDL_PROP_WINDOW_UIKIT_OPENGL_RENDERBUFFER_NUMBER, 0);
|
||||||
|
glBindRenderbuffer(GL_RENDERBUFFER, colorbuffer);
|
||||||
|
#else
|
||||||
SDL_SysWMinfo info = {};
|
SDL_SysWMinfo info = {};
|
||||||
SDL_VERSION(&info.version);
|
SDL_VERSION(&info.version);
|
||||||
SDL_GetWindowWMInfo(SDL_GL_GetCurrentWindow(), &info);
|
SDL_GetWindowWMInfo(SDL_GL_GetCurrentWindow(), &info);
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, info.info.uikit.colorbuffer);
|
glBindRenderbuffer(GL_RENDERBUFFER, info.info.uikit.colorbuffer);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (StreamBuffer *buffer : batchedDrawState.vb)
|
for (StreamBuffer *buffer : batchedDrawState.vb)
|
||||||
|
|||||||
@@ -44,7 +44,13 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LOVE_IOS
|
#ifdef LOVE_IOS
|
||||||
|
#if __has_include(<SDL3/SDL_video.h>)
|
||||||
|
#include <SDL3/SDL_video.h>
|
||||||
|
#include <SDL3/SDL_version.h>
|
||||||
|
#else
|
||||||
#include <SDL_syswm.h>
|
#include <SDL_syswm.h>
|
||||||
|
#include <SDL_version.h>
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LOVE_ANDROID
|
#ifdef LOVE_ANDROID
|
||||||
@@ -966,10 +972,15 @@ GLuint OpenGL::getDefaultFBO() const
|
|||||||
{
|
{
|
||||||
#ifdef LOVE_IOS
|
#ifdef LOVE_IOS
|
||||||
// Hack: iOS uses a custom FBO.
|
// Hack: iOS uses a custom FBO.
|
||||||
|
#if SDL_VERSION_ATLEAST(3, 0, 0)
|
||||||
|
SDL_PropertiesID props = SDL_GetWindowProperties(SDL_GL_GetCurrentWindow());
|
||||||
|
return (GLuint)SDL_GetNumberProperty(props, SDL_PROP_WINDOW_UIKIT_OPENGL_FRAMEBUFFER_NUMBER, 0);
|
||||||
|
#else
|
||||||
SDL_SysWMinfo info = {};
|
SDL_SysWMinfo info = {};
|
||||||
SDL_VERSION(&info.version);
|
SDL_VERSION(&info.version);
|
||||||
SDL_GetWindowWMInfo(SDL_GL_GetCurrentWindow(), &info);
|
SDL_GetWindowWMInfo(SDL_GL_GetCurrentWindow(), &info);
|
||||||
return info.info.uikit.framebuffer;
|
return info.info.uikit.framebuffer;
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -48,7 +48,11 @@
|
|||||||
#endif // LOVE_LEGENDARY_CONSOLE_IO_HACK
|
#endif // LOVE_LEGENDARY_CONSOLE_IO_HACK
|
||||||
|
|
||||||
#ifdef LOVE_LEGENDARY_ACCELEROMETER_AS_JOYSTICK_HACK
|
#ifdef LOVE_LEGENDARY_ACCELEROMETER_AS_JOYSTICK_HACK
|
||||||
|
#if __has_include(<SDL3/SDL_version.h>)
|
||||||
|
#undef LOVE_LEGENDARY_ACCELEROMETER_AS_JOYSTICK_HACK
|
||||||
|
#else
|
||||||
#include <SDL_hints.h>
|
#include <SDL_hints.h>
|
||||||
|
#endif
|
||||||
#endif // LOVE_LEGENDARY_ACCELEROMETER_AS_JOYSTICK_HACK
|
#endif // LOVE_LEGENDARY_ACCELEROMETER_AS_JOYSTICK_HACK
|
||||||
|
|
||||||
// Libraries.
|
// Libraries.
|
||||||
|
|||||||
Reference in New Issue
Block a user