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.
Properties
Section titled “Properties”
readonlykind:RendererKind
‘webgl2’, ‘webgl1’ or ‘canvas2d’.
canvas
Section titled “canvas”
readonlycanvas:HTMLCanvasElement
The canvas drawn in (after a switch to Canvas 2D, a fresh one in the old one’s place).
maxTextureSize
Section titled “maxTextureSize”
readonlymaxTextureSize:number
The largest texture side it takes, pixels.
features
Section titled “features”
readonlyfeatures:Record<string,boolean|number|string>
GL: instancing and vertex array objects in use; for logs.
support
Section titled “support”
readonlysupport:FilterSupport
What it can do with filters.
maxBlur
Section titled “maxBlur”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.
readonlylost:boolean
The GL context is lost right now: nothing is drawn.
readonlyinfo:Record<string,unknown>
Information for logs and the tier cache key (GPU string where allowed).
Methods
Section titled “Methods”resize()
Section titled “resize()”resize(
width,height):void
The backing store, in pixels.
Parameters
Section titled “Parameters”number
height
Section titled “height”number
Returns
Section titled “Returns”void
createTexture()
Section titled “createTexture()”createTexture(
source):Texture
A texture of source (uploaded now).
Parameters
Section titled “Parameters”source
Section titled “source”Returns
Section titled “Returns”updateTexture()
Section titled “updateTexture()”updateTexture(
texture,source?,x?,y?):void
source drawn into texture at (x, y): the whole texture by default.
Parameters
Section titled “Parameters”texture
Section titled “texture”source?
Section titled “source?”number
number
Returns
Section titled “Returns”void
destroyTexture()
Section titled “destroyTexture()”destroyTexture(
texture):void
Frees a texture.
Parameters
Section titled “Parameters”texture
Section titled “texture”Returns
Section titled “Returns”void
begin()
Section titled “begin()”begin(
clear,clearAlpha,scale):void
Starts a frame: clear (0xRRGGBB and alpha; alpha 0 for a transparent stage), scale: pixels per stage unit.
Parameters
Section titled “Parameters”number
clearAlpha
Section titled “clearAlpha”number
number
Returns
Section titled “Returns”void
quad()
Section titled “quad()”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).
Parameters
Section titled “Parameters”number
number
number
number
Returns
Section titled “Returns”void
ellipse()
Section titled “ellipse()”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.
Parameters
Section titled “Parameters”number
number
number
number
number
number
number
Returns
Section titled “Returns”void
polygon()
Section titled “polygon()”polygon(
pts,n,color,alpha):void
A filled polygon: pts x0, y0, x1, y1, … (n points).
Parameters
Section titled “Parameters”ArrayLike<number>
number
number
number
Returns
Section titled “Returns”void
stroke()
Section titled “stroke()”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.
Parameters
Section titled “Parameters”ArrayLike<number>
number
number
number
number
closed
Section titled “closed”boolean
Returns
Section titled “Returns”void
clip()
Section titled “clip()”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.
Parameters
Section titled “Parameters”number
number
number
number
Returns
Section titled “Returns”void
unclip()
Section titled “unclip()”unclip():
void
Turns the clip off.
Returns
Section titled “Returns”void
beginLayer()
Section titled “beginLayer()”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).
Returns
Section titled “Returns”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()
Section titled “beginMask()”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.
Returns
Section titled “Returns”void
endLayer()
Section titled “endLayer()”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).
Parameters
Section titled “Parameters”number
filters?
Section titled “filters?”readonly Filter[] | null
Returns
Section titled “Returns”void
end():
FrameStats
Ends the frame (flushes the batch); what it cost.
Returns
Section titled “Returns”onLost()
Section titled “onLost()”onLost(
listener):void
The context was lost (stop drawing) or restored (textures already uploaded again).
Parameters
Section titled “Parameters”listener
Section titled “listener”() => void
Returns
Section titled “Returns”void
onRestored()
Section titled “onRestored()”onRestored(
listener):void
Called when the context comes back, textures already uploaded again.
Parameters
Section titled “Parameters”listener
Section titled “listener”() => void
Returns
Section titled “Returns”void
destroy()
Section titled “destroy()”destroy():
void
Frees the context and every texture.
Returns
Section titled “Returns”void