API

Interface EngineContext

Handle to the WebGPU engine — pure state, no attached methods.

The engine owns the GPUDevice and all device-scoped GPU resources (textures, buffers, pipelines, bind groups). It also is itself a SurfaceContext bound to the canvas passed into createEngine — the primary surface. Additional canvases can be attached via createSurface(engine, canvas, ...); GPU resources are shared across all surfaces because they're device-scoped, while each surface owns its own swapchain context.

interface EngineContext {
    canvas: RenderCanvas;
    drawCallCount: number;
    engine: EngineContext;
    format: GPUTextureFormat;
    gpuFrameTimeMs: number;
    maxDevicePixelRatio: number;
    msaaSamples: number;
    scRT: RenderTarget;
    surfaces: readonly [SurfaceContext, SurfaceContext];
    useFloatingOrigin: boolean;
    useHighPrecisionMatrix: boolean;
}

Hierarchy (View Summary)

Index
canvas: RenderCanvas

Canvas this surface presents to.

drawCallCount: number

Number of GPU draw calls in the latest renderFrame call, summed across its selected surfaces.

Owning engine. For the engine's primary surface this points back to the engine itself (engine.engine === engine).

format: GPUTextureFormat

Swapchain texture format for this surface. Use as the format for offscreen RTs that will be composited onto this surface. When sRGB is enabled (see SurfaceOptions.srgb) this is the *-srgb view format that pipelines and the swapchain RenderTarget render through, not the format passed to GPUCanvasContext.configure() (that is _configureFormat).

gpuFrameTimeMs: number

Instrumented GPU interval for the last measured frame, in milliseconds — from the beginning of the opening marker dispatch through the end of the closing marker dispatch, including every command recorded for the frame and the two marker dispatches themselves. It is 0 until the first measured frame and while timing is disabled. Readback is asynchronous and does not stall rendering.

maxDevicePixelRatio: number

Clamps the effective device pixel ratio used for this surface's swapchain backing store. The backing store is sized at min(devicePixelRatio, maxDevicePixelRatio) * cssPixels. maxDevicePixelRatio = 1 renders at native CSS-pixel resolution (no DPR upscaling); the default Infinity is unclamped (full devicePixelRatio). Mutable at runtime — set before the next resizeSurface to take effect (mirrors Babylon setHardwareScalingRatio).

msaaSamples: number

MSAA sample count for the main render pass into this surface (1 or 4).

Surface-owned color-only render target that wraps this canvas's swapchain texture. Its _colorTexture/_colorView are re-acquired from context.getCurrentTexture() once per frame (see _refreshScRT), so it is always single-sample and carries no depth. Render/post-process/copy tasks target it (or resolve into it) to present to the canvas. It is _eager — buildRenderTarget and disposeRenderTarget both no-op on it and the surface owns its textures, so its shared _descriptor must never be mutated.

surfaces: readonly [SurfaceContext, SurfaceContext]

Rendering surfaces attached to this engine, in registration order. Index 0 is the engine itself (the primary surface) — the tuple type guarantees at least one entry so engine.surfaces[0] is always defined. Use createSurface(engine, canvas, ...) to append more.

useFloatingOrigin: boolean

When true, every scene on this engine uses the floating-origin (eye-relative upload) trick to render large-world coordinates without F32 jitter. Requires useHighPrecisionMatrix: true. Defaults to false.

LWR is engine-wide: all scenes created against this engine inherit the mode. The LWR runtime module (large-world/floating-origin.js) is dynamically imported during createEngine only when this flag is true, so non-LWR engines never pull the module into their bundle.

useHighPrecisionMatrix: boolean

When true, world matrices are computed using Float64 intermediate precision and downcast to Float32 at GPU upload time. Defaults to false.