Class VertexArray

java.lang.Object
arc.graphics.gl.VertexArray
All Implemented Interfaces:
VertexData, Disposable

public class VertexArray extends Object implements VertexData

Convenience class for working with OpenGL vertex arrays. It interleaves all data in the order you specified in the constructor via VertexAttribute.

This class is not compatible with OpenGL 3+ core profiles. For this VertexBufferObjects are needed.

  • Constructor Summary

    Constructors
    Constructor
    Description
    VertexArray(int numVertices, Mesh mesh)
    Constructs a new interleaved VertexArray
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    bind(Shader shader)
    Binds this VertexData for rendering via glDrawArrays or glDrawElements.
    Returns the underlying FloatBuffer and marks it as dirty, causing the buffer contents to be uploaded on the next call to bind.
    void
    Releases all resources of this object.
    int
    max()
     
    void
    render(IndexData indices, int primitiveType, int offset, int count)
     
    void
    set(float[] vertices, int offset, int count)
    Sets the vertices of this VertexData, discarding the old vertex data.
    int
     
    void
    unbind(Shader shader)
    Unbinds this VertexData.
    void
    update(int targetOffset, float[] vertices, int sourceOffset, int count)
    Update (a portion of) the vertices.

    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

    • VertexArray

      public VertexArray(int numVertices, Mesh mesh)
      Constructs a new interleaved VertexArray
      Parameters:
      numVertices - the maximum number of vertices
  • Method Details

    • render

      public void render(IndexData indices, int primitiveType, int offset, int count)
      Specified by:
      render in interface VertexData
    • dispose

      public void dispose()
      Description copied from interface: Disposable
      Releases all resources of this object.
      Specified by:
      dispose in interface Disposable
    • buffer

      public FloatBuffer buffer()
      Description copied from interface: VertexData
      Returns the underlying FloatBuffer and marks it as dirty, causing the buffer contents to be uploaded on the next call to bind. If you need immediate uploading use VertexData.set(float[], int, int); Any modifications made to the Buffer *after* the call to bind will not automatically be uploaded.
      Specified by:
      buffer in interface VertexData
      Returns:
      the underlying FloatBuffer holding the vertex data.
    • size

      public int size()
      Specified by:
      size in interface VertexData
      Returns:
      the number of vertices this VertexData stores
    • max

      public int max()
      Specified by:
      max in interface VertexData
      Returns:
      the number of vertices this VertexData can store
    • set

      public void set(float[] vertices, int offset, int count)
      Description copied from interface: VertexData
      Sets the vertices of this VertexData, discarding the old vertex data. The count must equal the number of floats per vertex times the number of vertices to be copied to this VertexData.

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

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

      public void update(int targetOffset, float[] vertices, int sourceOffset, int count)
      Description copied from interface: VertexData
      Update (a portion of) the vertices. Does not resize the backing buffer.
      Specified by:
      update in interface VertexData
      vertices - the vertex data
      sourceOffset - the offset to start copying the data from
      count - the number of floats to copy
    • bind

      public void bind(Shader shader)
      Description copied from interface: VertexData
      Binds this VertexData for rendering via glDrawArrays or glDrawElements.
      Specified by:
      bind in interface VertexData
    • unbind

      public void unbind(Shader shader)
      Description copied from interface: VertexData
      Unbinds this VertexData.
      Specified by:
      unbind in interface VertexData