rapid-render
    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

    backgroundColor: Color = ...

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

    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.

    physicsHeight: number = 0

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

    physicsWidth: number = 0

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

    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.

    spriteRegion: SpriteRegion

    Region dedicated to fast sprite rendering.

    Manager for creating and organizing textures.

    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 = 0xFFFFFFFF

        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(result) to display it on screen.

      const result = rapid.applyFilters(tex, [blurShader, outlineShader]);
      rapid.drawSprite(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

    • Draws a line geometry based on the provided options.

      Parameters

      • options: ILineRenderOptions

        Line rendering options.

      • Optionalcolor: Color

        An optional tint color applied to the line.

      • OptionalcustomShader: GLShader | CustomGlShader

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

      • OptionalcustomMatrix: number

        An optional custom matrix to use for transformation.

      Returns void

    • Utility method: Draws an image directly as a mask using a generic rectangle geometry.

      Parameters

      • texture: Texture

        The texture to be used as a mask.

      • OptionalcustomMatrix: number

      Returns void

    • Draws a rectangular sprite using the current world matrix from matrixStack.

      Parameters

      • texture: Texture

        The WebGL texture wrapper.

      • Optionalcolor: Color

        An optional tint color applied to the sprite.

      • flipX: boolean = false
      • flipY: boolean = false
      • OptionalcustomShader: GLShader | CustomGlShader

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

      • OptionalcustomMatrix: number

      Returns void

    • 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

    • Enters a specific rendering region, flushing the previous one if necessary.

      Parameters

      • region: Region

        The rendering region to enter.

      • OptionalcustomShader: GLShader | CustomGlShader

        An optional custom shader to use for this region.

      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.

      • OptionalphysicsWidth: number

        Optional new physical pixel width (canvas width).

      • OptionalphysicsHeight: number

        Optional new physical pixel height (canvas height).

      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