Rapid Render API
    Preparing search index...

    Class Rapid

    The main application class for the Rapid rendering engine. Manages the WebGL context, rendering regions, state, and matrices.

    Index

    Constructors

    Properties

    antialias: boolean

    Default texture filtering preference and requested canvas MSAA setting.

    atlasSpriteRegion: AtlasSpriteRegion
    backgroundColor: Color = Color.Black

    Background clear color [r, g, b, a], values range from 0 to 255.

    canvas: HTMLCanvasElement

    The target HTMLCanvasElement.

    currentRegion: Region | null = null

    The currently active rendering region.

    dpr: number

    The current device pixel ratio.

    drawcallCount: number = 0

    Counts the number of WebGL draw calls made in the current frame.

    gl: WebGL2RenderingContext

    The active WebGL context.

    graphicRegion: GraphicRegion

    Region dedicated to arbitrary geometry and shapes rendering.

    inCreateMask: boolean = false

    Indicates whether we are currently writing to the stencil buffer to create a mask.

    logicHeight: number = 0

    Logical height in CSS pixels, used for coordinate system and projection matrix.

    logicWidth: number = 0

    Logical width in CSS pixels, used for coordinate system and projection matrix.

    matrix: MatrixStore

    Direct access to the underlying matrix store.

    matrixStack: MatrixStack = ...

    Matrix stack for hierarchical transformations.

    maxTextureUnits: number = 0

    Maximum number of texture units supported by the device.

    particleRegion: ParticleRegion
    physicsHeight: number = 0

    Physical height (canvas actual pixels = logical height * dpr).

    physicsWidth: number = 0

    Physical width (canvas actual pixels = logical width * dpr).

    premultipliedAlpha: boolean

    Whether textures use premultiplied alpha. Set once at construction.

    projection: Float32Array = ...

    The current orthographic projection matrix (16 elements).

    projectionDirty: boolean = true

    Indicates if the projection matrix has changed and needs to be uploaded to shaders.

    roundPixels: boolean
    scaleMode?: CanvasScaleMode
    spriteRegion: SpriteRegion

    Region dedicated to fast sprite rendering.

    Manager for creating and organizing textures.

    textureFilter: TextureFilterMode

    Default filtering mode used when sampling textures.

    Accessors

    Methods

    • Pushes vertices for a circle geometry using TRIANGLES or similar primitives.

      Parameters

      • r: number

        The radius of the circle.

      • Optionalcolor: Color

        An optional tint color.

      • segments: number = 32

        The number of segments (polygons) used to approximate the circle.

      Returns void

    • Adds an individual vertex to the current graphics batch.

      Parameters

      • x: number

        The relative X coordinate of the vertex.

      • y: number

        The relative Y coordinate of the vertex.

      • u: number = 0

        The U texture coordinate (0 to 1).

      • v: number = 0

        The V texture coordinate (0 to 1).

      • color: number | Color

        The vertex color as a 32-bit unsigned integer.

      Returns void

    • Pushes vertices for a rectangle geometry. Should be enclosed by startGraphic and endGraphic.

      Parameters

      • w: number

        The width of the rectangle.

      • h: number

        The height of the rectangle.

      • Optionalcolor: Color

        An optional tint color.

      Returns void

    • Applies a chain of shaders to a texture sequentially using ping-pong RenderTextures. Each shader receives the output of the previous one as its input. Two internal RenderTextures are reused across calls (resized as needed).

      Parameters

      • source: Texture

        The input texture to start the filter chain from.

      • shaders: CustomGlShader[]

        An ordered array of CustomGlShader to apply in sequence.

      Returns RenderTexture

      The RenderTexture containing the final filtered result. Draw it with rapid.drawSprite({ texture: result }) to display it on screen.

      const result = rapid.applyFilters(tex, [blurShader, outlineShader]);
      rapid.drawSprite({ texture: result });
    • Clears the active framebuffer applying the default background color.

      Returns void

    • Clears bounds created into the stencil mask.

      Parameters

      • mask: number = 0xFF

        The bitmask specifying which stencil layer to clear.

      Returns void

    • Clears a RenderTexture to a solid color. Must be called while the RT is the active render target (i.e. inside enterRenderTexture/leaveRenderTexture). Can also be called standalone — it will bind the RT, clear it, but NOT restore the main framebuffer.

      Parameters

      • color: Color = ...

        Clear color. Defaults to transparent black (0, 0, 0, 0).

      Returns void

    • Convenience wrapper: enters a RenderTexture, optionally clears it, runs a callback, then leaves.

      Parameters

      • rt: RenderTexture

        The RenderTexture to render into.

      • cb: () => void

        The callback containing draw calls to execute inside the RT.

      • color: Color | null = ...

        Clear color before rendering. Pass null to skip clearing. Defaults to transparent black.

      Returns void

      rapid.drawToRenderTexture(myRT, () => {
      rapid.drawSprite({ texture: mySprite });
      });
    • Finishes the mask drawing phase and restores color buffer writing.

      Returns void

    • Ends the current graphics geometry definition, readying it for rendering.

      Returns void

    • Disables scissor clipping, restoring full-canvas rendering.

      Returns void

    • Enters a constrained rendering phase masked by the existing stencil buffer values.

      Parameters

      • type: MaskType

        Equality check type. Use "equal" to draw inside the mask, or "notEqual" to draw outside.

      • ref: number = 1

        The reference value to test against.

      • mask: number = 0xFF

        The bitmask specifying which stencil bits to consider.

      Returns void

    • Exits the masked rendering phase, restoring default full-screen stencil values tests.

      Returns void

    • Flushes currently buffered rendering operations across all active regions.

      Returns void

    • Completes rendering to an offscreen render texture and reverts rendering back to the main canvas.

      Returns void

    • Resizes the canvas, updates internal viewport values, and recreates projection boundaries.

      Parameters

      • logicWidth: number

        The new logical display width.

      • logicHeight: number

        The new logical display height.

      • OptionalcssWidth: number

        Optional CSS display width.

      • OptionalcssHeight: number

        Optional CSS display height.

      Returns void

    • Parameters

      • antialias: boolean

      Returns void

    • Configures the global WebGL blending behavior.

      Parameters

      • mode: BlendMode

        The targeted BlendMode to switch onto.

      Returns void

    • Starts drawing into the stencil buffer to construct a rendering mask.

      Parameters

      • ref: number = 1

        The stencil reference value.

      • mask: number = 0xFF

        The stencil bitmask.

      Returns void

    • Starts rendering arbitrary graphics geometries.

      Parameters

      • drawMode: number = ...

        The WebGL drawing mode (e.g., gl.TRIANGLES, gl.TRIANGLE_FAN).

      • Optionaltexture: Texture

        An optional texture applied to the graphic vertices.

      • OptionalcustomShader: GLShader | CustomGlShader

        An optional custom shader overriding the region's default shader.

      • OptionalcustomMatrix: number

      Returns void

    • Starts rendering graphics explicitly for use as a mask, overriding the shader.

      Parameters

      • drawMode: number = ...

        The WebGL drawing mode (e.g., gl.TRIANGLES).

      • Optionaltexture: Texture

        An optional texture whose alpha channel may dictate masking rules.

      • OptionalcustomMatrix: number

      Returns void

    • Enables rectangular scissor clipping. Only pixels within the specified rectangle (in logical coordinates) will be rendered. Coordinates use the same system as your drawing calls (top-left origin).

      Parameters

      • x: number

        Left edge in logical pixels.

      • y: number

        Top edge in logical pixels.

      • width: number

        Width in logical pixels.

      • height: number

        Height in logical pixels.

      Returns void

    • Exports a world matrix as a CSS matrix(...) string, ready to assign directly to a DOM element's style.transform. Unlike matrixStack.toCSSMatrix(), this bakes in the logic-pixel → CSS-pixel scale (accounting for dpr and a custom logicWidth/logicHeight), so the result lines up with the canvas without any extra scale(...) on your end.

      Parameters

      • Optionalindex: number

        Matrix index to export. Defaults to the current world matrix.

      Returns string

    • Convenience wrapper: sets a blend mode, runs a callback, then restores NORMAL blend mode.

      Parameters

      • mode: BlendMode

        The BlendMode to apply for the duration of the callback.

      • cb: () => void

        The callback to execute under the given blend mode.

      Returns void

      rapid.withBlendMode(BlendMode.ADD, () => {
      rapid.drawSprite({ texture: glowTexture });
      });
    • Convenience wrapper: writes a mask using the stencil buffer, then renders within it, then exits the mask.

      Parameters

      • maskCb: () => void

        Callback that defines the mask geometry (drawn to stencil, not visible).

      • drawCb: () => void

        Callback containing the actual draw calls masked by the stencil.

      • type: MaskType = MaskType.EQUAL

        Mask type: EQUAL (draw inside) or NOT_EQUAL (draw outside). Defaults to EQUAL.

      • ref: number = 1

        Stencil reference value. Defaults to 1.

      Returns void

      rapid.withMask(
      () => rapid.drawRect({ width: 200, height: 200 }),
      () => rapid.drawSprite({ texture: myTexture }),
      );
    • Convenience wrapper: enables scissor clipping for a region, runs a callback, then disables it.

      Parameters

      • x: number

        Left edge in logical pixels.

      • y: number

        Top edge in logical pixels.

      • width: number

        Width in logical pixels.

      • height: number

        Height in logical pixels.

      • cb: () => void

        The callback to execute within the scissor region.

      Returns void

      rapid.withScissor(50, 50, 300, 200, () => {
      rapid.drawSprite({ texture: myTexture });
      });
    • Convenience wrapper: saves the matrix stack, applies an optional transform, runs a callback, then restores. When transform is provided, delegates to matrixStack.applyTransform() which handles position, rotation, scale, offset, and origin automatically.

      Parameters

      • cb: () => void

        The callback to execute within the saved transform context.

      • Optionaltransform: ITransformOptions

        Optional transform options to apply before running the callback.

      • width: number = 0

        The logical width used to resolve origin anchoring. Defaults to 0.

      • height: number = 0

        The logical height used to resolve origin anchoring. Defaults to 0.

      Returns void

      // Simple save/restore
      rapid.withTransform(() => {
      rapid.matrixStack.translate(100, 100);
      rapid.drawSprite({ texture: myTexture });
      });
      // With a transform applied
      rapid.withTransform(() => {
      rapid.drawSprite({ texture: myTexture });
      }, { x: 100, y: 50, rotation: Math.PI / 4, origin: 0.5 }, myTexture.width, myTexture.height);