Optionaloptions: anyoptional parameters for the renderer
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).
The background color used to clear the main framebuffer. Note: alpha value will be set based on the transparent property of the renderer settings.
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.
the requested video size ratio
The GPU renderer string (WebGL only, undefined for Canvas)
true if the current rendering context is valid
The Path2D instance used by the renderer to draw primitives
The renderer state container (color, tint, transform, scissor, blend mode) with a zero-allocation save/restore stack.
The renderer renderTarget
the scaling ratio to be applied to the main canvas
The given constructor options
The renderer type : Canvas, WebGL, etc... (override this property with a specific value when implementing a custom renderer)
return the height of the canvas which this renderer draws to
height of the system Canvas
return the width of the canvas which this renderer draws to
width of the system Canvas
Blit a texture to the screen through a shader effect. Draws a screen-aligned quad using the given texture as source and the given shader for post-processing (e.g. scanlines, desaturation). No-op on Canvas renderer.
the source texture to blit
destination x position
destination y position
destination width
destination height
the shader effect to apply
OptionalkeepBlend: booleanif true, keep current blend mode (for sprite compositing)
prepare the framebuffer for drawing a new frame
Clear the current render target to transparent black (color + stencil). Used to prepare FBOs for post-effect capture. No-op on Canvas renderer.
Create a linear gradient that can be used with Renderer#setColor.
x-axis coordinate of the start point
y-axis coordinate of the start point
x-axis coordinate of the end point
y-axis coordinate of the end point
a Gradient object
Create a radial gradient that can be used with Renderer#setColor.
x-axis coordinate of the start circle
y-axis coordinate of the start circle
radius of the start circle
x-axis coordinate of the end circle
y-axis coordinate of the end circle
radius of the end circle
a Gradient object
Disable the scissor test, allowing rendering to the full viewport. No-op on Canvas renderer.
Render a Light2d instance.
Each renderer implements its own strategy: the WebGL renderer
draws lights as quads through a shared procedural radial-falloff
fragment shader (no per-light texture, color and intensity
encoded in the per-vertex tint so consecutive draws batch); the
Canvas renderer caches a small Gradient config object per
light in a WeakMap (rebuilt only when the light's radii /
color / intensity change), rasterizes it with Gradient.toCanvas()
into a single shared CanvasRenderTarget, and composites the
result via drawImage. The base implementation is a no-op so
renderers without a lighting path can be polymorphically
substituted.
Light2d itself is renderer-agnostic — it just calls
renderer.drawLight(this) and relies on the renderer to pick
the right machinery.
the Light2d instance to render
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).
WebGL uses hardware depth testing; Canvas uses painter's algorithm (back-to-front sort).
a Mesh renderable or compatible object
Enable the scissor test with the given rectangle. No-op on Canvas renderer.
x coordinate of the scissor rectangle
y coordinate of the scissor rectangle
width of the scissor rectangle
height of the scissor rectangle
render the main framebuffer on screen
returns the current blend mode for this renderer
blend mode
return a reference to the current render target corresponding canvas which this renderer draws to
return a reference to the current render target corresponding Context
Get the current line dash pattern.
the current dash pattern
return the list of supported compressed texture formats. The base implementation returns null for all formats (no GPU compressed texture support). The WebGL renderer overrides this with actual extension availability.
an object with one key per extension family, each value is the WebGL extension object or null
return the current global alpha
return true if the given compressed texture format is supported
a WebGL compressed texture format constant
Reset context state
resizes the system canvas
new width of the canvas
new height of the canvas
enable/disable image smoothing (scaling interpolation) for the current render target
Optionalenable: boolean = falseEnable or disable alpha blending. No-op on Canvas renderer (Canvas always blends).
true to enable blending, false to disable
set the current blend mode. Subclasses (CanvasRenderer, WebGLRenderer) implement the actual GL/Canvas logic.
Optionalmode: string = "normal"blend mode
Upload the active scene lights to the lit sprite pipeline.
Called once per camera per frame by Camera2d.draw() (after the
FBO is bound, before the world tree walk fires Sprite.draw for
any normal-mapped sprite). The WebGL renderer overrides this to
pack the lights into the lit shader's uniform buffers; the Canvas
renderer cannot do per-pixel normal-map lighting and silently
ignores the call. The first time a non-empty light list is passed
in Canvas mode, a one-shot console warning is emitted.
Stage stays renderer-agnostic by passing the raw scene data — lights iterable and ambient color — and letting the renderer decide how to encode them.
Optionallights: Iterable<object, any, any>active Light2d instances; falsy/empty no-ops
Optionalambient: objectambient lighting color (0..255 RGB)
OptionaltranslateX: numberworld-to-screen X translate (matches Camera2d.draw())
OptionaltranslateY: numberworld-to-screen Y translate
Set the line dash pattern for stroke operations.
an array of numbers specifying distances to alternately draw a line and a gap. An empty array clears the dash pattern (solid lines).
A mask limits rendering elements to the shape and position of the given mask object. So, if the renderable is larger than the mask, only the intersecting part of the renderable will be visible. Mask are not preserved through renderer context save and restore.
set a coloring tint for sprite based renderables
the tint color
Optionalalpha: number = tint.alphaan alpha value to be applied to the tint
Sets the viewport for the renderer. Defines the affine transformation from normalized device coordinates to window coordinates. No-op on Canvas renderer.
Optionalx: number = 0x coordinate of the viewport origin
Optionaly: number = 0y coordinate of the viewport origin
Optionalw: numberwidth of the viewport (defaults to canvas width)
Optionalh: numberheight of the viewport (defaults to canvas height)
tint the given image or canvas using the given color
the source image to be tinted
the color that will be used to tint the image
Optionalmode: string = "multiply"the composition mode used to tint the image
a new canvas or offscreencanvas (if supported) element representing the tinted image
creates a Blob object representing the last rendered frame
Optionaltype: string = "image/png"A string indicating the image format
Optionalquality: numberA 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.
A Promise returning a Blob object representing the last rendered frame
returns a data URL containing a representation of the last frame rendered
Optionaltype: string = "image/png"A string indicating the image format
Optionalquality: numberA 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.
A Promise returning a string containing the requested data URL.
creates an ImageBitmap object of the last frame rendered (not supported by standard Canvas)
Optionaltype: string = "image/png"A string indicating the image format
Optionalquality: numberA 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.
A Promise returning an ImageBitmap.
a base renderer object