-
public class EngineEngine 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
Engineinstance 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
Engineinstance is not thread-safe. The implementation makes no attempt to synchronize calls to anEngineinstance methods. If multi-threading is needed, synchronization must be external.When created, the
Engineinstance 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),
Enginemakes 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public enumEngine.BackendDenotes a backend
public enumEngine.FeatureLevelDefines the backend's feature levels.
public enumEngine.StereoscopicTypeThe type of technique for stereoscopic rendering. (Note that the materials used will need to becompatible with the chosen technique.)
public classEngine.BuilderConstructs
Engineobjects using a builder pattern.public classEngine.ConfigParameters for customizing the initialization of Engine.
-
Method Summary
Modifier and Type Method Description static Enginecreate()Creates an instance of Engine using the default BackendThis method is one of the few thread-safe methods. static Enginecreate(@NonNull() Engine.Backend backend)Creates an instance of Engine using the specified BackendThis method is one of the few thread-safe methods. static Enginecreate(@NonNull() Object sharedContext)Creates an instance of Engine using the OPENGL and a shared OpenGL context. booleanisValid()voiddestroy()Destroy the Engineinstance and all associated resources.Engine.BackendgetBackend()voidenableAccurateTranslations()Helper to enable accurate translations.If you need this Engine to handle a very large world space, one way to achieve thisautomatically is to enable accurate translations in the TransformManager. Engine.FeatureLevelgetSupportedFeatureLevel()Query the feature level supported by the selected backend.A specific feature level needs to be set before the corresponding features can be used. Engine.FeatureLevelsetActiveFeatureLevel(@NonNull() Engine.FeatureLevel featureLevel)Activate all features of a given feature level. Engine.FeatureLevelgetActiveFeatureLevel()Returns the currently active feature level. voidsetAutomaticInstancingEnabled(boolean enable)Enables or disables automatic instancing of render primitives. booleanisAutomaticInstancingEnabled()Engine.ConfiggetConfig()Retrieves the configuration settings of this Engine. longgetMaxStereoscopicEyes()Returns the maximum number of stereoscopic eyes supported by Filament. SwapChaincreateSwapChain(@NonNull() Object surface)Creates an opaque SwapChain from the given OS native window handle. SwapChaincreateSwapChain(@NonNull() Object surface, long flags)Creates a SwapChain from the given OS native window handle. SwapChaincreateSwapChain(int width, int height, long flags)Creates a headless SwapChain SwapChaincreateSwapChainFromNativeSurface(@NonNull() NativeSurface surface, long flags)Creates a SwapChain from a NativeSurface. voiddestroySwapChain(@NonNull() SwapChain swapChain)Destroys a SwapChain and frees all its associated resources. booleanisValidRenderer(@NonNull() Renderer object)Returns whether the object is valid. booleanisValidView(@NonNull() View object)Returns whether the object is valid. booleanisValidScene(@NonNull() Scene object)Returns whether the object is valid. booleanisValidFence(@NonNull() Fence object)Returns whether the object is valid. booleanisValidStream(@NonNull() Stream object)Returns whether the object is valid. booleanisValidIndexBuffer(@NonNull() IndexBuffer object)Returns whether the object is valid. booleanisValidVertexBuffer(@NonNull() VertexBuffer object)Returns whether the object is valid. booleanisValidSkinningBuffer(@NonNull() SkinningBuffer object)Returns whether the object is valid. booleanisValidIndirectLight(@NonNull() IndirectLight object)Returns whether the object is valid. booleanisValidMaterial(@NonNull() Material object)Returns whether the object is valid. booleanisValidMaterialInstance(@NonNull() Material ma, MaterialInstance mi)Returns whether the object is valid. booleanisValidExpensiveMaterialInstance(@NonNull() MaterialInstance object)Returns whether the object is valid. booleanisValidSkybox(@NonNull() Skybox object)Returns whether the object is valid. booleanisValidColorGrading(@NonNull() ColorGrading object)Returns whether the object is valid. booleanisValidTexture(@NonNull() Texture object)Returns whether the object is valid. booleanisValidRenderTarget(@NonNull() RenderTarget object)Returns whether the object is valid. booleanisValidSwapChain(@NonNull() SwapChain object)Returns whether the object is valid. ViewcreateView()Creates a View. voiddestroyView(@NonNull() View view)Destroys a View and frees all its associated resources. RenderercreateRenderer()Creates a Renderer. voiddestroyRenderer(@NonNull() Renderer renderer)Destroys a Renderer and frees all its associated resources. CameracreateCamera(int entity)Creates and adds a Camera component to a given entity.CameragetCameraComponent(int entity)Returns the Camera component of the given entity.voiddestroyCameraComponent(int entity)Destroys the Camera component associated with the given entity. ScenecreateScene()Creates a Scene. voiddestroyScene(@NonNull() Scene scene)Destroys a Scene and frees all its associated resources. voiddestroyStream(@NonNull() Stream stream)Destroys a Stream and frees all its associated resources. FencecreateFence()Creates a Fence. voiddestroyFence(@NonNull() Fence fence)Destroys a Fence and frees all its associated resources. voiddestroyIndexBuffer(@NonNull() IndexBuffer indexBuffer)Destroys a IndexBuffer and frees all its associated resources. voiddestroyVertexBuffer(@NonNull() VertexBuffer vertexBuffer)Destroys a VertexBuffer and frees all its associated resources. voiddestroySkinningBuffer(@NonNull() SkinningBuffer skinningBuffer)Destroys a SkinningBuffer and frees all its associated resources. voiddestroyIndirectLight(@NonNull() IndirectLight ibl)Destroys a IndirectLight and frees all its associated resources. voiddestroyMaterial(@NonNull() Material material)Destroys a Material and frees all its associated resources. voiddestroyMaterialInstance(@NonNull() MaterialInstance materialInstance)Destroys a MaterialInstance and frees all its associated resources. voiddestroySkybox(@NonNull() Skybox skybox)Destroys a Skybox and frees all its associated resources. voiddestroyColorGrading(@NonNull() ColorGrading colorGrading)Destroys a ColorGrading and frees all its associated resources. voiddestroyTexture(@NonNull() Texture texture)Destroys a Texture and frees all its associated resources. voiddestroyRenderTarget(@NonNull() RenderTarget target)Destroys a RenderTarget and frees all its associated resources. voiddestroyEntity(int entity)Destroys all Filament-known components from this entity.TransformManagergetTransformManager()LightManagergetLightManager()RenderableManagergetRenderableManager()EntityManagergetEntityManager()voidflushAndWait()Kicks the hardware thread (e.g.: the OpenGL, Vulkan or Metal thread) and blocks untilall commands to this point are executed. booleanflushAndWait(long timeout)Kicks the hardware thread (e.g. voidflush()Kicks the hardware thread (e.g. booleanisPaused()Get paused state of rendering thread. voidsetPaused(boolean paused)Pause or resume the rendering thread. voidunprotected()Switch the command queue to unprotected mode. static native longgetSteadyClockTimeNano()Get the current time. booleanhasFeatureFlag(@NonNull() String name)Checks if a feature flag exists booleansetFeatureFlag(@NonNull() String name, boolean value)Set the value of a non-constant feature flag. booleangetFeatureFlag(@NonNull() String name)Retrieves the value of any feature flag. longgetNativeObject()longgetNativeJobSystem()-
-
Method Detail
-
create
@NonNull() static Engine create()
Creates an instance of Engine using the default Backend
This method is one of the few thread-safe methods.
-
create
@NonNull() static Engine create(@NonNull() Engine.Backend backend)
Creates an instance of Engine using the specified Backend
This method is one of the few thread-safe methods.
- Parameters:
backend- driver backend to use
-
create
@NonNull() static Engine create(@NonNull() Object sharedContext)
Creates an instance of Engine using the OPENGL and a shared OpenGL context.
This method is one of the few thread-safe methods.
- Parameters:
sharedContext- A platform-dependant OpenGL context used as a shared contextwhen creating filament's internal context.
-
isValid
boolean isValid()
-
destroy
void destroy()
Destroy the
Engineinstance and all associated resources.This method is one of the few thread-safe methods.
destroy should be called last and after all other resources have beendestroyed, it ensures all filament resources are freed.
Destroy all internal software and hardware resources.Free all user allocated resources that are not already destroyed and logs a warning.Destroyperforms the following tasks:This indicates a "leak" in the user's code.
Terminate the rendering engine's thread.Engine engine = Engine.create(); engine.destroy();
-
getBackend
@NonNull() Engine.Backend getBackend()
-
enableAccurateTranslations
void enableAccurateTranslations()
Helper to enable accurate translations.If you need this Engine to handle a very large world space, one way to achieve thisautomatically is to enable accurate translations in the TransformManager. This helperprovides a convenient way of doing that.This is typically called once just after creating the Engine.
-
getSupportedFeatureLevel
@NonNull() Engine.FeatureLevel getSupportedFeatureLevel()
Query the feature level supported by the selected backend.A specific feature level needs to be set before the corresponding features can be used.
-
setActiveFeatureLevel
@NonNull() Engine.FeatureLevel setActiveFeatureLevel(@NonNull() Engine.FeatureLevel featureLevel)
Activate all features of a given feature level. If an explicit feature level is not specifiedat Engine initialization time via featureLevel, the default feature level is FEATURE_LEVEL_0 on devices not compatible with GLES 3.0; otherwise, thedefault is ::FEATURE_LEVEL_1. The selected feature level must not behigher than the value returned by getActiveFeatureLevel and it's not possible lowerthe active feature level. Additionally, it is not possible to modify the feature level at allif the Engine was initialized at FEATURE_LEVEL_0.
- Parameters:
featureLevel- the feature level to activate.
-
getActiveFeatureLevel
@NonNull() Engine.FeatureLevel getActiveFeatureLevel()
Returns the currently active feature level.
-
setAutomaticInstancingEnabled
void setAutomaticInstancingEnabled(boolean enable)
Enables or disables automatic instancing of render primitives. Instancing of render primitivecan greatly reduce CPU overhead but requires the instanced primitives to be identical(i.e. use the same geometry) and use the same MaterialInstance. If it is known that thescene doesn't contain any identical primitives, automatic instancing can have someoverhead and it is then best to disable it.Disabled by default.
- Parameters:
enable- true to enable, false to disable automatic instancing.
-
isAutomaticInstancingEnabled
boolean isAutomaticInstancingEnabled()
-
getConfig
@NonNull() Engine.Config getConfig()
Retrieves the configuration settings of this Engine.This method returns the configuration object that was supplied to the Engine's method during the creation of this Engine. If the ::config method was not explicitly called (or called with null), this method returns the defaultconfiguration settings.
-
getMaxStereoscopicEyes
long getMaxStereoscopicEyes()
Returns the maximum number of stereoscopic eyes supported by Filament. The actual number ofeyes rendered is set at Engine creation time with the stereoscopicEyeCount setting.
-
createSwapChain
@NonNull() SwapChain createSwapChain(@NonNull() Object surface)
Creates an opaque SwapChain from the given OS native window handle.
- Parameters:
surface- on Android, must be an instance of android.view.Surface
-
createSwapChain
@NonNull() SwapChain createSwapChain(@NonNull() Object surface, long flags)
Creates a SwapChain from the given OS native window handle.
- Parameters:
surface- on Android, must be an instance of android.view.Surfaceflags- configuration flags, see SwapChainFlags
-
createSwapChain
@NonNull() SwapChain createSwapChain(int width, int height, long flags)
Creates a headless SwapChain
- Parameters:
width- width of the rendering bufferheight- height of the rendering bufferflags- configuration flags, see SwapChainFlags
-
createSwapChainFromNativeSurface
@NonNull() SwapChain createSwapChainFromNativeSurface(@NonNull() NativeSurface surface, long flags)
Creates a SwapChain from a NativeSurface.
- Parameters:
surface- a properly initialized NativeSurfaceflags- configuration flags, see SwapChainFlags
-
destroySwapChain
void destroySwapChain(@NonNull() SwapChain swapChain)
Destroys a SwapChain and frees all its associated resources.
- Parameters:
swapChain- the SwapChain to destroy
-
isValidRenderer
boolean isValidRenderer(@NonNull() Renderer object)
Returns whether the object is valid.
- Parameters:
object- Object to check for validity
-
isValidView
boolean isValidView(@NonNull() View object)
Returns whether the object is valid.
- Parameters:
object- Object to check for validity
-
isValidScene
boolean isValidScene(@NonNull() Scene object)
Returns whether the object is valid.
- Parameters:
object- Object to check for validity
-
isValidFence
boolean isValidFence(@NonNull() Fence object)
Returns whether the object is valid.
- Parameters:
object- Object to check for validity
-
isValidStream
boolean isValidStream(@NonNull() Stream object)
Returns whether the object is valid.
- Parameters:
object- Object to check for validity
-
isValidIndexBuffer
boolean isValidIndexBuffer(@NonNull() IndexBuffer object)
Returns whether the object is valid.
- Parameters:
object- Object to check for validity
-
isValidVertexBuffer
boolean isValidVertexBuffer(@NonNull() VertexBuffer object)
Returns whether the object is valid.
- Parameters:
object- Object to check for validity
-
isValidSkinningBuffer
boolean isValidSkinningBuffer(@NonNull() SkinningBuffer object)
Returns whether the object is valid.
- Parameters:
object- Object to check for validity
-
isValidIndirectLight
boolean isValidIndirectLight(@NonNull() IndirectLight object)
Returns whether the object is valid.
- Parameters:
object- Object to check for validity
-
isValidMaterial
boolean isValidMaterial(@NonNull() Material object)
Returns whether the object is valid.
- Parameters:
object- Object to check for validity
-
isValidMaterialInstance
boolean isValidMaterialInstance(@NonNull() Material ma, MaterialInstance mi)
Returns whether the object is valid.
- Parameters:
ma- Materialmi- MaterialInstance to check for validity
-
isValidExpensiveMaterialInstance
boolean isValidExpensiveMaterialInstance(@NonNull() MaterialInstance object)
Returns whether the object is valid.
- Parameters:
object- Object to check for validity
-
isValidSkybox
boolean isValidSkybox(@NonNull() Skybox object)
Returns whether the object is valid.
- Parameters:
object- Object to check for validity
-
isValidColorGrading
boolean isValidColorGrading(@NonNull() ColorGrading object)
Returns whether the object is valid.
- Parameters:
object- Object to check for validity
-
isValidTexture
boolean isValidTexture(@NonNull() Texture object)
Returns whether the object is valid.
- Parameters:
object- Object to check for validity
-
isValidRenderTarget
boolean isValidRenderTarget(@NonNull() RenderTarget object)
Returns whether the object is valid.
- Parameters:
object- Object to check for validity
-
isValidSwapChain
boolean isValidSwapChain(@NonNull() SwapChain object)
Returns whether the object is valid.
- Parameters:
object- Object to check for validity
-
createView
@NonNull() View createView()
Creates a View.
-
destroyView
void destroyView(@NonNull() View view)
Destroys a View and frees all its associated resources.
- Parameters:
view- the View to destroy
-
createRenderer
@NonNull() Renderer createRenderer()
Creates a Renderer.
-
destroyRenderer
void destroyRenderer(@NonNull() Renderer renderer)
Destroys a Renderer and frees all its associated resources.
- Parameters:
renderer- the Renderer to destroy
-
createCamera
@NonNull() Camera createCamera(int entity)
Creates and adds a Camera component to a given
entity.- Parameters:
entity-entityto add the camera component to
-
getCameraComponent
@Nullable() Camera getCameraComponent(int entity)
Returns the Camera component of the given
entity.- Parameters:
entity- Anentity.
-
destroyCameraComponent
void destroyCameraComponent(int entity)
Destroys the Camera component associated with the given entity.
- Parameters:
entity- an entity
-
createScene
@NonNull() Scene createScene()
Creates a Scene.
-
destroyScene
void destroyScene(@NonNull() Scene scene)
Destroys a Scene and frees all its associated resources.
- Parameters:
scene- the Scene to destroy
-
destroyStream
void destroyStream(@NonNull() Stream stream)
Destroys a Stream and frees all its associated resources.
- Parameters:
stream- the Stream to destroy
-
createFence
@NonNull() Fence createFence()
Creates a Fence.
-
destroyFence
void destroyFence(@NonNull() Fence fence)
Destroys a Fence and frees all its associated resources.
- Parameters:
fence- the Fence to destroy
-
destroyIndexBuffer
void destroyIndexBuffer(@NonNull() IndexBuffer indexBuffer)
Destroys a IndexBuffer and frees all its associated resources.
- Parameters:
indexBuffer- the IndexBuffer to destroy
-
destroyVertexBuffer
void destroyVertexBuffer(@NonNull() VertexBuffer vertexBuffer)
Destroys a VertexBuffer and frees all its associated resources.
- Parameters:
vertexBuffer- the VertexBuffer to destroy
-
destroySkinningBuffer
void destroySkinningBuffer(@NonNull() SkinningBuffer skinningBuffer)
Destroys a SkinningBuffer and frees all its associated resources.
- Parameters:
skinningBuffer- the SkinningBuffer to destroy
-
destroyIndirectLight
void destroyIndirectLight(@NonNull() IndirectLight ibl)
Destroys a IndirectLight and frees all its associated resources.
- Parameters:
ibl- the IndirectLight to destroy
-
destroyMaterial
void destroyMaterial(@NonNull() Material material)
Destroys a Material and frees all its associated resources.
All MaterialInstance of the specified Material must be destroyed beforedestroying it; if some MaterialInstance remain, this method fails silently.
- Parameters:
material- the Material to destroy
-
destroyMaterialInstance
void destroyMaterialInstance(@NonNull() MaterialInstance materialInstance)
Destroys a MaterialInstance and frees all its associated resources.
- Parameters:
materialInstance- the MaterialInstance to destroy
-
destroySkybox
void destroySkybox(@NonNull() Skybox skybox)
Destroys a Skybox and frees all its associated resources.
- Parameters:
skybox- the Skybox to destroy
-
destroyColorGrading
void destroyColorGrading(@NonNull() ColorGrading colorGrading)
Destroys a ColorGrading and frees all its associated resources.
- Parameters:
colorGrading- the ColorGrading to destroy
-
destroyTexture
void destroyTexture(@NonNull() Texture texture)
Destroys a Texture and frees all its associated resources.
- Parameters:
texture- the Texture to destroy
-
destroyRenderTarget
void destroyRenderTarget(@NonNull() RenderTarget target)
Destroys a RenderTarget and frees all its associated resources.
- Parameters:
target- the RenderTarget to destroy
-
destroyEntity
void destroyEntity(int entity)
Destroys all Filament-known components from this
entity.This method destroys Filament components only, not the
entityitself. To destroytheentityuseEntityManager#destroy.It is recommended to destroy components individually before destroying theirentity, this gives more control as to when the destruction really happens.Otherwise, orphaned components are garbage collected, which can happen at a later time.Even when component are garbage collected, the destruction of theirentityterminates their participation immediately.- Parameters:
entity- theentityto destroy
-
getTransformManager
@NonNull() TransformManager getTransformManager()
-
getLightManager
@NonNull() LightManager getLightManager()
-
getRenderableManager
@NonNull() RenderableManager getRenderableManager()
-
getEntityManager
@NonNull() EntityManager getEntityManager()
-
flushAndWait
void flushAndWait()
Kicks the hardware thread (e.g.: the OpenGL, Vulkan or Metal thread) and blocks untilall commands to this point are executed. Note that this does guarantee that thehardware is actually finished.
This is typically used right after destroying the
SwapChain,in cases where a guarantee about the SwapChain destruction is needed in a timely fashion,such as when responding to Android's surfaceDestroyed.
-
flushAndWait
boolean flushAndWait(long timeout)
Kicks the hardware thread (e.g. the OpenGL, Vulkan or Metal thread) and blocks untilall commands to this point are executed. Note that does guarantee that thehardware is actually finished.A timeout can be specified, if for some reason this flushAndWait doesn't complete before the timeout, it willreturn false, true otherwise.
This is typically used right after destroying the
SwapChain,in cases where a guarantee about theSwapChaindestruction is needed in atimely fashion, such as when responding to Android'sandroid.view.SurfaceHolder.Callback.surfaceDestroyed- Parameters:
timeout- A timeout in nanoseconds
-
flush
void flush()
Kicks the hardware thread (e.g. the OpenGL, Vulkan or Metal thread) but does not waitfor commands to be either executed or the hardware finished.
This is typically used after creating a lot of objects to start draining the commandqueue which has a limited size.
-
isPaused
boolean isPaused()
Get paused state of rendering thread.
Warning: This is an experimental API.
-
setPaused
void setPaused(boolean paused)
Pause or resume the rendering thread.
Warning: This is an experimental API. In particular, note the following caveats.
- Buffer callbacks will never be called as long as the rendering thread is paused.Do not rely on a buffer callback to unpause the thread.
- While the rendering thread is paused, rendering commands will continue to be queued until thebuffer limit is reached. When the limit is reached, the program will abort.
-
unprotected
void unprotected()
Switch the command queue to unprotected mode. Protected mode can be activated viaRenderer::beginFrame() using a protected SwapChain.
-
getSteadyClockTimeNano
static native long getSteadyClockTimeNano()
Get the current time. This is a convenience function that simply returns thetime in nanosecond since epoch of std::chrono::steady_clock.
-
hasFeatureFlag
boolean hasFeatureFlag(@NonNull() String name)
Checks if a feature flag exists
- Parameters:
name- name of the feature flag to check
-
setFeatureFlag
boolean setFeatureFlag(@NonNull() String name, boolean value)
Set the value of a non-constant feature flag.
- Parameters:
name- name of the feature flag to setvalue- value to set
-
getFeatureFlag
boolean getFeatureFlag(@NonNull() String name)
Retrieves the value of any feature flag.
- Parameters:
name- name of the feature flag
-
getNativeObject
long getNativeObject()
-
getNativeJobSystem
long getNativeJobSystem()
-
-
-
-