melonjs-renderer-backends
Qué hace
Explica las opciones de renderizador WebGPU, WebGL 2 y Canvas, qué admite cada una y cómo escribir código que se degrade con elegancia. Va dirigida a desarrolladores cuyo juego funciona en unos dispositivos y en otros no.
Cuándo usarla
- ✓Cuando una función de melonJS funciona en un ordenador y en otro no.
- ✓Cuando un desarrollador quiere forzar un renderizador concreto para hacer pruebas.
- ✓Cuando un desarrollador necesita código que siga funcionando en dispositivos con solo soporte Canvas.
Link de la skill
https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-renderer-backends/SKILL.mdCópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.
Cómo usar
La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.
Mensaje listo para pegar
Para Claude Code, Codex o Cursor: ejecútalo en la carpeta del proyecto y la skill queda instalada.
Descarga el SKILL.md y ponlo en la carpeta de skills de tu agente.
Ejemplo de qué pedirle a la IA
“Mi juego de melonJS se ve bien en mi portátil, pero faltan los shaders en un teléfono antiguo. ¿Por qué?”
5 skills nuevas por semana. 1 minuto de lectura.
Cómo funciona
La skill explica el orden de respaldo de WebGPU a WebGL 2 y de ahí a Canvas, enumera qué funciones admite cada uno y muestra cómo comprobar las capacidades antes de depender de una función.
Contenido técnico (SKILL.md original)
Texto original del autor, en inglés, directo de 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
Preguntas frecuentes
¿Cuál es el orden de respaldo?
El ajuste predeterminado prueba primero WebGPU, luego WebGL 2 y después Canvas, usando el primero que se inicie.
¿Por qué no se ven los shaders en algunos dispositivos?
La skill dice que los shaders y los efectos posteriores no hacen nada en el renderizador Canvas, y no muestran error.
¿Puedo forzar un renderizador?
Sí. El ajuste puede fijar WebGPU, WebGL 2 o Canvas, aunque fijar uno puede fallar en dispositivos antiguos.
Detalles
Descripción original del autor
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
Popularidad
- Estrellas en GitHub
- 6,4 mil
- Posición en el ranking
- #14213
- Licencia
- MIT
- Actualizada
- 2/11/2026
Comentarios
- …
Más skills de este repositorio
melonjs-20-migration
6,4 milAyuda a tu agente a escribir código de juegos melonJS para la versión 20 y evitar métodos desactualizados de versiones anteriores, como el arranque asíncrono obligatorio.
melonjs-3d-assets
6,4 milAyuda a tu agente a cargar modelos 3D como archivos glTF, GLB y OBJ en un juego para navegador melonJS, con opciones de escala e iluminación.
melonjs-3d
6,4 milAyuda a tu agente a crear escenas 3D o 2.5D en un juego para navegador melonJS, con cámaras, mallas, luces y profundidad, usando las reglas de ejes del motor.
melonjs-audio
6,4 milAyuda a tu agente a añadir efectos de sonido y música a un juego melonJS, incluida la configuración de audio, las pistas de fondo, el control de volumen y el sonido espacial.
Skills parecidas
diffs
394 milPermite que tu agente genere un diff real y compartible de los cambios, como enlace de visualización o archivo de imagen, en lugar de un resumen escrito a mano.
coding-agent
394 milAyuda a tu agente a pasar un trabajo de programación grande a Codex, Claude Code u OpenCode como trabajador en segundo plano, y después revisar su progreso.
gh-issues
394 milAyuda a tu agente a encontrar incidencias de GitHub, elegir cuáles trabajar y abrir pull requests con correcciones, incluido el seguimiento de los comentarios de revisión.