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.

    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 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

    • 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

    • 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 nested validation, out-of-memory and internal error scopes around a single render pass. No-op when error handling is disabled.

      Parameters

      • _passName: string

        pass identifier (currently unused; reserved for diagnostics)

      Returns void