libgdx API

com.badlogic.gdx.graphics.glutils
Class VertexArray

java.lang.Object
  extended by com.badlogic.gdx.graphics.glutils.VertexArray
All Implemented Interfaces:
VertexData, Disposable

public class VertexArray
extends java.lang.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 does not support shaders and for that matter OpenGL ES 2.0. For this VertexBufferObjects are needed.

Author:
mzechner, Dave Clayton

Constructor Summary
VertexArray(int numVertices, VertexAttribute... attributes)
          Constructs a new interleaved VertexArray
VertexArray(int numVertices, VertexAttributes attributes)
          Constructs a new interleaved VertexArray
 
Method Summary
 void bind()
          Binds this VertexData for rendering via glDrawArrays or glDrawElements.
 void dispose()
          Disposes this VertexData and all its associated OpenGL resources.
 VertexAttributes getAttributes()
           
 java.nio.FloatBuffer getBuffer()
           Returns the underlying FloatBuffer.
 int getNumMaxVertices()
          
 int getNumVertices()
          
 void setVertices(float[] vertices, int offset, int count)
           Sets the vertices of this VertexData, discarding the old vertex data.
 void unbind()
          Unbinds this VertexData.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VertexArray

public VertexArray(int numVertices,
                   VertexAttribute... attributes)
Constructs a new interleaved VertexArray

Parameters:
numVertices - the maximum number of vertices
attributes - the VertexAttributes

VertexArray

public VertexArray(int numVertices,
                   VertexAttributes attributes)
Constructs a new interleaved VertexArray

Parameters:
numVertices - the maximum number of vertices
attributes - the VertexAttributes
Method Detail

dispose

public void dispose()
Disposes this VertexData and all its associated OpenGL resources.

Specified by:
dispose in interface VertexData
Specified by:
dispose in interface Disposable

getBuffer

public java.nio.FloatBuffer getBuffer()

Returns the underlying FloatBuffer. If you modify the buffer contents they will be uploaded on the next call to VertexData.bind(). If you need immediate uploading use VertexData.setVertices(float[], int, int);

Specified by:
getBuffer in interface VertexData
Returns:
the underlying FloatBuffer holding the vertex data.

getNumVertices

public int getNumVertices()

Specified by:
getNumVertices in interface VertexData
Returns:
the number of vertices this VertexData stores

getNumMaxVertices

public int getNumMaxVertices()

Specified by:
getNumMaxVertices in interface VertexData
Returns:
the number of vertices this VertedData can store

setVertices

public void setVertices(float[] vertices,
                        int offset,
                        int count)

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. The order of the vertex attributes must be the same as specified at construction time via VertexAttributes.

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

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

bind

public void bind()
Description copied from interface: VertexData
Binds this VertexData for rendering via glDrawArrays or glDrawElements.

Specified by:
bind in interface VertexData

unbind

public void unbind()
Description copied from interface: VertexData
Unbinds this VertexData.

Specified by:
unbind in interface VertexData

getAttributes

public VertexAttributes getAttributes()
Specified by:
getAttributes in interface VertexData
Returns:
the VertexAttributes as specified during construction.

libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)