public class VertexBufferObject extends java.lang.Object implements VertexData
A VertexData implementation based on OpenGL vertex buffer objects.
If the OpenGL ES context was lost you can call invalidate() to recreate a new OpenGL vertex buffer object. This class
can be used seamlessly with OpenGL ES 1.x and 2.0.
In case OpenGL ES 2.0 is used in the application the data is bound via glVertexAttribPointer() according to the attribute
aliases specified via VertexAttributes in the constructor.
Uses indirect Buffers on Android 1.5/1.6 to fix GC invocation due to leaking PlatformAddress instances.
VertexBufferObjects must be disposed via the dispose() method when no longer needed
| Constructor and Description |
|---|
VertexBufferObject(boolean isStatic,
int numVertices,
VertexAttribute... attributes)
Constructs a new interleaved VertexBufferObject.
|
VertexBufferObject(boolean isStatic,
int numVertices,
VertexAttributes attributes)
Constructs a new interleaved VertexBufferObject.
|
| Modifier and Type | Method and Description |
|---|---|
void |
bind()
Binds this VertexData for rendering via glDrawArrays or glDrawElements.
|
void |
bind(ShaderProgram shader)
Binds this VertexBufferObject for rendering via glDrawArrays or glDrawElements
|
void |
dispose()
Disposes of all resources this VertexBufferObject uses.
|
VertexAttributes |
getAttributes() |
java.nio.FloatBuffer |
getBuffer()
Returns the underlying FloatBuffer.
|
int |
getNumMaxVertices() |
int |
getNumVertices() |
void |
invalidate()
Invalidates the VertexBufferObject so a new OpenGL buffer handle is created.
|
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.
|
public VertexBufferObject(boolean isStatic,
int numVertices,
VertexAttribute... attributes)
isStatic - whether the vertex data is static.numVertices - the maximum number of verticesattributes - the VertexAttributes.public VertexBufferObject(boolean isStatic,
int numVertices,
VertexAttributes attributes)
isStatic - whether the vertex data is static.numVertices - the maximum number of verticesattributes - the VertexAttributes.public VertexAttributes getAttributes()
getAttributes in interface VertexDataVertexAttributes as specified during construction.public int getNumVertices()
getNumVertices in interface VertexDatapublic int getNumMaxVertices()
getNumMaxVertices in interface VertexDatapublic 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 VertexDatapublic 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 VertexDatavertices - the vertex dataoffset - the offset to start copying the data fromcount - the number of floats to copypublic void bind()
bind in interface VertexDatapublic void bind(ShaderProgram shader)
bind in interface VertexDatashader - the shaderpublic void unbind()
unbind in interface VertexDatapublic void unbind(ShaderProgram shader)
unbind in interface VertexDatashader - the shaderpublic void invalidate()
public void dispose()
dispose in interface VertexDatadispose in interface Disposable