melonjs-renderer-backends
できること
このガイドは、WebGPU、WebGL 2、Canvasのレンダラーの選択肢を説明します。それぞれが対応するもの、そして機能が段階的に低下するコードの書き方を扱います。ある端末では動くが他では動かないゲームを作る開発者向けです。
使う場面
- ✓melonJSの機能がある1台のコンピューターでは動くが、別のコンピューターでは動かないとき。
- ✓開発者が、テストのために特定のレンダラーを強制したいとき。
- ✓開発者が、Canvasのみに対応した端末でも動くコードを必要とするとき。
スキルのリンク
https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-renderer-backends/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“私のmelonJSのゲームはノートPCでは正しく見えますが、古いスマートフォンではシェーダーが表示されません。なぜですか?”
毎週5つの新しいスキル。1分で読めます。
仕組み
このガイドは、WebGPU、WebGL 2、Canvasの順のフォールバックを説明し、それぞれが対応する機能を一覧にし、機能に頼る前に対応状況を確認する方法を示します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)を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
よくある質問
フォールバックの順序はどうなっていますか?
既定の設定では、まずWebGPUを試し、次にWebGL 2、最後にCanvasを試し、最初に起動できたものを使います。
一部の端末でシェーダーが表示されないのはなぜですか?
Canvasのレンダラーではシェーダーとポストエフェクトはエラーなしで何もしないとスキルは述べています。
レンダラーを強制できますか?
はい。設定でWebGPU、WebGL 2、Canvasのどれかに固定できますが、古い端末では固定したものが失敗することがあります。
詳細
作者による元の説明
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
人気
- GitHubのスター
- 6.4k
- ランキング
- #14213
- ライセンス
- MIT
- 更新日
- 2026/11/2
コメント
- …
このリポジトリの他のスキル
melonjs-20-migration
6.4kエージェントが、バージョン20のmelonJSゲームのコードを書き、必要な非同期の起動など、古いバージョンの古いメソッドを避けられるよう支援します。
melonjs-3d-assets
6.4kエージェントが、glTF、GLB、OBJなどの3DモデルをmelonJSのブラウザゲームに読み込み、スケールとライティングのオプションを使えるよう支援します。
melonjs-3d
6.4kエージェントが、エンジン独自の軸のルールを使い、カメラ、メッシュ、ライト、奥行きを含めて、melonJSのブラウザゲームで3Dまたは2.5Dのシーンを作れるよう支援します。
melonjs-audio
6.4kエージェントが、音声の設定、背景の音楽、音量の制御、空間的な音響を含め、melonJSのゲームに効果音と音楽を追加できるよう支援します。
似ているスキル
diffs
394k編集内容の実際の共有可能な差分を、手書きの要約ではなく、ビューアーのリンクや画像ファイルとして作成するようエージェントを支援します。
coding-agent
394kCodex、Claude Code、OpenCodeに大きめのコーディング作業をバックグラウンドのワーカーとして渡し、その進捗を確認するようエージェントを支援します。
gh-issues
394kGitHubのイシューを探し、取り組むものを選び、修正を含むプルリクエストを開くようエージェントを支援します。レビューコメントへの対応も含みます。