Class IndexBufferObjectSubData

java.lang.Object
arc.graphics.gl.IndexBufferObjectSubData
All Implemented Interfaces:
IndexData, Disposable

public class IndexBufferObjectSubData extends Object implements IndexData

IndexBufferObject wraps OpenGL's index buffer functionality to be used in conjunction with VBOs.

You can also use this to store indices for vertex arrays. Do not call bind() or unbind() in this case but rather use buffer() to use the buffer directly with glDrawElements. You must also create the IndexBufferObject with the second constructor and specify isDirect as true as glDrawElements in conjunction with vertex arrays needs direct buffers.

VertexBufferObjects must be disposed via the dispose() method when no longer needed

  • Constructor Summary

    Constructors
    Constructor
    Description
    IndexBufferObjectSubData(boolean isStatic, int maxIndices)
    Creates a new IndexBufferObject.
    IndexBufferObjectSubData(int maxIndices)
    Creates a new IndexBufferObject to be used with vertex arrays.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Binds this IndexBufferObject for rendering with glDrawElements.
    Returns the underlying ShortBuffer.
    void
    Disposes this IndexBufferObject and all its associated OpenGL resources.
    int
    max()
     
    void
    set(short[] indices, int offset, int count)
    Sets the indices of this IndexBufferObject, discarding the old indices.
    void
    set(ShortBuffer indices)
    Copies the specified indices to the indices of this IndexBufferObject, discarding the old indices.
    int
     
    void
    Unbinds this IndexBufferObject.
    void
    update(int targetOffset, short[] indices, int offset, int count)
    Update (a portion of) the indices.

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface arc.util.Disposable

    isDisposed
  • Constructor Details

    • IndexBufferObjectSubData

      public IndexBufferObjectSubData(boolean isStatic, int maxIndices)
      Creates a new IndexBufferObject.
      Parameters:
      isStatic - whether the index buffer is static
      maxIndices - the maximum number of indices this buffer can hold
    • IndexBufferObjectSubData

      public IndexBufferObjectSubData(int maxIndices)
      Creates a new IndexBufferObject to be used with vertex arrays.
      Parameters:
      maxIndices - the maximum number of indices this buffer can hold
  • Method Details

    • size

      public int size()
      Specified by:
      size in interface IndexData
      Returns:
      the number of indices currently stored in this buffer
    • max

      public int max()
      Specified by:
      max in interface IndexData
      Returns:
      the maximum number of indices this IndexBufferObject can store.
    • set

      public void set(short[] indices, int offset, int count)

      Sets the indices of this IndexBufferObject, discarding the old indices. The count must equal the number of indices to be copied to this IndexBufferObject.

      This can be called in between calls to bind() and unbind(). The index data will be updated instantly.

      Specified by:
      set in interface IndexData
      Parameters:
      indices - the vertex data
      offset - the offset to start copying the data from
      count - the number of floats to copy
    • set

      public void set(ShortBuffer indices)
      Description copied from interface: IndexData
      Copies the specified indices to the indices of this IndexBufferObject, discarding the old indices. Copying start at the current Buffer.position() of the specified buffer and copied the Buffer.remaining() amount of indices. This can be called in between calls to IndexData.bind() and IndexData.unbind(). The index data will be updated instantly.
      Specified by:
      set in interface IndexData
      Parameters:
      indices - the index data to copy
    • update

      public void update(int targetOffset, short[] indices, int offset, int count)
      Description copied from interface: IndexData
      Update (a portion of) the indices.
      Specified by:
      update in interface IndexData
      Parameters:
      targetOffset - offset in indices buffer
      indices - the index data
      offset - the offset to start copying the data from
      count - the number of shorts to copy
    • buffer

      public ShortBuffer buffer()

      Returns the underlying ShortBuffer. If you modify the buffer contents they wil be uploaded on the call to bind(). If you need immediate uploading use set(short[], int, int).

      Specified by:
      buffer in interface IndexData
      Returns:
      the underlying short buffer.
    • bind

      public void bind()
      Binds this IndexBufferObject for rendering with glDrawElements.
      Specified by:
      bind in interface IndexData
    • unbind

      public void unbind()
      Unbinds this IndexBufferObject.
      Specified by:
      unbind in interface IndexData
    • dispose

      public void dispose()
      Disposes this IndexBufferObject and all its associated OpenGL resources.
      Specified by:
      dispose in interface Disposable
      Specified by:
      dispose in interface IndexData