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
| Property | Type | Description |
|---|---|---|
renderPipeline | RenderPipeline | Layout of attributes (type, size, step mode etc) will match the pipeline's shaderLayout/bufferLayouts. |
Members
device:Device- holds a reference to theDevicethat created thisVertexArray.handle:unknown- holds the underlying WebGL or WebGPU shader objectprops:VertexArrayProps- holds a copy of theVertexArrayPropsused to create thisVertexArray.
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.