-
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.
-
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()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. 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. 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. By default FeatureLevel::FEATURE_LEVEL_1 isactive. The selected feature level must not be higher than the value returned bygetActiveFeatureLevel() and it's not possible lower the active feature level.
- 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()
-
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 SwapChain
-
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 SwapChain
-
createSwapChainFromNativeSurface
@NonNull() SwapChain createSwapChainFromNativeSurface(@NonNull() NativeSurface surface, long flags)
Creates a SwapChain from a NativeSurface.
- Parameters:
surface- a properly initialized NativeSurfaceflags- configuration flags, see SwapChain
-
destroySwapChain
void destroySwapChain(@NonNull() SwapChain swapChain)
Destroys a SwapChain and frees all its associated resources.
- Parameters:
swapChain- the SwapChain to destroy
-
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.
-
getNativeObject
long getNativeObject()
-
getNativeJobSystem
long getNativeJobSystem()
-
-
-
-