Current SDF render op being extended by finalizeSdfBatch. Null when the
last op is not extendable (different atlas, clipping rect, or RTT state).
White pixel texture used by default when no texture is specified.
Whether the renderer is currently rendering to a texture.
Shared SDF vertex buffers — one per GPU layout.
All SDF text of a given layout writes into a single pre-allocated CPU
buffer that is uploaded to the GPU in one bufferData per frame. Compatible
consecutive text nodes are merged into a single SdfRenderOp, producing one
draw call for many strings.
The two layouts have different strides (6 floats plain / 7 floats rich) and can therefore never share a draw call; each gets its own buffer, and each SdfRenderOp carries the SdfBuffer it draws from.
ReadonlystageThis function adds a quad (a rectangle composed of two triangles) to the WebGL rendering pipeline.
It takes a set of options that define the quad's properties, such as its dimensions, colors, texture, shader, and transformation matrix. The function first updates the shader properties with the current dimensions if necessary, then sets the default texture if none is provided. It then checks if a new render operation is needed, based on the current shader and clipping rectangle. If a new render operation is needed, it creates one and updates the current render operation. The function then adjusts the texture coordinates based on the texture options and adds the texture to the texture manager.
Finally, it calculates the vertices for the quad, taking into account any transformations, and adds them to the quad buffer. The function updates the length and number of quads in the current render operation, and updates the current buffer index.
add RenderOp to the render pipeline
Fast path: copy pre-computed cached SDF vertex data into the shared buffer and create/extend an SdfRenderOp.
When a text node hasn't changed (same layout, transform, color, alpha),
the per-glyph matrix multiplication is skipped entirely. The cached
Float32Array is written via a single Float32Array.set() (memcpy), which
is orders of magnitude faster than the per-glyph computation path.
The cached data is already in the target SdfBuffer's GPU layout, so the
mem-copy must stay a typed-array set (bit-exact): packed RGBA colors
live in the same Float32Array and some bit patterns are float32 NaNs,
which element-wise float reads/writes may canonicalize and corrupt.
Exact cache hits write byte-identical data at identical offsets, so this
path deliberately does NOT set sdfBuffer.changed.
Append pre-transformed SDF glyph vertices to the given shared SDF buffer and manage SDF render op batching.
This method pre-transforms glyph positions from design units to world pixel space on the CPU, packs per-vertex color and distanceRange, and writes them into the shared SDF buffer of the given layout. Compatible consecutive calls (same layout, atlas, clipping, RTT state) are merged into a single SdfRenderOp, resulting in one draw call for many text nodes.
The design-unit glyph records are SDF_PLAIN_GLYPH_STRIDE (8) or
SDF_RICH_GLYPH_STRIDE (12) floats per glyph depending on the layout:
plain: x, y, w, h, u, v, uw, vh
rich: x, y, w, h, u, v, uw, vh, shearTop, shearBot, packed_span_color, style
where packed_span_color is RGBA bytes written via a Uint32 view of the
same ArrayBuffer (bit-identical read via uGlyphs below), shearTop/shearBot
are the per-corner x-deltas of the italic lean, and the decorated quads use
u = -1.0 as a solid-fill sentinel.
Append cached SDF vertices translated by (dx, dy) to the shared buffer.
The scroll fast path: a text node whose transform changed by pure translation reuses its world-space vertex cache — one mem-copy plus two adds per vertex instead of full per-glyph matrix math, and the cache keeps its original base so nothing is re-snapshotted per frame.
The copy MUST stay a typed-array set (bit-exact memcpy): packed RGBA
colors live in the same Float32Array and some bit patterns are float32
NaNs, which element-wise float reads/writes may canonicalize and corrupt.
Only the two position floats of each vertex are touched after the copy.
Inserts a "begin rounded clip" sentinel into renderOps for the given node. Called by Stage.addQuads before processing a rounded-clip node's children.
Optionalprops: Record<string, unknown>Optionalprogram: WebGlShaderProgramDelete a GPU buffer previously allocated by this renderer. No-op for renderers that do not use WebGL buffers (e.g. Canvas).
Inserts an "end rounded clip" sentinel into renderOps for the given node. Called by Stage.addSubtreeQuads after processing a rounded-clip node's children.
Render the current set of RenderOps to render to the specified surface.
TODO: 'screen' is the only supported surface at the moment.
Test if the current Render operation can be reused for the specified parameters.
Sets the glClearColor to the specified color. *
The color to set as the clear color, represented as a 32-bit integer.
Deprecated
Use
import { WebGlRenderer } @lightningjs/renderer/webglinstead