Renderers and quality tiers
You don’t need to know WebGL to use the engine: it picks the best way to draw on each device by itself. This page says what it picks, how to check it, and how to force a choice while testing.
The renderer
Section titled “The renderer”At start the engine tries, in order:
- WebGL2;
- WebGL1, the baseline every target TV must run well;
- Canvas 2D, the fallback: no WebGL, a blocklisted GPU, or a software-only WebGL.
Both WebGL tries refuse a context the browser says is much slower than usual (failIfMajorPerformanceCaveat), which
is typically software rendering: Canvas 2D usually beats it. WebGL1 and WebGL2 share one code path and draw the same
pixels; WebGL2 (or WebGL1 with the right extensions) only batches faster.
engine.renderer.kind says which one it got: 'webgl2', 'webgl1' or 'canvas2d'. Log it; don’t branch your
game on it.
What differs on Canvas 2D: tints are cached tinted copies, additive blending is 'lighter' (which may be slow on
some TVs), and the tier is never high.
The quality tier
Section titled “The quality tier”The renderer says what is possible; the tier says what is fast. engine.tier is an object:
high |
medium |
low |
|
|---|---|---|---|
| Typical devices | Desktop, recent tablets, recent TVs | Most TVs | Old TVs, Canvas 2D |
tier.resolution: most backing-store pixels per stage unit |
1.5 | 1 | 0.75 |
tier.particles: what tier.scale(n) multiplies by |
× 1 | × 0.5 | × 0.2 |
tier.effects: shape and text shadows and glows |
yes | no (flat look) | no (flat look) |
tier.maxBlur: largest blur of a filter, px |
32 | 16 | 0 |
What a game reads: engine.tier.name, engine.tier.scale(n) for counts (at least 1 when n ≥ 1), and
engine.tier.effects to decide whether additive glows are worth it. The engine applies the rest: the resolution, and
dropping shadow from shapes and texts below high (they bake without it, so a tier change bakes them again).
const sparks = stage.add(engine.particles(spark, { max: engine.tier.scale(200), blend: engine.tier.effects ? 'add' : 'normal' }))const starsAtOnce = engine.tier.scale(30)How the tier is chosen
Section titled “How the tier is chosen”The engine starts at the first of these it has:
- A forced tier:
?tier=on the game’s address, or thetieroption (below). It is never stepped down. - The TV’s hint: on a TV, Fabi Play’s screen tells the game what it knows about the device (
play.device, see The device hint): a starting tier and the display’s refresh rate. The engine starts at that tier, no higher than the tier it cached for this game last time (which keeps the drops of earlier matches), and skips its probe. On Canvas 2D ahighhint counts asmedium. A hint with only the rate still spares the probe its first step, measuring the display. - The cached tier: what this game measured on this device before (below).
- The probe: no hint and nothing cached, so the engine measures the device.
The hint makes the first start of every game on a TV immediate: each game lives on its own site, so what one game measured is not seen by the next, but the screen’s hint is the same for all of them.
With the script tag, FabiPlay may hear from the screen after createEngine was called. A late hint still
counts: it cuts a running probe short and sets the tier, never higher than the cached tier, the probe’s pick or a
drop during play. A forced tier ignores it.
The probe. With no hint and no cached tier, createEngine measures the device before it resolves, in under a
second:
- It watches 12 animation frames with nothing drawn, to learn the display’s own rate. Many TVs run at 50 Hz and some browsers cap animation frames at 30: “slow” means missing the display’s frames, not “under 60”.
- It draws a representative scene (300 rotating sprites, ellipses and strokes, nearly invisible) for half a second, after a quarter of a second of warm-up, at the high tier’s resolution.
- WebGL: high when the 90th percentile frame interval fits the display’s frame (+25%) and drawing takes under half a frame; medium when the median fits; otherwise low. Canvas 2D: medium only when the 90th percentile fits and drawing (with rasterising) takes under a quarter of a frame; otherwise low.
The result is cached in the game’s localStorage for 30 days, per renderer, GPU, screen size and engine version, so
the next start is immediate.
During play the engine watches frame times. When most frames of a 3-second window miss the display’s rate, it
drops one tier (lower resolution, fewer particles from tier.scale, no effects) and caches it, so the next match
starts there. It never goes back up in the middle of a match. Read engine.tier when you need it rather than keeping
a copy: it can change.
The thresholds are first guesses, to be tuned on real TVs.
Forcing a renderer or a tier
Section titled “Forcing a renderer or a tier”For testing, add to the game page’s address:
| Parameter | Values |
|---|---|
?renderer= |
webgl2, webgl1, canvas2d (also canvas, the same; webgl: 2, else 1; auto) |
?tier= |
high, medium, low |
They combine: ?renderer=canvas2d&tier=low is the weakest TV’s case, on your laptop.
In the simulator, the «Motore» (Engine) panel sets them for you: «Renderer» and «Tier» add ?renderer= and
?tier= to the game frame’s address, and «Suggerimento TV» (TV hint) sends the tier hint a TV would, to see where the
engine starts without forcing it. The status line under the game shows the renderer, tier and frame rate the engine
reports. See The «Motore» panel. You can also put them on the game’s
address yourself: https://simulator.fabiplay.app/?game=http://localhost:5180/index.html?renderer=canvas2d.
The same from code: createEngine({ play, renderer: 'canvas2d', tier: 'low' }). A forced tier is never stepped down
and never cached. A forced renderer that fails still falls back to the next one (WebGL1, then Canvas 2D).
Context loss
Section titled “Context loss”TVs lose GPU contexts: the app goes to the background, a video decoder takes the memory, the driver resets. The engine handles it:
- WebGL: drawing stops while the context is lost. When it comes back, the engine uploads every texture again from the pixels it keeps: nothing to reload or bake on your side.
- If the context does not come back within 3 seconds, the engine moves to Canvas 2D on a fresh canvas, put where
the old one was, and carries on.
engine.canvasandengine.rendererare then the new ones. - A Canvas 2D context can be lost too (Chrome, under memory pressure). It has no fallback: drawing waits for the browser to restore it.
While the context is lost the game’s clock keeps running (onFrame is called); only drawing stops.
To try it, run this in the game frame’s console (with webgl in place of webgl2 on a WebGL1 renderer); the
standard WEBGL_lose_context extension loses the context on purpose:
const lose = document.querySelector('canvas').getContext('webgl2').getExtension('WEBGL_lose_context')lose.loseContext() // drawing stopslose.restoreContext() // it comes back; skip this to see the switch to Canvas 2D after 3 secondsengine.stats
Section titled “engine.stats”What the last second cost, refreshed every second, for a debug overlay:
| Field | What it is |
|---|---|
fps |
Frames drawn in the last second |
cpuMs |
CPU time of a frame (your onFrame and onRender, and drawing), ms, averaged |
drawCalls |
Draw calls (WebGL) in the last frame |
quads |
Quads (sprites and pieces) drawn in the last frame |
filtersSkipped |
Filters skipped in the last frame (over the tier’s limits, or a shader on Canvas 2D) |
const debug = new URLSearchParams(location.search).has('debug')const info = debug ? stage.add(engine.text('', { x: 20, y: 700, size: 20, align: 'left', z: 100 })) : nullengine.onRender(() => { if (info) info.text = `${engine.renderer.kind} ${engine.tier.name} ${engine.stats.fps} fps ${engine.stats.cpuMs} ms`})(Changing a text bakes it again: fine for a debug line. For a counter that changes every frame, use a bitmap font.)
Your laptop is much faster than a TV. The numbers that matter come from the device itself.
What the engine reports
Section titled “What the engine reports”Once a second the engine also tells the SDK how it draws: play.reportStats({ fps, renderer, tier }), with
engine.stats.fps, engine.renderer.kind and engine.tier.name. The SDK passes them on only to a debug host that
asked for them, the simulator, which shows them in its status line («· webgl2 · tier medium · 60 fps»). On a TV
nothing is sent. You don’t call it yourself: see The device hint and stats
for other engines.