APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.graphics.g3d.decals

public Class DecalBatch

extends Object
implements Disposable
Class Inheritance
All Implemented Interfaces
com.badlogic.gdx.utils.Disposable
Imports
com.badlogic.gdx.Gdx, com.badlogic.gdx.graphics.GL20, .Mesh, .VertexAttribute, .VertexAttributes, com.badlogic.gdx.graphics.glutils.ShaderProgram, com.badlogic.gdx.utils.Array, .Disposable, .Pool, .SortedIntList

Renderer for Decal objects.

New objects are added using DecalBatch#add(Decal), there is no limit on how many decals can be added.
Once all the decals have been submitted a call to DecalBatch#flush() will batch them together and send big chunks of geometry to the GL.

The size of the batch specifies the maximum number of decals that can be batched together before they have to be submitted to the graphics pipeline. The default size is DecalBatch#DEFAULT_SIZE. If it is known before hand that not as many will be needed on average the batch can be downsized to save memory. If the game is basically 3d based and decals will only be needed for an orthogonal HUD it makes sense to tune the size down.

The way the batch handles things depends on the GroupStrategy. Different strategies can be used to customize shaders, states, culling etc. for more details see the GroupStrategy java doc.
While it shouldn't be necessary to change strategies, if you have to do so, do it before calling add(Decal), and if you already did, call flush() first.

Field Summary

Modifier and TypeField and Description
private static final int
private final SortedIntList<Array<Decal>>
private final Pool<Array<Decal>>
private GroupStrategy
private Mesh
private final Array<Array<Decal>>
private float[]

Constructor Summary

AccessConstructor and Description
public
DecalBatch(GroupStrategy groupStrategy)

Creates a new DecalBatch using the given GroupStrategy.

public
DecalBatch(int size, GroupStrategy groupStrategy)

Method Summary

Modifier and TypeMethod and Description
public void
add(Decal
Decal to add for rendering
decal
)

Add a decal to the batch, marking it for later rendering

protected void
clear()

Remove all decals from batch

public void
dispose()

Implements com.badlogic.gdx.utils.Disposable.dispose.

Frees up memory by dropping the buffer and underlying resources.

public void
flush()

Flush this batch sending all contained decals to GL.

protected void
flush(ShaderProgram shader, int
Amount of elements from the vertices array to flush
verticesPosition
)

Flushes vertices[0,verticesPosition[ to GL verticesPosition % Decal.SIZE must equal 0

public int
getSize()

Returns: maximum amount of decal objects this buffer can hold in memory

public void
initialize(int
Maximum size of decal objects to hold in memory
size
)

Initializes the batch with the given amount of decal objects the buffer is able to hold when full.

protected void
render()

Renders all decals to the buffer and flushes the buffer to the GL when full/done

private void
render(ShaderProgram shader, Array<Decal>
Decals to render
decals
)

Renders a group of vertices to the buffer, flushing them to GL when done/full

public void
setGroupStrategy(GroupStrategy
Group strategy to use
groupStrategy
)

Sets the GroupStrategy used

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_SIZEback to summary
private static final int DEFAULT_SIZE
groupListback to summary
private final SortedIntList<Array<Decal>> groupList
groupPoolback to summary
private final Pool<Array<Decal>> groupPool
groupStrategyback to summary
private GroupStrategy groupStrategy
meshback to summary
private Mesh mesh
usedGroupsback to summary
private final Array<Array<Decal>> usedGroups
verticesback to summary
private float[] vertices

Constructor Detail

DecalBatchback to summary
public DecalBatch(GroupStrategy groupStrategy)

Creates a new DecalBatch using the given GroupStrategy. The most commong strategy to use is a CameraGroupStrategy

DecalBatchback to summary
public DecalBatch(int size, GroupStrategy groupStrategy)

Method Detail

addback to summary
public void add(Decal decal)

Add a decal to the batch, marking it for later rendering

Parameters
decal:Decal

Decal to add for rendering

clearback to summary
protected void clear()

Remove all decals from batch

disposeback to summary
public void dispose()

Implements com.badlogic.gdx.utils.Disposable.dispose.

Frees up memory by dropping the buffer and underlying resources. If the batch is needed again after disposing it can be initialized again.

flushback to summary
public void flush()

Flush this batch sending all contained decals to GL. After flushing the batch is empty once again.

flushback to summary
protected void flush(ShaderProgram shader, int verticesPosition)

Flushes vertices[0,verticesPosition[ to GL verticesPosition % Decal.SIZE must equal 0

Parameters
verticesPosition:int

Amount of elements from the vertices array to flush

getSizeback to summary
public int getSize()
Returns:int

maximum amount of decal objects this buffer can hold in memory

initializeback to summary
public void initialize(int size)

Initializes the batch with the given amount of decal objects the buffer is able to hold when full.

Parameters
size:int

Maximum size of decal objects to hold in memory

renderback to summary
protected void render()

Renders all decals to the buffer and flushes the buffer to the GL when full/done

renderback to summary
private void render(ShaderProgram shader, Array<Decal> decals)

Renders a group of vertices to the buffer, flushing them to GL when done/full

Parameters
decals:Array<Decal>

Decals to render

setGroupStrategyback to summary
public void setGroupStrategy(GroupStrategy groupStrategy)

Sets the GroupStrategy used

Parameters
groupStrategy:GroupStrategy

Group strategy to use