Skip to content

RenderSurfaceSource

RenderSurfaceSource = { handle: number; kind: "gl-context"; } | { canvasSelector?: string; kind: "webgpu"; } | { kind: "default"; }

Defined in: app.ts:1048

How the host provides the render surface the C++ renderer binds to — the single seam every platform’s renderer init flows through:

  • gl-context: an emscripten-registered WebGL2 context handle (web/desktop/WeChat).
  • webgpu: the host acquired a GPUDevice (navigator.gpu) and passed it as the module factory’s preinitializedWebGPUDevice before instantiation; the engine owns the swapchain, resolving the canvas via canvasSelector (default ‘#canvas’, via document.querySelector — so the canvas must be in the DOM).
  • default: the module resolves its own surface (module.initRenderer()).

Native (wasm-on-JSC, no DOM): the host injects the device AND an already-built CAMetalLayer/ANativeWindow surface, so { kind: 'webgpu' } omits canvasSelector and must not reach the ‘#canvas’ fallback.