Given an array of GPUVertexAttributes and a corresponding array of TypedArrays, interleaves the contents of the typed arrays into the given ArrayBuffer
GPUVertexAttribute
example:
const attributes: GPUVertexAttribute[] = [ { shaderLocation: 0, offset: 0, format: 'float32x3' }, { shaderLocation: 1, offset: 12, format: 'float32x3' }, { shaderLocation: 2, offset: 24, format: 'float32x2' },];const typedArrays = [ new Float32Array([1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, -1, -1, 1, 1, -1, 1, -1, -1, -1, -1, -1, -1, 1, -1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, -1, 1, -1, 1, 1, -1, 1, -1, -1, -1, -1, -1]), new Float32Array([1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1]), new Float32Array([1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1]),];const arrayStride = (3 + 3 + 2) * 4; // pos + nrm + uvconst arrayBuffer = new ArrayBuffer(arrayStride * 24)interleaveVertexData(attributes, typedArrays, arrayStride, arrayBuffer) Copy
const attributes: GPUVertexAttribute[] = [ { shaderLocation: 0, offset: 0, format: 'float32x3' }, { shaderLocation: 1, offset: 12, format: 'float32x3' }, { shaderLocation: 2, offset: 24, format: 'float32x2' },];const typedArrays = [ new Float32Array([1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, -1, -1, 1, 1, -1, 1, -1, -1, -1, -1, -1, -1, 1, -1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, -1, 1, -1, 1, 1, -1, 1, -1, -1, -1, -1, -1]), new Float32Array([1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1]), new Float32Array([1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1]),];const arrayStride = (3 + 3 + 2) * 4; // pos + nrm + uvconst arrayBuffer = new ArrayBuffer(arrayStride * 24)interleaveVertexData(attributes, typedArrays, arrayStride, arrayBuffer)
results in the contents of arrayBuffer to be the 3 TypedArrays interleaved
arrayBuffer
See Arrays for details on the various types of arrays.
Note: You can generate attributes and typedArrays above by calling createBufferLayoutsFromArrays
attributes
typedArrays
Generated using TypeDoc
Given an array of
GPUVertexAttribute
s and a corresponding array of TypedArrays, interleaves the contents of the typed arrays into the given ArrayBufferexample:
results in the contents of
arrayBuffer
to be the 3 TypedArrays interleavedSee Arrays for details on the various types of arrays.
Note: You can generate
attributes
andtypedArrays
above by calling createBufferLayoutsFromArrays