Manages uniform data for shaders in WebGPU.

Constructors

  • Creates a new Uniforms instance.

    Parameters

    • device: GPUDevice

      The GPUDevice to use for creating the uniform buffer.

    • canvas: HTMLCanvasElement

      The HTMLCanvasElement to get dimensions from.

    Returns Uniforms

Properties

device: GPUDevice

The GPUDevice to use for creating the uniform buffer.

uniformBuffer: GPUBuffer
uniformBufferArray: Float32Array

Methods

  • Sets uniform values in the uniform buffer array.

    Parameters

    • values: ArrayLike<number>

      An array of values to set.

    • offset: number

      The offset in the array where the values should be written.

    Returns void

  • Updates the uniform buffer on the GPU with the data from the uniform buffer array.

    Returns void

  • Initializes a Float32Array with default values for uniforms.

    Parameters

    • w: number

      The width of the canvas.

    • h: number

      The height of the canvas.

    Returns Float32Array

    A new Float32Array with initialized values.