Draw
Instance Members
The graphics batcher instance for batched rendering operations. Stored in a static field for performance, since there's only one Draw instance.
Renders an array of visual objects.
| Name | Type | Description |
|---|---|---|
visuals |
Array<ceramic.Visual> | Array of Visual objects to render |
Swaps the front and back buffers (unused in Clay backend). Buffer swapping is handled automatically by Clay framework.
Initializes the vertex and index buffers for rendering.
This method sets up the buffer management system and prepares the first set of buffers for use. Should be called before any rendering operations begin.
Begins a rendering pass by enabling vertex attributes.
Enables the core vertex attributes used by all shaders:
- Position (x, y, z)
- Texture coordinates (u, v)
- Color (r, g, b, a)
Additional attributes are enabled dynamically based on the active shader.
Ends the current rendering frame.
Performs any cleanup or finalization needed after all draw operations.
Clears the current render target to transparent white.
This method clears the color buffer with a transparent white background. When rendering to a texture, this marks the render target as updated.
Clears the current render target and applies the application background color.
This method clears the color buffer with the application's configured background color (fully opaque). Used for the main screen clearing.
Enables alpha blending for transparent rendering.
This activates the GPU's blending functionality, allowing pixels to be combined based on their alpha values. Must be enabled for transparency to work correctly.
Disables alpha blending.
When disabled, pixels are rendered opaque regardless of alpha values. This can improve performance when rendering fully opaque content.
Sets the active texture unit slot for multi-texturing.
Modern GPUs support multiple texture units, allowing shaders to sample from multiple textures simultaneously. This method selects which texture unit subsequent texture operations will affect.
| Name | Type | Description |
|---|---|---|
slot |
Int | The texture unit index (0-based) |
Sets the primitive type for rendering.
Determines how vertices are interpreted:
- TRIANGLE: Every 3 vertices form a triangle (default)
- LINE: Every 2 vertices form a line
| Name | Type | Description |
|---|---|---|
primitiveType |
ceramic.RenderPrimitiveType | The primitive type to use for subsequent draw calls |
Gets the currently active texture unit slot.
| Returns | Description |
|---|---|
| Int | The index of the active texture unit |
Sets the active render target for subsequent drawing operations.
This method switches between rendering to a texture (off-screen) or to the main screen buffer. When switching targets, it handles:
- MSAA buffer blitting for antialiased render targets
- Projection and view matrix updates
- Viewport configuration
- Optional automatic clearing
When renderTarget is null, rendering switches back to the main screen.
| Name | Type | Default | Description |
|---|---|---|---|
renderTarget |
ceramic.RenderTexture | The render texture to render to, or null for main screen | |
force |
Bool | false |
Force the render target switch even if it's the same target |
Activates a shader program for rendering.
This method:
- Sets the shader as the active GPU program
- Uploads projection and modelview matrices as uniforms
- Configures vertex layout based on shader attributes
- Determines if multi-texture batching is supported
- Calculates maximum vertices per batch based on attribute size
The vertex size calculation includes:
- 3 floats for position (x, y, z)
- Custom float attributes defined by the shader
- 1 float for texture slot (if multi-texturing is enabled)
| Name | Type | Description |
|---|---|---|
shader |
Shader | The shader to activate |
setBlendFuncSeparate(srcRgb: BlendMode, dstRgb: BlendMode, srcAlpha: BlendMode, dstAlpha: BlendMode): VoidSets separate blend functions for RGB and alpha channels.
This allows fine control over how colors are blended, with different blend modes for color (RGB) and transparency (alpha) channels.
| Name | Type | Description |
|---|---|---|
srcRgb |
BlendMode | Blend factor for source RGB |
dstRgb |
BlendMode | Blend factor for destination RGB |
srcAlpha |
BlendMode | Blend factor for source alpha |
dstAlpha |
BlendMode | Blend factor for destination alpha |
Called before drawing a quad (currently unused).
Reserved for future optimizations or quad-specific setup.
| Name | Type | Description |
|---|---|---|
quad |
ceramic.Quad | The quad about to be drawn |
Called after drawing a quad (currently unused).
Reserved for future optimizations or quad-specific cleanup.
Called before drawing a mesh (currently unused).
| Name | Type |
|---|---|
mesh |
ceramic.Mesh |
Called after drawing a mesh (currently unused).
Enables scissor testing to clip rendering to a rectangular area.
Scissor testing restricts rendering to pixels within the specified rectangle. Any pixels outside this area are discarded by the GPU.
The coordinates are transformed by the current modelview matrix and adjusted for screen density.
| Name | Type | Description |
|---|---|---|
x |
Float | Left edge of the scissor rectangle in logical coordinates |
y |
Float | Top edge of the scissor rectangle in logical coordinates |
width |
Float | Width of the scissor rectangle in logical pixels |
height |
Float | Height of the scissor rectangle in logical pixels |
Disables scissor testing.
After calling this, rendering is no longer clipped to a rectangular area.
Enables stencil testing for masked rendering.
This configures the stencil test to only render pixels where the stencil buffer equals 1. Used after drawing to the stencil buffer to render content only within the stenciled area.
Disables stencil testing for normal rendering.
Resets stencil configuration to default values where all pixels pass the stencil test and the stencil buffer can be written to.
Begins drawing to the stencil buffer for masking operations.
This sets up the GPU to write to the stencil buffer instead of the color buffer. Pixels drawn will mark areas in the stencil buffer with a value of 1, creating a mask for subsequent rendering.
Ends drawing to the stencil buffer.
Returns to normal color buffer rendering.
Binds a texture to the current texture unit.
Makes the texture available for sampling in shaders. The texture will be bound to the currently active texture unit.
| Name | Type | Description |
|---|---|---|
backendItem |
Texture | The texture to bind |
Binds no texture (or a default white texture depending on the graphics backend).
Used when rendering untextured geometry or solid colors.
Checks if a backend texture matches a texture ID.
| Name | Type | Description |
|---|---|---|
backendItem |
Texture | The backend texture to check |
textureId |
TextureId | The texture ID to compare against |
| Returns | Description |
|---|---|
| Bool | True if the texture matches the ID |
Gets the texture ID from a backend texture.
| Name | Type | Description |
|---|---|---|
backendItem |
Texture | The backend texture |
| Returns | Description |
|---|---|
| TextureId | The texture ID |
Gets the width of a backend texture.
| Name | Type | Description |
|---|---|---|
backendItem |
Texture | The backend texture |
| Returns | Description |
|---|---|
| Int | The texture width in pixels |
Gets the height of a backend texture.
| Name | Type | Description |
|---|---|---|
backendItem |
Texture | The backend texture |
| Returns | Description |
|---|---|
| Int | The texture height in pixels |
Gets the actual width of a backend texture (may differ from logical width).
| Name | Type | Description |
|---|---|---|
backendItem |
Texture | The backend texture |
| Returns | Description |
|---|---|
| Int | The actual texture width in pixels |
Gets the actual height of a backend texture (may differ from logical height).
| Name | Type | Description |
|---|---|---|
backendItem |
Texture | The backend texture |
| Returns | Description |
|---|---|
| Int | The actual texture height in pixels |
Gets the number of vertices currently in the buffer.
| Returns | Description |
|---|---|
| Int | Current vertex count |
Adds a vertex position to the current batch.
| Name | Type | Description |
|---|---|---|
x |
ceramic.Float32 | X coordinate in screen space |
y |
ceramic.Float32 | Y coordinate in screen space |
z |
ceramic.Float32 | Z coordinate for depth ordering |
putPosAndTextureSlot(x: ceramic.Float32, y: ceramic.Float32, z: ceramic.Float32, textureSlot: ceramic.Float32): VoidAdds a vertex position with texture slot for multi-texture batching.
| Name | Type | Description |
|---|---|---|
x |
ceramic.Float32 | X coordinate in screen space |
y |
ceramic.Float32 | Y coordinate in screen space |
z |
ceramic.Float32 | Z coordinate for depth ordering |
textureSlot |
ceramic.Float32 | Texture slot index |
Begins adding float attributes for a vertex.
Adds a custom float attribute value for the current vertex.
| Name | Type | Description |
|---|---|---|
index |
Int | Attribute index |
value |
Float | Attribute value |
Ends adding float attributes for the current vertex.
Adds an index to the index buffer.
| Name | Type | Description |
|---|---|---|
i |
Int | Vertex index |
Adds texture coordinates for the current vertex.
| Name | Type | Description |
|---|---|---|
uvX |
Float | Horizontal texture coordinate (0.0 to 1.0) |
uvY |
Float | Vertical texture coordinate (0.0 to 1.0) |
Adds a vertex color to the current batch.
| Name | Type | Description |
|---|---|---|
r |
Float | Red component (0.0 to 1.0) |
g |
Float | Green component (0.0 to 1.0) |
b |
Float | Blue component (0.0 to 1.0) |
a |
Float | Alpha component (0.0 to 1.0) |
Checks if there is any geometry in the buffer to flush.
| Returns | Description |
|---|---|
| Bool | True if there are vertices waiting to be submitted |
Checks if the current batch should be flushed before adding more vertices.
Returns true if adding the specified number of vertices or indices would exceed buffer capacity, indicating that the current batch should be sent to the GPU before continuing.
| Name | Type | Description |
|---|---|---|
numVerticesAfter |
Int | Number of vertices to be added |
numIndicesAfter |
Int | Number of indices to be added |
customFloatAttributesSize |
Int | Size of custom attributes |
| Returns | Description |
|---|---|
| Bool | True if flush is needed, false otherwise |
Gets the remaining vertex capacity in the buffer.
| Returns | Description |
|---|---|
| Int | Number of vertices that can still be added |
Gets the remaining index capacity in the buffer.
| Returns | Description |
|---|---|
| Int | Number of indices that can still be added |
Flushes the current batch of vertices to the GPU.
This is the core rendering method that submits all accumulated geometry to the GPU for rendering.
Creates a new Draw backend instance. Initializes the Ceramic renderer for handling visual rendering.
Private Members
The Ceramic renderer instance used for high-level rendering operations.
Begins a rendering frame (currently unused). Reserved for future use or platform-specific initialization.
Ends a rendering frame (currently unused). Reserved for future use or platform-specific cleanup.
Updates the projection matrix for orthographic rendering.
Creates an orthographic projection matrix that maps logical coordinates to normalized device coordinates (-1 to 1).
The projection uses:
- Origin at top-left (0,0)
- X increases rightward
- Y increases downward
- Z range from -1000 to 1000 for layering
| Name | Type | Description |
|---|---|---|
width |
Float | Viewport width in logical pixels |
height |
Float | Viewport height in logical pixels |
updateViewMatrix(density: Float, width: Float, height: Float, ?transform: ceramic.Transform, ?flipY: Float = 1): VoidUpdates the view matrix for camera transformations.
The view matrix handles:
- Camera position and rotation (via transform parameter)
- Screen density scaling for high-DPI displays
- Y-axis flipping for render-to-texture (textures have inverted Y)
The matrix is inverted at the end (if needed) because the view matrix represents the inverse of the camera transform.
| Name | Type | Default | Description |
|---|---|---|---|
density |
Float | Screen density multiplier (e.g., 2 for retina) | |
width |
Float | Viewport width in logical pixels | |
height |
Float | Viewport height in logical pixels | |
transform |
ceramic.Transform | (optional) | Optional camera transform |
flipY |
Float | 1 |
-1 to flip Y axis (for render targets), 1 for normal |
Sets a matrix to identity.
| Name | Type | Description |
|---|---|---|
m |
ceramic.Float32Array | The matrix to set |
Sets a matrix from a 2D transform.
| Name | Type | Description |
|---|---|---|
m |
ceramic.Float32Array | The matrix to set |
transform |
ceramic.Transform | The 2D transform to convert |
Metadata
| Name | Parameters |
|---|---|
:allow |
backend.Backend |
:access |
backend.Backend |