diff --git a/Apps/Playground/visionOS/App.swift b/Apps/Playground/visionOS/App.swift index a920a6329..354b90760 100644 --- a/Apps/Playground/visionOS/App.swift +++ b/Apps/Playground/visionOS/App.swift @@ -16,45 +16,6 @@ struct ContentStageConfiguration: CompositorLayerConfiguration { } } -class Renderer { - let layerRenderer: LayerRenderer - var libNativeBridge: LibNativeBridge - - init(_ layerRenderer: LayerRenderer) { - self.layerRenderer = layerRenderer - self.libNativeBridge = LibNativeBridge(layerRenderer) - } - - func startRenderLoop() { - let renderThread = Thread { - self.renderLoop() - } - renderThread.name = "Render Thread" - renderThread.start() - } - - - func renderLoop() { - while true { - if layerRenderer.state == .invalidated { - print("Layer is invalidated") - - libNativeBridge.shutdown() - return - } else if layerRenderer.state == .paused { - layerRenderer.waitUntilRunning() - continue - } else { - autoreleasepool { - libNativeBridge.initialize() - libNativeBridge.render() - } - } - } - } -} - - @main struct ExampleApp: App { @State private var showImmersiveSpace = false @@ -92,8 +53,12 @@ struct ExampleApp: App { } ImmersiveSpace(id: "ImmersiveSpace") { CompositorLayer(configuration: ContentStageConfiguration()) { layerRenderer in - let renderer = Renderer(layerRenderer) - renderer.startRenderLoop() + let renderThread = Thread { + var engine = LibNativeBridge(layerRenderer) + engine.renderLoop() + } + renderThread.name = "Render Thread" + renderThread.start() } }.immersionStyle(selection: .constant(.full), in: .full) } diff --git a/Apps/Playground/visionOS/LibNativeBridge.hpp b/Apps/Playground/visionOS/LibNativeBridge.hpp index c3b2c033f..55043665c 100644 --- a/Apps/Playground/visionOS/LibNativeBridge.hpp +++ b/Apps/Playground/visionOS/LibNativeBridge.hpp @@ -5,23 +5,22 @@ #include class LibNativeBridge { -private: - bool m_initialized = false; - cp_layer_renderer_t m_layerRenderer = NULL; - ar_world_tracking_provider_t world_tracking = NULL; - ar_session_t ar_session = NULL; public: - LibNativeBridge(cp_layer_renderer_t layerRenderer) : m_layerRenderer(layerRenderer) { - } - - ~LibNativeBridge() { - shutdown(); - } + LibNativeBridge(cp_layer_renderer_t layerRenderer) : m_layerRenderer(layerRenderer) {} + ~LibNativeBridge() { shutdown(); } void runARSession(void); bool initialize(void); void shutdown(void); + void renderLoop(void); + +private: + bool m_initialized = false; + cp_layer_renderer_t m_layerRenderer = NULL; + ar_world_tracking_provider_t world_tracking = NULL; + ar_session_t ar_session = NULL; + void render(void); };