Langsung ke konten
Skillpedia
Pemrograman umum6.4k Β· #14213

melonjs-renderer-backends

Fungsinya

Dokumen ini menjelaskan pilihan renderer WebGPU, WebGL 2, dan Canvas, apa saja yang didukung masing-masing, serta cara menulis kode yang tetap berjalan dengan baik. Skill ini ditujukan untuk pengembang game yang berjalan di sebagian perangkat tetapi tidak di perangkat lain.

Kapan dipakai

  • βœ“Saat fitur melonJS berfungsi di satu komputer tetapi tidak di komputer lain.
  • βœ“Ketika pengembang ingin memaksa renderer tertentu untuk pengujian.
  • βœ“Saat pengembang membutuhkan kode yang tetap bisa berjalan di perangkat yang hanya mendukung Canvas.

Link skill

https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-renderer-backends/SKILL.md

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-renderer-backends/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit β†’

Contoh permintaan ke AI

β€œGame melonJS saya tampil benar di laptop saya, tetapi shader-nya hilang di ponsel lama. Mengapa?”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Skill ini menjelaskan urutan cadangan dari WebGPU ke WebGL 2 lalu ke Canvas, mencantumkan fitur yang didukung tiap renderer, dan menunjukkan cara memeriksa kemampuan sebelum mengandalkan suatu fitur.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.

Renderer backends and graceful degradation

video.AUTO picks 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

Pertanyaan umum

Apa urutan cadangannya?

Pengaturan default mencoba WebGPU terlebih dahulu, lalu WebGL 2, lalu Canvas, dan memakai yang pertama berhasil dimulai.

Mengapa shader tidak tampil di sebagian perangkat?

Skill ini menyebutkan bahwa shader dan efek pascaproses tidak berfungsi pada renderer Canvas, dan tidak menampilkan error.

Bisakah saya memaksa renderer tertentu?

Bisa. Pengaturan dapat menetapkan WebGPU, WebGL 2, atau Canvas, tetapi pemaksaan bisa gagal pada perangkat lama.

Detail

Deskripsi asli dari pembuat

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

Popularitas

Bintang GitHub
6.4k
Peringkat
#14213
Lisensi
MIT
Diperbarui
2/11/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa