Skip to content

Renderer

engine.renderer: the backend that draws (WebGL2, WebGL1 or Canvas 2D). Games read kind for logs; the scene graph and the avatars draw with the rest.

readonly kind: RendererKind

‘webgl2’, ‘webgl1’ or ‘canvas2d’.


readonly canvas: HTMLCanvasElement

The canvas drawn in (after a switch to Canvas 2D, a fresh one in the old one’s place).


readonly maxTextureSize: number

The largest texture side it takes, pixels.


readonly features: Record<string, boolean | number | string>

GL: instancing and vertex array objects in use; for logs.


readonly support: FilterSupport

What it can do with filters.


maxBlur: number

The largest blur, stage units (the engine sets the tier’s; 0: blurs off, drop shadows hard).


time: number

Game time, seconds (the engine sets it every frame): a custom shader’s uTime.


readonly lost: boolean

The GL context is lost right now: nothing is drawn.


readonly info: Record<string, unknown>

Information for logs and the tier cache key (GPU string where allowed).

resize(width, height): void

The backing store, in pixels.

number

number

void


createTexture(source): Texture

A texture of source (uploaded now).

TextureSource

Texture


updateTexture(texture, source?, x?, y?): void

source drawn into texture at (x, y): the whole texture by default.

Texture

TextureSource

number

number

void


destroyTexture(texture): void

Frees a texture.

Texture

void


begin(clear, clearAlpha, scale): void

Starts a frame: clear (0xRRGGBB and alpha; alpha 0 for a transparent stage), scale: pixels per stage unit.

number

number

number

void


quad(t, r, m, w, h, tint, alpha, blend): void

Draws region r of t over the local rectangle (0, 0)–(w, h), transformed by m (stage units).

Texture

Region

Mat

number

number

number

number

Blend

void


ellipse(cx, cy, rx, ry, rot, color, alpha): void

A filled ellipse centred at (cx, cy), radii rx, ry, rotated by rot radians; color 0xRRGGBB.

number

number

number

number

number

number

number

void


polygon(pts, n, color, alpha): void

A filled polygon: pts x0, y0, x1, y1, … (n points).

ArrayLike<number>

number

number

number

void


stroke(pts, n, w, color, alpha, closed): void

A polyline of width w, round joins and caps; closed joins the last point to the first.

ArrayLike<number>

number

number

number

number

boolean

void


clip(x, y, w, h): void

Clips what follows to an axis-aligned rectangle of the stage (stage units, snapped to whole backing pixels), until the next clip or unclip. It holds inside layers and for their composites. GL clips quads on the CPU where they stay axis-aligned and uses the scissor only for the others, so a clip rarely breaks the batch.

number

number

number

number

void


unclip(): void

Turns the clip off.

void


beginLayer(): boolean

Draws what follows, until endLayer, into an offscreen layer the size of the canvas (cleared), then composites the layer at alpha: a faint avatar is see-through as a whole, without its overlapping parts showing through each other. Layers nest up to MAX_LAYERS deep; past that, a layer is drawn straight through (and its mask and filters ignored).

boolean

false when it is drawn straight through (too deep, or no layer could be made): then draw what follows at the alpha yourself, endLayer’s alpha does not apply.


beginMask(): void

Inside a layer: what follows, until endLayer, is drawn into a mask instead. At endLayer the layer keeps its pixels only where the mask is opaque (times the mask’s alpha), then is composited.

void


endLayer(alpha, filters?): void

Composites the layer begun by beginLayer at alpha (masked first, if beginMask was called), through filters if given (the enabled ones, in order). Only the area drawn into the layer is composited (plus what filters reach).

number

readonly Filter[] | null

void


end(): FrameStats

Ends the frame (flushes the batch); what it cost.

FrameStats


onLost(listener): void

The context was lost (stop drawing) or restored (textures already uploaded again).

() => void

void


onRestored(listener): void

Called when the context comes back, textures already uploaded again.

() => void

void


destroy(): void

Frees the context and every texture.

void