Interface InstanceData
-
- All Superinterfaces:
Disposable
- All Known Implementing Classes:
InstanceBufferObject,InstanceBufferObjectSubData
public interface InstanceData extends Disposable
A InstanceData instance holds instance data for rendering with OpenGL. It is implemented as either aInstanceBufferObjector aInstanceBufferObjectSubData. Both require Open GL 3.3+.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description voidbind(ShaderProgram shader)Binds this InstanceData for rendering via glDrawArraysInstanced or glDrawElementsInstanced.voidbind(ShaderProgram shader, int[] locations)Binds this InstanceData for rendering via glDrawArraysInstanced or glDrawElementsInstanced.voiddispose()Disposes this InstanceData and all its associated OpenGL resources.VertexAttributesgetAttributes()java.nio.FloatBuffergetBuffer()Deprecated.usegetBuffer(boolean)insteadjava.nio.FloatBuffergetBuffer(boolean forWriting)Returns the underlying FloatBuffer for reading or writing.intgetNumInstances()intgetNumMaxInstances()voidinvalidate()Invalidates the InstanceData if applicable.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 InstanceData.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.
-
-
-
Method Detail
-
getNumInstances
int getNumInstances()
- Returns:
- the number of vertices this InstanceData stores
-
getNumMaxInstances
int getNumMaxInstances()
- Returns:
- the number of vertices this InstanceData can store
-
getAttributes
VertexAttributes getAttributes()
- Returns:
- the
VertexAttributesas specified during construction.
-
setInstanceData
void setInstanceData(float[] data, int offset, int count)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.
- Parameters:
data- the instance dataoffset- the offset to start copying the data fromcount- the number of floats to copy
-
updateInstanceData
void updateInstanceData(int targetOffset, float[] data, int sourceOffset, int count)Update (a portion of) the vertices. Does not resize the backing buffer.- Parameters:
data- the instance datasourceOffset- the offset to start copying the data fromcount- the number of floats to copy
-
setInstanceData
void setInstanceData(java.nio.FloatBuffer data, int count)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.
- Parameters:
data- the instance datacount- the number of floats to copy
-
updateInstanceData
void updateInstanceData(int targetOffset, java.nio.FloatBuffer data, int sourceOffset, int count)Update (a portion of) the vertices. Does not resize the backing buffer.- Parameters:
data- the vertex datasourceOffset- the offset to start copying the data fromcount- the number of floats to copy
-
getBuffer
@Deprecated java.nio.FloatBuffer getBuffer()
Deprecated.usegetBuffer(boolean)insteadReturns 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 usesetInstanceData(float[], int, int); Any modifications made to the Buffer *after* the call to bind will not automatically be uploaded.- Returns:
- the underlying FloatBuffer holding the vertex data.
-
getBuffer
java.nio.FloatBuffer getBuffer(boolean forWriting)
Returns the underlying FloatBuffer for reading or writing.- Parameters:
forWriting- when true, the underlying buffer will be uploaded on the next call to bind. If you need immediate uploading usesetInstanceData(float[], int, int).- Returns:
- the underlying FloatBuffer holding the vertex data.
-
bind
void bind(ShaderProgram shader)
Binds this InstanceData for rendering via glDrawArraysInstanced or glDrawElementsInstanced.
-
bind
void bind(ShaderProgram shader, int[] locations)
Binds this InstanceData for rendering via glDrawArraysInstanced or glDrawElementsInstanced.- Parameters:
locations- array containing the attribute locations.
-
unbind
void unbind(ShaderProgram shader)
Unbinds this InstanceData.
-
unbind
void unbind(ShaderProgram shader, int[] locations)
Unbinds this InstanceData.- Parameters:
locations- array containing the attribute locations.
-
invalidate
void invalidate()
Invalidates the InstanceData if applicable. Use this in case of a context loss.
-
dispose
void dispose()
Disposes this InstanceData and all its associated OpenGL resources.- Specified by:
disposein interfaceDisposable
-
-