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 theVertexBufferObjectSubDataclass. Sets the glVertexAttribDivisor for everyVertexAttributeautomatically.
-
-
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 voidbind(ShaderProgram shader)Binds this InstanceBufferObject for rendering via glDrawArraysInstanced or glDrawElementsInstancedvoidbind(ShaderProgram shader, int[] locations)Binds this InstanceData for rendering via glDrawArraysInstanced or glDrawElementsInstanced.voiddispose()Disposes of all resources this InstanceBufferObject uses.VertexAttributesgetAttributes()java.nio.FloatBuffergetBuffer()Deprecated.usegetBuffer(boolean)insteadjava.nio.FloatBuffergetBuffer(boolean forWriting)Returns the underlying FloatBuffer for reading or writing.intgetBufferHandle()Returns the InstanceBufferObject handleintgetNumInstances()Effectively returnsgetNumInstances().intgetNumMaxInstances()Effectively returnsgetNumMaxInstances().voidinvalidate()Invalidates the InstanceBufferObject so a new OpenGL buffer handle is created.voidsetInstanceData(float[] data, int offset, int count)Sets the vertices of this InstanceData, discarding the old vertex data.voidsetInstanceData(java.nio.FloatBuffer data, int count)Sets the vertices of this InstanceData, discarding the old vertex data.voidunbind(ShaderProgram shader)Unbinds this InstanceBufferObject.voidunbind(ShaderProgram shader, int[] locations)Unbinds this InstanceData.voidupdateInstanceData(int targetOffset, float[] data, int sourceOffset, int count)Update (a portion of) the vertices.voidupdateInstanceData(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- theVertexAttributes.
-
-
Method Detail
-
getAttributes
public VertexAttributes getAttributes()
- Specified by:
getAttributesin interfaceInstanceData- Returns:
- the
VertexAttributesas specified during construction.
-
getNumInstances
public int getNumInstances()
Effectively returnsgetNumInstances().- Specified by:
getNumInstancesin interfaceInstanceData- Returns:
- number of instances in this buffer
-
getNumMaxInstances
public int getNumMaxInstances()
Effectively returnsgetNumMaxInstances().- Specified by:
getNumMaxInstancesin interfaceInstanceData- Returns:
- maximum number of instances in this buffer
-
getBuffer
@Deprecated public java.nio.FloatBuffer getBuffer()
Deprecated.usegetBuffer(boolean)insteadDescription copied from interface:InstanceDataReturns 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:
getBufferin interfaceInstanceData- Returns:
- the underlying FloatBuffer holding the vertex data.
-
getBuffer
public java.nio.FloatBuffer getBuffer(boolean forWriting)
Description copied from interface:InstanceDataReturns the underlying FloatBuffer for reading or writing.- Specified by:
getBufferin 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:InstanceDataSets 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:
setInstanceDatain 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:InstanceDataSets 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:
setInstanceDatain 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:InstanceDataUpdate (a portion of) the vertices. Does not resize the backing buffer.- Specified by:
updateInstanceDatain interfaceInstanceDatadata- 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:InstanceDataUpdate (a portion of) the vertices. Does not resize the backing buffer.- Specified by:
updateInstanceDatain interfaceInstanceDatadata- 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:
bindin interfaceInstanceData- Parameters:
shader- the shader
-
bind
public void bind(ShaderProgram shader, int[] locations)
Description copied from interface:InstanceDataBinds this InstanceData for rendering via glDrawArraysInstanced or glDrawElementsInstanced.- Specified by:
bindin interfaceInstanceDatalocations- array containing the attribute locations.
-
unbind
public void unbind(ShaderProgram shader)
Unbinds this InstanceBufferObject.- Specified by:
unbindin interfaceInstanceData- Parameters:
shader- the shader
-
unbind
public void unbind(ShaderProgram shader, int[] locations)
Description copied from interface:InstanceDataUnbinds this InstanceData.- Specified by:
unbindin interfaceInstanceDatalocations- 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:
invalidatein interfaceInstanceData
-
dispose
public void dispose()
Disposes of all resources this InstanceBufferObject uses.- Specified by:
disposein interfaceDisposable- Specified by:
disposein interfaceInstanceData
-
getBufferHandle
public int getBufferHandle()
Returns the InstanceBufferObject handle- Returns:
- the InstanceBufferObject handle
-
-