Nano WebGPU API - v0.11.0
    Preparing search index...

    Class Context

    Context acts as the primary orchestrator for a WebGPU instance on a target HTMLCanvasElement. It encapsulates the GPUDevice connection, the GPUCanvasContext configuration, and aggregates key framework singletons such as the PipelineManager, asset Loader, VRAMTracker, and PrimitivesFactory.

    Index

    Constructors

    Methods

    • Releases context resources, stops render loop, destroys default textures, and shuts down the logical GPU connection.

      Returns void

    • Configures the HTML5 canvas for WebGPU, requests physical adapter connections, initializes GPUDevice capabilities, and instantiates shared managers.

      Parameters

      • canvas: HTMLCanvasElement

        Target HTMLCanvasElement for WebGPU swapchain presentation.

      Returns Promise<void>

    • Executes a standard high-performance requestAnimationFrame render loop. Automatically calculates and supplies delta times while resetting frame-transient inputs.

      Parameters

      • loopFunction: (dt: number) => void

        Callback invoked every render frame, receiving the frame delta time in seconds.

      Returns void

    • Stops the active requestAnimationFrame render loop.

      Returns void

    • High-level initialization routine that resolves a canvas element and boots WebGPU services.

      Parameters

      • selector: string | HTMLCanvasElement

        A CSS query selector string or a direct HTMLCanvasElement reference.

      Returns Promise<Context>

      A Promise resolving to an initialized Context.

    • Assesses whether the active navigator environment implements standard WebGPU interfaces.

      Returns boolean

      True if WebGPU is supported, false otherwise.

    Properties

    context: GPUCanvasContext

    The WebGPU-specific canvas rendering context. Configured to represent presentable textures rendered directly into the DOM canvas.

    debug: boolean = false

    If true, enables extended runtime validation and debug logging. Defaults to false.

    defaultTextures: { black?: ITexture; normal?: ITexture; white?: ITexture } = {}

    Shared fallback textures representing solid white colors and flat normal vectors.

    Type Declaration

    • Optionalblack?: ITexture

      Standard solid black 1x1 pixels texture fallback (used for black emission).

    • Optionalnormal?: ITexture

      Default tangent-space normal map fallback (128, 128, 255).

    • Optionalwhite?: ITexture

      Standard solid white 1x1 pixels texture.

    device: GPUDevice

    The logical GPU device interface representing a connection to the physical GPU. Utilized for resource allocation (buffers, textures, pipelines).

    format: GPUTextureFormat

    The preferred color format optimized for display on the local system (usually 'bgra8unorm' or 'rgba8unorm').

    Local input manager instance for this context.

    loader: Loader

    Asset loader instance associated with this context. Manages network loading, parsing of GLB/GLTF models, textures, and custom formats.

    pipelineManager: PipelineManager

    Pipeline manager associated with this context. Manages WebGPU pipeline compilations and cached bind group layouts.

    primitives: PrimitivesFactory = ...

    Primitive geometry generator and cache. Avoids redundant pipeline / vertex allocations for standard geometric shapes like cubes, planes, or spheres.

    vramTracker: VRAMTracker = ...

    VRAM tracker instance. Monitored inside the context to log, register, and analyze VRAM allocations for debug visualizer purposes.