Renderer

class Renderer(nativeHandle: NativePointer)

Renderer represents an operating system window and manages frame rendering and pacing.

Typically, applications create a Renderer per window. The Renderer generates drawing commands for the render thread and manages frame latency to keep it low.

A Renderer generates drawing commands from a View, which itself contains a Scene description.

Typical render loop:

while (!quit) {
if (renderer.beginFrame(swapChain)) {
renderer.render(view)
renderer.endFrame()
}
}

Frame pacing: beginFrame() manages frame pacing and returns false if the GPU is falling behind (to skip frames and reduce latency). When false is returned, either skip the frame or proceed anyway; if proceeding, you must still call endFrame().

See also

Constructors

Link copied to clipboard
constructor(nativeHandle: NativePointer)

Types

Link copied to clipboard

ClearOptions control how the SwapChain is cleared or discarded at the beginning of a frame.

Link copied to clipboard
object Companion
Link copied to clipboard

Display refresh-rate information for frame pacing and dynamic resolution scaling.

Link copied to clipboard
class FrameInfo(val frameId: Int, val gpuFrameDuration: Long, val denoisedGpuFrameDuration: Long, val beginFrame: Long, val endFrame: Long, val backendBeginFrame: Long, val backendEndFrame: Long, val gpuFrameComplete: Long, val vsync: Long, val displayPresent: Long, val presentDeadline: Long, val displayPresentInterval: Long, val compositionToPresentLatency: Long, val expectedPresentLatency: Long, val frameScheduleTime: Long)

Timing information about a frame. Times are nanoseconds since the steady-clock epoch; durations are nanoseconds.

Link copied to clipboard

Frame rate control and dynamic resolution scaling options.

Properties

Link copied to clipboard

Get/set clear behavior for the SwapChain. The getter returns a snapshot — mutate it and assign back to apply.

Link copied to clipboard

Get the Engine that created this Renderer.

Link copied to clipboard

Get the number of frames left to skip.

Link copied to clipboard

Whether GPU execution has fallen behind the CPU, to detect latency build-up when driving the presentation loop manually.

Link copied to clipboard

Get material time in seconds.

Link copied to clipboard

The maximum supported frame history size.

Link copied to clipboard

The native object, for interop with code calling the Fila* C API directly. Read-only: this wrapper owns it.

Link copied to clipboard

Get elapsed time since resetUserTime() in seconds.

Functions

Link copied to clipboard
fun beginFrame(swapChain: SwapChain, frameTimeNanos: Long = 0): Boolean

Prepare a frame for rendering and manage frame pacing.

Link copied to clipboard
fun copyFrame(dstSwapChain: SwapChain, dstViewport: Viewport, srcViewport: Viewport, flags: Int)

Copy the rendered frame to another SwapChain at a specified viewport.

Link copied to clipboard
fun endFrame()

Finish the current frame and schedule it for display.

Link copied to clipboard

Returns up to historySize entries of frame timing history, most recent first. The history can be lost when beginFrame() switches SwapChain.

Link copied to clipboard
fun pauseRenderThread(timeNs: Long)

Pause the render thread for a specified duration in nanoseconds.

Link copied to clipboard
@PlatformGap(platforms = [FilamentPlatform.WEB], behavior = "delivers asynchronously — the pixels are copied into the buffer when the frame completes, before its callback runs, rather than on return.")
fun readPixels(xoffset: Int, yoffset: Int, width: Int, height: Int, buffer: Texture.PixelBufferDescriptor)

Read back SwapChain pixels asynchronously.

@PlatformGap(platforms = [FilamentPlatform.WEB], behavior = "delivers asynchronously — the pixels are copied into the buffer when the frame completes, before its callback runs, rather than on return.")
fun readPixels(renderTarget: RenderTarget, xoffset: Int, yoffset: Int, width: Int, height: Int, buffer: Texture.PixelBufferDescriptor)

Read back RenderTarget pixels asynchronously.

fun readPixels(xoffset: Int, yoffset: Int, width: Int, height: Int, address: NativePointer, sizeInBytes: Int, format: Texture.Format, type: Texture.Type, stride: Int, onDone: () -> Unit)

readPixels straight into native memory the caller owns, without a copy (e.g. a Skia bitmap's pixels). onDone runs once address holds the frame, possibly on Filament's driver thread.

Link copied to clipboard
fun render(view: View)

Render a View into this Renderer's target.

Link copied to clipboard

Render a View without frame pacing.

Link copied to clipboard

Reset the user time clock to zero.

Link copied to clipboard
fun setDesiredPresentationTime(monotonicClockNanos: Long)

Set the real desired presentation time targeted for this frame.

Link copied to clipboard

Sets display information for frame pacing and dynamic resolution.

Link copied to clipboard

Sets frame rate control and dynamic resolution options.

Link copied to clipboard
fun setFrameScheduleTime(timeSteadyClockNano: Long)

Sets the steady-clock time the frame scheduling callback was entered, so frame pacing can measure the CPU time spent before beginFrame().

Link copied to clipboard
fun setMaterialTimeEpoch(timeEpochInNs: Long)

Set the epoch for material time in nanoseconds.

Link copied to clipboard
fun setPresentationTime(monotonicClockNanos: Long)

Set the time at which the frame must be presented.

Link copied to clipboard
fun setRenderingDeadline(monotonicClockNanos: Long)

Set the deadline by which CPU and GPU rendering must complete for the buffer to meet its target display latching window. Must be called before endFrame().

Link copied to clipboard
fun setVsyncTime(steadyClockTimeNano: Long)

Set the VSYNC time expressed as the duration in nanoseconds since epoch of std::chrono::steady_clock.

Link copied to clipboard

Check if the current frame should be rendered.

Link copied to clipboard
fun skipFrame(vsyncSteadyClockTimeNano: Long = 0)

Skip the current frame for frame pacing.

Link copied to clipboard
fun skipNextFrames(frameCount: Int)

Skip the next N frames for frame pacing.