Skip to content

Commit 25a3c27

Browse files
authored
Merge pull request #105628 from rsanchezsaez/apple/ios-visionos-4.5
Native visionOS platform support
2 parents a12e9d5 + 47971c0 commit 25a3c27

File tree

141 files changed

+8707
-5424
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+8707
-5424
lines changed

SConstruct

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,11 @@ if env["scu_build"]:
647647
# are actually handled to change compile options, etc.
648648
detect.configure(env)
649649

650-
print(f'Building for platform "{env["platform"]}", architecture "{env["arch"]}", target "{env["target"]}".')
650+
platform_string = env["platform"]
651+
if env.get("simulator"):
652+
platform_string += " (simulator)"
653+
print(f'Building for platform "{platform_string}", architecture "{env["arch"]}", target "{env["target"]}".')
654+
651655
if env.dev_build:
652656
print_info("Developer build, with debug optimization level and debug symbols (unless overridden).")
653657

core/input/input_builders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def make_default_controller_mappings(target, source, env):
4848
"Windows": "WINDOWS",
4949
"Mac OS X": "MACOS",
5050
"Android": "ANDROID",
51-
"iOS": "IOS",
51+
"iOS": "APPLE_EMBEDDED",
5252
"Web": "WEB",
5353
}
5454

core/os/os.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ bool OS::has_feature(const String &p_feature) {
585585
}
586586
#endif
587587

