Package arc.graphics.gl
Class VertexBufferObject
java.lang.Object
arc.graphics.gl.VertexBufferObject
- All Implemented Interfaces:
VertexData
,Disposable
A VertexData
implementation based on OpenGL vertex buffer objects.
The data is bound via glVertexAttribPointer() according to the attribute aliases specified in the constructor.
VertexBufferObjects must be disposed via the dispose()
method when no longer needed
-
Constructor Summary
ConstructorDescriptionVertexBufferObject
(boolean isStatic, int numVertices, Mesh mesh) Constructs a new interleaved VertexBufferObject. -
Method Summary
Modifier and TypeMethodDescriptionvoid
bind()
Binds the buffer and updates data if necessary.void
Binds this VertexBufferObject for rendering via glDrawArrays or glDrawElementsbuffer()
Returns the underlying FloatBuffer and marks it as dirty, causing the buffer contents to be uploaded on the next call to bind.void
dispose()
Disposes of all resources this VertexBufferObject uses.int
max()
void
set
(float[] vertices, int offset, int count) Sets the vertices of this VertexData, discarding the old vertex data.protected void
Low level method to reset the buffer and attributes to the specified values.int
size()
void
Unbinds this VertexData.void
update
(int targetOffset, float[] vertices, int sourceOffset, int count) Update (a portion of) the vertices.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface arc.util.Disposable
isDisposed
Methods inherited from interface arc.graphics.gl.VertexData
render
-
Constructor Details
-
VertexBufferObject
Constructs a new interleaved VertexBufferObject.- Parameters:
isStatic
- whether the vertex data is static.numVertices
- the maximum number of vertices
-
-
Method Details
-
size
public int size()- Specified by:
size
in interfaceVertexData
- Returns:
- the number of vertices this VertexData stores
-
max
public int max()- Specified by:
max
in interfaceVertexData
- Returns:
- the number of vertices this VertexData can store
-
buffer
Description copied from interface:VertexData
Returns the underlying FloatBuffer and marks it as dirty, causing the buffer contents to be uploaded on the next call to bind. If you need immediate uploading useVertexData.set(float[], int, int)
; Any modifications made to the Buffer *after* the call to bind will not automatically be uploaded.- Specified by:
buffer
in interfaceVertexData
- Returns:
- the underlying FloatBuffer holding the vertex data.
-
setBuffer
Low level method to reset the buffer and attributes to the specified values. Use with care! -
set
public void set(float[] vertices, int offset, int count) Description copied from interface:VertexData
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.This can be called in between calls to bind and unbind. The vertex data will be updated instantly.
- Specified by:
set
in interfaceVertexData
- Parameters:
vertices
- the vertex dataoffset
- the offset to start copying the data fromcount
- the number of floats to copy
-
update
public void update(int targetOffset, float[] vertices, int sourceOffset, int count) Description copied from interface:VertexData
Update (a portion of) the vertices. Does not resize the backing buffer.- Specified by:
update
in interfaceVertexData
vertices
- the vertex datasourceOffset
- the offset to start copying the data fromcount
- the number of floats to copy
-
bind
public void bind()Binds the buffer and updates data if necessary. Does not activate/deactivate attributes. Advanced use only. -
bind
Binds this VertexBufferObject for rendering via glDrawArrays or glDrawElements- Specified by:
bind
in interfaceVertexData
- Parameters:
shader
- the shader
-
unbind
Description copied from interface:VertexData
Unbinds this VertexData.- Specified by:
unbind
in interfaceVertexData
-
dispose
public void dispose()Disposes of all resources this VertexBufferObject uses.- Specified by:
dispose
in interfaceDisposable
-