Atlaslog
Atlaslog / luma.gl / Tutorial / Geometry and buffer layouts
luma.gl · Tutorial

Geometry and buffer layouts

Quick answer

This tutorial explains the three layers between typed arrays and the GPU: the array, the Buffer and the layout declaration. It shows createBuffer with explicit usage flags such as VERTEX, INDEX, UNIFORM, STORAGE, COPY_DST and COPY_SRC, then defines bufferLayout entries with name, stepMode and format. It describes interleaved records through byteStride and byteOffset, instance step modes, and Geometry versus GPUGeometry. Readers can feed vertices without silent attribute mismatches.

Last verified 2026-11-03 · luma.gl 9.4 · Cite this page
Key points
Example
const positions = device.createBuffer(new Float32Array([
  -0.6, -0.45, 0,
   0.6, -0.45, 0,
   0.0,  0.55, 0
]));
const dynamic = device.createBuffer({
  data: new Float32Array(3 * 2048),
  usage: luma.Buffer.VERTEX | luma.Buffer.COPY_DST
});
const indices = device.createBuffer({
  data: new Uint32Array([0, 1, 2]),
  usage: luma.Buffer.INDEX,
  indexType: 'uint32'
});

dynamic.write(newData);          // 覆盖写入
console.log(dynamic.byteLength, dynamic.updateTimestamp);
const model = new luma.Model(device, {
  vs: vsSource,
  fs: fsSource,
  attributes: {
    positions: device.createBuffer(new Float32Array([...])),
    colors: device.createBuffer(new Float32Array([...]))
  },
  bufferLayout: [
    { name: 'positions', stepMode: 'vertex', format: 'float32x3' },
    { name: 'colors',    stepMode: 'vertex', format: 'float32x3' }
  ],
  vertexCount: 3,
  topology: 'triangle-list'
});
Notes
Runnable examplesChinese originalAll Tutorials
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Cite this page

Atlaslog (2026). Geometry and buffer layouts. https://www.jingweizhi.com/en/lumagl/tutorials/geometry-buffers.html (accessed 2026-11-03).