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 VertexBufferObject
s are needed.
Constructor and Description |
---|
VertexArray(int numVertices,
VertexAttribute... attributes)
Constructs a new interleaved VertexArray
|
VertexArray(int numVertices,
VertexAttributes attributes)
Constructs a new interleaved VertexArray
|
Modifier and Type | Method and Description |
---|---|
void |
bind()
Binds this VertexData for rendering via glDrawArrays or glDrawElements.
|
void |
bind(ShaderProgram shader)
Binds this VertexData for rendering via glDrawArrays or glDrawElements.
|
void |
bind(ShaderProgram shader,
int[] locations)
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.
|
void |
unbind(ShaderProgram shader)
Unbinds this VertexBufferObject.
|
void |
unbind(ShaderProgram shader,
int[] locations)
Unbinds this VertexData.
|
public VertexArray(int numVertices, VertexAttribute... attributes)
numVertices
- the maximum number of verticesattributes
- the VertexAttribute
spublic VertexArray(int numVertices, VertexAttributes attributes)
numVertices
- the maximum number of verticesattributes
- the VertexAttributes
public void dispose()
dispose
in interface VertexData
dispose
in interface Disposable
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)
;
getBuffer
in interface VertexData
public int getNumVertices()
getNumVertices
in interface VertexData
public int getNumMaxVertices()
getNumMaxVertices
in interface VertexData
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.
setVertices
in interface VertexData
vertices
- the vertex dataoffset
- the offset to start copying the data fromcount
- the number of floats to copypublic void bind()
VertexData
bind
in interface VertexData
public void unbind()
VertexData
unbind
in interface VertexData
public void bind(ShaderProgram shader)
VertexData
bind
in interface VertexData
public void bind(ShaderProgram shader, int[] locations)
VertexData
bind
in interface VertexData
locations
- array containing the attribute locations.public void unbind(ShaderProgram shader)
unbind
in interface VertexData
shader
- the shaderpublic void unbind(ShaderProgram shader, int[] locations)
VertexData
unbind
in interface VertexData
locations
- array containing the attribute locations.public VertexAttributes getAttributes()
getAttributes
in interface VertexData
VertexAttributes
as specified during construction.