Skip to content

Commit 257e413

Browse files
Integrate VisionOS platform
1 parent ff88c1d commit 257e413

18 files changed

Lines changed: 323 additions & 10 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set(DILIGENT_TOOLS_FOUND TRUE CACHE INTERNAL "DiligentTools module is found")
88

99
file(RELATIVE_PATH DILIGENT_TOOLS_DIR "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")
1010

11-
if(PLATFORM_WIN32 OR PLATFORM_UNIVERSAL_WINDOWS OR PLATFORM_LINUX OR PLATFORM_MACOS OR PLATFORM_IOS OR PLATFORM_TVOS OR PLATFORM_WEB)
11+
if(PLATFORM_WIN32 OR PLATFORM_UNIVERSAL_WINDOWS OR PLATFORM_LINUX OR PLATFORM_MACOS OR PLATFORM_IOS OR PLATFORM_TVOS OR PLATFORM_VISIONOS OR PLATFORM_WEB)
1212
option(DILIGENT_INSTALL_TOOLS "Install DiligentTool module headers and libraries" ON)
1313
else()
1414
set(DILIGENT_INSTALL_TOOLS OFF)

Imgui/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ if(EXISTS "${DILIGENT_DEAR_IMGUI_PATH}/backends")
4545
elseif(PLATFORM_TVOS)
4646
list(APPEND SOURCE src/ImGuiImplTVOS.mm)
4747
list(APPEND INTERFACE interface/ImGuiImplTVOS.hpp)
48+
elseif(PLATFORM_VISIONOS)
49+
list(APPEND SOURCE src/ImGuiImplIOS.mm)
50+
list(APPEND INTERFACE interface/ImGuiImplIOS.hpp)
4851
elseif(PLATFORM_WEB)
4952
list(APPEND SOURCE src/ImGuiImplEmscripten.cpp)
5053
list(APPEND INTERFACE interface/ImGuiImplEmscripten.hpp)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>APPL</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleVersion</key>
20+
<string>1</string>
21+
<key>UIApplicationSceneManifest</key>
22+
<dict>
23+
<key>UIApplicationSupportsMultipleScenes</key>
24+
<false/>
25+
<key>UISceneConfigurations</key>
26+
<dict>
27+
<key>UIWindowSceneSessionRoleApplication</key>
28+
<array>
29+
<dict>
30+
<key>UISceneConfigurationName</key>
31+
<string>Default Configuration</string>
32+
<key>UISceneDelegateClassName</key>
33+
<string>SceneDelegate</string>
34+
</dict>
35+
</array>
36+
</dict>
37+
</dict>
38+
<key>UILaunchScreen</key>
39+
<dict/>
40+
</dict>
41+
</plist>

NativeApp/Apple/Source/Classes/iOS/MetalView.mm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ - (instancetype) initWithCoder:(NSCoder*)coder
2121
return self;
2222
}
2323

