docs/android/dokka/filament-android/com.google.android.filament/-engine/index.md
//filament-android/com.google.android.filament/Engine
open class Engine
Engine is filament's main entry-point.
An Engine instance main function is to keep track of all resources created by the user and manage the rendering thread as well as the hardware renderer.
To use filament, an Engine instance must be created first:
import com.google.android.filament.*
Engine engine = Engine.create();
Engine essentially represents (or is associated to) a hardware context (e.g. an OpenGL ES context).
Rendering typically happens in an operating system's window (which can be full screen), such window is managed by a Renderer.
A typical filament render loop looks like this:
import com.google.android.filament.*
Engine engine = Engine.create();
SwapChain swapChain = engine.createSwapChain(nativeWindow);
Renderer renderer = engine.createRenderer();
Scene scene = engine.createScene();
View view = engine.createView();
view.setScene(scene);
do {
// typically we wait for VSYNC and user input events
if (renderer.beginFrame(swapChain)) {
renderer.render(view);
renderer.endFrame();
}
} while (!quit);
engine.destroyView(view);
engine.destroyScene(scene);
engine.destroyRenderer(renderer);
engine.destroySwapChain(swapChain);
engine.destroy();
Each Engine instance keeps track of all objects created by the user, such as vertex and index buffers, lights, cameras, etc... The user is expected to free those resources, however, leaked resources are freed when the engine instance is destroyed and a warning is emitted in the console.
An Engine instance is not thread-safe. The implementation makes no attempt to synchronize calls to an Engine instance methods. If multi-threading is needed, synchronization must be external.
When created, the Engine instance starts a render thread as well as multiple worker threads, these threads have an elevated priority appropriate for rendering, based on the platform's best practices. The number of worker threads depends on the platform and is automatically chosen for best performance.
On platforms with asymmetric cores (e.g. ARM's Big.Little), Engine makes some educated guesses as to which cores to use for the render thread and worker threads. For example, it'll try to keep an OpenGL ES thread on a Big core.
A swap chain represents an Operating System's native renderable surface. Typically it's a window or a view. Because a SwapChain is initialized from a native object, it is given to filament as an Object, which must be of the proper type for each platform filament is running on.
| SwapChain |
| Renderer |
| Name | Summary |
|---|---|
| Backend | [main] |
| enum Backend | |
| Denotes a backend | |
| Builder | [main] |
| open class Builder | |
Constructs Engine objects using a builder pattern. | |
| Config | [main] |
| open class Config | |
| Parameters for customizing the initialization of Engine. | |
| FeatureLevel | [main] |
| enum FeatureLevel | |
| Defines the backend's feature levels. | |
| FeatureState | [main] |
| enum FeatureState | |
| Three-state feature state. | |
| GpuContextPriority | [main] |
| enum GpuContextPriority | |
| This controls the priority level for GPU work scheduling, which helps prioritize the submitted GPU work and enables preemption. | |
| StereoscopicType | [main] |
| enum StereoscopicType | |
| The type of technique for stereoscopic rendering. |
| Name | Summary |
|---|---|
| compile | [main] |
| open fun compile(priority: Material.CompilerPriorityQueue, material: Material, view: View, shadowReceiver: Engine.FeatureState, skinning: Engine.FeatureState, handler: Any, callback: Runnable) | |
| Asynchronously ensures that the variants of the specified Material required to render it in the provided View are compiled. | |
| create | [main] |
| open fun create(): Engine | |
| Creates an instance of Engine using the default Backend This method is one of the few thread-safe methods. | |
| [main] | |
| open fun create(backend: Engine.Backend): Engine | |
| Creates an instance of Engine using the specified Backend This method is one of the few thread-safe methods. | |
| [main] | |
| open fun create(sharedContext: Any): Engine | |
| Creates an instance of Engine using the OPENGL and a shared OpenGL context. | |
| createCamera | [main] |
| open fun createCamera(entity: Int): Camera | |
Creates and adds a Camera component to a given entity. | |
| createFence | [main] |
| open fun createFence(): Fence | |
| Creates a Fence. | |
| createRenderer | [main] |
| open fun createRenderer(): Renderer | |
| Creates a Renderer. | |
| createScene | [main] |
| open fun createScene(): Scene | |
| Creates a Scene. | |
| createSwapChain | [main] |
| open fun createSwapChain(surface: Any): SwapChain | |
| Creates an opaque SwapChain from the given OS native window handle. | |
| [main] | |
| open fun createSwapChain(surface: Any, flags: Long): SwapChain | |
| Creates a SwapChain from the given OS native window handle. | |
| [main] | |
| open fun createSwapChain(width: Int, height: Int, flags: Long): SwapChain | |
| Creates a headless SwapChain | |
| createSwapChainFromNativeSurface | [main] |
| open fun createSwapChainFromNativeSurface(surface: NativeSurface, flags: Long): SwapChain | |
| Creates a SwapChain from a NativeSurface. | |
| createView | [main] |
| open fun createView(): View | |
| Creates a View. | |
| destroy | [main] |
| open fun destroy() | |
Destroy the Engine instance and all associated resources. | |
| destroyCameraComponent | [main] |
| open fun destroyCameraComponent(entity: Int) | |
| Destroys the Camera component associated with the given entity. | |
| destroyColorGrading | [main] |
| open fun destroyColorGrading(colorGrading: ColorGrading) | |
| Destroys a ColorGrading and frees all its associated resources. | |
| destroyEntity | [main] |
| open fun destroyEntity(entity: Int) | |
Destroys all Filament-known components from this entity. | |
| destroyFence | [main] |
| open fun destroyFence(fence: Fence) | |
| Destroys a Fence and frees all its associated resources. | |
| destroyIndexBuffer | [main] |
| open fun destroyIndexBuffer(indexBuffer: IndexBuffer) | |
| Destroys a IndexBuffer and frees all its associated resources. | |
| destroyIndirectLight | [main] |
| open fun destroyIndirectLight(ibl: IndirectLight) | |
| Destroys a IndirectLight and frees all its associated resources. | |
| destroyMaterial | [main] |
| open fun destroyMaterial(material: Material) | |
| Destroys a Material and frees all its associated resources. | |
| destroyMaterialInstance | [main] |
| open fun destroyMaterialInstance(materialInstance: MaterialInstance) | |
| Destroys a MaterialInstance and frees all its associated resources. | |
| destroyMorphTargetBuffer | [main] |
| open fun destroyMorphTargetBuffer(morphTargetBuffer: MorphTargetBuffer) | |
| Destroys a MorphTargetBuffer and frees all its associated resources. | |
| destroyRenderer | [main] |
| open fun destroyRenderer(renderer: Renderer) | |
| Destroys a Renderer and frees all its associated resources. | |
| destroyRenderTarget | [main] |
| open fun destroyRenderTarget(target: RenderTarget) | |
| Destroys a RenderTarget and frees all its associated resources. | |
| destroyScene | [main] |
| open fun destroyScene(scene: Scene) | |
| Destroys a Scene and frees all its associated resources. | |
| destroySkinningBuffer | [main] |
| open fun destroySkinningBuffer(skinningBuffer: SkinningBuffer) | |
| Destroys a SkinningBuffer and frees all its associated resources. | |
| destroySkybox | [main] |
| open fun destroySkybox(skybox: Skybox) | |
| Destroys a Skybox and frees all its associated resources. | |
| destroyStream | [main] |
| open fun destroyStream(stream: Stream) | |
| Destroys a Stream and frees all its associated resources. | |
| destroySwapChain | [main] |
| open fun destroySwapChain(swapChain: SwapChain) | |
| Destroys a SwapChain and frees all its associated resources. | |
| destroyTexture | [main] |
| open fun destroyTexture(texture: Texture) | |
| Destroys a Texture and frees all its associated resources. | |
| destroyVertexBuffer | [main] |
| open fun destroyVertexBuffer(vertexBuffer: VertexBuffer) | |
| Destroys a VertexBuffer and frees all its associated resources. | |
| destroyView | [main] |
| open fun destroyView(view: View) | |
| Destroys a View and frees all its associated resources. | |
| enableAccurateTranslations | [main] |
| open fun enableAccurateTranslations() | |
| Helper to enable accurate translations. | |
| flush | [main] |
| open fun flush() | |
| Kicks the hardware thread (e.g. | |
| flushAndWait | [main] |
| open fun flushAndWait() | |
| Kicks the hardware thread (e.g.: the OpenGL, Vulkan or Metal thread) and blocks until all commands to this point are executed. | |
| [main] | |
| open fun flushAndWait(timeout: Long): Boolean | |
| Kicks the hardware thread (e.g. | |
| getActiveFeatureLevel | [main] |
| open fun getActiveFeatureLevel(): Engine.FeatureLevel | |
| Returns the currently active feature level. | |
| getBackend | [main] |
| open fun getBackend(): Engine.Backend | |
| getCameraComponent | [main] |
| open fun getCameraComponent(entity: Int): Camera | |
Returns the Camera component of the given entity. | |
| getConfig | [main] |
| open fun getConfig(): Engine.Config | |
| Retrieves the configuration settings of this Engine. | |
| getEntityManager | [main] |
| open fun getEntityManager(): EntityManager | |
| getFeatureFlag | [main] |
| open fun getFeatureFlag(name: String): Boolean | |
| Retrieves the value of any feature flag. | |
| getLightManager | [main] |
| open fun getLightManager(): LightManager | |
| getMaxStereoscopicEyes | [main] |
| open fun getMaxStereoscopicEyes(): Long | |
| Returns the maximum number of stereoscopic eyes supported by Filament. | |
| getNativeJobSystem | [main] |
| open fun getNativeJobSystem(): Long | |
| getNativeObject | [main] |
| open fun getNativeObject(): Long | |
| getRenderableManager | [main] |
| open fun getRenderableManager(): RenderableManager | |
| getSteadyClockTimeNano | [main] |
| open fun getSteadyClockTimeNano(): Long | |
| Get the current time. | |
| getSupportedFeatureLevel | [main] |
| open fun getSupportedFeatureLevel(): Engine.FeatureLevel | |
| Query the feature level supported by the selected backend. | |
| getTransformManager | [main] |
| open fun getTransformManager(): TransformManager | |
| hasFeatureFlag | [main] |
| open fun hasFeatureFlag(name: String): Boolean | |
| Checks if a feature flag exists | |
| hasUnrecoverableFailure | [main] |
| open fun hasUnrecoverableFailure(): Boolean | |
| Returns whether the engine has encountered an unrecoverable failure. | |
| isAutomaticInstancingEnabled | [main] |
| open fun isAutomaticInstancingEnabled(): Boolean | |
| isPaused | [main] |
| open fun isPaused(): Boolean | |
| Get paused state of rendering thread. | |
| isValid | [main] |
| open fun isValid(): Boolean | |
| isValidColorGrading | [main] |
| open fun isValidColorGrading(object: ColorGrading): Boolean | |
| Returns whether the object is valid. | |
| isValidExpensiveMaterialInstance | [main] |
| open fun isValidExpensiveMaterialInstance(object: MaterialInstance): Boolean | |
| Returns whether the object is valid. | |
| isValidFence | [main] |
| open fun isValidFence(object: Fence): Boolean | |
| Returns whether the object is valid. | |
| isValidIndexBuffer | [main] |
| open fun isValidIndexBuffer(object: IndexBuffer): Boolean | |
| Returns whether the object is valid. | |
| isValidIndirectLight | [main] |
| open fun isValidIndirectLight(object: IndirectLight): Boolean | |
| Returns whether the object is valid. | |
| isValidMaterial | [main] |
| open fun isValidMaterial(object: Material): Boolean | |
| Returns whether the object is valid. | |
| isValidMaterialInstance | [main] |
| open fun isValidMaterialInstance(ma: Material, mi: MaterialInstance): Boolean | |
| Returns whether the object is valid. | |
| isValidMorphTargetBuffer | [main] |
| open fun isValidMorphTargetBuffer(object: MorphTargetBuffer): Boolean | |
| Returns whether the object is valid. | |
| isValidRenderer | [main] |
| open fun isValidRenderer(object: Renderer): Boolean | |
| Returns whether the object is valid. | |
| isValidRenderTarget | [main] |
| open fun isValidRenderTarget(object: RenderTarget): Boolean | |
| Returns whether the object is valid. | |
| isValidScene | [main] |
| open fun isValidScene(object: Scene): Boolean | |
| Returns whether the object is valid. | |
| isValidSkinningBuffer | [main] |
| open fun isValidSkinningBuffer(object: SkinningBuffer): Boolean | |
| Returns whether the object is valid. | |
| isValidSkybox | [main] |
| open fun isValidSkybox(object: Skybox): Boolean | |
| Returns whether the object is valid. | |
| isValidStream | [main] |
| open fun isValidStream(object: Stream): Boolean | |
| Returns whether the object is valid. | |
| isValidSwapChain | [main] |
| open fun isValidSwapChain(object: SwapChain): Boolean | |
| Returns whether the object is valid. | |
| isValidTexture | [main] |
| open fun isValidTexture(object: Texture): Boolean | |
| Returns whether the object is valid. | |
| isValidVertexBuffer | [main] |
| open fun isValidVertexBuffer(object: VertexBuffer): Boolean | |
| Returns whether the object is valid. | |
| isValidView | [main] |
| open fun isValidView(object: View): Boolean | |
| Returns whether the object is valid. | |
| setActiveFeatureLevel | [main] |
| open fun setActiveFeatureLevel(featureLevel: Engine.FeatureLevel): Engine.FeatureLevel | |
| Activate all features of a given feature level. | |
| setAutomaticInstancingEnabled | [main] |
| open fun setAutomaticInstancingEnabled(enable: Boolean) | |
| Enables or disables automatic instancing of render primitives. | |
| setFeatureFlag | [main] |
| open fun setFeatureFlag(name: String, value: Boolean): Boolean | |
| Set the value of a non-constant feature flag. | |
| setPaused | [main] |
| open fun setPaused(paused: Boolean) | |
| Pause or resume the rendering thread. | |
| unprotected | [main] |
| open fun unprotected() | |
| Switch the command queue to unprotected mode. |