public class InstanceBufferObject extends java.lang.Object implements InstanceData
VertexBufferObject
class.
Sets the glVertexAttribDivisor for every VertexAttribute
automatically.Constructor and Description |
---|
InstanceBufferObject(boolean isStatic,
int numVertices,
VertexAttribute... attributes) |
InstanceBufferObject(boolean isStatic,
int numVertices,
VertexAttributes instanceAttributes) |
Modifier and Type | Method and Description |
---|---|
void |
bind(ShaderProgram shader)
Binds this InstanceBufferObject for rendering via glDrawArraysInstanced or glDrawElementsInstanced
|
void |
bind(ShaderProgram shader,
int[] locations)
Binds this InstanceData for rendering via glDrawArraysInstanced or glDrawElementsInstanced.
|
void |
dispose()
Disposes of all resources this InstanceBufferObject 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 |
getNumInstances() |
int |
getNumMaxInstances() |
protected int |
getUsage() |
void |
invalidate()
Invalidates the InstanceBufferObject 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.
|
void |
setInstanceData(float[] data,
int offset,
int count)
Sets the vertices of this InstanceData, discarding the old vertex data.
|
void |
setInstanceData(java.nio.FloatBuffer data,
int count)
Sets the vertices of this InstanceData, discarding the old vertex data.
|
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 |
unbind(ShaderProgram shader)
Unbinds this InstanceBufferObject.
|
void |
unbind(ShaderProgram shader,
int[] locations)
Unbinds this InstanceData.
|
void |
updateInstanceData(int targetOffset,
float[] data,
int sourceOffset,
int count)
Update (a portion of) the vertices.
|
void |
updateInstanceData(int targetOffset,
java.nio.FloatBuffer data,
int sourceOffset,
int count)
Update (a portion of) the vertices.
|
public InstanceBufferObject(boolean isStatic, int numVertices, VertexAttribute... attributes)
public InstanceBufferObject(boolean isStatic, int numVertices, VertexAttributes instanceAttributes)
public VertexAttributes getAttributes()
getAttributes
in interface InstanceData
VertexAttributes
as specified during construction.public int getNumInstances()
getNumInstances
in interface InstanceData
public int getNumMaxInstances()
getNumMaxInstances
in interface InstanceData
public java.nio.FloatBuffer getBuffer()
InstanceData
InstanceData.setInstanceData(float[], int, int)
; Any modifications made to the Buffer
*after* the call to bind will not automatically be uploaded.getBuffer
in interface InstanceData
protected void setBuffer(java.nio.Buffer data, boolean ownsBuffer, VertexAttributes value)
data
- ownsBuffer
- value
- public void setInstanceData(float[] data, int offset, int count)
InstanceData
VertexAttributes
.
This can be called in between calls to bind and unbind. The vertex data will be updated instantly.
setInstanceData
in interface InstanceData
data
- the instance dataoffset
- the offset to start copying the data fromcount
- the number of floats to copypublic void setInstanceData(java.nio.FloatBuffer data, int count)
InstanceData
VertexAttributes
.
This can be called in between calls to bind and unbind. The vertex data will be updated instantly.
setInstanceData
in interface InstanceData
data
- the instance datacount
- the number of floats to copypublic void updateInstanceData(int targetOffset, float[] data, int sourceOffset, int count)
InstanceData
updateInstanceData
in interface InstanceData
data
- the instance datasourceOffset
- the offset to start copying the data fromcount
- the number of floats to copypublic void updateInstanceData(int targetOffset, java.nio.FloatBuffer data, int sourceOffset, int count)
InstanceData
updateInstanceData
in interface InstanceData
data
- 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 InstanceData
shader
- the shaderpublic void bind(ShaderProgram shader, int[] locations)
InstanceData
bind
in interface InstanceData
locations
- array containing the attribute locations.public void unbind(ShaderProgram shader)
unbind
in interface InstanceData
shader
- the shaderpublic void unbind(ShaderProgram shader, int[] locations)
InstanceData
unbind
in interface InstanceData
locations
- array containing the attribute locations.public void invalidate()
invalidate
in interface InstanceData
public void dispose()
dispose
in interface InstanceData
dispose
in interface Disposable