Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 13.1 — WebGPURenderer and Its Fallback
3D Web · Example 2 of 3

Drawing before init, and forcing WebGL 2

forceWebGL: true gives the same result in every browser, so this example has a fixed output. The error text is three.js's own.

WebGPURenderer from three/webgpu uses WebGPU when the browser has it and WebGL 2 when it does not, with the same code. It starts asynchronously, so you await renderer.init() before the first frame and read renderer.backend to see what you got.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 3 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write a function createRenderer(container) that returns a started WebGPURenderer and logs the backend name. What must it be?

02

Using the first example, make a version that stays on WebGL 2 when the URL contains ?gl=1.

Explain it without notes

01

Why must you await renderer.init() with WebGPURenderer, and what happens if you do not?

02

A visitor reports the scene looks different in Firefox on Linux. What do you check first?

Drawing before init, and forcing WebGL 2
Press Run to see the page.
idle

Console

Nothing logged yet.

Expected console output

too early: THREE.Renderer: .render() called before the backend is initialized. Use "await renderer.init();" before rendering.
backend: WebGL 2
first frame: draw calls 2 | triangles 13