Use this skill when a feature works on one machine and not another, when choosing or pinning a renderer, or when writing code that must degrade gracefully. Covers the WebGPU to WebGL 2 to Canvas fallback ladder, what each backend supports, capability detection, and the subsystems that warn once and then stop working on Canvas. Triggers on: video.AUTO, video.WEBGPU, video.WEBGL, video.CANVAS, renderer.type, supportsDepthBuffer, shaderLanguage, WebGPU, WebGL2, Canvas fallback, failIfMajorPerformanceCaveat, software rendering, supportsHDR, hdrOutput, context loss, backend, works on my machine.
Capabilities
The ladder
WebGL 1 is not in the ladder — 20.x made WebGL 2 the baseline, and…
What each backend can do
The Canvas column is the problem: none of it throws
Detecting what you have
For a scene that genuinely requires a GPU backend, fail loudly rather…
Writing code that degrades well
Decorative effects — let them no-op
Getting started
Full instructionsInstall the skill, then ask your AI tool for the task in plain words. The full SKILL.md below shows what it covers.
Instructions: SKILL.mdv1.0.2
Renderer backends and graceful degradation
video.AUTOpicks a backend at runtime. The same code runs on a different
renderer depending on the machine, and several subsystems degrade to nothing
rather than erroring. This is the root cause of most "works on my machine"
reports.
The ladder
video.AUTO (the default) tries WebGPU → WebGL 2 → Canvas and uses the first
that initialises.
const app = new Application(800, 600, {
parent: "screen",
renderer: video.AUTO, // or video.WEBGPU / video.WEBGL / video.CANVAS
});
await app.init();
WebGL 1 is not in the ladder — 20.x made WebGL 2 the baseline, and pinning
video.WEBGL rejects on a WebGL-1-only device rather than degrading.
A GPU backend also counts as unavailable when the browser says it would run
far slower than native — a software rasterizer, a blocklisted driver. The
failIfMajorPerformanceCaveat setting (true by default, stricter than
WebGL's own default) refuses such a context, and the WebGPU backend refuses a
software adapter the same way: under AUTO that machine gets Canvas, and
under video.WEBGL or video.WEBGPU init() rejects. Set it false to accept
the slow context instead.
What each backend can do
| WebGPU | WebGL 2 | Canvas | |
|---|---|---|---|
| sprites, tilemaps, text | ✅ | ✅ | ✅ |
| blend modes | ✅ | ✅ | ✅ except "none" |
| shaders and post effects | ✅ | ✅ | ❌ inert |
Light2d glow (drawLight) |
✅ | ✅ | ✅ cached radial gradient |
normal-map lighting, Light3d |
✅ | ✅ | ❌ inert |
Mesh |
✅ | ✅ | ⚠️ last resort: 2D camera only, CPU-projected, no depth, unlit |
Camera3d / depth sorting |
✅ | ✅ | ❌ warns, renders wrong |
InstancedMesh |
✅ | ✅ | ⚠️ one draw per instance |
| GPU tilemap rendering | ✅ | ✅ | ❌ per-tile CPU path |
textureFilter: "linear-mipmap" |
✅ | ✅ | ❌ no mipmaps |
hdr (headroom through the effects) |
✅ | ✅ where the driver can render and filter half-float | ❌ |
hdrOutput (HDR presentation) |
✅ with hdr on too |
❌ | ❌ |
state.transition("pixelate", …) |
✅ | ✅ | ❌ the state changes with no transition |
The Canvas column is the problem: none of it throws. Most of those paths warn
once and then degrade or no-op, and some (the pixelate transition, hdr) do
so without a word, so the game runs and looks wrong.
Two Canvas rows are worth spelling out because they are easy to misread as total
failures. A Light2d still draws — the Canvas renderer bakes a radial gradient
per light and blits it — what disappears is per-pixel normal-map shading, which
warns once (Light2d normal-map lighting requires a GPU backend), the first time
a normal-mapped sprite is drawn under a light, and then renders sprites unlit. A Mesh under a 2D camera still draws too, textured,
sorted with the painter's algorithm and no depth buffer, so convex models look
right and a self-overlapping one can draw a few triangles over the wrong ones.
That is a last resort so a game does not go blank, not a target: anything
built on meshes should run on WebGPU or WebGL 2. "none" (replace, alpha included) is the one blend
mode Canvas cannot express — there is no globalCompositeOperation that
disables blending for the drawn area alone — so it resolves to "normal", and
setBlendMode reports that back.
Detecting what you have
app.renderer.type; // "WebGPU" | "WebGL2" | "CANVAS"
app.renderer.supportsDepthBuffer; // the practical "is this a GPU backend" test
app.renderer.shaderLanguage; // "wgsl" | "glsl" | null (null on Canvas)
There are narrower flags for the features that do not travel together:
supportsShaderTileLayers, supportsRetainedMesh and supportsInstancing —
all three false on Canvas, true on both GPU backends. supportsHDR and
supportsHDROutput say what the hdr and hdrOutput settings were actually
granted, which can be less than was asked. Prefer a capability
flag over comparing type against a string; type is an identity check for
code coupled to one backend's machinery.
For a scene that genuinely requires a GPU backend, fail loudly rather than
rendering something broken:
await app.init();
if (!app.renderer.supportsDepthBuffer) {
throw new Error("this game needs WebGL 2 or WebGPU");
}
Writing code that degrades well
Decorative effects — let them no-op. A missing vignette is fine.
Load-bearing effects — guard the carrier. If a shader draws your content
rather than decorating it, the carrier renderable shows through raw when the
effect is disabled: a 1×1 white texture stretched to fill a quad renders as a
white box exactly where the effect should have been.
if (effect.enabled) {
// draw the carrier the shader consumes
}
Dual-language shaders — a ShaderEffect compiles the body matching
renderer.shaderLanguage. With no matching body — a GLSL-only effect on WebGPU,
any effect on Canvas — the constructor warns once, leaves enabled === false,
and every method becomes a no-op. Pass { glsl, wgsl } rather than a bare
string, or gate on renderer.shaderLanguage.
Pinning a backend
Pin only with a reason. video.WEBGL costs you the WebGPU path and the Canvas
fallback, so a WebGL-1-only device gets nothing at all.
Legitimate reasons: reproducing a backend-specific bug, a benchmark, or a known
driver issue in the field.
For one-off testing you do not need to touch the settings at all: the URI
fragments #webgpu, #webgl (or #webgl2) and #canvas override the
renderer setting for that run, and behave exactly like passing the matching
constant — #webgl on a WebGL-1-only device rejects rather than falling back.
Context loss
A GPU context can be lost at any time — tab backgrounding, driver reset, memory
pressure. melonJS handles restoration on both GPU backends: WebGL recompiles
every live GLShader and replays its uniform snapshot, WebGPU renegotiates a
device and rebuilds its batchers, and both then emit
event.ONCONTEXT_RESTORED (the paired loss event is event.ONCONTEXT_LOST).
What you must handle is your own GPU-side state. If you cached a raw texture or
program handle, re-acquire it on restore rather than holding the stale one:
import { event } from "melonjs";
event.on(event.ONCONTEXT_RESTORED, (renderer) => {
// re-acquire anything you were holding by raw handle
});
Test on the backend your users get, not the one your harness picks
video.AUTO prefers WebGPU where it exists. Headless Chromium usually has no
GPU adapter and falls back to WebGL, so an automated suite can pass every run
while the WebGPU path is broken — the two differ in real, throwing ways (see
below). Pin the backend explicitly when it matters: renderer: video.WEBGPU,
or the #webgpu / #webgl URI fragment on a page you can open by hand.
Practical differences
- Frame capture orientation differs: row 0 of a
toFrameTexture()capture is
the bottom of the frame under WebGL and the top under WebGPU, so a GLSL body
that flips with1.0 - uv.ymust not do so in its WGSL twin. The WebGPU
capture also preserves alpha, where the WebGL one captures into an opaque RGB
texture. - The advanced blend modes cost far more than they look.
overlay,
difference,hard-light,soft-light,color-dodge,color-burn,
darkenandlightencannot be expressed as fixed-function blending, so on
both GPU backends each such draw is bracketed individually: capture the
destination, redraw offscreen, composite throughBlendEffect. Fine for
accents, ruinous for hundreds of objects.normal,additive,multiply,
screenandexclusionare ordinary fixed-function state and cost nothing
extra. - WebGPU rejects a zero-sized image source; WebGL shrugs at it. Uploading a
0-width or 0-height canvas throws
OperationError: GPUQueue.copyExternalImageToTexture: External image state is not valid, from a stack that readsdrawImage → addQuad → getBinding. WebGL
uploads the same source without complaint, so this is a class of bug that
cannot appear on one backend and stops the game dead on the other. Check
any canvas the game sizes from content that can be empty before it is drawn.
An empty or whitespace-onlyTextdid this before 20.11; its glyph canvas
is now at least 32 pixels on each side. - 3D meshes do not honour the advanced blend modes. The mesh pass draws
with its own depth/blend state; asking for one of them logs a one-time
blend mode "…" is not supported for 3D mesheswarning and falls back to
"normal". Gradient fills warn the same way.
Symptom → cause
| symptom | cause |
|---|---|
| effect works locally, not for a user | they got the Canvas fallback, or a different GPU backend |
| sprites render unlit though lights are in the scene | Canvas fallback — normal-map shading is inert (check the console) |
| a few triangles of a mesh drawn over the wrong ones where it overlaps itself | Canvas fallback — painter's algorithm sorts whole triangles, no depth buffer |
| a mesh shows its far side through its near one (looks inside-out) on Canvas | melonJS older than 20.14 sorted the triangles the wrong way round; update |
| a textured OBJ + MTL mesh is a white silhouette on Canvas | melonJS older than 20.14 filled it with its material color and skipped the texture; update |
| a low-poly (palette) model looks faceted on Canvas, with faint lines between its triangles | melonJS older than 20.14 filled each of its triangles with one texel; update |
| shader works on one machine only | GLSL-only effect, AUTO chose WebGPU elsewhere — the console carries the warning |
| a solid box where an effect should be | carrier drawn while the effect is disabled |
| nothing renders at all on an old device | video.WEBGL pinned; WebGL 1 is rejected, not downgraded |
| ported shader is vertically flipped | the WebGL capture is bottom-up, the WebGPU one top-down |
copyExternalImageToTexture: External image state is not valid |
a zero-sized upload source: a canvas sized from empty content (an empty Text before 20.11) |
Canvas renderer on a machine that has a GPU, or init() rejects with a pinned backend |
software rendering or a blocklisted driver, refused by failIfMajorPerformanceCaveat (default true) |
| runs on the test machine, dies on the dev's | the harness fell back to WebGL and never exercised WebGPU |
| an advanced blend mode is ignored on a mesh | meshes fall back to "normal" for those; look for the one-time warning |
| textures vanish after the tab is restored | cached raw GPU handles not re-acquired on context restore |
Related skills
melonjs-getting-started— renderer selection in the Application settingsmelonjs-effects-and-shaders— dual-language shaders and the Canvas no-opmelonjs-3d— the tier that requires a GPU backend outright
Explore more skills
Browse all- Melonjs PlatformsUse this skill when a melonJS game runs somewhere other than a plain browser tab: a game portal (YouTube Playables,…
- melonjsUse this skill FIRST for any melonJS task, and when asked to build a game for the browser with no engine named; it says…
- Melonjs TilemapsUse this skill for tile maps in melonJS: Tiled maps, LDtk levels, Sprite Fusion maps, and tile layers built in code.…
- Melonjs Particles and TrailsUse this skill for particle effects and motion trails in melonJS — ParticleEmitter configuration, burst versus stream…
- Melonjs Sprites and AnimationUse this skill when creating sprites, playing frame animations, or working with texture atlases in melonJS. Covers…
- Melonjs LightingUse this skill for 2D dynamic lighting in melonJS — Light2d, ambient light on a Stage, multiple lights, and per-pixel…
Security
Reviews (0)
More from melonJS
View source →Frequently asked questions about melonjs-renderer-backends
What does the melonjs-renderer-backends skill do?
Use this skill when a feature works on one machine and not another, when choosing or pinning a renderer, or when writing code that must degrade gracefully. Covers the WebGPU to WebGL 2 to Canvas fallback ladder, what each backend supports, capability detection, and the subsystems that warn once and then stop working on Canvas. Triggers on: video.AUTO, video.WEBGPU, video.WEBGL, video.CANVAS, renderer.type, supportsDepthBuffer, shaderLanguage, WebGPU, WebGL2, Canvas fallback, failIfMajorPerformanceCaveat, software rendering, supportsHDR, hdrOutput, context loss, backend, works on my machine. It's a reusable SKILL.md instruction set that loads into your AI coding assistant on demand, no prompt engineering, no copy-pasting every session.
How do I install the melonjs-renderer-backends skill?
Run `npx @skills-hub-ai/cli install melonjs-renderer-backends` from your terminal. The CLI writes the SKILL.md to the correct location for your AI tool (e.g. ~/.claude/skills/melonjs-renderer-backends/ for Claude Code or ~/.cursor/skills/ for Cursor with --target cursor) and adds it to your project's .skills.json lockfile.
Which AI tools does melonjs-renderer-backends work with?
melonjs-renderer-backends runs in Claude Code. It follows the open Agent Skills standard (SKILL.md), so the same skill works in every supported tool without modification.
Is the melonjs-renderer-backends skill free?
Yes. Every skill on skills-hub.ai is free and open-source. There are no premium tiers, paywalls, or usage limits. You only pay for whatever AI assistant you're already using.
How do I use melonjs-renderer-backends after installing it?
In Claude Code, type `/melonjs-renderer-backends` (or whatever slash command the skill registers) and the AI follows the skill's instructions immediately. You can also reference it by name in natural language, your AI loads the skill into context when relevant.
Can I share the melonjs-renderer-backends skill with my team?
Yes. Commit your project's .skills.json lockfile and teammates run `npx @skills-hub-ai/cli install` (no args) to install every skill at the exact version you pinned. Organization-scoped installs work via skills-hub.ai organizations.
Badge for your README
Show that this skill is on Skills Hub. The badge links back to this page and shows the live install count.
[](https://skills-hub.ai/skills/melonjs-renderer-backends)<a href="https://skills-hub.ai/skills/melonjs-renderer-backends"><img src="https://skills-hub.ai/api/badges/skill/melonjs-renderer-backends" alt="Install on Skills Hub"></a>More options in the badge docs.