A container that holds the view’s render callbacks.
Render callbacks are closures RealityKit calls at predefined times. You can use render callbacks
to modify the results of RealityKit’s rendering. If you assign a function or closure to any of the
contained callback properties, RealityKit calls that function or closure at a predefined time. Setting
the ``ARView/RenderCallbacks-swift.struct/postProcess`` property, for example,
causes RealityKit to call the assigned function or closure every frame, after RealityKit renders the
scene, but before it displays it.
Members (5)
get · iOS 15.0+
postProcess
TypeScript
get postProcess(): Promise<(((arg0: ARView_PostProcessContext) => Promise<void>)) | null>
Swift declaration
var postProcess: ((ARView.PostProcessContext) -> Void)?
A callback function for implementing postprocess effects.
Assign a function or closure to this property to implement
postprocessing effects for a RealityKit scene. If this value is
non-`nil`, RealityKit calls the assigned function or closure once
every frame before it displays the scene. If you register a
postprocess render callback, the callback function needs to encode the
modified frame buffer to the context’s
``ARView/PostProcessContext/targetColorTexture``, or nothing
renders.
A postprocess callback looks like this:
```swift
func myPostProcessCallback(context:ARView.PostProcessContext) {
// Handle postprocessing here.
}
```
To register the function so RealityKit begins calling it, assign it
to the ``ARView/RenderCallbacks-swift.struct/postProcess`` property
of the view’s ``ARView/renderCallbacks-swift.property`` property.
```swift
arView.renderCallbacks.postProcess = myPostProcessCallback
```
To stop RealityKit from calling your function, assign `nil`:
```swift
arView.renderCallbacks.postProcess = nil
```
If your app turns postprocessing on and off frequently, another
option for disabling postprocess effects is to keep your callback
registered, but use an
<doc://com.apple.documentation/documentation/metal/mtlblitcommandencoder>
to encode the unmodified frame directly to the output texture
whenever postprocess effects aren’t active.
```swift
func myPostProcessCallback(context:ARView.PostProcessContext) {
if (usePostProcessEffects) {
handlePostProcessing(context: ARView.PostProcessContext)
return
}
// If postprocess effects are disabled, copy sourceColorTexture
// directly to targetColorTexture.
let blitEncoder = context.commandBuffer.makeBlitCommandEncoder()
blitEncoder?.copy(from: context.sourceColorTexture, to: context.targetColorTexture)
blitEncoder?.endEncoding()
}
```
var postProcess: ((ARView.PostProcessContext) -> Void)?
A callback function for implementing postprocess effects.
Assign a function or closure to this property to implement
postprocessing effects for a RealityKit scene. If this value is
non-`nil`, RealityKit calls the assigned function or closure once
every frame before it displays the scene. If you register a
postprocess render callback, the callback function needs to encode the
modified frame buffer to the context’s
``ARView/PostProcessContext/targetColorTexture``, or nothing
renders.
A postprocess callback looks like this:
```swift
func myPostProcessCallback(context:ARView.PostProcessContext) {
// Handle postprocessing here.
}
```
To register the function so RealityKit begins calling it, assign it
to the ``ARView/RenderCallbacks-swift.struct/postProcess`` property
of the view’s ``ARView/renderCallbacks-swift.property`` property.
```swift
arView.renderCallbacks.postProcess = myPostProcessCallback
```
To stop RealityKit from calling your function, assign `nil`:
```swift
arView.renderCallbacks.postProcess = nil
```
If your app turns postprocessing on and off frequently, another
option for disabling postprocess effects is to keep your callback
registered, but use an
<doc://com.apple.documentation/documentation/metal/mtlblitcommandencoder>
to encode the unmodified frame directly to the output texture
whenever postprocess effects aren’t active.
```swift
func myPostProcessCallback(context:ARView.PostProcessContext) {
if (usePostProcessEffects) {
handlePostProcessing(context: ARView.PostProcessContext)
return
}
// If postprocess effects are disabled, copy sourceColorTexture
// directly to targetColorTexture.
let blitEncoder = context.commandBuffer.makeBlitCommandEncoder()
blitEncoder?.copy(from: context.sourceColorTexture, to: context.targetColorTexture)
blitEncoder?.endEncoding()
}
```
get · iOS 15.0+
prepareWithDevice
TypeScript
get prepareWithDevice(): Promise<(((arg0: SDKHandle) => Promise<void>)) | null>
Swift declaration
var prepareWithDevice: ((any MTLDevice) -> Void)?
A callback function for doing initial setup work.
If you assign a function to
``ARView/RenderCallbacks-swift.struct/prepareWithDevice``,
RealityKit calls that function once, after it does its setup work,
but before it renders the next frame. If you register a
``ARView/RenderCallbacks-swift.struct/prepareWithDevice`` callback
during app startup, RealityKit calls it before it renders the first
frame. A callback function looks like this:
```swift
func myPostProcessSetupCallback(device: MTLDevice) {
// Handle setup work here.
}
```
To register the function so RealityKit calls it, assign it to the
``ARView/RenderCallbacks-swift.struct/prepareWithDevice`` property
of the view’s ``ARView/renderCallbacks-swift.property`` property.
```swift
arView.renderCallbacks.prepareWithDevice = myPostProcessSetupCallback
```
To remove the callback, assign `nil`.
```swift
arView.renderCallbacks.prepareWithDevice = nil
```
If you assign a new closure or function to the property after
setting it to `nil`, RealityKit calls the new closure before it
renders the next frame. In that case, avoid doing long-running tasks
in the callback function to avoid rendering hitches.
A callback function for doing initial setup work.
If you assign a function to
``ARView/RenderCallbacks-swift.struct/prepareWithDevice``,
RealityKit calls that function once, after it does its setup work,
but before it renders the next frame. If you register a
``ARView/RenderCallbacks-swift.struct/prepareWithDevice`` callback
during app startup, RealityKit calls it before it renders the first
frame. A callback function looks like this:
```swift
func myPostProcessSetupCallback(device: MTLDevice) {
// Handle setup work here.
}
```
To register the function so RealityKit calls it, assign it to the
``ARView/RenderCallbacks-swift.struct/prepareWithDevice`` property
of the view’s ``ARView/renderCallbacks-swift.property`` property.
```swift
arView.renderCallbacks.prepareWithDevice = myPostProcessSetupCallback
```
To remove the callback, assign `nil`.
```swift
arView.renderCallbacks.prepareWithDevice = nil
```
If you assign a new closure or function to the property after
setting it to `nil`, RealityKit calls the new closure before it
renders the next frame. In that case, avoid doing long-running tasks
in the callback function to avoid rendering hitches.
init · iOS 15.0+
init
TypeScript
static init(): Promise<ARView_RenderCallbacks>
Swift declaration
init()
Creates a new object.
When you create a new ``ARView``, it automatically creates an
``ARView/RenderCallbacks-swift.struct`` object and assigns it to the
``ARView/renderCallbacks-swift.property`` property. Your code won’t
usually need to create ``ARView/RenderCallbacks-swift.struct``
objects.