Initial support for building and running SDL platform on macOS

This commit is contained in:
2025-04-20 15:57:18 +03:00
parent c7be6f6e0e
commit 78f6080321
10 changed files with 113 additions and 14 deletions

View File

@@ -6,6 +6,7 @@
#include "../RenderToolsVulkan.h"
#include "Engine/Platform/Window.h"
#include <Cocoa/Cocoa.h>
#include <QuartzCore/CAMetalLayer.h>
void MacVulkanPlatform::GetInstanceExtensions(Array<const char*>& extensions, Array<const char*>& layers)
{
@@ -17,10 +18,14 @@ void MacVulkanPlatform::CreateSurface(Window* window, VkInstance instance, VkSur
{
void* windowHandle = window->GetNativePtr();
NSWindow* nswindow = (NSWindow*)windowHandle;
VkMacOSSurfaceCreateInfoMVK surfaceCreateInfo;
RenderToolsVulkan::ZeroStruct(surfaceCreateInfo, VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK);
surfaceCreateInfo.pView = (void*)nswindow.contentView;
VALIDATE_VULKAN_RESULT(vkCreateMacOSSurfaceMVK(instance, &surfaceCreateInfo, nullptr, surface));
#if PLATFORM_SDL
nswindow.contentView.wantsLayer = YES;
nswindow.contentView.layer = [CAMetalLayer layer];
#endif
VkMacOSSurfaceCreateInfoMVK surfaceCreateInfo;
RenderToolsVulkan::ZeroStruct(surfaceCreateInfo, VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK);
surfaceCreateInfo.pView = (void*)nswindow.contentView;
VALIDATE_VULKAN_RESULT(vkCreateMacOSSurfaceMVK(instance, &surfaceCreateInfo, nullptr, surface));
}
#endif

View File

@@ -423,11 +423,15 @@ String MacPlatform::GetMainDirectory()
return path;
}
#if !PLATFORM_SDL
Window* MacPlatform::CreateWindow(const CreateWindowSettings& settings)
{
return New<MacWindow>(settings);
}
#endif
int32 MacPlatform::CreateProcess(CreateProcessSettings& settings)
{
LOG(Info, "Command: {0} {1}", settings.FileName, settings.Arguments);

View File

@@ -1,6 +1,6 @@
// Copyright (c) Wojciech Figat. All rights reserved.
#if PLATFORM_MAC
#if PLATFORM_MAC && !PLATFORM_SDL
#include "../Window.h"
#include "Engine/Platform/Apple/AppleUtils.h"

View File

@@ -2,11 +2,81 @@
#if PLATFORM_SDL && PLATFORM_MAC
static_assert(false, "TODO");
#include "SDLWindow.h"
#include "Engine/Core/Log.h"
#include "Engine/Core/Collections/Array.h"
#include "Engine/Engine/CommandLine.h"
#include "Engine/Engine/Engine.h"
#include "Engine/Engine/Time.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Input/Input.h"
#include "Engine/Input/Mouse.h"
#include "Engine/Platform/IGuiData.h"
#include "Engine/Platform/MessageBox.h"
#include "Engine/Platform/Platform.h"
#include "Engine/Platform/WindowsManager.h"
#include "Engine/Platform/Base/DragDropHelper.h"
#include "Engine/Platform/SDL/SDLClipboard.h"
#include "Engine/Platform/Unix/UnixFile.h"
#include "Engine/Profiler/ProfilerCPU.h"
#include "Engine/Platform/Linux/IncludeX11.h"
#include <SDL3/SDL_events.h>
#include <SDL3/SDL_hints.h>
#include <SDL3/SDL_messagebox.h>
#include <SDL3/SDL_mouse.h>
#include <SDL3/SDL_system.h>
#include <SDL3/SDL_timer.h>
#include <SDL3/SDL_video.h>
bool SDLPlatform::InitInternal()
{
return false;
}
bool SDLPlatform::UsesWindows()
{
return false;
}
bool SDLPlatform::UsesWayland()
{
return false;
}
bool SDLPlatform::UsesX11()
{
return false;
}
void SDLPlatform::PreHandleEvents()
{
}
void SDLPlatform::PostHandleEvents()
{
}
bool SDLWindow::HandleEventInternal(SDL_Event& event)
{
return false;
}
void SDLPlatform::SetHighDpiAwarenessEnabled(bool enable)
{
// TODO: This is now called before Platform::Init, ensure the scaling is changed accordingly during Platform::Init (see ApplePlatform::SetHighDpiAwarenessEnabled)
}
DragDropEffect SDLWindow::DoDragDrop(const StringView& data)
{
return DragDropEffect::None;
}
DragDropEffect SDLWindow::DoDragDrop(const StringView& data, const Float2& offset, Window* dragSourceWindow)
{
Show();
return DragDropEffect::None;
}
#endif

View File

@@ -11,7 +11,10 @@ typedef struct tagMSG MSG;
#elif PLATFORM_LINUX
#include "Engine/Platform/Linux/LinuxPlatform.h"
union _XEvent;
#elif PLATFORM_MAC
#include "Engine/Platform/Mac/MacPlatform.h"
#else
static_assert(false, "Unsupported Platform");
#endif
class SDLWindow;
@@ -29,8 +32,13 @@ class FLAXENGINE_API SDLPlatform
: public LinuxPlatform
{
using base = LinuxPlatform;
#elif PLATFORM_MAC
: public MacPlatform
{
using base = MacPlatform;
#else
{
static_assert(false, "Unsupported Platform");
#endif
friend SDLWindow;

View File

@@ -30,6 +30,10 @@
#endif
#elif PLATFORM_LINUX
#include "Engine/Platform/Linux/IncludeX11.h"
#elif PLATFORM_MAC
#else
static_assert(false, "Unsupported Platform");
#endif
#define DefaultDPI 96

View File

@@ -265,10 +265,12 @@ class AppleThread;
typedef AppleThread Thread;
class MacClipboard;
typedef MacClipboard Clipboard;
#if !PLATFORM_SDL
class MacPlatform;
typedef MacPlatform Platform;
class MacWindow;
typedef MacWindow Window;
#endif
class UnixNetwork;
typedef UnixNetwork Network;
class UserBase;

View File

@@ -300,7 +300,9 @@ namespace Flax.Build
public static bool WithSDL(NativeCpp.BuildOptions options)
{
bool supportedPlatform = options.Platform.Target == TargetPlatform.Windows || options.Platform.Target == TargetPlatform.Linux;
bool supportedPlatform = options.Platform.Target == TargetPlatform.Windows ||
options.Platform.Target == TargetPlatform.Linux ||
options.Platform.Target == TargetPlatform.Mac;
return UseSDL && supportedPlatform;
}
}

View File

@@ -37,7 +37,6 @@ namespace Flax.Deps.Dependencies
return new[]
{
TargetPlatform.Mac,
TargetPlatform.iOS,
};
default: return new TargetPlatform[0];
}
@@ -63,6 +62,7 @@ namespace Flax.Deps.Dependencies
"-DSDL_RENDER_VULKAN=OFF",
"-DSDL_DIRECTX=OFF",
"-DSDL_METAL=OFF",
"-DSDL_VULKAN=OFF",
"-DSDL_OPENGL=OFF",
"-DSDL_OPENGLES=OFF",
@@ -123,8 +123,9 @@ namespace Flax.Deps.Dependencies
break;
}
case TargetPlatform.Linux:
case TargetPlatform.Mac:
{
foreach (var architecture in new TargetArchitecture[] { TargetArchitecture.x64 })
foreach (var architecture in new [] { TargetArchitecture.x64, TargetArchitecture.ARM64 })
{
var buildDir = Path.Combine(root, "build-" + architecture.ToString());
@@ -147,11 +148,6 @@ namespace Flax.Deps.Dependencies
}
break;
}
case TargetPlatform.Mac:
{
// TODO
break;
}
}
}

View File

@@ -52,6 +52,14 @@ namespace Flax.Build.Platforms
options.LinkEnv.InputLibraries.Add("Cocoa.framework");
options.LinkEnv.InputLibraries.Add("QuartzCore.framework");
options.LinkEnv.InputLibraries.Add("AVFoundation.framework");
// SDL3 requires the following frameworks:
options.LinkEnv.InputLibraries.Add("Foundation.framework");
options.LinkEnv.InputLibraries.Add("GameController.framework");
options.LinkEnv.InputLibraries.Add("Carbon.framework");
options.LinkEnv.InputLibraries.Add("ForceFeedback.framework");
options.LinkEnv.InputLibraries.Add("UniformTypeIdentifiers.framework");
options.LinkEnv.InputLibraries.Add("CoreHaptics.framework");
}
protected override void AddArgsCommon(BuildOptions options, List<string> args)