Engine

Engine is Filament's main entry-point.

An Engine instance keeps track of all resources created by the user and manages the rendering thread as well as the hardware renderer.

To use Filament, an Engine instance must be created first using Engine.create(). Engine essentially represents (or is associated with) a hardware context (e.g., an OpenGL ES context or a Vulkan device).

Rendering typically happens in an operating system's window (which can be fullscreen), which is managed by a Renderer.

A typical Filament render loop looks like this:

val engine = Engine.create()!!
val swapChain = engine.createSwapChain(nativeWindow)
val renderer = engine.createRenderer()
val scene = engine.createScene()
val view = engine.createView()

view.setScene(scene)

while (!quit) {
// Wait for VSYNC and user input events
if (renderer.beginFrame(swapChain)) {
renderer.render(view)
renderer.endFrame()
}
}

engine.destroy(view)
engine.destroy(scene)
engine.destroy(renderer)
engine.destroy(swapChain)
Engine.destroy(engine)

Constructors

Link copied to clipboard
constructor(nativeHandle: NativePointer)

Types

Link copied to clipboard

How the engine handles asynchronous operations.

Link copied to clipboard

Rendering backend selection.

Link copied to clipboard
class Builder

Builder for creating and configuring an Engine instance.

Link copied to clipboard
object Companion
Link copied to clipboard
class Config

Advanced parameters for customizing Engine initialization.

Link copied to clipboard
class FeatureFlag(val name: String, val description: String, val value: Boolean, val constant: Boolean)

A feature flag: a last-resort switch for a faulty feature, set when the Engine is built and, unless constant, at any time with setFeatureFlag.

Link copied to clipboard

Backend feature levels control available rendering capabilities and performance characteristics.

Link copied to clipboard

A tri-state for compile's shadow-receiver and skinning variants.

Link copied to clipboard

GPU context priority, a hint to the driver for work scheduling and preemption.

Link copied to clipboard

Stereoscopic rendering technique for VR and 3D displays.

Link copied to clipboard
class Token

The opaque token Builder.build's callback gets, for getEngine.

Properties

Link copied to clipboard

The currently active feature level.

Link copied to clipboard

The rendering backend being used by this Engine.

Link copied to clipboard
Link copied to clipboard

The canvas this engine renders into.

Link copied to clipboard
Link copied to clipboard

The configuration this Engine was built with.

Link copied to clipboard

The default Material: 80% white, lit. Owned by the Engine.

Link copied to clipboard

The EntityManager for creating and managing entities.

Link copied to clipboard

Whether the Engine is in an unrecoverable failure state (e.g. the GPU device was lost). Once true, the Engine must be destroyed and recreated.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Whether asynchronous operations can be used (see Config.asynchronousMode).

Link copied to clipboard

Whether the engine batches identical renderables into instanced draw calls.

Link copied to clipboard
@PlatformGap(platforms = [FilamentPlatform.WEB], behavior = "state is only tracked locally — Filament's pause needs threads, which the wasm build doesn't have, so it has no effect on rendering.")
var isPaused: Boolean

Whether the render thread is paused. Set to pause or resume it.

Link copied to clipboard

Whether this Engine hasn't been destroyed.

Link copied to clipboard

The LightManager for managing light components.

Link copied to clipboard
Link copied to clipboard

The maximum number of instances automatic instancing batches together.

Link copied to clipboard
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

The RenderableManager for managing renderable components.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

The highest feature level supported by this backend.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

The TransformManager for managing entity transforms.

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard

Cancels the async call id (runCommandAsync, setBufferAsync, setBufferAtAsync, setImageAsync…). Its completion callback still runs, with AsyncCallStatus.CANCELED. False if it's running, done or already canceled.

Link copied to clipboard
open override fun close()

Same as destroy; lets this be used with use { } and try-with-resources.

Link copied to clipboard
fun compile(priority: Material.CompilerPriorityQueue, material: Material, view: View, shadowReceiver: Engine.FeatureState, skinning: Engine.FeatureState, callback: (Material) -> Unit? = null)

Asynchronously compiles the variants of material needed to render it in view, taking into account the view's features (lighting, fog, stereo, shadowing) and shadowReceiver and skinning.

Link copied to clipboard
fun createCamera(entity: Entity): Camera

Creates a Camera component on entity.

Link copied to clipboard

Creates a Fence.

Link copied to clipboard

Creates a Renderer.

Link copied to clipboard

Creates a Scene.

Link copied to clipboard
fun createSwapChain(surface: NativeSurface, flags: Long = 0): SwapChain

Creates a SwapChain rendering into a native display surface.

fun createSwapChain(width: Int, height: Int, flags: Long = 0): SwapChain

Creates an offscreen SwapChain of the given size.

Link copied to clipboard

Creates a View.

Link copied to clipboard
fun destroy(bufferObject: BufferObject): Boolean

Destroys a BufferObject.

fun destroy(colorGrading: ColorGrading): Boolean

Destroys a ColorGrading.

fun destroy(fence: Fence): Boolean

Destroys a Fence.

fun destroy(framePacer: FramePacer): Boolean

Destroys a FramePacer.

fun destroy(indexBuffer: IndexBuffer): Boolean

Destroys an IndexBuffer.

fun destroy(indirectLight: IndirectLight): Boolean

Destroys an IndirectLight.

fun destroy(instanceBuffer: InstanceBuffer): Boolean

Destroys an InstanceBuffer.

