Godot Engine – Multi-platform 2D and 3D game engine
/**************************************************************************/
/* godot_app_delegate_service_visionos.mm */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#import "godot_app_delegate_service_visionos.h"
#include "core/config/project_settings.h"
#import "drivers/apple_embedded/os_apple_embedded.h"
// Generated by `setup_swift_builder` (`platform_methods.py`). Exposes `@objc` Swift
// declarations (e.g. `GDTSwiftBridge`) to ObjC++.
#import "godot_swift_module-Swift.gen.h"
static GDTRenderMode _renderMode = GDTRenderModeWindowed;
static __weak cp_layer_renderer_t _layerRenderer = nil;
static __strong cp_layer_renderer_capabilities_t _layerRendererCapabilities = nil;
@implementation GDTAppDelegateServiceVisionOS
+ (GDTRenderMode)renderMode {
return _renderMode;
}
+ (void)setRenderMode:(GDTRenderMode)renderMode {
_renderMode = renderMode;
}
+ (cp_layer_renderer_t)layerRenderer {
if (_renderMode != GDTRenderModeCompositorServices) {
NSLog(@"GDTAppDelegate error, layerRenderer only supported in Compositor Services mode");
return nil;
}
return _layerRenderer;
}
+ (void)setLayerRenderer:(cp_layer_renderer_t)layerRenderer {
if (_renderMode != GDTRenderModeCompositorServices) {
NSLog(@"GDTAppDelegate error, layerRenderer only supported in Compositor Services mode");
return;
}
_layerRenderer = layerRenderer;
}
+ (cp_layer_renderer_capabilities_t)layerRendererCapabilities {
if (_renderMode != GDTRenderModeCompositorServices) {
NSLog(@"GDTAppDelegate error, layerRenderer only supported in Compositor Services mode");
return nil;
}
return _layerRendererCapabilities;
}
+ (void)setLayerRendererCapabilities:(cp_layer_renderer_capabilities_t)layerRendererCapabilities {
if (_renderMode != GDTRenderModeCompositorServices) {
NSLog(@"GDTAppDelegate error, layerRenderer only supported in Compositor Services mode");
return;
}
_layerRendererCapabilities = layerRendererCapabilities;
}
+ (BOOL)isDynamicRenderQualityEnabled {
return GLOBAL_GET("xr/visionos/dynamic_render_quality/enable");
}
+ (float)maxRenderQuality {
return GLOBAL_GET("xr/visionos/dynamic_render_quality/maximum_quality");
}
+ (GDTVisibility)initialUpperLimbVisibility {
return (GDTVisibility)(int)GLOBAL_GET("xr/visionos/upper_limb_visibility");
}
+ (GDTVisibility)initialPersistentSystemOverlays {
return (GDTVisibility)(int)GLOBAL_GET("xr/visionos/persistent_system_overlays");
}
// `immersionStyle`, `upperLimbVisibility` and `persistentSystemOverlays` are stored on the
// SwiftUI `Model`; these accessors forward through `GDTSwiftBridge`, which does the
// SwiftUI<->ObjC conversion.
+ (GDTImmersionStyle)immersionStyle {
return GDTSwiftBridge.immersionStyle;
}
+ (void)setImmersionStyle:(GDTImmersionStyle)immersionStyle {
GDTSwiftBridge.immersionStyle = immersionStyle;
}
+ (GDTVisibility)upperLimbVisibility {
return GDTSwiftBridge.upperLimbVisibility;
}
+ (void)setUpperLimbVisibility:(GDTVisibility)upperLimbVisibility {
GDTSwiftBridge.upperLimbVisibility = upperLimbVisibility;
}
+ (GDTVisibility)persistentSystemOverlays {
return GDTSwiftBridge.persistentSystemOverlays;
}
+ (void)setPersistentSystemOverlays:(GDTVisibility)persistentSystemOverlays {
GDTSwiftBridge.persistentSystemOverlays = persistentSystemOverlays;
}
- (void)sceneDidBecomeActive:(UIScene *)scene API_AVAILABLE(ios(13.0), tvos(13.0), visionos(1.0)) {
[super sceneDidBecomeActive:scene];
// On Compositor Services scenes, sceneDidBecomeActive: is called too soon when
// donning the device, which attempts to start the audio driver too early. Start it
// again after a short delay so audio resumes correctly.
if (_renderMode == GDTRenderModeCompositorServices) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
OS_AppleEmbedded::get_singleton()->audio_driver_start();
});
}
}
@end