An index buffer stores index values into a VertexBuffer. Indexed graphical primitives can normally utilize less memory that unindexed primitives (if vertices are shared).

Typically, index buffers are set on Mesh objects.

Constructors

  • Create a new IndexBuffer instance.

    Parameters

    • graphicsDevice: GraphicsDevice

      The graphics device used to manage this index buffer.

    • format: number

      The type of each index to be stored in the index buffer. Can be:

    • numIndices: number

      The number of indices to be stored in the index buffer.

    • Optionalusage: number = BUFFER_STATIC

      The usage type of the vertex buffer. Can be:

      Defaults to BUFFER_STATIC.

    • OptionalinitialData: ArrayBuffer

      Initial data. If left unspecified, the index buffer will be initialized to zeros.

    • Optionaloptions: { storage?: boolean }

      Object for passing optional arguments.

      • Optionalstorage?: boolean

        Defines if the index buffer can be used as a storage buffer by a compute shader. Defaults to false. Only supported on WebGPU.

    Returns IndexBuffer

    // Create an index buffer holding 3 16-bit indices. The buffer is marked as
    // static, hinting that the buffer will never be modified.
    const indices = new UInt16Array([0, 1, 2]);
    const indexBuffer = new pc.IndexBuffer(graphicsDevice,
    pc.INDEXFORMAT_UINT16,
    3,
    pc.BUFFER_STATIC,
    indices);

Methods