Function createBufferLayoutsFromArrays

  • Given a set of named arrays, generates an array GPUBufferLayouts

    Examples:

      const arrays = {
    position: [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],
    normal: [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],
    texcoord: [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 { bufferLayouts, typedArrays } = createBufferLayoutsFromArrays(arrays);

    results in bufferLayouts being

    [
    {
    stepMode: 'vertex',
    arrayStride: 32,
    attributes: [
    { shaderLocation: 0, offset: 0, format: 'float32x3' },
    { shaderLocation: 1, offset: 12, format: 'float32x3' },
    { shaderLocation: 2, offset: 24, format: 'float32x2' },
    ],
    },
    ]

    and typedArrays being

    [
    someFloat32Array0,
    someFloat32Array1,
    someFloat32Array2,
    ]

    See Arrays for details on the various types of arrays.

    Note: If typed arrays are passed in the same typed arrays will come out (copies will not be made)

    Parameters

    Returns {
        bufferLayouts: GPUVertexBufferLayout[];
        typedArrays: TypedArrayWithOffsetAndStride[];
    }

Generated using TypeDoc