melonJS
    Preparing search index...

    Class WebGPURenderer

    The experimental WebGPU renderer.

    The asynchronous bootstrap — getContext("webgpu") at construction, then adapter/device negotiation and canvas configuration in WebGPURenderer#init (the reason Application#init is asynchronous at all) — plus the core 2D frame pipeline: one command encoder and one render pass per frame, opened by WebGPURenderer#clear and submitted by WebGPURenderer#flush, with a depth24plus-stencil8 attachment carried from day one (the stencil half serves masks; the depth half is reserved for the mesh path).

    It is opt-in only: renderer: video.WEBGPU (or the #webgpu URI fragment). video.AUTO never selects it, and will not until it reaches feature parity with the WebGL backend.

    Hierarchy (View Summary)

    Index
    _litPipelineWarned: boolean | undefined
    _shadowCount: any
    _shadowFlushing: boolean | undefined
    activeLightCount: number

    Number of active Light2d instances uploaded to the lit batcher for the current frame. Set by setLightUniforms. The WebGL renderer's drawImage reads this to decide between the unlit fast-path batcher (default) and the lit batcher (only when lights AND a normal map are both in play).

    adapter: GPUAdapter | undefined

    The WebGPU adapter, set once WebGPURenderer#init resolves.

    backgroundColor: Color

    The background color used to clear the main framebuffer. Note: alpha value will be set based on the transparent property of the renderer settings.

    black
    
    cache: TextureCache
    context: GPUCanvasContext

    The WebGPU canvas context

    context

    currentColor: Color
    currentNormalMap:
        | ImageBitmap
        | HTMLImageElement
        | HTMLCanvasElement
        | OffscreenCanvas
        | null

    The normal-map texture associated with the next drawImage call, if any. Set by Sprite.draw (and any other normal-map-aware renderable) just before calling drawImage, then cleared back to null after. The WebGL renderer reads this state and routes lit quads through the shader's lighting path; the Canvas renderer ignores it entirely.

    currentScissor: Int32Array<ArrayBufferLike>
    currentTint: Color
    currentTransform: Matrix3d
    designRatio: number

    the requested video size ratio

    device: GPUDevice | undefined

    The WebGPU device, set once WebGPURenderer#init resolves.

    device

    GPURenderer: string | undefined

    The GPU device identifier string (set by GPU renderers — WebGL today, WebGPU once it lands; undefined for Canvas).

    GPUVendor: string | undefined
    isContextValid: boolean

    true if the current rendering context is valid

    true
    
    lightAtlas: TextureAtlas | undefined
    lightShader: RadialGradientEffect | undefined
    lightUniformsScratch: LightUniformScratch | undefined
    lineWidth: number

    The thickness of lines for shape drawing operations like Renderer#strokeRect, Renderer#strokeEllipse and Renderer#strokeLine. Subclasses override the storage — CanvasRenderer proxies it to the underlying 2D context via a getter/setter, while WebGLRenderer treats it as a regular field consumed by its shape-stroke routines.

    1
    
    maskDepthWarned: boolean | undefined
    onCanvasResize: () => void
    onGameReset: () => void
    parentApplication: any

    The Application this renderer belongs to, set by Application.init() — engine code holding a renderer reference must use this rather than the global game instance.

    path2D: Path2D

    The Path2D instance used by the renderer to draw primitives

    preferredFormat: string | undefined

    The preferred canvas texture format reported by the platform, set once WebGPURenderer#init resolves.

    projectionMatrix: Matrix3d
    renderState: RenderState

    The renderer state container (color, tint, transform, scissor, blend mode) with a zero-allocation save/restore stack.

    renderTarget: CanvasRenderTarget

    The renderer renderTarget

    renderTarget

    savedBlendMode: string | undefined
    scaleRatio: Vector2d

    the scaling ratio to be applied to the main canvas

    <1,1>
    
    settings: object

    The given constructor options

    shaderLanguage: "glsl" | "wgsl" | null

    The source language this backend accepts for user-supplied shaders, or null when it has no programmable pipeline at all (the Canvas backend). "glsl" on the WebGL backend, "wgsl" on the WebGPU backend.

    Consumers that need a specific language — ShaderEffect and the loader's {vertex, fragment} shader assets both hand GLSL source straight to the driver — must compare against the language rather than test for a GPU backend, or they would accept a backend that cannot read what they are about to give it.

    null
    
    stubTextureView: GPUTextureView | null | undefined
    supportedCompressedFormats:
        | {
            astc: | {
                COMPRESSED_RGBA_ASTC_4x4_KHR: number;
                COMPRESSED_RGBA_ASTC_5x4_KHR: number;
                COMPRESSED_RGBA_ASTC_5x5_KHR: number;
                COMPRESSED_RGBA_ASTC_6x5_KHR: number;
                COMPRESSED_RGBA_ASTC_6x6_KHR: number;
                COMPRESSED_RGBA_ASTC_8x5_KHR: number;
                COMPRESSED_RGBA_ASTC_8x6_KHR: number;
                COMPRESSED_RGBA_ASTC_8x8_KHR: number;
                COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR: number;
                COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR: number;
                COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR: number;
                COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR: number;
                COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR: number;
                COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR: number;
                COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR: number;
                COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR: number;
            }
            | null;
            bptc: { COMPRESSED_RGBA_BPTC_UNORM_EXT: number }
            | null;
            etc1: { COMPRESSED_RGB_ETC1_WEBGL: number } | null;
            etc2:
                | {
                    COMPRESSED_R11_EAC: number;
                    COMPRESSED_RG11_EAC: number;
                    COMPRESSED_RGB8_ETC2: number;
                    COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: number;
                    COMPRESSED_RGBA8_ETC2_EAC: number;
                    COMPRESSED_SIGNED_R11_EAC: number;
                    COMPRESSED_SIGNED_RG11_EAC: number;
                    COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: number;
                    COMPRESSED_SRGB8_ETC2: number;
                    COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: number;
                }
                | null;
            pvrtc: null;
            s3tc: | {
                COMPRESSED_RGB_S3TC_DXT1_EXT: number;
                COMPRESSED_RGBA_S3TC_DXT3_EXT: number;
                COMPRESSED_RGBA_S3TC_DXT5_EXT: number;
            }
            | null;
            s3tc_srgb: | {
                COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: number;
                COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: number;
                COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: number;
                COMPRESSED_SRGB_S3TC_DXT1_EXT: number;
            }
            | null;
        }
        | undefined
    supportsDepthBuffer: boolean

    Whether this backend has a depth buffer, and with it the 3D projection and mesh paths a depth-sorted scene needs (Camera3d and any camera declaring defaultSortOn = "depth"). false here on the base/Canvas renderer.

    false
    
    supportsInstancing: boolean

    Whether this renderer backend can draw one geometry many times in a single call from per-instance data — what InstancedMesh needs. false here on the base/Canvas renderer, which falls back to drawing each instance individually.

    false
    
    supportsRetainedMesh: boolean

    Whether this renderer backend can keep mesh geometry resident on the GPU, letting a mesh supply a model matrix instead of vertices it has already positioned itself. false here on the base/Canvas renderer.

    false
    
    supportsShaderTileLayers: boolean

    Whether this renderer backend can draw TMX tile layers through a GPU shader path (see the gpuTilemap application setting). false here on the base/Canvas renderer; GPU backends flip it. A capability flag rather than a version/class check so future backends advertise support without consumers growing type checks.

    false
    
    type: string

    The renderer backend identity — the built-in renderers report "CANVAS", "WebGL2" and "WebGPU". Use it for identity checks (code coupled to one backend's machinery); prefer the capability flags (shaderLanguage, supportsDepthBuffer, supportsRetainedMesh, supportsShaderTileLayers) when the requirement is a capability rather than a specific backend. (override this property with a specific value when implementing a custom renderer)

    uvOffset: number
    _whitePixel: any
    • get currentDepth(): number

      Current per-renderable depth value. The GPU batchers (WebGL and WebGPU) push it into the vertex stream as the z component of each vertex — a no-op under the default orthographic projection, used by perspective (Camera3d) to scale and parallax sprites by distance. Mirrors renderable.depth, set automatically by Renderable.preDraw via Renderer#setDepth.

      Returns number

      0
      
    • set currentDepth(value: number): void

      Parameters

      • value: number

      Returns void

    • Adds a circular arc to the current sub-path, using the given control points and radius.

      Parameters

      • x1: number

        the x-axis coordinate of the first control point

      • y1: number

        the y-axis coordinate of the first control point

      • x2: number

        the x-axis coordinate of the second control point

      • y2: number

        the y-axis coordinate of the second control point

      • radius: number

        the arc's radius; must be non-negative

      Returns void

    • Adds a cubic Bezier curve to the current sub-path.

      Parameters

      • cp1x: number

        the x-axis coordinate of the first control point

      • cp1y: number

        the y-axis coordinate of the first control point

      • cp2x: number

        the x-axis coordinate of the second control point

      • cp2y: number

        the y-axis coordinate of the second control point

      • x: number

        the x-axis coordinate of the end point

      • y: number

        the y-axis coordinate of the end point

      Returns void

    • Draw a pooled render target through an effect's pipeline as a screen-space quad — the compositing primitive of the post-effect chain. Blending is disabled for camera blits (the target is fully composited) and kept for per-sprite blits (transparent texels must not overwrite the scene).

      Parameters

      • source: WebGPURenderTarget

        the target to sample

      • x: number

        destination x

      • y: number

        destination y

      • width: number

        destination width

      • height: number

        destination height

      • effect: ShaderEffect

        the effect to composite with

      • OptionalkeepBlend: boolean = false

        keep the current blend mode

      Returns void

    • Begin the frame: reset the per-frame allocators, acquire the canvas texture, and open the frame's command encoder and render pass with a clear load — the WebGPU realization of gl.clearColor + gl.clear. Called by Application.draw() at the top of every frame.

      Returns void

    • Clear the current clip region with the given color — a full-viewport triangle clipped by the active scissor, drawn with blending replaced (WebGPU has no scissored clear operation). Used mid-frame by ColorLayer and Container backgrounds.

      Deliberate divergence from the GL backend: because this is a draw, it honors an active stencil mask (GL's gl.clear ignores stencil and clears the whole scissor region) — under a mask, the clear fills the mask window only, which is the behavior masks actually promise.

      Parameters

      • Optionalcolor: string | Color = "#000000"

        css color

      • Optionalopaque: boolean = false

        allow transparency or not

      Returns void

    • Erase the pixels in the given rectangular area by setting them to transparent black (rgba(0,0,0,0)).

      Parameters

      • x: number

        x axis of the coordinate for the rectangle starting point.

      • y: number

        y axis of the coordinate for the rectangle starting point.

      • width: number

        The rectangle's width.

      • height: number

        The rectangle's height.

      Returns void

    • clip the given region from the canvas — all future drawing is limited to it. The clip is a transform-derived screen-space AABB applied through the pass scissor (WebGPU's setScissorRect is top-left-origin, so the stored coords apply without the GL y-flip; it validates containment, so the box is clamped to the canvas).

      Parameters

      • x: number

        x axis of the upper-left corner of the region

      • y: number

        y axis of the upper-left corner of the region

      • width: number

        the width of the region

      • height: number

        the height of the region

      Returns void

    • Create and return a new Canvas element, sized as requested.

      The instance form of Renderer.createCanvas. app.renderer is the renderer entry point, and a static is not reachable through an instance — so this is what user code actually calls.

      Parameters

      • width: number

        width in pixels

      • height: number

        height in pixels

      • OptionalreturnOffscreenCanvas: boolean = false

        return an OffscreenCanvas where supported

      Returns HTMLCanvasElement | OffscreenCanvas

      the new canvas

    • Create a pattern with the specified repetition

      Parameters

      • image:
            | ImageBitmap
            | HTMLImageElement
            | HTMLVideoElement
            | VideoFrame
            | HTMLCanvasElement
            | OffscreenCanvas
            | SVGImageElement

        source image

      • Optionalrepeat: string = "no-repeat"

        one of "repeat" / "repeat-x" / "repeat-y" / "no-repeat"

      Returns TextureAtlas

      the patterned texture created

    • Create a radial gradient that can be used with Renderer#setColor.

      Parameters

      • x0: number

        x-axis coordinate of the start circle

      • y0: number

        y-axis coordinate of the start circle

      • r0: number

        radius of the start circle

      • x1: number

        x-axis coordinate of the end circle

      • y1: number

        y-axis coordinate of the end circle

      • r1: number

        radius of the end circle

      Returns Gradient

      a Gradient object

    • Release any retained geometry held for the given mesh (called from Mesh.onDeactivateEvent / Mesh.destroy).

      Parameters

      • mesh: object

        the mesh whose GPU geometry should be freed

      Returns void

    • Draw an image onto the frame (Canvas-compatible 3/5/9-argument forms).

      Parameters

      • image:
            | ImageBitmap
            | HTMLImageElement
            | HTMLVideoElement
            | VideoFrame
            | HTMLCanvasElement
            | OffscreenCanvas

        the source image

      • sx: number

        source x (or destination x in the 3/5-arg forms)

      • sy: number

        source y (or destination y in the 3/5-arg forms)

      • Optionalsw: number

        source width

      • Optionalsh: number

        source height

      • Optionaldx: number

        destination x

      • Optionaldy: number

        destination y

      • Optionaldw: number

        destination width

      • Optionaldh: number

        destination height

      Returns void

    • Draw a Light2d glow quad through the radial-gradient effect's single-effect fast path — the light's color and intensity ride the per-vertex tint, so back-to-back lights share the same pipeline.

      Parameters

      • light: Light2d

        the light to draw

      Returns void

    • Draw a textured triangle mesh. The mesh object must provide: vertices (Float32Array, x/y/z triplets), uvs (Float32Array, u/v pairs), indices (Uint16Array, triangle indices), texture (TextureAtlas), vertexCount (number), and optionally cullBackFaces (boolean, default true).

      On the GPU backends (WebGL and WebGPU — hardware depth testing), passing a modelMatrix selects the retained path: the mesh's model-space geometry stays resident on the GPU and the matrix places it, so redrawing never re-uploads vertices (see Renderer#supportsRetainedMesh). Without a matrix the vertices are taken as already CPU-projected (the 2D-camera path — the only path the Canvas renderer supports, using painter's algorithm). Mesh.draw selects the right form automatically.

      Parameters

      • mesh: any

        a Mesh renderable or compatible object

      • modelMatrix: any

        the mesh's placement, for the retained path (GPU backends)

      Returns void

    • Draw a TMX tile layer: WGSL-eligible layers (renderMode === "shader") draw through the GPU tile path — one quad per tileset, GID lookup in a per-layer index texture; everything else falls through to the base per-tile loop.

      Parameters

      • layer: object

        the TMXLayer to draw

      • rect: object

        the visible region in world coords

      Returns void

    • Enable the scissor test with the given rectangle (transformed by the current transform, like the WebGL renderer). Unlike WebGPURenderer#clipRect a full-canvas rectangle still enables the scissor rather than reading as "no clip".

      Parameters

      • x: number

        x coordinate of the scissor rectangle

      • y: number

        y coordinate of the scissor rectangle

      • width: number

        width of the scissor rectangle

      • height: number

        height of the scissor rectangle

      Returns void

    • Fill an arc at the specified coordinates with given radius, start and end points

      Parameters

      • x: number

        arc center point x-axis

      • y: number

        arc center point y-axis

      • radius: number

        arc radius

      • start: number

        start angle in radians

      • end: number

        end angle in radians

      • OptionalantiClockwise: boolean = false

        draw arc anti-clockwise

      Returns void

    • Fill an ellipse at the specified coordinates with given radius

      Parameters

      • x: number

        ellipse center point x-axis

      • y: number

        ellipse center point y-axis

      • w: number

        horizontal radius of the ellipse

      • h: number

        vertical radius of the ellipse

      Returns void

    • Fill a line between the given two points

      Parameters

      • startX: number

        the start x coordinate

      • startY: number

        the start y coordinate

      • endX: number

        the end x coordinate

      • endY: number

        the end y coordinate

      Returns void

    • Draw a filled rectangle at the specified coordinates

      Parameters

      • x: number

        x axis of the coordinate for the rectangle starting point

      • y: number

        y axis of the coordinate for the rectangle starting point

      • width: number

        the rectangle's width

      • height: number

        the rectangle's height

      Returns void

    • Draw a rounded filled rectangle at the specified coordinates

      Parameters

      • x: number

        x axis of the coordinate for the rounded rectangle starting point

      • y: number

        y axis of the coordinate for the rounded rectangle starting point

      • width: number

        the rounded rectangle's width

      • height: number

        the rounded rectangle's height

      • radius: number

        the rounded corner's radius

      Returns void

    • Draw every ground shadow queued since the last drain, then empty the queue (#1515). Called when the renderer leaves mesh mode, and once more at end of frame for a scene made only of meshes, which never switches away from mesh mode on its own.

      Inert on a backend that never queues — the Canvas renderer has no depth buffer and so no ground shadows at all.

      Returns void

    • Resolve the default texture filter mode for this renderer, decoupled from Renderer#setAntiAlias (which controls polygon-edge MSAA on GPU backends). Honors the textureFilter setting ("nearest" / "linear"), falling back to the antiAlias setting when it's "auto" (the default).

      Backend-neutral on purpose: it returns the mode as a string so each GPU backend maps it to its own enum (WebGL gl.LINEAR / gl.NEAREST, a future WebGPU renderer GPUFilterMode). The Canvas renderer has no per-texture filtering, so this is informational there.

      Returns "linear" | "nearest"

      the resolved default filter mode

    • The compressed-texture families this device supports, in the same shape as the GL backend (one key per family; supported families hold an object of WebGL format constants — the values the loader parsers emit — unsupported ones are null, so the shared hasSupportedCompressedFormats works unchanged). PVRTC has no WebGPU equivalent and stays null.

      Returns object

      one key per extension family

    • Negotiate the GPU adapter and device, configure the canvas context, and build the GPU-facing infrastructure (pipeline cache, buffer arenas, depth-stencil attachment). Awaited by Application#init right after construction — a WebGPU device cannot be acquired synchronously, which is what this hook exists for.

      Returns Promise<void>

      resolves once the device is configured

      (as a rejection) when WebGPU is unavailable or no suitable adapter is found

    • Adds a quadratic Bezier curve to the current sub-path.

      Parameters

      • cpx: number

        the x-axis coordinate of the control point

      • cpy: number

        the y-axis coordinate of the control point

      • x: number

        the x-axis coordinate of the end point

      • y: number

        the y-axis coordinate of the end point

      Returns void

    • creates a rectangular path whose starting point is at (x, y)

      Parameters

      • x: number

        the x axis of the coordinate for the rectangle starting point

      • y: number

        the y axis of the coordinate for the rectangle starting point

      • width: number

        the rectangle's width

      • height: number

        the rectangle's height

      Returns void

    • adds a rounded rectangle to the current path

      Parameters

      • x: number

        the x axis of the coordinate for the rectangle starting point

      • y: number

        the y axis of the coordinate for the rectangle starting point

      • width: number

        the rectangle's width

      • height: number

        the rectangle's height

      • radii: number

        the corner radius

      Returns void

    • Enable/disable anti-aliasing — under WebGPU this only drives the default sampler filter: textures stay resident and every (texture, sampler) bind-group pairing is rebuilt on next draw.

      Parameters

      • Optionalenable: boolean = false

        whether to enable anti-aliasing

      Returns void

    • Set the active batcher for this renderer — flush + unbind the outgoing one, bind the incoming. Unlike the GL backend there is no projection re-sync: the projection lives in the shared frame-globals bind group, not in per-program uniforms.

      Parameters

      • Optionalname: string = "default"

        a batcher name

      Returns WebGPUBatcher

      the now-active batcher

    • Enable or disable blending — blend state is pipeline state on this backend, so this maps onto the blend-mode axis: disabling stashes the current mode and switches to "none" (source replaces destination), enabling restores the stashed mode.

      Parameters

      • enable: boolean

        whether blending should be enabled

      Returns void

    • Set the blend mode for subsequent draws. Under WebGPU blending is pipeline state: the change is recorded (after draining vertices queued under the previous mode) and the next batcher flush picks the matching pipeline variant.

      Parameters

      • Optionalmode: string = "normal"

        blend mode ("normal", "multiply", "additive"/"lighter", "screen", "darken", "lighten", "none")

      • OptionalpremultipliedAlpha: boolean = true

        whether textures use premultiplied alpha (affects the source blend factor)

      Returns string

      the blend mode actually applied

    • Set the current per-renderable depth value. GPU batchers (WebGL today, WebGPU once it lands) push it into the vertex stream as the z component of each vertex — a no-op under the default orthographic projection, used by perspective (Camera3d) to scale and parallax sprites by distance.

      Typically called automatically by Renderable.preDraw from the renderable's depth property. User code only needs to call this directly when emitting draw calls outside of a Renderable.draw() — e.g. from a custom Container.draw() override.

      Honored by the save/restore stack like setTint / setColor.

      Parameters

      • depth: number

        the depth value to set

      Returns void

      Renderable#depth

    • Pack the active 2D lights and hand the std140 block to the lit batcher — the WebGPU realization of the backend-neutral lighting contract (Camera2d calls this once per camera per frame).

      Parameters

      • lights: Set<Light2d> | Light2d[]

        active lights

      • ambient: Color

        the ambient lighting floor

      • OptionaltranslateX: number = 0

        camera translate x

      • OptionaltranslateY: number = 0

        camera translate y

      Returns void

    • Set the line dash pattern for stroke operations.

      Parameters

      • segments: number[]

        an array of numbers specifying distances to alternately draw a line and a gap. An empty array clears the dash pattern (solid lines).

      Returns void

      // draw a dashed line
      renderer.setLineDash([10, 5]);
      renderer.strokeLine(0, 0, 100, 0);
      // clear the dash pattern
      renderer.setLineDash([]);
    • A mask limits rendering elements to the shape and position of the given mask object — realized on the stencil half of the pass's depth-stencil attachment, exactly like the GL backend: a write phase increments the stencil under the mask shape (color writes off), then the render phase only passes fragments where the stencil equals the current mask level (or 0 when inverted).

      Entering the first mask level clears the stencil, which WebGPU can only do at a pass boundary — the frame's pass is broken and restarted with stencilLoadOp: "clear" (color preserved). (Note: masks are not preserved through save/restore and need to be manually cleared, same as the other backends.)

      Parameters

      • Optionalmask: any

        the shape defining the mask to be applied

      • Optionalinvert: boolean = false

        either the given shape should define what is visible (default) or the opposite

      Returns void

    • Reset then multiply the transformation matrix

      Parameters

      • a: any

        a matrix, or the a component

      • Optionalb: number

        the b component

      • Optionalc: number

        the c component

      • Optionald: number

        the d component

      • Optionale: number

        the e component

      • Optionalf: number

        the f component

      Returns void

    • Restrict rendering to a sub-rectangle of the canvas — the split-screen camera surface (Camera2d/Camera3d._setupNonDefaultProjection). Callers pass GL-convention rects with a BOTTOM-left origin (the flip is baked into the camera code, which the GL backend depends on); WebGPU viewports are top-left, so it is un-flipped here. The rect applies to canvas passes only — offscreen post-effect targets always render full size, like the GL pool path re-viewporting per target.

      Parameters

      • x: number

        viewport x (pixels)

      • y: number

        viewport y, bottom-left origin (pixels)

      • width: number

        viewport width (pixels)

      • height: number

        viewport height (pixels)

      Returns void

    • Stroke an arc at the specified coordinates with given radius, start and end points

      Parameters

      • x: number

        arc center point x-axis

      • y: number

        arc center point y-axis

      • radius: number

        arc radius

      • start: number

        start angle in radians

      • end: number

        end angle in radians

      • OptionalantiClockwise: boolean = false

        draw arc anti-clockwise

      • Optionalfill: boolean = false

        also fill the shape with the current color if true

      Returns void

    • Stroke an ellipse at the specified coordinates with given radius

      Parameters

      • x: number

        ellipse center point x-axis

      • y: number

        ellipse center point y-axis

      • w: number

        horizontal radius of the ellipse

      • h: number

        vertical radius of the ellipse

      • Optionalfill: boolean = false

        also fill the shape with the current color if true

      Returns void

    • Stroke a line between the given two points

      Parameters

      • startX: number

        the start x coordinate

      • startY: number

        the start y coordinate

      • endX: number

        the end x coordinate

      • endY: number

        the end y coordinate

      Returns void

    • Stroke a Polygon on the screen with the current color

      Parameters

      • poly: Polygon

        the shape to draw

      • Optionalfill: boolean = false

        also fill the shape with the current color if true

      Returns void

    • Draw a stroke rectangle at the specified coordinates

      Parameters

      • x: number

        x axis of the coordinate for the rectangle starting point

      • y: number

        y axis of the coordinate for the rectangle starting point

      • width: number

        the rectangle's width

      • height: number

        the rectangle's height

      • Optionalfill: boolean = false

        also fill the shape with the current color if true

      Returns void

    • Stroke a rounded rectangle at the specified coordinates

      Parameters

      • x: number

        x axis of the coordinate for the rounded rectangle starting point

      • y: number

        y axis of the coordinate for the rounded rectangle starting point

      • width: number

        the rounded rectangle's width

      • height: number

        the rounded rectangle's height

      • radius: number

        the rounded corner's radius

      • Optionalfill: boolean = false

        also fill the shape with the current color if true

      Returns void

    • tint the given image or canvas using the given color

      Parameters

      • src: HTMLImageElement | HTMLCanvasElement | OffscreenCanvas

        the source image to be tinted

      • color: string | Color

        the color that will be used to tint the image

      • Optionalmode: string = "multiply"

        the composition mode used to tint the image

      Returns HTMLCanvasElement | OffscreenCanvas

      a new canvas or offscreencanvas (if supported) element representing the tinted image

    • creates a Blob object representing the last rendered frame

      Parameters

      • Optionaltype: string = "image/png"

        A string indicating the image format

      • Optionalquality: number

        A Number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.

      Returns Promise<any>

      A Promise returning a Blob object representing the last rendered frame

      renderer.convertToBlob().then((blob) => console.log(blob));
      
    • returns a data URL containing a representation of the last frame rendered

      Parameters

      • Optionaltype: string = "image/png"

        A string indicating the image format

      • Optionalquality: number

        A Number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.

      Returns Promise<any>

      A Promise returning a string containing the requested data URL.

      renderer.toDataURL().then((dataURL) => console.log(dataURL));
      
    • Capture the current frame — everything drawn to the active target so far — into a Texture2d, entirely on the GPU (an encoder-ordered copyTextureToTexture; no readback round-trip). Same contract as the WebGL backend's toFrameTexture: a shared, renderer-owned slot by default, target: null for a fresh caller-owned capture, or a prior capture as target to refresh it in place; options.region captures a sub-region (framebuffer pixels, bottom-left origin — converted to this backend's top-left copy origin internally).

      Two documented divergences from the GL capture:

      • alpha is preserved (the GL path captures into an opaque RGB texture)
      • row 0 of the capture is the TOP of the frame (matching screen_uv), where the GL capture is bottom-up — GLSL bodies sampling a capture flip with 1.0 - uv.y; their WGSL twins must not.

      Parameters

      • Optionaloptions: {
            region?:
                | Bounds
                | { height: number; width: number; x: number; y: number };
            target?: any;
        } = {}
        • Optionalregion?: Bounds | { height: number; width: number; x: number; y: number }

          capture only this sub-region; defaults to the whole frame

        • Optionaltarget?: any

          omit for the shared renderer slot; a prior capture to refresh it in place; null to mint a fresh, caller-owned capture (destroy() it yourself when done)

      Returns any

      a GPU-resident texture holding the captured frame, or null when no device is available

    • creates an ImageBitmap object of the last frame rendered (not supported by standard Canvas)

      Parameters

      • Optionaltype: string = "image/png"

        A string indicating the image format

      • Optionalquality: number

        A Number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.

      Returns Promise<any>

      A Promise returning an ImageBitmap.

      renderer.transferToImageBitmap().then((image) => console.log(image));
      
    • Multiply the given matrix (or 2D affine components) into the current transformation matrix

      Parameters

      • a: any

        a matrix, or the a component

      • Optionalb: number

        the b component

      • Optionalc: number

        the c component

      • Optionald: number

        the d component

      • Optionale: number

        the e component

      • Optionalf: number

        the f component

      Returns void

    • Create and return a new Canvas element (or OffscreenCanvas when supported and returnOffscreenCanvas is true). Centralized renderer-side allocator so every scratch / fallback / render- target canvas in the engine routes through the same OffscreenCanvas-aware path, instead of duplicating document.createElement calls that throw in worker contexts.

      Parameters

      • width: number

        canvas width in pixels

      • height: number

        canvas height in pixels

      • OptionalreturnOffscreenCanvas: boolean = false

        return an OffscreenCanvas if the platform supports it

      Returns HTMLCanvasElement | OffscreenCanvas

      a new canvas of the given size

    • Shared 1×1 fully-white canvas used as a no-op texture fallback. Renderers and renderables that need a "blank" texture binding (e.g. to satisfy a shader's sampler input when there's no real image — Kd-only Mesh materials, solid-color quad fills, etc.) should use this rather than allocating their own.

      Lazily created on first call; shared across every caller; uses OffscreenCanvas where supported (worker-safe). Static so it's accessible without a renderer instance (e.g. from a Mesh constructor that runs before the active renderer is set).

      Returns HTMLCanvasElement | OffscreenCanvas

      the shared 1×1 white canvas