Class InstanceBufferObjectSubData
- java.lang.Object
-
- com.badlogic.gdx.graphics.glutils.InstanceBufferObjectSubData
-
- All Implemented Interfaces:
InstanceData
,Disposable
public class InstanceBufferObjectSubData extends java.lang.Object implements InstanceData
Modification of theVertexBufferObjectSubData
class. Sets the glVertexAttribDivisor for everyVertexAttribute
automatically.
-
-
Constructor Summary
Constructors Constructor Description InstanceBufferObjectSubData(boolean isStatic, int numInstances, VertexAttribute... instanceAttributes)
Constructs a new interleaved InstanceBufferObject.InstanceBufferObjectSubData(boolean isStatic, int numInstances, VertexAttributes instanceAttributes)
Constructs a new interleaved InstanceBufferObject.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
bind(ShaderProgram shader)
Binds this InstanceBufferObject for rendering via glDrawArraysInstanced or glDrawElementsInstancedvoid
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()
Deprecated.usegetBuffer(boolean)
insteadjava.nio.FloatBuffer
getBuffer(boolean forWriting)
Returns the underlying FloatBuffer for reading or writing.int
getBufferHandle()
Returns the InstanceBufferObject handleint
getNumInstances()
Effectively returnsgetNumInstances()
.int
getNumMaxInstances()
Effectively returnsgetNumMaxInstances()
.void
invalidate()
Invalidates the InstanceBufferObject so a new OpenGL buffer handle is created.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.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.
-
-
-
Constructor Detail
-
InstanceBufferObjectSubData
public InstanceBufferObjectSubData(boolean isStatic, int numInstances, VertexAttribute... instanceAttributes)
Constructs a new interleaved InstanceBufferObject.- Parameters:
isStatic
- whether the vertex data is static.numInstances
- the maximum number of verticesinstanceAttributes
- theVertexAttributes
.
-
InstanceBufferObjectSubData
public InstanceBufferObjectSubData(boolean isStatic, int numInstances, VertexAttributes instanceAttributes)
Constructs a new interleaved InstanceBufferObject.- Parameters:
isStatic
- whether the vertex data is static.numInstances
- the maximum number of verticesinstanceAttributes
- theVertexAttribute
s.
-
-
Method Detail
-
getAttributes
public VertexAttributes getAttributes()
- Specified by:
getAttributes
in interfaceInstanceData
- Returns:
- the
VertexAttributes
as specified during construction.
-
getNumInstances
public int getNumInstances()
Effectively returnsgetNumInstances()
.- Specified by:
getNumInstances
in interfaceInstanceData
- Returns:
- number of instances in this buffer
-
getNumMaxInstances
public int getNumMaxInstances()
Effectively returnsgetNumMaxInstances()
.- Specified by:
getNumMaxInstances
in interfaceInstanceData
- Returns:
- maximum number of instances in this buffer
-
getBuffer
@Deprecated public java.nio.FloatBuffer getBuffer()
Deprecated.usegetBuffer(boolean)
insteadDescription copied from interface:InstanceData
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 useInstanceData.setInstanceData(float[], int, int)
; Any modifications made to the Buffer *after* the call to bind will not automatically be uploaded.- Specified by:
getBuffer
in interfaceInstanceData
- Returns:
- the underlying FloatBuffer holding the vertex data.
-
getBuffer
public java.nio.FloatBuffer getBuffer(boolean forWriting)
Description copied from interface:InstanceData
Returns the underlying FloatBuffer for reading or writing.- Specified by:
getBuffer
in interfaceInstanceData
- Parameters:
forWriting
- when true, the underlying buffer will be uploaded on the next call to bind. If you need immediate uploading useInstanceData.setInstanceData(float[], int, int)
.- Returns:
- the underlying FloatBuffer holding the vertex data.
-
setInstanceData
public void setInstanceData(float[] data, int offset, int count)
Description copied from interface:InstanceData
Sets the vertices of this InstanceData, 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 viaVertexAttributes
.This can be called in between calls to bind and unbind. The vertex data will be updated instantly.
- Specified by:
setInstanceData
in interfaceInstanceData
- Parameters:
data
- the instance dataoffset
- the offset to start copying the data fromcount
- the number of floats to copy
-
setInstanceData
public void setInstanceData(java.nio.FloatBuffer data, int count)
Description copied from interface:InstanceData
Sets the vertices of this InstanceData, 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 InstanceData. The order of the vertex attributes must be the same as specified at construction time viaVertexAttributes
.This can be called in between calls to bind and unbind. The vertex data will be updated instantly.
- Specified by:
setInstanceData
in interfaceInstanceData
- Parameters:
data
- the instance datacount
- the number of floats to copy
-
updateInstanceData
public void updateInstanceData(int targetOffset, float[] data, int sourceOffset, int count)
Description copied from interface:InstanceData
Update (a portion of) the vertices. Does not resize the backing buffer.- Specified by:
updateInstanceData
in interfaceInstanceData
data
- the instance datasourceOffset
- the offset to start copying the data fromcount
- the number of floats to copy
-
updateInstanceData
public void updateInstanceData(int targetOffset, java.nio.FloatBuffer data, int sourceOffset, int count)
Description copied from interface:InstanceData
Update (a portion of) the vertices. Does not resize the backing buffer.- Specified by:
updateInstanceData
in interfaceInstanceData
data
- the vertex datasourceOffset
- the offset to start copying the data fromcount
- the number of floats to copy
-
bind
public void bind(ShaderProgram shader)
Binds this InstanceBufferObject for rendering via glDrawArraysInstanced or glDrawElementsInstanced- Specified by:
bind
in interfaceInstanceData
- Parameters:
shader
- the shader
-
bind
public void bind(ShaderProgram shader, int[] locations)
Description copied from interface:InstanceData
Binds this InstanceData for rendering via glDrawArraysInstanced or glDrawElementsInstanced.- Specified by:
bind
in interfaceInstanceData
locations
- array containing the attribute locations.
-
unbind
public void unbind(ShaderProgram shader)
Unbinds this InstanceBufferObject.- Specified by:
unbind
in interfaceInstanceData
- Parameters:
shader
- the shader
-
unbind
public void unbind(ShaderProgram shader, int[] locations)
Description copied from interface:InstanceData
Unbinds this InstanceData.- Specified by:
unbind
in interfaceInstanceData
locations
- array containing the attribute locations.
-
invalidate
public void invalidate()
Invalidates the InstanceBufferObject so a new OpenGL buffer handle is created. Use this in case of a context loss.- Specified by:
invalidate
in interfaceInstanceData
-
dispose
public void dispose()
Disposes of all resources this InstanceBufferObject uses.- Specified by:
dispose
in interfaceDisposable
- Specified by:
dispose
in interfaceInstanceData
-
getBufferHandle
public int getBufferHandle()
Returns the InstanceBufferObject handle- Returns:
- the InstanceBufferObject handle
-
-