public abstract class Quad extends Batchable.FixedSizeBatchable implements com.badlogic.gdx.utils.Pool.Poolable
By default, one texture is used. It may be subclassed to create a Batchable class that supports zero or multiple textures and
additional attributes--see getNumberOfTextures() and addVertexAttributes().
A Quad has fixed size, so its indices do not need to be recalculated for every draw call.
Batchable.FixedSizeBatchable| Modifier and Type | Field and Description |
|---|---|
float |
color |
int |
coordinatesRotation
The number of times the texture coordinates should be rotated clockwise by 90 degrees.
|
protected float |
height
Width and height must be set with
size(float, float). |
float |
originX |
float |
originY |
protected Region2D[] |
regions |
float |
scaleX |
float |
scaleY |
protected boolean |
sizeSet
Whether the width and height have been set since the last call to
refresh(). |
protected com.badlogic.gdx.graphics.GLTexture[] |
textures |
protected static float |
WHITE |
protected float |
width
Width and height must be set with
size(float, float). |
float |
x |
float |
y |
| Modifier | Constructor and Description |
|---|---|
protected |
Quad() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addVertexAttributes(com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.VertexAttribute> attributes)
A Batchable implementation calls this to populate a list of vertex attributes that will be used by the FlexBatch.
|
protected int |
apply(float[] vertices,
int vertexStartingIndex,
AttributeOffsets offsets,
int vertexSize)
Called by FlexBatch.
|
Quad |
color(com.badlogic.gdx.graphics.Color color) |
Quad |
color(float floatBits) |
Quad |
color(float r,
float g,
float b,
float a) |
Quad |
flip(boolean flipX,
boolean flipY)
Flips the UV region of the most recently applied texture.
|
Quad |
flipAll(boolean flipX,
boolean flipY)
Flips the texture region(s) from their current state.
|
protected int |
getNumberOfTextures() |
protected int |
getTrianglesPerBatchable() |
protected int |
getVerticesPerBatchable() |
protected abstract boolean |
isPosition3D()
Determines whether the position data has a Z component.
|
protected abstract boolean |
isTextureCoordinate3D()
Determines whether the texture coordinate data has a third component (for TextureArray layers).
|
Quad |
origin(float originX,
float originY)
Sets the center point for transformations (rotation and scale).
|
protected void |
populateTriangleIndices(short[] triangles)
Populate the fixed triangle array for the FlexBatch's mesh.
|
protected boolean |
prepareContext(RenderContextAccumulator renderContext,
int remainingVertices,
int remainingIndices)
Called before
Batchable.apply(float[], int, AttributeOffsets, int) to set render context states and texture bindings, and to
determine if a flush is necessary before this Batchable can be drawn. |
void |
refresh()
Resets the state and default parameters of the Batchable so it can be reused for an entirely new image.
|
Quad |
region(float u,
float v,
float u2,
float v2)
Sets the UV region of the most recently applied texture.
|
Quad |
regionTexels(int x,
int y,
int width,
int height)
Sets the UV region of the most recently applied texture, using texel units.
|
void |
reset()
Resets the state of the object and drops Texture references to prepare it for returning to a
Pool. |
Quad |
rotateCoordinates90(boolean clockwise)
Rotates the texture region(s) 90 degrees in place by rotating the texture coordinates.
|
Quad |
scale(float scaleX,
float scaleY) |
Quad |
size(float width,
float height) |
Quad |
texture(com.badlogic.gdx.graphics.GLTexture texture)
Sets the texture and sets the region to match the size of the texture.
|
Quad |
textureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion region)
Sets the texture region.
|
apply, prepareIndicesprepareSharedContextprotected final com.badlogic.gdx.graphics.GLTexture[] textures
protected final Region2D[] regions
public float x
public float y
public float color
public float originX
public float originY
public float scaleX
public float scaleY
protected float width
size(float, float). If they are not set, they default to the size of the first
texture region.protected float height
size(float, float). If they are not set, they default to the size of the first
texture region.protected boolean sizeSet
refresh(). If they have not been set, they will
be set to match the size of the first texture region when drawing occurs.public int coordinatesRotation
protected static final float WHITE
protected final void populateTriangleIndices(short[] triangles)
Batchable.FixedSizeBatchablepopulateTriangleIndices in class Batchable.FixedSizeBatchabletriangles - An array of triangle indices that, before this method returns, must be fully populated for drawing a
series of this Batchable type.protected final int getTrianglesPerBatchable()
getTrianglesPerBatchable in class Batchable.FixedSizeBatchableprotected final int getVerticesPerBatchable()
getVerticesPerBatchable in class Batchable.FixedSizeBatchableprotected void addVertexAttributes(com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.VertexAttribute> attributes)
BatchableaddVertexAttributes in class Batchableattributes - An array to which attributes can be added.protected int getNumberOfTextures()
getNumberOfTextures in class Batchableprotected abstract boolean isPosition3D()
Overriding this method will produce a subclass that is incompatible with a FlexBatch that was instantiated for the superclass type.
protected abstract boolean isTextureCoordinate3D()
Overriding this method will produce a subclass that is incompatible with a FlexBatch that was instantiated for the superclass type.
protected boolean prepareContext(RenderContextAccumulator renderContext, int remainingVertices, int remainingIndices)
BatchableBatchable.apply(float[], int, AttributeOffsets, int) to set render context states and texture bindings, and to
determine if a flush is necessary before this Batchable can be drawn.
Overriding this method may produce a subclass that is incompatible with a FlexBatch that was instantiated for the superclass
type.prepareContext in class BatchablerenderContext - The FlexBatch's manager of GL state changes and texture bindings. Pending state changes and texture
bindings can be made on this context, and the context will return whether the context is now changed, which means
a flush is required and this method needs to return true.remainingVertices - The number of vertices that can be drawn before the next flush is required.remainingIndices - The number of triangle indices that can be drawn before the next flush is required. This value is
undefined for Batchable.FixedSizeBatchable and should not be used or checked against.public void refresh()
Batchablepublic void reset()
Pool.reset in interface com.badlogic.gdx.utils.Pool.Poolablepublic Quad texture(com.badlogic.gdx.graphics.GLTexture texture)
textureRegion(TextureRegion) will sequentially set the textures in order.
This method must not be called in a Batchable that supports zero textures.
public Quad region(float u, float v, float u2, float v2)
texture(GLTexture) or textureRegion(TextureRegion). Note that TextureRegions have a Y-down coordinate
system for UVs.
This method must not be called in a Batchable that supports zero textures.
u - The left side of the region.v - The top side of the region.u2 - The right side of the region.v2 - The bottom side of the region.public Quad regionTexels(int x, int y, int width, int height)
texture(GLTexture) or textureRegion(TextureRegion). Note that
TextureRegions have a Y-down coordinate system for UVs.
This method must not be called in a Batchable that supports zero textures.
x - The left side of the region.y - The top side of the region.width - The width of the region. May be negative to flip the region in place.height - The height of the region. May be negative to flip the region in place.public Quad textureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion region)
texture(GLTexture) will sequentially set the textures in order.
This method must not be called in a Batchable that supports zero textures.
public Quad flip(boolean flipX, boolean flipY)
texture(GLTexture) or textureRegion(TextureRegion).public Quad flipAll(boolean flipX, boolean flipY)
public Quad size(float width, float height)
public Quad origin(float originX, float originY)
Quad2D, this is relative to the bottom left
corner of the texture region. For Quad3D, this is relative to the center of the texture region and is in the local
coordinate system.public Quad rotateCoordinates90(boolean clockwise)
public Quad color(com.badlogic.gdx.graphics.Color color)
public Quad color(float r, float g, float b, float a)
public Quad color(float floatBits)
public Quad scale(float scaleX, float scaleY)
protected int apply(float[] vertices,
int vertexStartingIndex,
AttributeOffsets offsets,
int vertexSize)
Batchableapply in class Batchableoffsets - The offsets of the vertex attributes.vertexSize - The size of a vertex in floats.Batchable.FixedSizeBatchable, as it is
assumed to match Batchable.FixedSizeBatchable.getVerticesPerBatchable().