Renderer · function

createRenderer

Build a renderer on the best backend this browser will actually give us.

Explained in Hello world.

function createRenderer(canvas: HTMLCanvasElement, quality?: QualityForBackend, options?: CreateRendererOptions): Promise<CreatedRenderer>
import { createRenderer } from '@driftengine/core';

Parameters

ParameterTypeDescription
canvasHTMLCanvasElement
quality?QualityForBackend
options?CreateRendererOptions

In depth

Asynchronous because it has to be. navigator.gpu.requestAdapter() returns a promise and there is no synchronous way to learn whether a usable device exists. That is the one change this reaches into a consumer's boot sequence, and it is exactly why new Renderer(canvas, quality) keeps working untouched: three applications construct one today and none of them should be made to move on this plan's schedule.

Both backends are behind it now, and which one a caller gets is this function's whole job: WebGPU where the browser offers a usable device, WebGL2 everywhere else. The returned backend and reason say which and why, and they are meant to be read — reason was returned and ignored by every caller for long enough that a silent fallback could be mistaken for a comparison.