24+
- (instancetype) initWithFrame:(CGRect)frame
25+
{
26+
if ((self = [super initWithFrame:frame]))
27+
{
28+
[self initApp:(int)Diligent::RENDER_DEVICE_TYPE_METAL];
29+
}
30+
31+
return self;
32+
}
33+
2434
- (void) drawView:(id)sender
2535
{
2636
// There is no autorelease pool when this method is called
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#import <UIKit/UIKit.h>
2+
3+
@interface AppDelegate : UIResponder <UIApplicationDelegate>
4+
@end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#import "AppDelegate.h"
2+
#import "SceneDelegate.h"
3+
4+
@implementation AppDelegate
5+
6+
- (UISceneConfiguration*) application:(UIApplication*)application
7+
configurationForConnectingSceneSession:(UISceneSession*)connectingSceneSession
8+
options:(UISceneConnectionOptions*)options
9+
{
10+
UISceneConfiguration* configuration =
11+
[[[UISceneConfiguration alloc] initWithName:@"Default Configuration"
12+
sessionRole:connectingSceneSession.role] autorelease];
13+
configuration.delegateClass = [SceneDelegate class];
14+
return configuration;
15+
}
16+
17+
@end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#import <UIKit/UIKit.h>
2+
3+
@interface SceneDelegate : UIResponder <UIWindowSceneDelegate>
4+
5+
@property (nonatomic, retain) UIWindow* window;
6+
7+
@end
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#import "SceneDelegate.h"
2+
#import "BaseView.h"
3+
#import "MetalView.h"
4+
5+
@implementation SceneDelegate
6+
7+
@synthesize window = _window;
8+
9+
- (void) scene:(UIScene*)scene
10+
willConnectToSession:(UISceneSession*)session
11+
options:(UISceneConnectionOptions*)connectionOptions
12+
{
13+
if (![scene isKindOfClass:[UIWindowScene class]])
14+
return;
15+
16+
UIWindow* window = [[UIWindow alloc] initWithWindowScene:(UIWindowScene*)scene];
17+
18+
UIViewController* viewController = [[UIViewController alloc] init];
19+
MetalView* view = [[MetalView alloc] initWithFrame:window.bounds];
20+
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
21+
viewController.view = view;
22+
23+
window.rootViewController = viewController;
24+
self.window = window;
25+
[window makeKeyAndVisible];
26+
[view startAnimation];
27+
28+
[view release];
29+
[viewController release];
30+
[window release];
31+
}
32+
33+
- (void) sceneDidDisconnect:(UIScene*)scene
34+
{
35+
[(BaseView*)self.window.rootViewController.view stopAnimation];
36+
[(BaseView*)self.window.rootViewController.view terminate];
37+
self.window = nil;
38+
}
39+
40+
- (void) sceneWillResignActive:(UIScene*)scene
41+
{
42+
[(BaseView*)self.window.rootViewController.view stopAnimation];
43+
}
44+
45+
- (void) sceneDidEnterBackground:(UIScene*)scene
46+
{
47+
[(BaseView*)self.window.rootViewController.view stopAnimation];
48+
}
49+
50+
- (void) sceneWillEnterForeground:(UIScene*)scene
51+
{
52+
[(BaseView*)self.window.rootViewController.view startAnimation];
53+
}
54+
55+
- (void) sceneDidBecomeActive:(UIScene*)scene
56+
{
57+
[(BaseView*)self.window.rootViewController.view startAnimation];
58+
}
59+
60+
- (void) dealloc
61+
{
62+
[_window release];
63+
[super dealloc];
64+
}
65+
66+
@end

NativeApp/Apple/Source/main.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
Standard AppKit entry point.
77
*/
88

9-
#if PLATFORM_IOS || PLATFORM_TVOS
9+
#if PLATFORM_IOS || PLATFORM_TVOS || PLATFORM_VISIONOS
1010
#import "AppDelegate.h"
1111
#else // OS X
1212
#import <Cocoa/Cocoa.h>
1313
#endif
1414

1515
int main(int argc, char * argv[]) {
1616

17-
#if PLATFORM_IOS || PLATFORM_TVOS
17+
#if PLATFORM_IOS || PLATFORM_TVOS || PLATFORM_VISIONOS
1818
@autoreleasepool {
1919
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
2020
}

NativeApp/CMakeLists.txt

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,72 @@ elseif(PLATFORM_TVOS)
400400
add_tvos_app("${TARGET_NAME}" "${SOURCE}" "${INCLUDE}" "${ASSETS}")
401401
endfunction()
402402

403+
elseif(PLATFORM_VISIONOS)
404+
405+
set(SOURCE
406+
src/VisionOS/VisionOSAppBase.cpp
407+
)
408+
set(INCLUDE
409+
include/VisionOS/VisionOSAppBase.hpp
410+
)
411+
412+
function(add_visionos_app TARGET_NAME SOURCE INCLUDE ASSETS)
413+
get_target_property(NATIVE_APP_SOURCE_DIR Diligent-NativeAppBase SOURCE_DIR)
414+
415+
set(APPLE_SOURCE
416+
${NATIVE_APP_SOURCE_DIR}/Apple/Source/main.m
417+
${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/visionOS/AppDelegate.mm
418+
${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/visionOS/SceneDelegate.mm
419+
${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/iOS/BaseView.mm
420+
${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/iOS/AppViewBase.mm
421+
${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/iOS/MetalView.mm
422+
)
423+
424+
set(APPLE_INCLUDE
425+
${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/visionOS/AppDelegate.h
426+
${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/visionOS/SceneDelegate.h
427+
${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/iOS/BaseView.h
428+
${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/iOS/AppViewBase.h
429+
${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/iOS/MetalView.h
430+
)
431+
432+
set(APPLE_INFO_PLIST
433+
${NATIVE_APP_SOURCE_DIR}/Apple/Data/visionOS/Info.plist
434+
)
435+
436+
set(APPLE_INCLUDE_DIRS
437+
${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/visionOS
438+
${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/iOS
439+
)
440+
441+
add_executable(${TARGET_NAME} MACOSX_BUNDLE ${SOURCE} ${APPLE_SOURCE} ${INCLUDE} ${APPLE_INCLUDE} ${ASSETS})
442+
string(REPLACE "_" "-" BUNDLE_NAME ${TARGET_NAME})
443+
set_target_properties(${TARGET_NAME} PROPERTIES
444+
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.diligentengine.samples.${BUNDLE_NAME}"
445+
MACOSX_BUNDLE_INFO_PLIST "${APPLE_INFO_PLIST}"
446+
BUILD_RPATH "@executable_path"
447+
)
448+
source_group("visionOS" FILES ${APPLE_SOURCE})
449+
source_group("visionOS" FILES ${APPLE_INCLUDE})
450+
target_include_directories(${TARGET_NAME} PRIVATE ${APPLE_INCLUDE_DIRS})
451+
452+
find_library(UIKIT UIKit)
453+
if (NOT UIKIT)
454+
message(FATAL_ERROR "UIKit is not found")
455+
endif()
456+
457+
find_library(CORE_ANIMATION QuartzCore)
458+
if (NOT CORE_ANIMATION)
459+
message(FATAL_ERROR "QuartzCore (CoreAnimation) is not found")
460+
endif()
461+
462+
target_link_libraries(${TARGET_NAME} PRIVATE ${UIKIT} ${CORE_ANIMATION})
463+
endfunction()
464+
465+
function(add_target_platform_app TARGET_NAME SOURCE INCLUDE ASSETS)
466+
add_visionos_app("${TARGET_NAME}" "${SOURCE}" "${INCLUDE}" "${ASSETS}")
467+
endfunction()
468+
403469
elseif(PLATFORM_WEB)
404470
set(SOURCE
405471
src/Emscripten/EmscriptenAppBase.cpp
@@ -530,6 +596,10 @@ elseif(PLATFORM_TVOS)
530596
target_include_directories(Diligent-NativeAppBase PUBLIC
531597
include/TVOS
532598
)
599+
elseif(PLATFORM_VISIONOS)
600+
target_include_directories(Diligent-NativeAppBase PUBLIC
601+
include/VisionOS
602+
)
533603
elseif(PLATFORM_WEB)
534604
target_include_directories(Diligent-NativeAppBase PUBLIC
535605
include/Emscripten

0 commit comments

Comments
 (0)