The Renderer Main API

Remarks

This is the primary class used to configure and operate the Renderer.

It is used to create and destroy Nodes, as well as Texture and Shader references.

Example:

import { RendererMain, MainCoreDriver } from '@lightningjs/renderer';

// Initialize the Renderer
const renderer = new RendererMain(
{
appWidth: 1920,
appHeight: 1080
},
'app',
new MainCoreDriver(),
);

Events

  • fpsUpdate
    • Emitted every fpsUpdateInterval milliseconds with the current FPS
  • frameTick
    • Emitted every frame tick
  • idle
    • Emitted when the renderer is idle (no changes to the scene graph/animations running)
  • criticalCleanup
  • Emitted when the Texture Memory Manager Cleanup process is triggered
  • Payload: { memUsed: number, criticalThreshold: number }
    • memUsed - The amount of memory (in bytes) used by textures before the cleanup process
    • criticalThreshold - The critical threshold (in bytes)
  • criticalCleanupFailed
    • Emitted when the Texture Memory Manager Cleanup process is unable to free up enough texture memory to reach below the critical threshold. This can happen when there is not enough non-renderable textures to free up.
    • Payload (object with keys):
      • memUsed - The amount of memory (in bytes) used by textures after the cleanup process
      • criticalThreshold - The critical threshold (in bytes)

Hierarchy

Constructors

Properties

canvas: HTMLCanvasElement
inspector: null | Inspector = null
root: INode<ShaderController<"DefaultShader">>
settings: Readonly<Required<RendererMainSettings>>
stage: Stage

Methods

  • Create a new Dynamic Shader controller

    Type Parameters

    Parameters

    • effects: [...T[]]

    Returns DynamicShaderController<T>

    Remarks

    A Dynamic Shader is a shader that can be composed of an array of mulitple effects. Each effect can be animated or changed after creation (provided the effect is given a name).

    Example:

    renderer.createNode({
    shader: renderer.createDynamicShader([
    renderer.createEffect('radius', {
    radius: 0
    }, 'effect1'),
    renderer.createEffect('border', {
    color: 0xff00ffff,
    width: 10,
    }, 'effect2'),
    ]),
    });
  • Create an effect to be used in a Dynamic Shader

    Type Parameters

    • Type extends keyof EffectMap

    • Name extends undefined | string = undefined

    Parameters

    • type: Type
    • props: ExtractProps<EffectMap[Type]>
    • Optional name: Name

    Returns EffectDesc<{
        name: Name;
        type: Type;
    }>

    Remark

    The {name} parameter is optional but required if you want to animate the effect or change the effect's properties after creation.

    See createDynamicShader for an example.

  • Create a new scene graph node

    Type Parameters

    Parameters

    Returns INode<ShCtr>

    Remarks

    A node is the main graphical building block of the Renderer scene graph. It can be a container for other nodes, or it can be a leaf node that renders a solid color, gradient, image, or specific texture, using a specific shader.

    To create a text node, see createTextNode.

    See CoreNode for more details.

  • Create a new shader controller for a shader type

    Type Parameters

    Parameters

    • shaderType: ShType
    • Optional props: ExtractProps<ShaderMap[ShType]>

    Returns ShaderController<ShType>

    Remarks

    This method creates a new Shader Controller for a specific shader type.

    If the shader has not been loaded yet, it will be loaded. Otherwise, the existing shader will be reused.

    It can be assigned to a Node's shader property.

  • Create a new scene graph text node

    Parameters

    Returns ITextNode

    Remarks

    A text node is the second graphical building block of the Renderer scene graph. It renders text using a specific text renderer that is automatically chosen based on the font requested and what type of fonts are installed into an app.

    See ITextNode for more details.

  • Create a new texture reference

    Type Parameters

    Parameters

    • textureType: TxType
    • props: ExtractProps<TextureMap[TxType]>

    Returns InstanceType<TextureMap[TxType]>

    Remarks

    This method creates a new reference to a texture. The texture is not loaded until it is used on a node.

    It can be assigned to a node's texture property, or it can be used when creating a SubTexture.

  • Get a Node by its ID

    Parameters

    • id: number

    Returns null | CoreNode

  • Parameters

    • event: string
    • Optional listener: ((target, data) => void)
        • (target, data): void
        • Parameters

          • target: any
          • data: any

          Returns void

    Returns void

  • Parameters

    • event: string
    • listener: ((target, data) => void)
        • (target, data): void
        • Parameters

          • target: any
          • data: any

          Returns void

    Returns void

  • Parameters

    • event: string
    • listener: ((target, data) => void)
        • (target, data): void
        • Parameters

          • target: any
          • data: any

          Returns void

    Returns void

  • Re-render the current frame without advancing any running animations.

    Returns void

    Remarks

    Any state changes will be reflected in the re-rendered frame. Useful for debugging.

    May not do anything if the render loop is running on a separate worker.

Generated using TypeDoc