Contents

CompositorLayer

A type that you use with an immersive space to display fully immersive content using Metal.

Declaration

struct CompositorLayer
@MainActor @preconcurrency struct CompositorLayer

Mentioned in

Overview

Use a CompositorLayer to specify the content of an ImmersiveSpace when you want to render that content yourself using Metal. When you present a space with this content, Compositor Services creates a LayerRenderer type for you to use with your rendering code. The layer renderer provides configuration details, timing information, and the Metal types and information you need to configure your rendering loop and manage the rendering process.

The following example shows a ImmersiveSpace that uses a CompositorLayer to specify its content. Use the closure for the CompositorLayer to set up and start your Metal rendering code. In this example, Compositor Services creates the layer using a default set of Metal configuration options. To customize the configuration of your Metal rendering environment, pass a custom CompositorLayerConfiguration type to your CompositorLayer at initialization time.

ImmersiveSpace(id: "MyContent") {
    CompositorLayer { layerRenderer in
        // Set up and run the Metal render loop.
        let renderThread = Thread {
            let engine = my_engine_create(layerRenderer)
            my_engine_render_loop(engine)
        }
        renderThread.name = "Render Thread"
        renderThread.start()
    }
}

For more information about how to set up and start your Metal rendering engine, see Drawing fully immersive content using Metal.

Topics

Initializers

See Also

App integration