RenderTexture
A texture that can be rendered to, allowing off-screen rendering.
RenderTexture enables rendering visuals to a texture instead of the screen. This is essential for many advanced graphics techniques and effects.
Key features:
- Off-screen rendering for post-processing effects
- Render-to-texture for reflections, shadows, minimaps
- Texture composition and layering
- Dynamic texture generation
- Render dependency management
Common uses:
- Post-processing filters (blur, glow, distortion)
- Dynamic texture generation (procedural textures)
- Render passes for complex effects
- UI rendering to texture
- Reflection/refraction effects
- Shadow mapping
RenderTextures are automatically managed by Ceramic's rendering system, which handles render order based on texture dependencies.
// Create a render texture
var rt = new RenderTexture(512, 512);
// Render visuals to it
myVisual.renderTarget = rt;
// Use as a regular texture
var quad = new Quad();
quad.texture = rt;
// Manual rendering with stamp
rt.autoRender = false;
rt.stamp(myVisual, () -> {
trace('Rendering complete');
});
// Clear with color
rt.clear(Color.BLUE, 0.5, 0, 0, 100, 100, () -> {
trace('Clear complete');
});
Instance Members
autoRender: Bool
Whether this texture automatically renders when visuals target it.
- true: Renders automatically when needed (default)
- false: Manual control via stamp() or renderDirty flag
clearOnRender: Bool
Whether to clear the texture before each render.
- true: Clears to transparent before rendering (default)
- false: Preserves previous contents (for accumulation effects)
renderDirty: Bool
Marks the texture as needing to be rendered. Set to true to trigger a render in the next frame. Automatically set when visuals targeting this texture change.
depth: Bool
Whether this render texture has a depth buffer. Required for proper depth testing and 3D rendering.
stencil: Bool
Whether this render texture has a stencil buffer. Required for stencil-based masking effects.
antialiasing: Int
Antialiasing level (multisampling).
- 0 = No antialiasing (default)
- 2, 4, 8, etc. = Number of samples Higher values provide smoother edges but use more GPU resources.
priority: Float
Render priority for dependency sorting. Used internally to determine render order when textures depend on each other. Higher priority textures render first.
destroy(): Void
Draws the given visual onto the render texture.
The drawing operation is asynchronous - it happens during the next render frame. The visual is temporarily assigned to this render texture, rendered, then restored to its original state.
This is typically used with autoRender set to false for manual control.
Name | Type | Description |
---|---|---|
visual |
Visual | The visual to render onto this texture |
done |
Function | Callback invoked after rendering completes |
clear(?color: Color = 0xFFFFFF, ?alpha: Float = 0, ?clipX: Float = -1, ?clipY: Float = -1, ?clipWidth: Float = -1, ?clipHeight: Float = -1, done: Function): Void
Clears the texture or a specific area with a color.
The clear operation is asynchronous - it happens during the next render frame. Use -1 for clip parameters to clear the entire texture.
This is typically used with autoRender set to false for manual control.
Name | Type | Default | Description |
---|---|---|---|
color |
Color | 0xFFFFFF |
Fill color (default: white) |
alpha |
Float | 0 |
Fill alpha (default: 0 = transparent) |
clipX |
Float | -1 |
X position of area to clear (-1 = full texture) |
clipY |
Float | -1 |
Y position of area to clear (-1 = full texture) |
clipWidth |
Float | -1 |
Width of area to clear (-1 = full texture) |
clipHeight |
Float | -1 |
Height of area to clear (-1 = full texture) |
done |
Function | Callback invoked after clearing completes |
new(width: Float, height: Float, ?density: Float = -1, ?depth: Bool = true, ?stencil: Bool = true, ?antialiasing: Int = 0): Void
Creates a new render texture.
Name | Type | Default | Description |
---|---|---|---|
width |
Float | Width in logical pixels | |
height |
Float | Height in logical pixels | |
density |
Float | -1 |
Pixel density multiplier (-1 = use screen density) |
depth |
Bool | true |
Enable depth buffer (default: true) |
stencil |
Bool | true |
Enable stencil buffer (default: true) |
antialiasing |
Int | 0 |
Multisampling level (default: 0) |
Private Members
toString(): String
Returns |
---|
String |
Metadata
Name | Parameters |
---|---|
:build |
tracker.macros.EventsMacro.build() |
:autoBuild |
tracker.macros.EventsMacro.build() |
:build |
ceramic.macros.EntityMacro.buildForCompletion() |
:autoBuild |
ceramic.macros.EntityMacro.buildForCompletion() |
:allow |
ceramic.App |