Atlaslog
Atlaslog / luma.gl / API reference / VertexArray
luma.gl · API reference

VertexArray

Quick answer

VertexArray binds buffers to shader attribute slots so one pipeline can draw different geometry. Create it with device.createVertexArray({shaderLayout, bufferLayout}), then bind slots with setBuffer and setIndexBuffer for indexed draws. It also reports draw-readiness through getDrawValidationError, and swapping vertex arrays between draws is cheap.

Last verified 2026-11-03 · luma.gl 9.4 · Cite this page
device. createVertexArray ({ shaderLayout, bufferLayout }) → VertexArray
Key points
Example
const positions = device.createBuffer({
  data: new Float32Array([
    -0.5, -0.5,
     0.5, -0.5,
     0.0,  0.5
  ]),
  usage: Buffer.VERTEX
});

const vertexArray = device.createVertexArray({
  shaderLayout: pipeline.shaderLayout,
  bufferLayout: pipeline.bufferLayout
});

const slot = vertexArray.getBufferSlot('positions');

if (slot !== null) {
  vertexArray.setBuffer(slot, positions);
}

console.log(vertexArray.getDrawValidationError());   // null 表示可以绘制
const indices = device.createBuffer({
  data: new Uint32Array([0, 1, 2]),
  usage: Buffer.INDEX,
  indexType: 'uint32'
});

vertexArray.setIndexBuffer(indices);

pass.setPipeline(pipeline);
pass.setVertexArray(vertexArray);
pass.draw({ indexCount: 3 });
Notes
Runnable examplesChinese originalAll API references
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Cite this page

Atlaslog (2026). VertexArray. https://www.jingweizhi.com/en/lumagl/api/vertex-array.html (accessed 2026-11-03).