melonjs-renderer-backends
Was er macht
Es erklärt die Renderer-Optionen WebGPU, WebGL 2 und Canvas, was jede unterstützt und wie man Code schreibt, der sauber zurückfällt. Es richtet sich an Spieleentwickler, deren Spiel auf manchen Geräten läuft und auf anderen nicht.
Wann du ihn nutzt
- ✓Wenn eine melonJS-Funktion auf einem Computer funktioniert, auf einem anderen aber nicht.
- ✓Wenn ein Entwickler für Tests einen bestimmten Renderer erzwingen will.
- ✓Wenn ein Entwickler Code braucht, der auch auf Geräten mit nur Canvas-Unterstützung läuft.
Link zum Skill
https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-renderer-backends/SKILL.mdKopiere ihn und füge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.
So nutzt du ihn
Am einfachsten: Kopiere die Nachricht und füge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.
Fertige Nachricht zum Einfügen
Für Claude Code, Codex oder Cursor: Führe den Befehl in deinem Projektordner aus, dann wird der Skill installiert.
Lade die SKILL.md herunter und lege sie in den Skills-Ordner deines Agenten.
Beispielanfrage an deine KI
“Mein melonJS-Spiel sieht auf meinem Laptop richtig aus, aber auf einem älteren Handy fehlen die Shader. Warum?”
5 neue Skills pro Woche. 1 Minute Lesezeit.
So funktioniert es
Die Fähigkeit erklärt die Rückfall-Reihenfolge von WebGPU über WebGL 2 zu Canvas, listet auf, welche Funktionen jede unterstützt, und zeigt, wie man Fähigkeiten prüft, bevor man sich auf eine Funktion verlässt.
Technischer Inhalt (originale SKILL.md)
Originaltext des Autors, auf Englisch, direkt von GitHub.
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.
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 |
✅ | ✅ | ⚠️ CPU-projected, no depth |
Camera3d / depth sorting |
✅ | ✅ | ❌ warns, renders wrong |
InstancedMesh |
✅ | ✅ | ⚠️ one draw per instance |
| GPU tilemap rendering | ✅ | ✅ | ❌ per-tile CPU path |
The Canvas column is the problem: none of it throws. Each of those paths warns once and then degrades or no-ops, 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 still draws too, sorted with the painter's
algorithm and no depth buffer, so convex models look right and anything
self-overlapping does not. "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. 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
Häufige Fragen
Wie lautet die Rückfall-Reihenfolge?
Die Standardeinstellung versucht zuerst WebGPU, dann WebGL 2 und dann Canvas und nimmt den ersten, der startet.
Warum erscheinen Shader auf manchen Geräten nicht?
Die Fähigkeit sagt, Shader und Nachbearbeitungseffekte tun im Canvas-Renderer nichts, und zwar ohne Fehlermeldung.
Kann ich einen Renderer erzwingen?
Ja. Die Einstellung kann WebGPU, WebGL 2 oder Canvas festlegen, wobei das Festlegen auf älteren Geräten scheitern kann.
Details
Originalbeschreibung des Autors
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, context loss, backend, works on my machine.
repo: melonjs/melonJS
Beliebtheit
- GitHub-Sterne
- 6.4k
- Platz im Ranking
- #14213
- Lizenz
- MIT
- Aktualisiert
- 2.11.2026
Kommentare
- …
Weitere Skills aus diesem Repository
melonjs-20-migration
6.4kHilft deinem Agenten, melonJS-Spielcode für Version 20 zu schreiben und veraltete Methoden aus älteren Versionen zu vermeiden, etwa den nun nötigen asynchronen Start.
melonjs-3d-assets
6.4kHilft deinem Agenten, 3D-Modelle wie glTF-, GLB- und OBJ-Dateien in ein melonJS-Browserspiel zu laden, mit Optionen für Maßstab und Beleuchtung.
melonjs-3d
6.4kHilft deinem Agenten, 3D- oder 2,5D-Szenen in einem melonJS-Browserspiel zu bauen, mit Kameras, Meshes, Lichtern und Tiefe, unter Beachtung der eigenen Achsenregeln der Engine.
melonjs-audio
6.4kHilft deinem Agenten, Soundeffekte und Musik in ein melonJS-Spiel einzubauen, einschließlich Audio-Einrichtung, Hintergrundmusik, Lautstärkeregelung und räumlichem Klang.
Ähnliche Skills
diffs
394kLässt deinen Agenten einen echten, teilbaren Diff seiner Änderungen als Viewer-Link oder Bilddatei erstellen, statt einer handgeschriebenen Zusammenfassung.
coding-agent
394kHilft deinem Agenten, eine größere Programmieraufgabe als Hintergrund-Worker an Codex, Claude Code oder OpenCode zu übergeben und danach den Fortschritt zu prüfen.
gh-issues
394kHilft deinem Agenten, GitHub-Issues zu finden, die zu bearbeitenden auszuwählen und Pull Requests mit Korrekturen zu öffnen, einschließlich der Nacharbeit an Review-Kommentaren.