Taos API Reference
    Preparing search index...

    Class RenderContext

    Owns the WebGPU device, queue and canvas configuration for the renderer.

    Acts as the single shared handle to GPU resources, and exposes helpers for buffer creation, swap-chain access and scoped validation error capture.

    Index

    Properties

    DEFAULT_DEPTH_FORMAT: GPUTextureFormat = 'depth32float'
    device: GPUDevice
    queue: GPUQueue
    format: GPUTextureFormat
    depthFormat: GPUTextureFormat | null
    hdr: boolean
    enableErrorHandling: boolean
    shaderBlockManager: ShaderBlockManager
    xrCompatible: boolean
    maxPixelRatio: number
    reversedZ: boolean

    See RenderContextOptions.reversedZ. Read by passes/Camera to flip depth.

    activeCamera: Camera | null = null

    The camera that subsequent render passes will sample matrices from via pass.updateCamera(ctx). Set this each frame (per camera, if multi-camera later) after camera.updateRender(ctx). Null until first set.

    gpuProfiler: GpuProfiler | null = null

    Optional per-pass GPU timing. When set (and enabled), RenderGraph brackets every render/compute pass with timestamp queries and accumulates EMA-smoothed per-pass durations. Null by default — the caller creates one via GpuProfiler.create(ctx.device) and assigns it. Costs nothing while gpuProfiler.enabled === false.

    elapsedTime: number = 0

    Seconds since the first call to update. Updated every frame.

    deltaTime: number = 0

    Seconds since the last call to update. Updated every frame.

    frameCount: number = 0

    Total frames rendered since creation. Incremented every frame by update.

    framesPerSecond: number = 0

    Smoothed frames-per-second (EMA with alpha 0.1). Updated every frame by update.

    fps: number = 0

    Frames-per-second clamped to an integer. Updated every frame by update.

    Accessors

    • get width(): number

      Render width: the XR override when set, else the canvas width scaled by renderScale. All scene/lighting/post passes size their targets to this, so lowering renderScale renders the whole scene sub-native.

      Returns number

    • get displayWidth(): number

      Display (presentation) width: the canvas backing-store size, unaffected by renderScale (the XR override stands in for the canvas under XR). The temporal upscaler resolves to this; the final blit / tonemap targets it.

      Returns number

    • get depthClearValue(): number

      Depth value the main camera's depth buffer clears to: the FAR plane. 0 under reversed-Z (far→0), 1 under standard-Z. Use this for depth attachment clearValue/depthClearValue so a pass works in either mode.

      Returns number

    Methods

    • Override the reported render size (see _renderSizeOverride); pass null to revert to the canvas backing-store size. Used by the engine's WebXR driver per eye.

      Parameters

      • size: { width: number; height: number } | null

      Returns void

    • Maps a standard-Z depth-compare function to the equivalent under the active mode. Under reversed-Z, "nearer" is a GREATER depth, so 'less'→'greater' and 'less-equal'→'greater-equal'; other functions pass through. Pass the standard-Z function you'd normally use; the result is what the pipeline should use.

      Parameters

      • standard: GPUCompareFunction

      Returns GPUCompareFunction

    • Sign to multiply a "toward the camera" polygon depth-bias by, so the same positive value nudges a fragment nearer the viewer under either Z mode. Standard-Z: nearer = smaller depth → -1. Reversed-Z: nearer = larger depth → +1. Multiply both depthBias and depthBiasSlopeScale by this when building a pipeline (e.g. draped overlays that must win the depth test against coincident terrain behind them). See Material.depthBias.

      Returns number

    • Creates a GPU shader module from the provided WGSL code.

      Parameters

      • code: string

        WGSL shader code

      • Optionallabel: string

        optional debug label

      • Optionaldefines: Record<string, string>

        optional preprocessor defines for shader block imports

      Returns GPUShaderModule

      GPUShaderModule instance

    • Creates a render pipeline via the async WebGPU API. Prefer this for one-time (boot/setup) pipeline creation: async compiles run on the driver's background threads and overlap each other, while the sync createRenderPipeline serializes on the device's command stream — with a large feature roster boot then pays the sum of every compile instead of roughly the slowest one.

      Errors: a validation failure rejects the async call (it does not reach device error scopes). To preserve the sync path's log-and-continue semantics this logs the failure and falls back to the sync variant, whose invalid pipeline surfaces the same error through the device's regular error handling at first use.

      Parameters

      • desc: GPURenderPipelineDescriptor

      Returns Promise<GPURenderPipeline>

    • Registers a shader block for later use in shader modules.

      Parameters

      • name: string

        unique identifier for the shader block

      • code: string

        WGSL code of the shader block

      Returns void

    • Removes a previously registered shader block by name.

      Parameters

      • name: string

        name of the shader block to remove

      Returns void

    • Retrieves the WGSL code for a registered shader block by name.

      Parameters

      • name: string

        name of the shader block

      • Optionaldefines: Record<string, string>

      Returns string

      WGSL code of the shader block, or a placeholder comment if not found

    • Convenience wrapper around device.createBuffer.

      Parameters

      • size: number

        buffer size in bytes

      • usage: number

        usage flags

      • Optionallabel: string

        optional debug label

      Returns GPUBuffer

    • Uploads CPU data into a GPU buffer, handling both ArrayBuffer and typed-array sources.

      Parameters

      • buffer: GPUBuffer

        destination GPU buffer

      • data: ArrayBuffer | ArrayBufferView<ArrayBufferLike>

        source bytes to copy

      • offset: number = 0

        destination byte offset

      Returns void

    • Pushes a validation error scope used during one-time resource initialization. No-op when error handling is disabled.

      Returns void

    • Pops the matching init error scope and logs any validation failure.

      Parameters

      • label: string

        identifier included in the log message

      Returns Promise<void>

    • Pushes a per-frame validation error scope. No-op when error handling is disabled or the device has been lost.

      Returns void

    • Pushes nested validation, out-of-memory and internal error scopes around a single render pass. No-op when error handling is disabled or the device has been lost.

      Parameters

      • _passName: string

        pass identifier (currently unused; reserved for diagnostics)

      Returns void