588-
#if defined(IOS_SIMULATOR)
588+
#if defined(IOS_SIMULATOR) || defined(VISIONOS_SIMULATOR)
589589
if (p_feature == "simulator") {
590590
return true;
591591
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<class name="EditorExportPlatformAppleEmbedded" inherits="EditorExportPlatform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3+
<brief_description>
4+
Base class for the Apple embedded platform exporters (iOS and visionOS).
5+
</brief_description>
6+
<description>
7+
The base class for Apple embedded platform exporters. These include iOS and visionOS, but not macOS. See the classes inheriting from this one for more details.
8+
</description>
9+
<tutorials>
10+
<link title="Exporting for iOS">$DOCS_URL/tutorials/export/exporting_for_ios.html</link>
11+
<link title="iOS plugins documentation index">$DOCS_URL/tutorials/platform/ios/index.html</link>
12+
</tutorials>
13+
</class>

doc/classes/EditorExportPlatformPC.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Base class for the desktop platform exporter (Windows and Linux/BSD).
55
</brief_description>
66
<description>
7-
The base class for the desktop platform exporters. These include Windows and Linux/BSD, but not macOS. See the classes inheriting this one for more details.
7+
The base class for the desktop platform exporters. These include Windows and Linux/BSD, but not macOS. See the classes inheriting from this one for more details.
88
</description>
99
<tutorials>
1010
<link title="Exporting for Windows">$DOCS_URL/tutorials/export/exporting_for_windows.html</link>

doc/classes/EditorExportPlugin.xml

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,57 @@
251251
If no modifications are needed, then an empty [PackedByteArray] should be returned.
252252
</description>
253253
</method>
254+
<method name="add_apple_embedded_platform_bundle_file">
255+
<return type="void" />
256+
<param index="0" name="path" type="String" />
257+
<description>
258+
Adds an Apple embedded platform bundle file from the given [param path] to the exported project.
259+
</description>
260+
</method>
261+
<method name="add_apple_embedded_platform_cpp_code">
262+
<return type="void" />
263+
<param index="0" name="code" type="String" />
264+
<description>
265+
Adds C++ code to the Apple embedded platform export. The final code is created from the code appended by each active export plugin.
266+
</description>
267+
</method>
268+
<method name="add_apple_embedded_platform_embedded_framework">
269+
<return type="void" />
270+
<param index="0" name="path" type="String" />
271+
<description>
272+
Adds a dynamic library (*.dylib, *.framework) to the Linking Phase in the Apple embedded platform's Xcode project and embeds it into the resulting binary.
273+
[b]Note:[/b] For static libraries (*.a), this works in the same way as [method add_apple_embedded_platform_framework].
274+
[b]Note:[/b] This method should not be used for System libraries as they are already present on the device.
275+
</description>
276+
</method>
277+
<method name="add_apple_embedded_platform_framework">
278+
<return type="void" />
279+
<param index="0" name="path" type="String" />
280+
<description>
281+
Adds a static library (*.a) or a dynamic library (*.dylib, *.framework) to the Linking Phase to the Apple embedded platform's Xcode project.
282+
</description>
283+
</method>
284+
<method name="add_apple_embedded_platform_linker_flags">
285+
<return type="void" />
286+
<param index="0" name="flags" type="String" />
287+
<description>
288+
Adds linker flags for the Apple embedded platform export.
289+
</description>
290+
</method>
291+
<method name="add_apple_embedded_platform_plist_content">
292+
<return type="void" />
293+
<param index="0" name="plist_content" type="String" />
294+
<description>
295+
Adds additional fields to the Apple embedded platform's project Info.plist file.
296+
</description>
297+
</method>
298+
<method name="add_apple_embedded_platform_project_static_lib">
299+
<return type="void" />
300+
<param index="0" name="path" type="String" />
301+
<description>
302+
Adds a static library from the given [param path] to the Apple embedded platform project.
303+
</description>
304+
</method>
254305
<method name="add_file">
255306
<return type="void" />
256307
<param index="0" name="path" type="String" />
@@ -262,55 +313,55 @@
262313
[param file] will not be imported, so consider using [method _customize_resource] to remap imported resources.
263314
</description>
264315
</method>
265-
<method name="add_ios_bundle_file">
316+
<method name="add_ios_bundle_file" deprecated="Use [method add_apple_embedded_platform_bundle_file] instead.">
266317
<return type="void" />
267318
<param index="0" name="path" type="String" />
268319
<description>
269320
Adds an iOS bundle file from the given [param path] to the exported project.
270321
</description>
271322
</method>
272-
<method name="add_ios_cpp_code">
323+
<method name="add_ios_cpp_code" deprecated="Use [method add_apple_embedded_platform_cpp_code] instead.">
273324
<return type="void" />
274325
<param index="0" name="code" type="String" />
275326
<description>
276-
Adds a C++ code to the iOS export. The final code is created from the code appended by each active export plugin.
327+
Adds C++ code to the iOS export. The final code is created from the code appended by each active export plugin.
277328
</description>
278329
</method>
279-
<method name="add_ios_embedded_framework">
330+
<method name="add_ios_embedded_framework" deprecated="Use [method add_apple_embedded_platform_embedded_framework] instead.">
280331
<return type="void" />
281332
<param index="0" name="path" type="String" />
282333
<description>
283334
Adds a dynamic library (*.dylib, *.framework) to Linking Phase in iOS's Xcode project and embeds it into resulting binary.
284-
[b]Note:[/b] For static libraries (*.a) works in same way as [method add_ios_framework].
335+
[b]Note:[/b] For static libraries (*.a), this works the in same way as [method add_apple_embedded_platform_framework].
285336
[b]Note:[/b] This method should not be used for System libraries as they are already present on the device.
286337
</description>
287338
</method>
288-
<method name="add_ios_framework">
339+
<method name="add_ios_framework" deprecated="Use [method add_apple_embedded_platform_framework] instead.">
289340
<return type="void" />
290341
<param index="0" name="path" type="String" />
291342
<description>
292-
Adds a static library (*.a) or dynamic library (*.dylib, *.framework) to Linking Phase in iOS's Xcode project.
343+
Adds a static library (*.a) or a dynamic library (*.dylib, *.framework) to the Linking Phase to the iOS Xcode project.
293344
</description>
294345
</method>
295-
<method name="add_ios_linker_flags">
346+
<method name="add_ios_linker_flags" deprecated="Use [method add_apple_embedded_platform_linker_flags] instead.">
296347
<return type="void" />
297348
<param index="0" name="flags" type="String" />
298349
<description>
299350
Adds linker flags for the iOS export.
300351
</description>
301352
</method>
302-
<method name="add_ios_plist_content">
353+
<method name="add_ios_plist_content" deprecated="Use [method add_apple_embedded_platform_plist_content] instead.">
303354
<return type="void" />
304355
<param index="0" name="plist_content" type="String" />
305356
<description>
306-
Adds content for iOS Property List files.
357+
Adds additional fields to the iOS project Info.plist file.
307358
</description>
308359
</method>
309-
<method name="add_ios_project_static_lib">
360+
<method name="add_ios_project_static_lib" deprecated="Use [method add_apple_embedded_platform_project_static_lib] instead.">
310361
<return type="void" />
311362
<param index="0" name="path" type="String" />
312363
<description>
313-
Adds a static lib from the given [param path] to the iOS project.
364+
Adds a static library from the given [param path] to the iOS project.
314365
</description>
315366
</method>
316367
<method name="add_macos_plugin_file">

doc/classes/ProjectSettings.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,9 @@
900900
<member name="display/display_server/driver.macos" type="String" setter="" getter="">
901901
MacOS override for [member display/display_server/driver].
902902
</member>
903+
<member name="display/display_server/driver.visionos" type="String" setter="" getter="">
904+
visionOS override for [member display/display_server/driver].
905+
</member>
903906
<member name="display/display_server/driver.windows" type="String" setter="" getter="">
904907
Windows override for [member display/display_server/driver].
905908
</member>
@@ -3163,6 +3166,11 @@
31633166
- [code]metal[/code] (default), Metal from native drivers, only supported on Apple Silicon Macs. On Intel Macs, it will automatically fall back to [code]vulkan[/code] as Metal support is not implemented.
31643167
- [code]vulkan[/code], Vulkan over Metal via MoltenVK, supported on both Apple Silicon and Intel Macs.
31653168
</member>
3169+
<member name="rendering/rendering_device/driver.visionos" type="String" setter="" getter="" default="&quot;metal&quot;">
3170+
visionOS override for [member rendering/rendering_device/driver].
3171+
Only one option is supported:
3172+
- [code]metal[/code] (default), Metal from native drivers.
3173+
</member>
31663174
<member name="rendering/rendering_device/driver.windows" type="String" setter="" getter="" default="&quot;vulkan&quot;">
31673175
Windows override for [member rendering/rendering_device/driver].
31683176
Two options are supported:

drivers/SCsub

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ SConscript("windows/SCsub")
1414

1515
# Sounds drivers
1616
SConscript("alsa/SCsub")
17-
if env["platform"] == "ios" or env["platform"] == "macos":
18-
SConscript("coreaudio/SCsub")
1917
SConscript("pulseaudio/SCsub")
2018
if env["platform"] == "windows":
2119
SConscript("wasapi/SCsub")
@@ -28,16 +26,19 @@ if env["xaudio2"]:
2826
SConscript("xaudio2/SCsub")
2927

3028
# Shared Apple platform drivers
31-
if env["platform"] in ["macos", "ios"]:
29+
if env["platform"] in ["macos", "ios", "visionos"]:
3230
SConscript("apple/SCsub")
31+
SConscript("coreaudio/SCsub")
32+
if env["platform"] in ["ios", "visionos"]:
33+
SConscript("apple_embedded/SCsub")
3334

3435
# Accessibility
3536
if env["accesskit"] and env["platform"] in ["macos", "windows", "linuxbsd"]:
3637
SConscript("accesskit/SCsub")
3738

3839
# Midi drivers
3940
SConscript("alsamidi/SCsub")
40-
if env["platform"] in ["macos", "ios"]:
41+
if env["platform"] in ["macos"]:
4142
SConscript("coremidi/SCsub")
4243
SConscript("winmidi/SCsub")
4344

drivers/apple_embedded/SCsub

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python
2+
from misc.utility.scons_hints import *
3+
4+
Import("env")
5+
6+
env_apple_embedded = env.Clone()
7+
8+
# Enable module support
9+
env_apple_embedded.Append(CCFLAGS=["-fmodules", "-fcxx-modules"])
10+
11+
# Use bundled Vulkan headers
12+
vulkan_dir = "#thirdparty/vulkan"
13+
env_apple_embedded.Prepend(CPPPATH=[vulkan_dir, vulkan_dir + "/include"])
14+
15+
# Driver source files
16+
env_apple_embedded.add_source_files(env.drivers_sources, "*.mm")

platform/ios/app_delegate.h renamed to drivers/apple_embedded/app_delegate_service.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**************************************************************************/
2-
/* app_delegate.h */
2+
/* app_delegate_service.h */
33
/**************************************************************************/
44
/* This file is part of: */
55
/* GODOT ENGINE */
@@ -32,18 +32,11 @@
3232

3333
#import <UIKit/UIKit.h>
3434

35-
@class ViewController;
35+
@class GDTViewController;
3636

37-
// FIXME: Add support for both OpenGL and Vulkan when OpenGL is implemented again,
38-
// so it can't be done with compilation time branching.
39-
//#if defined(GLES3_ENABLED)
40-
//@interface AppDelegate : NSObject <UIApplicationDelegate, GLViewDelegate> {
41-
//#endif
42-
//#if defined(VULKAN_ENABLED)
43-
@interface AppDelegate : NSObject <UIApplicationDelegate>
44-
//#endif
37+
@interface GDTAppDelegateService : NSObject <UIApplicationDelegate>
4538

4639
@property(strong, nonatomic) UIWindow *window;
47-
@property(strong, class, readonly, nonatomic) ViewController *viewController;
40+
@property(strong, class, readonly, nonatomic) GDTViewController *viewController;
4841

4942
@end

platform/ios/app_delegate.mm renamed to drivers/apple_embedded/app_delegate_service.mm

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**************************************************************************/
2-
/* app_delegate.mm */
2+
/* app_delegate_service.mm */
33
/**************************************************************************/
44
/* This file is part of: */
55
/* GODOT ENGINE */
@@ -28,10 +28,10 @@
2828
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2929
/**************************************************************************/
3030

31-
#import "app_delegate.h"
31+
#import "app_delegate_service.h"
3232

33-
#import "godot_view.h"
34-
#import "os_ios.h"
33+
#import "godot_view_apple_embedded.h"
34+
#import "os_apple_embedded.h"
3535
#import "view_controller.h"
3636

3737
#include "core/config/project_settings.h"
@@ -46,10 +46,10 @@
4646
extern int gargc;
4747
extern char **gargv;
4848

49-
extern int ios_main(int, char **);
50-
extern void ios_finish();
49+
extern int apple_embedded_main(int, char **);
50+
extern void apple_embedded_finish();
5151

52-
@implementation AppDelegate
52+
@implementation GDTAppDelegateService
5353

5454
enum {
5555
SESSION_CATEGORY_AMBIENT,
@@ -60,9 +60,9 @@ @implementation AppDelegate
6060
SESSION_CATEGORY_SOLO_AMBIENT
6161
};
6262

63-
static ViewController *mainViewController = nil;
63+
static GDTViewController *mainViewController = nil;
6464

65-
+ (ViewController *)viewController {
65+
+ (GDTViewController *)viewController {
6666
return mainViewController;
6767
}
6868

@@ -71,20 +71,23 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
7171
// TODO: logo screen is not displayed while shaders are compiling
7272
// DummyViewController(Splash/LoadingViewController) -> setup -> GodotViewController
7373

74-
CGRect windowBounds = [[UIScreen mainScreen] bounds];
75-
74+
#if !defined(VISIONOS_ENABLED)
7675
// Create a full-screen window
76+
CGRect windowBounds = [[UIScreen mainScreen] bounds];
7777
self.window = [[UIWindow alloc] initWithFrame:windowBounds];
78+
#else
79+
self.window = [[UIWindow alloc] init];
80+
#endif
7881

79-
int err = ios_main(gargc, gargv);
82+
int err = apple_embedded_main(gargc, gargv);
8083

8184
if (err != 0) {
8285
// bail, things did not go very well for us, should probably output a message on screen with our error code...
8386
exit(0);
8487
return NO;
8588
}
8689

87-
ViewController *viewController = [[ViewController alloc] init];
90+
GDTViewController *viewController = [[GDTViewController alloc] init];
8891
viewController.godotView.useCADisplayLink = bool(GLOBAL_DEF("display.iOS/use_cadisplaylink", true)) ? YES : NO;
8992
viewController.godotView.renderingInterval = 1.0 / kRenderingFrequency;
9093

@@ -135,10 +138,10 @@ - (void)onAudioInterruption:(NSNotification *)notification {
135138
if ([notification.name isEqualToString:AVAudioSessionInterruptionNotification]) {
136139
if ([[notification.userInfo valueForKey:AVAudioSessionInterruptionTypeKey] isEqualToNumber:[NSNumber numberWithInt:AVAudioSessionInterruptionTypeBegan]]) {
137140
NSLog(@"Audio interruption began");
138-
OS_IOS::get_singleton()->on_focus_out();
141+
OS_AppleEmbedded::get_singleton()->on_focus_out();
139142
} else if ([[notification.userInfo valueForKey:AVAudioSessionInterruptionTypeKey] isEqualToNumber:[NSNumber numberWithInt:AVAudioSessionInterruptionTypeEnded]]) {
140143
NSLog(@"Audio interruption ended");
141-
OS_IOS::get_singleton()->on_focus_in();
144+
OS_AppleEmbedded::get_singleton()->on_focus_in();
142145
}
143146
}
144147
}
@@ -150,7 +153,7 @@ - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
150153
}
151154

152155
- (void)applicationWillTerminate:(UIApplication *)application {
153-
ios_finish();
156+
apple_embedded_finish();
154157
}
155158

156159
// When application goes to background (e.g. user switches to another app or presses Home),
@@ -164,19 +167,19 @@ - (void)applicationWillTerminate:(UIApplication *)application {
164167
// notification panel by swiping from the upper part of the screen.
165168

166169
- (void)applicationWillResignActive:(UIApplication *)application {
167-
OS_IOS::get_singleton()->on_focus_out();
170+
OS_AppleEmbedded::get_singleton()->on_focus_out();
168171
}
169172

170173
- (void)applicationDidBecomeActive:(UIApplication *)application {
171-
OS_IOS::get_singleton()->on_focus_in();
174+
OS_AppleEmbedded::get_singleton()->on_focus_in();
172175
}
173176

174177
- (void)applicationDidEnterBackground:(UIApplication *)application {
175-
OS_IOS::get_singleton()->on_enter_background();
178+
OS_AppleEmbedded::get_singleton()->on_enter_background();
176179
}
177180

178181
- (void)applicationWillEnterForeground:(UIApplication *)application {
179-
OS_IOS::get_singleton()->on_exit_background();
182+
OS_AppleEmbedded::get_singleton()->on_exit_background();
180183
}
181184

182185
- (void)dealloc {

0 commit comments

Comments
 (0)