Buffer
Quick answer
Buffer is a linear GPU memory block created by device.createBuffer, holding vertex, index, uniform or storage data. Set data or byteLength at creation, choose usage flags such as Buffer.VERTEX or Buffer.INDEX, and rewrite contents through write(). Index buffers also take an indexType so uint16 and uint32 bind correctly.
device. createBuffer ( props ) → Buffer
Key points
- device.createBuffer accepts data, byteLength, usage and indexType props.
- write(data, byteOffset) overwrites a byte range without recreating the buffer.
- readAsync returns a Uint8Array for GPU data you need on the CPU.
Example
const positions = device.createBuffer(new Float32Array([
-0.5, -0.5, 0,
0.5, -0.5, 0,
0.0, 0.5, 0
]));const vertexBuffer = device.createBuffer({
data: new Float32Array(vertexData),
usage: Buffer.VERTEX | Buffer.COPY_DST
});
const indexBuffer = device.createBuffer({
data: new Uint32Array([0, 1, 2]),
usage: Buffer.INDEX,
indexType: 'uint32'
});
const uniformBuffer = device.createBuffer({
byteLength: 64,
usage: Buffer.UNIFORM | Buffer.COPY_DST
});
Notes
- Updating a buffer without the COPY_DST usage flag throws at write time.
- Passing a Float32Array as index data silently produces wrong triangles.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). Buffer. https://www.jingweizhi.com/en/lumagl/api/buffer.html (accessed 2026-11-03).