@lightningjs/renderer
    Preparing search index...

    Interface WebGlCoreRenderer

    Use import { WebGlRenderer } @lightningjs/renderer/webgl instead

    interface WebGlCoreRenderer {
        activeRttNode: null | CoreNode;
        clearColor: WebGlColor;
        curBufferIdx: number;
        curRenderOp: null | WebGlRenderOp;
        curSdfRenderOp: null | SdfRenderOp;
        defaultShaderNode: null | WebGlShaderNode<Record<string, unknown>>;
        defaultTextureCoords: Bound;
        dirtyQuadCount: number;
        fQuadBuffer: Float32Array;
        fRttQuadBuffer: null | Float32Array<ArrayBufferLike>;
        glw: GlContextWrapper;
        lastUploadedBufferSize: number;
        mode: undefined | "canvas" | "webgl";
        needsFullUpload: boolean;
        numQuadsRendered: number;
        quadBuffer: ArrayBuffer;
        quadBufferCollection: BufferCollection;
        quadBufferUsage: number;
        renderOps: WebGlRenderOp[];
        renderToTextureActive: boolean;
        rttNodes: CoreNode[];
        rttQuadBuffer: null | ArrayBuffer;
        sdfBufferPlain: SdfBuffer;
        sdfBufferRich: SdfBuffer;
        stage: Stage;
        stencilClipProgram: null | WebGlShaderProgram;
        stencilDepth: number;
        system: CoreWebGlSystem;
        uiQuadBuffer: Uint32Array;
        uiRttQuadBuffer: null | Uint32Array<ArrayBufferLike>;
        addQuad(node: CoreNode): void;
        addRenderOp(renderable: WebGlRenderOp): void;
        addSdfCachedQuads(
            sdfBuffer: SdfBuffer,
            cachedVertices: Float32Array,
            numGlyphs: number,
            atlasTexture: WebGlCoreCtxTexture,
            clippingRect: RectWithValid,
            worldAlpha: number,
            width: number,
            height: number,
            parentHasRenderTexture: boolean,
            framebufferDimensions: null | Dimensions,
            sdfShader: WebGlShaderNode,
        ): void;
        addSdfQuads(
            sdfBuffer: SdfBuffer,
            glyphs: Float32Array,
            glyphCount: number,
            fontScale: number,
            transform: Float32Array,
            color: number,
            worldAlpha: number,
            distanceRange: number,
            atlasTexture: WebGlCoreCtxTexture,
            clippingRect: RectWithValid,
            width: number,
            height: number,
            parentHasRenderTexture: boolean,
            framebufferDimensions: null | Dimensions,
            sdfShader: WebGlShaderNode,
        ): void;
        addSdfTranslatedQuads(
            sdfBuffer: SdfBuffer,
            cachedVertices: Float32Array,
            numGlyphs: number,
            dx: number,
            dy: number,
            atlasTexture: WebGlCoreCtxTexture,
            clippingRect: RectWithValid,
            worldAlpha: number,
            width: number,
            height: number,
            parentHasRenderTexture: boolean,
            framebufferDimensions: null | Dimensions,
            sdfShader: WebGlShaderNode,
        ): void;
        beginRoundedClip(node: CoreNode): void;
        createCtxTexture(textureSource: Texture): CoreContextTexture;
        createShaderNode(
            shaderKey: string,
            shaderType: WebGlShaderType,
            props?: Record<string, unknown>,
            program?: WebGlShaderProgram,
        ): WebGlShaderNode<Record<string, unknown>>;
        createShaderProgram(
            shaderType: WebGlShaderType,
            props: Record<string, unknown>,
        ): WebGlShaderProgram;
        deleteBuffer(buffer: WebGLBuffer): void;
        destroy(): void;
        endRoundedClip(_node: CoreNode): void;
        getBufferInfo(): null | BufferInfo;
        getDefaultShaderNode(): WebGlShaderNode;
        getQuadCount(): number;
        getTextureCoords(node: CoreNode): undefined | Bound;
        invalidateQuadBuffer(): void;
        removeRTTNode(node: CoreNode): void;
        render(_surface?: "screen" | CoreContextTexture): void;
        renderRTTNodes(): void;
        renderToTexture(node: CoreNode): void;
        reset(): void;
        reuseRenderOp(node: CoreNode): boolean;
        supportsShaderType(shaderType: Readonly<WebGlShaderType>): boolean;
        updateClearColor(color: number): void;
        updateViewport(): void;
    }

    Hierarchy

    • CoreRenderer
      • WebGlCoreRenderer
    Index

    Properties

    activeRttNode: null | CoreNode = null
    clearColor: WebGlColor = ...
    curBufferIdx: number = 0
    curRenderOp: null | WebGlRenderOp = null
    curSdfRenderOp: null | SdfRenderOp = null

    Current SDF render op being extended by finalizeSdfBatch. Null when the last op is not extendable (different atlas, clipping rect, or RTT state).

    defaultShaderNode: null | WebGlShaderNode<Record<string, unknown>> = null
    defaultTextureCoords: Bound = ...
    dirtyQuadCount: number = 0
    fQuadBuffer: Float32Array
    fRttQuadBuffer: null | Float32Array<ArrayBufferLike> = null
    glw: GlContextWrapper
    lastUploadedBufferSize: number = 0
    mode: undefined | "canvas" | "webgl"
    needsFullUpload: boolean = true
    numQuadsRendered: number = 0
    quadBuffer: ArrayBuffer
    quadBufferCollection: BufferCollection
    quadBufferUsage: number = 0

    White pixel texture used by default when no texture is specified.

    renderOps: WebGlRenderOp[] = []
    renderToTextureActive: boolean = false

    Whether the renderer is currently rendering to a texture.

    rttNodes: CoreNode[] = []
    rttQuadBuffer: null | ArrayBuffer = null
    sdfBufferPlain: SdfBuffer

    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.

    sdfBufferRich: SdfBuffer
    stage: Stage
    stencilClipProgram: null | WebGlShaderProgram = null
    stencilDepth: number = 0
    system: CoreWebGlSystem
    uiQuadBuffer: Uint32Array
    uiRttQuadBuffer: null | Uint32Array<ArrayBufferLike> = null

    Methods

    • This 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.

      Parameters

      Returns void

    • Fast path: copy pre-computed cached SDF vertex data into the shared buffer and create/extend an SdfRenderOp.

      Parameters

      • sdfBuffer: SdfBuffer
      • cachedVertices: Float32Array
      • numGlyphs: number
      • atlasTexture: WebGlCoreCtxTexture
      • clippingRect: RectWithValid
      • worldAlpha: number
      • width: number
      • height: number
      • parentHasRenderTexture: boolean
      • framebufferDimensions: null | Dimensions
      • sdfShader: WebGlShaderNode

      Returns void

      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.

      Parameters

      • sdfBuffer: SdfBuffer
      • glyphs: Float32Array
      • glyphCount: number
      • fontScale: number
      • transform: Float32Array
      • color: number
      • worldAlpha: number
      • distanceRange: number
      • atlasTexture: WebGlCoreCtxTexture
      • clippingRect: RectWithValid
      • width: number
      • height: number
      • parentHasRenderTexture: boolean
      • framebufferDimensions: null | Dimensions
      • sdfShader: WebGlShaderNode

      Returns void

      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.

      Parameters

      • sdfBuffer: SdfBuffer
      • cachedVertices: Float32Array
      • numGlyphs: number
      • dx: number
      • dy: number
      • atlasTexture: WebGlCoreCtxTexture
      • clippingRect: RectWithValid
      • worldAlpha: number
      • width: number
      • height: number
      • parentHasRenderTexture: boolean
      • framebufferDimensions: null | Dimensions
      • sdfShader: WebGlShaderNode

      Returns void

      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.

      Parameters

      Returns void

    • Delete a GPU buffer previously allocated by this renderer. No-op for renderers that do not use WebGL buffers (e.g. Canvas).

      Parameters

      • buffer: WebGLBuffer

      Returns void

    • Inserts an "end rounded clip" sentinel into renderOps for the given node. Called by Stage.addSubtreeQuads after processing a rounded-clip node's children.

      Parameters

      Returns void

    • Render the current set of RenderOps to render to the specified surface.

      TODO: 'screen' is the only supported surface at the moment.

      Parameters

      • _surface: "screen" | CoreContextTexture = 'screen'

      Returns void

    • Sets the glClearColor to the specified color. *

      Parameters

      • color: number

        The color to set as the clear color, represented as a 32-bit integer.

      Returns void