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.

    • Optional usage: number = BUFFER_STATIC

      The usage type of the vertex buffer. Can be:

      Defaults to BUFFER_STATIC.

    • Optional initialData: ArrayBuffer

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

    • Optional options: {
          storage: boolean;
      }

      Object for passing optional arguments.

      • storage: 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

    Example

    // 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

  • Signals that the block of memory returned by a call to the lock function is ready to be given to the graphics hardware. Only unlocked index buffers can be set on the currently active device.

    Returns void