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
Modifier | 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.
|
protected |
VertexBufferObject(int usage,
java.nio.ByteBuffer data,
boolean ownsBuffer,
VertexAttributes attributes) |
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.
|
int |
getNumMaxVertices() |
int |
getNumVertices() |
protected int |
getUsage() |
void |
invalidate()
Invalidates the VertexBufferObject so a new OpenGL buffer handle is created.
|
protected void |
setBuffer(java.nio.Buffer data,
boolean ownsBuffer,
VertexAttributes value)
Low level method to reset the buffer and attributes to the specified values.
|
protected void |
setUsage(int value)
Set the GL enum used in the call to
GL20.glBufferData(int, int, java.nio.Buffer, int) , can only be called when the
VBO is not bound. |
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 VertexBufferObject(boolean isStatic, int numVertices, VertexAttribute... attributes)
isStatic
- whether the vertex data is static.numVertices
- the maximum number of verticesattributes
- the VertexAttribute
s.public VertexBufferObject(boolean isStatic, int numVertices, VertexAttributes attributes)
isStatic
- whether the vertex data is static.numVertices
- the maximum number of verticesattributes
- the VertexAttributes
.protected VertexBufferObject(int usage, java.nio.ByteBuffer data, boolean ownsBuffer, VertexAttributes attributes)
public VertexAttributes getAttributes()
getAttributes
in interface VertexData
VertexAttributes
as specified during construction.public int getNumVertices()
getNumVertices
in interface VertexData
public int getNumMaxVertices()
getNumMaxVertices
in interface VertexData
public java.nio.FloatBuffer getBuffer()
VertexData
VertexData.setVertices(float[], int, int)
;getBuffer
in interface VertexData
protected void setBuffer(java.nio.Buffer data, boolean ownsBuffer, VertexAttributes value)
data
- ownsBuffer
- value
- public void setVertices(float[] vertices, int offset, int count)
VertexData
VertexAttributes
.
This can be called in between calls to bind and 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 updateVertices(int targetOffset, float[] vertices, int sourceOffset, int count)
VertexData
updateVertices
in interface VertexData
vertices
- the vertex datasourceOffset
- the offset to start copying the data fromcount
- the number of floats to copyprotected int getUsage()
GL20.glBufferData(int, int, java.nio.Buffer, int)
, e.g. GL_STATIC_DRAW or
GL_DYNAMIC_DRAWprotected void setUsage(int value)
GL20.glBufferData(int, int, java.nio.Buffer, int)
, can only be called when the
VBO is not bound.public void bind(ShaderProgram shader)
bind
in interface VertexData
shader
- the shaderpublic 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 void invalidate()
invalidate
in interface VertexData
public void dispose()
dispose
in interface VertexData
dispose
in interface Disposable