मुख्य सामग्री पर जाएँ
Skillpedia
सामान्य कोडिंग6.4k · #14213

melonjs-renderer-backends

यह क्या करती है

यह WebGPU, WebGL 2 और Canvas renderer विकल्प समझाती है, हर एक क्या सपोर्ट करता है, और ऐसा कोड कैसे लिखें जो सुचारु रूप से घटता चले। यह उन गेम डेवलपर्स के लिए है जिनका गेम कुछ डिवाइस पर चलता है और कुछ पर नहीं।

कब इस्तेमाल करें

  • ✓जब melonJS का फ़ीचर एक कंप्यूटर पर काम करे पर दूसरे पर नहीं।
  • ✓जब डेवलपर परीक्षण के लिए कोई खास renderer तय करना चाहे।
  • ✓जब डेवलपर को ऐसा कोड चाहिए जो केवल Canvas सपोर्ट वाले डिवाइसों पर भी चले।

Skill का लिंक

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

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-renderer-backends/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“मेरा melonJS गेम मेरे लैपटॉप पर सही दिखता है, पर पुराने फ़ोन पर shaders गायब हैं। ऐसा क्यों?”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

यह स्किल WebGPU से WebGL 2 और फिर Canvas तक फ़ॉलबैक क्रम समझाती है, बताती है कि हर एक क्या सपोर्ट करता है, और दिखाती है कि किसी फ़ीचर पर भरोसा करने से पहले क्षमताएँ कैसे जाँचें।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे 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

अक्सर पूछे जाने वाले सवाल

फ़ॉलबैक का क्रम क्या है?

डिफ़ॉल्ट सेटिंग पहले WebGPU आज़माती है, फिर WebGL 2, फिर Canvas, और जो पहले शुरू हो जाए उसे चुनती है।

कुछ डिवाइस पर shaders क्यों नहीं दिखते?

स्किल कहती है कि Canvas renderer पर shaders और post effects बिना त्रुटि के कुछ नहीं करते।

क्या मैं renderer तय कर सकता हूँ?

हाँ। सेटिंग 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
अपडेट की गई
2/11/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

melonjs-20-migration

6.4k

आपके एजेंट को melonJS वर्शन 20 के लिए गेम कोड लिखने में मदद करती है और पुराने वर्शन के आउटडेटेड तरीकों से बचाती है, जैसे ज़रूरी async स्टार्टअप।

कोडिंगसामान्य कोडिंग

melonjs-3d-assets

6.4k

आपके एजेंट को glTF, GLB और OBJ जैसे 3D मॉडल melonJS ब्राउज़र गेम में लोड करने में मदद करती है, scale और lighting विकल्पों के साथ।

कोडिंगसामान्य कोडिंग

melonjs-3d

6.4k

आपके एजेंट को melonJS ब्राउज़र गेम में 3D या 2.5D दृश्य बनाने में मदद करती है, जिसमें कैमरा, मेश, लाइट और गहराई शामिल हैं, इंजन के अपने axis नियमों के साथ।

कोडिंगसामान्य कोडिंग

melonjs-audio

6.4k

आपके एजेंट को melonJS गेम में साउंड इफ़ेक्ट और संगीत जोड़ने में मदद करती है, जिसमें ऑडियो सेटअप, बैकग्राउंड ट्रैक, वॉल्यूम नियंत्रण और स्थानिक ध्वनि शामिल हैं।

कोडिंगसामान्य कोडिंग

मिलती-जुलती skills