CompositorContent
A type that describes content a scene renders directly with Metal, rather than composing from SwiftUI views.
Declaration
@MainActor protocol CompositorContentOverview
Conform to this protocol when you draw an immersive scene with your own Metal renderer. Implement body to describe the content, then pass the type to an ImmersiveSpace in place of a view. The CompositorLayer type in CompositorServices gives you the render loop to draw into.
The following example wraps a renderer in a type that an immersive space can present:
struct StarField: CompositorContent {
var body: some CompositorContent {
CompositorLayer(configuration: StarFieldConfiguration()) {
layerRenderer in
renderLoop(layerRenderer)
}
}
}
@main
struct StarFieldApp: App {
var body: some Scene {
ImmersiveSpace {
StarField()
}
}
}Compose these types the same way you compose views: a body can contain another CompositorContent, and AnyCompositorContent erases the concrete type when you need to return one of several kinds.