fun destroy(material: Material): Boolean

Destroys a Material; its instances must be destroyed first.

fun destroy(materialInstance: MaterialInstance): Boolean

Destroys a MaterialInstance.

fun destroy(morphTargetBuffer: MorphTargetBuffer): Boolean

Destroys a MorphTargetBuffer.

fun destroy(renderTarget: RenderTarget): Boolean

Destroys a RenderTarget.

fun destroy(renderer: Renderer): Boolean

Destroys a Renderer.

fun destroy(scene: Scene): Boolean

Destroys a Scene.

fun destroy(skinningBuffer: SkinningBuffer): Boolean

Destroys a SkinningBuffer.

fun destroy(skybox: Skybox): Boolean

Destroys a Skybox.

fun destroy(stream: Stream): Boolean

Destroys a Stream.

fun destroy(swapChain: SwapChain): Boolean

Destroys a SwapChain, and releases the native window it rendered into.

fun destroy(texture: Texture): Boolean

Destroys a Texture.

fun destroy(vertexBuffer: VertexBuffer): Boolean

Destroys a VertexBuffer.

fun destroy(view: View): Boolean

Destroys a View.

fun destroy(entity: Entity)

Destroys every Filament component of entity; the entity itself is the EntityManager's.

Link copied to clipboard

Destroys the Camera component of entity.

Link copied to clipboard

Enables high-precision world-space translations, for better numerical stability with large translations.

Link copied to clipboard
fun execute()

Runs the engine's pending work on this thread, for platforms without a render thread.

Link copied to clipboard
fun flush()

Kicks the hardware thread (e.g. the OpenGL, Vulkan or Metal thread) without blocking.

Link copied to clipboard

Blocks until all pending commands have been executed by the GPU.

fun flushAndWait(timeout: Long): Boolean

Blocks until all pending commands have been executed by the GPU, or timeout nanoseconds pass.

Link copied to clipboard

The Camera component of entity, or null if it has none.

Link copied to clipboard

A feature flag's value, or null if it doesn't exist.

Link copied to clipboard

The feature flags this Engine knows.

Link copied to clipboard

Whether a feature flag named name exists.

Link copied to clipboard

Whether this Engine supports stereoscopicType rendering.

Link copied to clipboard
fun isValid(bufferObject: BufferObject): Boolean

Whether bufferObject is a live object of this Engine.

fun isValid(colorGrading: ColorGrading): Boolean

Whether colorGrading is a live object of this Engine.

fun isValid(fence: Fence): Boolean

Whether fence is a live object of this Engine.

fun isValid(indexBuffer: IndexBuffer): Boolean

Whether indexBuffer is a live object of this Engine.

fun isValid(indirectLight: IndirectLight): Boolean

Whether indirectLight is a live object of this Engine.

fun isValid(instanceBuffer: InstanceBuffer): Boolean

Whether instanceBuffer is a live object of this Engine.

fun isValid(material: Material): Boolean

Whether material is a live object of this Engine.

fun isValid(morphTargetBuffer: MorphTargetBuffer): Boolean

Whether morphTargetBuffer is a live object of this Engine.

fun isValid(renderTarget: RenderTarget): Boolean

Whether renderTarget is a live object of this Engine.

fun isValid(renderer: Renderer): Boolean

Whether renderer is a live object of this Engine.

fun isValid(scene: Scene): Boolean

Whether scene is a live object of this Engine.

fun isValid(skinningBuffer: SkinningBuffer): Boolean

Whether skinningBuffer is a live object of this Engine.

fun isValid(skybox: Skybox): Boolean

Whether skybox is a live object of this Engine.

fun isValid(stream: Stream): Boolean

Whether stream is a live object of this Engine.

fun isValid(swapChain: SwapChain): Boolean

Whether swapChain is a live object of this Engine.

fun isValid(texture: Texture): Boolean

Whether texture is a live object of this Engine.

fun isValid(vertexBuffer: VertexBuffer): Boolean

Whether vertexBuffer is a live object of this Engine.

fun isValid(view: View): Boolean

Whether view is a live object of this Engine.

fun isValid(material: Material, materialInstance: MaterialInstance): Boolean

Whether materialInstance is a live instance of material.

Link copied to clipboard
fun isValidExpensive(materialInstance: MaterialInstance): Boolean

Whether materialInstance is a live instance of any of this Engine's materials; slower than isValid.

Link copied to clipboard

Runs the pending user callbacks now instead of later, e.g. once per frame after the vsync tick.

Link copied to clipboard
fun runCommandAsync(command: () -> Unit, onComplete: (AsyncCallStatus) -> Unit? = null): Int

Queues command to run asynchronously, in order with the other async calls (texture and buffer uploads), and returns an ID for cancelAsyncCall. Meant for resource preparation such as asset loading; flooding it delays those uploads. onComplete runs once on the main thread (see pumpMessageQueues): AsyncCallStatus.COMPLETED if command ran, AsyncCallStatus.CANCELED if it never did. Needs isAsynchronousModeEnabled.

Link copied to clipboard

Activates featureLevel, at most supportedFeatureLevel; a level can't be lowered once activated.

Link copied to clipboard
fun setFeatureFlag(name: String, value: Boolean): Boolean

Sets a feature flag; constant flags can only be set on the Builder. @return false if it doesn't exist or is constant.

Link copied to clipboard

Switches the command queue to unprotected mode, after a frame on a protected SwapChain.