# Class IndexBuffer

java.lang.Object
com.codename1.gpu.IndexBuffer

public final class IndexBuffer extends Object
Holds the element indices used to assemble primitives from a `VertexBuffer`. Indices are stored as 16 bit unsigned values (`short`) which is the portable baseline supported on every backend including WebGL 1. A buffer therefore addresses at most 65536 distinct vertices.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `IndexBuffer(int indexCount)`
  Allocates an index buffer with room for `indexCount` indices.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `clearDirty()`
  Clears the dirty flag.
  `short[]`
  `getData()`
  Returns the backing short array.
  `Object`
  `getHandle()`
  Returns the opaque backend GPU handle, or null if not yet uploaded.
  `int`
  `getIndexCount()`
  Returns the number of indices this buffer holds.
  `boolean`
  `isDirty()`
  Returns true if the buffer has pending changes.
  `void`
  `setData(int[] src)`
  Copies `src` into the backing array and marks the buffer dirty.
  `void`
  `setDirty()`
  Marks the buffer as needing re-upload to the GPU before the next draw.
  `void`
  `setHandle(Object handle)`
  Stores the opaque backend GPU handle.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### IndexBuffer

    public IndexBuffer(int indexCount)

    Allocates an index buffer with room for `indexCount` indices. Prefer creating buffers through `GraphicsDevice.createIndexBuffer(int)` so the GPU handle is tracked by the device.

    ###### Parameters

    - `indexCount`: the number of indices the buffer can hold

- ## Method Details

  - ### getIndexCount

    public int getIndexCount()
    Returns the number of indices this buffer holds.

  - ### getData

    public short[] getData()
    Returns the backing short array. Index values are treated as unsigned.

  - ### setData

    public void setData(int[] src)

    Copies `src` into the backing array and marks the buffer dirty. Each int must fit in an unsigned 16 bit range.

    ###### Parameters

    - `src`: the index values to store

  - ### setDirty

    public void setDirty()
    Marks the buffer as needing re-upload to the GPU before the next draw.

  - ### isDirty

    public boolean isDirty()
    Returns true if the buffer has pending changes. Intended for backend use.

  - ### clearDirty

    public void clearDirty()
    Clears the dirty flag. Intended for backend use after an upload.

  - ### getHandle

    public Object getHandle()
    Returns the opaque backend GPU handle, or null if not yet uploaded. Intended for backend use.

  - ### setHandle

    public void setHandle(Object handle)

    Stores the opaque backend GPU handle. Intended for backend use.

    ###### Parameters

    - `handle`: the backend specific GPU resource handle