public class VertexBufferObjectWithVAO extends java.lang.Object implements VertexData
A VertexData implementation that uses vertex buffer objects and vertex array objects.
(This is required for OpenGL 3.0+ core profiles. In particular, the default VAO has been
deprecated, as has the use of client memory for passing vertex attributes.) Use of VAOs should
give a slight performance benefit since you don't have to bind the attributes on every draw
anymore.
If the OpenGL ES context was lost you can call invalidate() to recreate a new OpenGL vertex buffer object.
VertexBufferObjectWithVAO objects must be disposed via the dispose() method when no longer needed
VertexBufferObject.| Constructor and Description |
|---|
VertexBufferObjectWithVAO(boolean isStatic,
int numVertices,
VertexAttribute... attributes)
Constructs a new interleaved VertexBufferObjectWithVAO.
|
VertexBufferObjectWithVAO(boolean isStatic,
int numVertices,
VertexAttributes attributes)
Constructs a new interleaved VertexBufferObjectWithVAO.
|
| Modifier and Type | Method and Description |
|---|---|
void |
bind(ShaderProgram shader)
Binds this VertexBufferObject for rendering via glDrawArrays or glDrawElements
|
void |
bind(ShaderProgram shader,
int[] locations)
Binds this VertexData 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 and marks it as dirty, causing the buffer contents to be uploaded on the next call to
bind.
|
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(ShaderProgram shader)
Unbinds this VertexBufferObject.
|
void |
unbind(ShaderProgram shader,
int[] locations)
Unbinds this VertexData.
|
void |
updateVertices(int targetOffset,
float[] vertices,
int sourceOffset,
int count)
Update (a portion of) the vertices.
|
public VertexBufferObjectWithVAO(boolean isStatic,
int numVertices,
VertexAttribute... attributes)
isStatic - whether the vertex data is static.numVertices - the maximum number of verticesattributes - the VertexAttributes.public VertexBufferObjectWithVAO(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()
VertexDataVertexData.setVertices(float[], int, int); Any modifications made to the Buffer
*after* the call to bind will not automatically be uploaded.getBuffer in interface VertexDatapublic void setVertices(float[] vertices,
int offset,
int count)
VertexDataVertexAttributes.
This can be called in between calls to bind and 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 updateVertices(int targetOffset,
float[] vertices,
int sourceOffset,
int count)
VertexDataupdateVertices in interface VertexDatavertices - the vertex datasourceOffset - the offset to start copying the data fromcount - the number of floats to copypublic void bind(ShaderProgram shader)
bind in interface VertexDatashader - the shaderpublic void bind(ShaderProgram shader, int[] locations)
VertexDatabind in interface VertexDatalocations - array containing the attribute locations.public void unbind(ShaderProgram shader)
unbind in interface VertexDatashader - the shaderpublic void unbind(ShaderProgram shader, int[] locations)
VertexDataunbind in interface VertexDatalocations - array containing the attribute locations.public void invalidate()
invalidate in interface VertexDatapublic void dispose()
dispose in interface VertexDatadispose in interface Disposable