6. Rendering

The rendering process starts by passing the image sampleBuffer and metadataObjects to the ARGSession. Once ARGear renders the frame, ARGSession calls the didUpdateFrame function of ARGSessionDelegate and with the ARGFrame parameter. The renderedPixelBuffer of ARGFrame contains final rendered data in the CVPixelBuffer data type.

The rendered frames can be drawn to a view using the data from ARGFrame.

The sample code below shows how to obtain renderedPixelBuffer in ARGFrame from didUpdateFrame. ARGScene is implemented in the Sample App and uses an OpenGL View to draw the frame.

Objective-C
Swift
Objective-C
// Sample Code.Obtaining ARGFrame from didUpdateFrame
ARGScene *sceneView = [[ARGScene alloc] initSceneviewAt:self.view withViewTransform:displayTramsform];
- (void)didUpdateFrame:(ARGFrame *)frame {
if ([frame renderedPixelBuffer]) {
[sceneView displayPixelBuffer:[frame renderedPixelBuffer]];;
}
}
Swift
// Sample Code.Obtaining ARGFrame from didUpdateFrame
public func didUpdate(_ arFrame: ARGFrame) {
guard let renderedPixelbuffer = arFrame.renderedPixelBuffer else {
return
}
// draw sublayer(CALayer())'s contents
self.cameraPreviewCALayer.contents = renderedPixelbuffer
}