APIdia Launch Partner
Top Description Methods
com.badlogic.gdx.graphics.glutils

public Interface InstanceData

extends Disposable
Known Direct Implementers
com.badlogic.gdx.graphics.glutils.InstanceBufferObject, com.badlogic.gdx.graphics.glutils.InstanceBufferObjectSubData
Imports
com.badlogic.gdx.graphics.VertexAttributes, com.badlogic.gdx.utils.Disposable, java.nio.FloatBuffer

A InstanceData instance holds instance data for rendering with OpenGL. It is implemented as either a InstanceBufferObject or a InstanceBufferObjectSubData. Both require Open GL 3.3+.
Author
mrdlink

Method Summary

Modifier and TypeMethod and Description
public void
bind(ShaderProgram shader)

Binds this InstanceData for rendering via glDrawArraysInstanced or glDrawElementsInstanced.

public void
bind(ShaderProgram shader, int[]
array containing the attribute locations.
locations
)

Binds this InstanceData for rendering via glDrawArraysInstanced or glDrawElementsInstanced.

public void
dispose()

Redeclares com.badlogic.gdx.utils.Disposable.dispose.

Disposes this InstanceData and all its associated OpenGL resources.

public VertexAttributes
getAttributes()

Returns: the VertexAttributes as specified during construction.

public FloatBuffer

Returns:

the underlying FloatBuffer holding the vertex data.
getBuffer
()
Deprecated use getBuffer(boolean) instead

Returns the underlying FloatBuffer and marks it as dirty, causing the buffer contents to be uploaded on the next call to bind.

public FloatBuffer

Returns:

the underlying FloatBuffer holding the vertex data.
getBuffer
(boolean
when true, the underlying buffer will be uploaded on the next call to bind. If you need immediate uploading use setInstanceData(float[], int, int).
forWriting
)

Returns the underlying FloatBuffer for reading or writing.

public int
getNumInstances()

Returns: the number of vertices this InstanceData stores

public int
getNumMaxInstances()

Returns: the number of vertices this InstanceData can store

public void
invalidate()

Invalidates the InstanceData if applicable.

public void
setInstanceData(float[]
the instance data
data
,
int
the offset to start copying the data from
offset
,
int
the number of floats to copy
count
)

Sets the vertices of this InstanceData, discarding the old vertex data.

public void
setInstanceData(FloatBuffer
the instance data
data
,
int
the number of floats to copy
count
)

Sets the vertices of this InstanceData, discarding the old vertex data.

public void
unbind(ShaderProgram shader)

Unbinds this InstanceData.

public void
unbind(ShaderProgram shader, int[]
array containing the attribute locations.
locations
)

Unbinds this InstanceData.

public void
updateInstanceData(int targetOffset, float[]
the instance data
data
,
int
the offset to start copying the data from
sourceOffset
,
int
the number of floats to copy
count
)

Update (a portion of) the vertices.

public void
updateInstanceData(int targetOffset, FloatBuffer
the vertex data
data
,
int
the offset to start copying the data from
sourceOffset
,
int
the number of floats to copy
count
)

Update (a portion of) the vertices.

Method Detail

bindback to summary
public void bind(ShaderProgram shader)

Binds this InstanceData for rendering via glDrawArraysInstanced or glDrawElementsInstanced.

bindback to summary
public void bind(ShaderProgram shader, int[] locations)

Binds this InstanceData for rendering via glDrawArraysInstanced or glDrawElementsInstanced.

Parameters
locations:int[]

array containing the attribute locations.

disposeback to summary
public void dispose()

Redeclares com.badlogic.gdx.utils.Disposable.dispose.

Disposes this InstanceData and all its associated OpenGL resources.

getAttributesback to summary
public VertexAttributes getAttributes()
Returns:VertexAttributes

the VertexAttributes as specified during construction.

getBufferback to summary
public FloatBuffer getBuffer()

Deprecated

use getBuffer(boolean) instead

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 use setInstanceData(float[], int, int); Any modifications made to the Buffer *after* the call to bind will not automatically be uploaded.

Returns:FloatBuffer

the underlying FloatBuffer holding the vertex data.

Annotations
@Deprecated
getBufferback to summary
public FloatBuffer getBuffer(boolean forWriting)

Returns the underlying FloatBuffer for reading or writing.

Parameters
forWriting:boolean

when true, the underlying buffer will be uploaded on the next call to bind. If you need immediate uploading use setInstanceData(float[], int, int).

Returns:FloatBuffer

the underlying FloatBuffer holding the vertex data.

getNumInstancesback to summary
public int getNumInstances()
Returns:int

the number of vertices this InstanceData stores

getNumMaxInstancesback to summary
public int getNumMaxInstances()
Returns:int

the number of vertices this InstanceData can store

invalidateback to summary
public void invalidate()

Invalidates the InstanceData if applicable. Use this in case of a context loss.

setInstanceDataback to summary
public 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 via VertexAttributes.

This can be called in between calls to bind and unbind. The vertex data will be updated instantly.

Parameters
data:float[]

the instance data

offset:int

the offset to start copying the data from

count:int

the number of floats to copy

setInstanceDataback to summary
public void setInstanceData(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 via VertexAttributes.

This can be called in between calls to bind and unbind. The vertex data will be updated instantly.

Parameters
data:FloatBuffer

the instance data

count:int

the number of floats to copy

unbindback to summary
public void unbind(ShaderProgram shader)

Unbinds this InstanceData.

unbindback to summary
public void unbind(ShaderProgram shader, int[] locations)

Unbinds this InstanceData.

Parameters
locations:int[]

array containing the attribute locations.

updateInstanceDataback to summary
public void updateInstanceData(int targetOffset, float[] data, int sourceOffset, int count)

Update (a portion of) the vertices. Does not resize the backing buffer.

Parameters
data:float[]

the instance data

sourceOffset:int

the offset to start copying the data from

count:int

the number of floats to copy

updateInstanceDataback to summary
public void updateInstanceData(int targetOffset, FloatBuffer data, int sourceOffset, int count)

Update (a portion of) the vertices. Does not resize the backing buffer.

Parameters
data:FloatBuffer

the vertex data

sourceOffset:int

the offset to start copying the data from

count:int

the number of floats to copy