Overview
Filament uses a structured rendering loop where each frame follows a specific sequence: setup, rendering, and presentation. Understanding this loop is essential for building efficient real-time rendering applications.Basic Rendering Loop
A typical Filament rendering loop consists of three main phases executed each frame:Minimal Render Loop
Here’s the minimal structure from the Engine documentation:Engine.h:132-138
Complete Setup Example
A full application setup includes engine initialization, resource creation, and the render loop:hellotriangle.cpp:125-161
Frame Timing and Updates
Filament provides timing information for animation and updates:hellotriangle.cpp:173-184
Key Rendering Components
Engine
The Engine is the main entry point and manages all rendering resources:Engine.h:99-106
The Engine keeps track of all resources created by the user. Leaked resources are automatically freed when the engine instance is destroyed, but a warning is emitted.
SwapChain
Represents the operating system’s native renderable surface (window or view):Engine.h:125
Renderer
Handles the actual rendering operations for a window:Engine.h:126
Scene
A flat container of renderable entities and lights:Engine.h:127
View
Defines what to render and how to render it:Engine.h:128-130
Thread Safety
Multi-threading Support
When created, the Engine automatically starts:- A render thread with elevated priority
- Multiple worker threads (automatically chosen based on platform)
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.
Resource Management
Creating Resources
All Filament resources are created through the Engine:createSwapChain()- Window surfacescreateRenderer()- Rendering contextscreateView()- Render viewscreateScene()- Entity containerscreateCamera()- Camera components
Destroying Resources
Resources must be explicitly destroyed:hellotriangle.cpp:163-171
Flushing and Synchronization
Flush
Kick the hardware thread without waiting:Flush and Wait
Block until all commands are executed:Best Practices
Frame Pacing
Frame Pacing
Always check the return value of
beginFrame() before rendering. It returns false when the swap chain is not ready.Command Buffering
Command Buffering
Filament uses command buffering for efficiency. Commands are queued and executed asynchronously on the render thread.
Memory Management
Memory Management
Configure memory footprint using
Engine::Config to balance performance and memory usage based on your application’s needs.VSYNC Timing
VSYNC Timing
Wait for VSYNC and process user input events before calling
beginFrame() for smooth rendering.Platform-Specific Considerations
Mobile Platforms
Filament is optimized for mobile with:- Automatic core selection on asymmetric architectures (ARM Big.Little)
- Configurable command buffer sizes
- Metal-specific upload buffer configuration
Single-Threaded Platforms
For platforms without threading support:Related Topics
Entity-Component System
Learn how entities and components work together
Materials Overview
Understanding the material system