Skip to main content

VertexArray

A VertexArray stores a set of vertex attribute bindings, including the index buffer.

On WebGL, attribute can be bound to constants,

Usage

const renderPipeline = device.createRenderPipeline({bufferLayout, ...});
const vertexArray = device.createVertexArray({renderPipeline});

vertexArray.setIndexBuffer(device.createBuffer({usage: Buffer.INDEX, ...));
vertexArray.setBuffer(0, device.createBuffer({usage: Buffer.VERTEX, ...));
vertexArray.setConstant(1, new Float32Array([1, 2, 3]));

const renderPipeline.setVertexArray(vertexArray);

Types

VertexArrayProps

PropertyTypeDescription
renderPipelineRenderPipelineLayout of attributes (type, size, step mode etc) will match the pipeline's shaderLayout/bufferLayouts.

Members

  • device: Device - holds a reference to the Device that created this VertexArray.
  • handle: unknown - holds the underlying WebGL or WebGPU shader object
  • props: VertexArrayProps - holds a copy of the VertexArrayProps used to create this VertexArray.

Methods

constructor(props: VertexArrayProps)

VertexArray is an abstract class and cannot be instantiated directly. Create with device.beginVertexArray(...).

setIndexBuffer

vertexArray.setIndexBuffer(location: number, buffer | null): void

Note that the index buffer can be unbound by calling `vertexArray.setUb

setBuffer(location: number): void

vertexArray.setBuffer(location: number, buffer | null): void

setConstant(location: number: Float32Array | Int32Array | Uint32Array): void

vertexArray.setConstant(location: number, buffer | null): void

Note:

  • Under WebGL, a WebGL VertexArrayObject will be created.
  • Under WebGPU, this is a simply an API class that holds attributes.