diff --git a/examples/common/entry/SwiftBridgingHeader.h b/examples/common/entry/SwiftBridgingHeader.h deleted file mode 100644 index 998769322c..0000000000 --- a/examples/common/entry/SwiftBridgingHeader.h +++ /dev/null @@ -1 +0,0 @@ -#include "SwiftAdapter.hpp" diff --git a/examples/common/entry/entry_visionos.swift b/examples/common/entry/entry_visionos.swift index 8e322ac533..101a43b17a 100644 --- a/examples/common/entry/entry_visionos.swift +++ b/examples/common/entry/entry_visionos.swift @@ -6,52 +6,40 @@ struct ContentStageConfiguration: CompositorLayerConfiguration { func makeConfiguration(capabilities: LayerRenderer.Capabilities, configuration: inout LayerRenderer.Configuration) { configuration.depthFormat = .depth32Float configuration.colorFormat = .bgra8Unorm_srgb - + let foveationEnabled = capabilities.supportsFoveation configuration.isFoveationEnabled = foveationEnabled - + let options: LayerRenderer.Capabilities.SupportedLayoutsOptions = foveationEnabled ? [.foveationEnabled] : [] let supportedLayouts = capabilities.supportedLayouts(options: options) - + configuration.layout = supportedLayouts.contains(.layered) ? .layered : .dedicated } } class Renderer { - let arSession: ARKitSession - let worldTracking: WorldTrackingProvider let layerRenderer: LayerRenderer var bgfxAdapter: BgfxAdapter - + init(_ layerRenderer: LayerRenderer) { self.layerRenderer = layerRenderer bgfxAdapter = BgfxAdapter(layerRenderer) - worldTracking = WorldTrackingProvider() - arSession = ARKitSession() } - + func startRenderLoop() { - Task { - do { - try await arSession.run([worldTracking]) - } catch { - fatalError("Failed to initialize ARSession") - } - let renderThread = Thread { self.renderLoop() } renderThread.name = "Render Thread" renderThread.start() - } } - - + + func renderLoop() { while true { if layerRenderer.state == .invalidated { print("Layer is invalidated") - + bgfxAdapter.shutdown() return } else if layerRenderer.state == .paused { @@ -72,10 +60,10 @@ class Renderer { struct ExampeApp: App { @State private var showImmersiveSpace = false @State private var immersiveSpaceIsShown = false - + @Environment(\.openImmersiveSpace) var openImmersiveSpace @Environment(\.dismissImmersiveSpace) var dismissImmersiveSpace - + var body: some Scene { WindowGroup { VStack { @@ -101,7 +89,7 @@ struct ExampeApp: App { } } } - + } ImmersiveSpace(id: "ImmersiveSpace") { CompositorLayer(configuration: ContentStageConfiguration()) { layerRenderer in diff --git a/examples/common/entry/SwiftAdapter.cpp b/examples/common/entry/swift_adapter.cpp similarity index 95% rename from examples/common/entry/SwiftAdapter.cpp rename to examples/common/entry/swift_adapter.cpp index 1e471179c4..448946fef0 100644 --- a/examples/common/entry/SwiftAdapter.cpp +++ b/examples/common/entry/swift_adapter.cpp @@ -2,7 +2,7 @@ #if ENTRY_CONFIG_USE_NATIVE && BX_PLATFORM_VISIONOS -#include "SwiftAdapter.hpp" +#include "swift_adapter.hpp" #include #include @@ -30,12 +30,14 @@ namespace entry m_eventQueue.postSizeEvent(s_defaultWindow, _width, _height); + // Prevent render thread creation. bgfx::renderFrame(); m_thread.init(MainThreadEntry::threadFunc, &m_mte); } + ~Context() { m_thread.shutdown(); @@ -54,6 +56,10 @@ namespace entry { BX_UNUSED(_thread); + if (_thread != NULL) { + _thread->setThreadName("Main Thread BGFX"); + } + CFBundleRef mainBundle = CFBundleGetMainBundle(); if (mainBundle != nil) { @@ -171,12 +177,10 @@ bool BgfxAdapter::initialize(void) { void BgfxAdapter::shutdown(void) { if (m_initialized) { - bgfx::shutdown(); - - AppI *currentApp = entry::getCurrentApp(); - currentApp->shutdown(); + s_ctx->m_eventQueue.postExitEvent(); + s_ctx = NULL; } - + m_initialized = false; } diff --git a/examples/common/entry/SwiftAdapter.hpp b/examples/common/entry/swift_adapter.hpp similarity index 100% rename from examples/common/entry/SwiftAdapter.hpp rename to examples/common/entry/swift_adapter.hpp diff --git a/examples/common/entry/swift_bridging_header.h b/examples/common/entry/swift_bridging_header.h new file mode 100644 index 0000000000..734ee563c0 --- /dev/null +++ b/examples/common/entry/swift_bridging_header.h @@ -0,0 +1 @@ +#include "swift_adapter.hpp" diff --git a/scripts/example-common.lua b/scripts/example-common.lua index f6f61c7f5c..32ea02b642 100644 --- a/scripts/example-common.lua +++ b/scripts/example-common.lua @@ -99,7 +99,7 @@ project ("example-common") } xcodeprojectopts { SWIFT_VERSION = "5.0", - SWIFT_OBJC_BRIDGING_HEADER = path.join(BGFX_DIR, "examples/common/entry/SwiftBridgingHeader.h"), + SWIFT_OBJC_BRIDGING_HEADER = path.join(BGFX_DIR, "examples/common/entry/swift_bridging_header.h"), SWIFT_OBJC_INTEROP_MODE = "objcxx", }