Engine API Reference - v2.23.0-beta.17
    Preparing search index...

    Class IndexBuffer

    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.

    Index
    • 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 | ArrayBufferView<ArrayBufferLike>

        Initial data. Can be an ArrayBuffer or a typed array (for example a Uint16Array). The data is stored by reference and is not copied, so a typed array that is a view into a larger buffer is kept as-is. 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 IndexBuffer(graphicsDevice,
      INDEXFORMAT_UINT16,
      3,
      BUFFER_STATIC,
      indices);
    • Returns the number of indices stored in the specified index buffer.

      Returns number

      The number of indices stored in the specified index buffer.

    • Uploads the client side copy of the index buffer to the GPU. When called without arguments, uploads the entire buffer. An explicit range uploads only those bytes at the same GPU offset. The first upload always initializes the entire GPU buffer, regardless of the requested range. A zero byte length does nothing, including before the first upload.

      Partial uploads do not resize the buffer or change its CPU storage. The caller must upload every modified range before expecting those changes on the GPU. Context restoration uploads the entire CPU storage. Invalid ranges are ignored in all builds and report an assertion in debug builds.

      Parameters

      • OptionalbyteOffset: number

        Offset in bytes from the start of the buffer's storage. Defaults to 0. Must be a non-negative integer and a multiple of 4 on all graphics backends.

      • OptionalbyteLength: number

        Number of bytes to upload. Defaults to the remaining bytes after byteOffset. The length must be a non-negative integer and the range must fit within the buffer. Partial ranges require a length that is a multiple of 4. Full-buffer uploads support any byte length, whether the range is explicit or the arguments are omitted.

      Returns void

      // After modifying bytes 16 through 31 of the CPU storage:
      indexBuffer.unlock(16, 16);