Class TextureArrayPolygonSpriteBatch
- All Implemented Interfaces:
com.badlogic.gdx.graphics.g2d.Batch,com.badlogic.gdx.graphics.g2d.PolygonBatch,com.badlogic.gdx.utils.Disposable
- Direct Known Subclasses:
TextureArrayCpuPolygonSpriteBatch
PolygonSpriteBatch and optimizations for Batches that switch between Textures frequently. This can be useful
when you need either PolygonSpriteBatch methods for drawing PolygonSprites or drawing from multiple Textures. If you
use transform matrices, such as from scene2d Groups with transform enabled, you should prefer the subclass
TextureArrayCpuPolygonSpriteBatch instead.
If you're using this Batch to draw Fonts with a non-STANDARD Font.DistanceFieldType, you should read
the documentation for TextureArrayShaders and use its TextureArrayShaders.initializeTextureArrayShaders()
method after creating this Batch, but before using any KnownFonts methods.
This is an optimized version of the PolygonSpriteBatch that maintains an LFU texture-cache to combine draw calls with different textures effectively.
Use this Batch if you frequently utilize more than a single texture between calling begin() and
end(). An example would be if your Atlas is spread over multiple Textures or if you draw with individual
Textures. This extends PolygonSpriteBatch), which makes it suitable for Spine
animations. Consider using TextureArrayCpuPolygonSpriteBatch instead, which may perform better in GUIs.
Taken from Hyperlap2D's GitHub repo. Originally licensed under Apache 2.0, like TextraTypist and libGDX. The tint field, which modified the Batch color, has been removed because it was unused in TextraTypist.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected floatintThe maximum number of triangles rendered in one batch so far.intNumber of render calls since the lastbegin().static final StringintNumber of rendering calls, ever.Fields inherited from interface com.badlogic.gdx.graphics.g2d.Batch
C1, C2, C3, C4, U1, U2, U3, U4, V1, V2, V3, V4, X1, X2, X3, X4, Y1, Y2, Y3, Y4 -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a TextureArrayPolygonSpriteBatch with the default shader, 2000 vertices, and 4000 triangles.TextureArrayPolygonSpriteBatch(int size) Constructs a TextureArrayPolygonSpriteBatch with the default shader, size vertices, and size * 2 triangles.TextureArrayPolygonSpriteBatch(int maxVertices, int maxTriangles, com.badlogic.gdx.graphics.glutils.ShaderProgram defaultShader) Constructs a new PolygonSpriteBatch.TextureArrayPolygonSpriteBatch(int size, com.badlogic.gdx.graphics.glutils.ShaderProgram defaultShader) Constructs a TextureArrayPolygonSpriteBatch with the specified shader, size vertices and size * 2 triangles. -
Method Summary
Modifier and TypeMethodDescriptionprotected intactivateTexture(com.badlogic.gdx.graphics.Texture texture) Assigns Texture units and manages the LFU cache.voidbegin()static com.badlogic.gdx.graphics.glutils.ShaderProgramvoidvoiddispose()voiddraw(com.badlogic.gdx.graphics.g2d.PolygonRegion region, float x, float y) voiddraw(com.badlogic.gdx.graphics.g2d.PolygonRegion region, float x, float y, float width, float height) voiddraw(com.badlogic.gdx.graphics.g2d.PolygonRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation) voiddraw(com.badlogic.gdx.graphics.g2d.TextureRegion region, float x, float y) voiddraw(com.badlogic.gdx.graphics.g2d.TextureRegion region, float x, float y, float width, float height) voiddraw(com.badlogic.gdx.graphics.g2d.TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation) voiddraw(com.badlogic.gdx.graphics.g2d.TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation, boolean clockwise) voiddraw(com.badlogic.gdx.graphics.g2d.TextureRegion region, float width, float height, com.badlogic.gdx.math.Affine2 transform) voiddraw(com.badlogic.gdx.graphics.Texture texture, float[] spriteVertices, int offset, int count) voiddraw(com.badlogic.gdx.graphics.Texture texture, float[] polygonVertices, int verticesOffset, int verticesCount, short[] polygonTriangles, int trianglesOffset, int trianglesCount) voiddraw(com.badlogic.gdx.graphics.Texture texture, float x, float y) voiddraw(com.badlogic.gdx.graphics.Texture texture, float x, float y, float width, float height) voiddraw(com.badlogic.gdx.graphics.Texture texture, float x, float y, float width, float height, float u, float v, float u2, float v2) voiddraw(com.badlogic.gdx.graphics.Texture texture, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation, int srcX, int srcY, int srcWidth, int srcHeight, boolean flipX, boolean flipY) voiddraw(com.badlogic.gdx.graphics.Texture texture, float x, float y, float width, float height, int srcX, int srcY, int srcWidth, int srcHeight, boolean flipX, boolean flipY) voiddraw(com.badlogic.gdx.graphics.Texture texture, float x, float y, int srcX, int srcY, int srcWidth, int srcHeight) voidvoidend()voidflush()intintintintstatic intQueries the number of supported textures in a texture array by trying to create the default shader.
The first call of this method is very expensive, after that it simply returns a cached value.floatcom.badlogic.gdx.math.Matrix4com.badlogic.gdx.graphics.glutils.ShaderProgramintintintcom.badlogic.gdx.math.Matrix4booleanbooleanvoidsetBlendFunction(int srcFunc, int dstFunc) voidsetBlendFunctionSeparate(int srcFuncColor, int dstFuncColor, int srcFuncAlpha, int dstFuncAlpha) voidsetProjectionMatrix(com.badlogic.gdx.math.Matrix4 projection) voidsetShader(com.badlogic.gdx.graphics.glutils.ShaderProgram shader) voidsetTransformMatrix(com.badlogic.gdx.math.Matrix4 transform) protected voidprotected voidswitchTexture(com.badlogic.gdx.graphics.Texture texture) Methods inherited from class com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
getColor, setColor, setColor, setPackedColor
-
Field Details
-
TEXTURE_INDEX_ATTRIBUTE
- See Also:
-
colorPacked
protected float colorPacked -
renderCalls
public int renderCallsNumber of render calls since the lastbegin(). -
totalRenderCalls
public int totalRenderCallsNumber of rendering calls, ever. Will not be reset unless set manually. -
maxTrianglesInBatch
public int maxTrianglesInBatchThe maximum number of triangles rendered in one batch so far.
-
-
Constructor Details
-
TextureArrayPolygonSpriteBatch
public TextureArrayPolygonSpriteBatch()Constructs a TextureArrayPolygonSpriteBatch with the default shader, 2000 vertices, and 4000 triangles.- See Also:
-
TextureArrayPolygonSpriteBatch
public TextureArrayPolygonSpriteBatch(int size) Constructs a TextureArrayPolygonSpriteBatch with the default shader, size vertices, and size * 2 triangles.- Parameters:
size- The max number of vertices and number of triangles in a single batch. Max of 32767.- See Also:
-
TextureArrayPolygonSpriteBatch
public TextureArrayPolygonSpriteBatch(int size, com.badlogic.gdx.graphics.glutils.ShaderProgram defaultShader) Constructs a TextureArrayPolygonSpriteBatch with the specified shader, size vertices and size * 2 triangles.- Parameters:
size- The max number of vertices and number of triangles in a single batch. Max of 32767.- See Also:
-
TextureArrayPolygonSpriteBatch
public TextureArrayPolygonSpriteBatch(int maxVertices, int maxTriangles, com.badlogic.gdx.graphics.glutils.ShaderProgram defaultShader) Constructs a new PolygonSpriteBatch. Sets the projection matrix to an orthographic projection with y-axis point upwards, x-axis point to the right and the origin being in the bottom left corner of the screen. The projection will be pixel perfect with respect to the current screen resolution.The defaultShader specifies the shader to use. Note that the names for uniforms for this default shader are different from the ones expect for shaders set with
setShader(ShaderProgram). SeeSpriteBatch.createDefaultShader().- Parameters:
maxVertices- The max number of vertices in a single batch. Max of 32767.maxTriangles- The max number of triangles in a single batch.defaultShader- The default shader to use. This is not owned by the PolygonSpriteBatch and must be disposed separately. May be null to use the default shader.
-
-
Method Details
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.PolygonRegion region, float x, float y) - Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.PolygonBatch- Overrides:
drawin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.PolygonRegion region, float x, float y, float width, float height) - Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.PolygonBatch- Overrides:
drawin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.PolygonRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation) - Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.PolygonBatch- Overrides:
drawin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
draw
public void draw(com.badlogic.gdx.graphics.Texture texture, float[] polygonVertices, int verticesOffset, int verticesCount, short[] polygonTriangles, int trianglesOffset, int trianglesCount) - Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.PolygonBatch- Overrides:
drawin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
draw
public void draw(com.badlogic.gdx.graphics.Texture texture, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation, int srcX, int srcY, int srcWidth, int srcHeight, boolean flipX, boolean flipY) - Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
drawin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
draw
public void draw(com.badlogic.gdx.graphics.Texture texture, float x, float y, float width, float height, int srcX, int srcY, int srcWidth, int srcHeight, boolean flipX, boolean flipY) - Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
drawin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
draw
public void draw(com.badlogic.gdx.graphics.Texture texture, float x, float y, int srcX, int srcY, int srcWidth, int srcHeight) - Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
drawin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
draw
public void draw(com.badlogic.gdx.graphics.Texture texture, float x, float y, float width, float height, float u, float v, float u2, float v2) - Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
drawin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
draw
public void draw(com.badlogic.gdx.graphics.Texture texture, float x, float y) - Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
drawin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
draw
public void draw(com.badlogic.gdx.graphics.Texture texture, float x, float y, float width, float height) - Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
drawin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
draw
public void draw(com.badlogic.gdx.graphics.Texture texture, float[] spriteVertices, int offset, int count) - Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
drawin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.TextureRegion region, float x, float y) - Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
drawin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.TextureRegion region, float x, float y, float width, float height) - Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
drawin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation) - Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
drawin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation, boolean clockwise) - Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
drawin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.TextureRegion region, float width, float height, com.badlogic.gdx.math.Affine2 transform) - Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
drawin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
begin
public void begin()- Specified by:
beginin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
beginin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
end
public void end()- Specified by:
endin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
endin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
getPackedColor
public float getPackedColor()- Specified by:
getPackedColorin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
getPackedColorin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
getTextureLFUSwaps
public int getTextureLFUSwaps()- Returns:
- The number of texture swaps the LFU cache performed since calling
begin().
-
getTextureLFUSize
public int getTextureLFUSize()- Returns:
- The current number of textures in the LFU cache. Gets reset when calling
begin().
-
getTextureLFUCapacity
public int getTextureLFUCapacity()- Returns:
- The maximum number of textures that the LFU cache can hold. This limit is imposed by the driver.
-
disableBlending
public void disableBlending()- Specified by:
disableBlendingin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
disableBlendingin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
enableBlending
public void enableBlending()- Specified by:
enableBlendingin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
enableBlendingin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
setBlendFunction
public void setBlendFunction(int srcFunc, int dstFunc) - Specified by:
setBlendFunctionin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
setBlendFunctionin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
setBlendFunctionSeparate
public void setBlendFunctionSeparate(int srcFuncColor, int dstFuncColor, int srcFuncAlpha, int dstFuncAlpha) - Specified by:
setBlendFunctionSeparatein interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
setBlendFunctionSeparatein classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
getBlendSrcFunc
public int getBlendSrcFunc()- Specified by:
getBlendSrcFuncin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
getBlendSrcFuncin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
getBlendDstFunc
public int getBlendDstFunc()- Specified by:
getBlendDstFuncin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
getBlendDstFuncin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
getBlendSrcFuncAlpha
public int getBlendSrcFuncAlpha()- Specified by:
getBlendSrcFuncAlphain interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
getBlendSrcFuncAlphain classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
getBlendDstFuncAlpha
public int getBlendDstFuncAlpha()- Specified by:
getBlendDstFuncAlphain interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
getBlendDstFuncAlphain classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
dispose
public void dispose()- Specified by:
disposein interfacecom.badlogic.gdx.utils.Disposable- Overrides:
disposein classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
getProjectionMatrix
public com.badlogic.gdx.math.Matrix4 getProjectionMatrix()- Specified by:
getProjectionMatrixin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
getProjectionMatrixin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
getTransformMatrix
public com.badlogic.gdx.math.Matrix4 getTransformMatrix()- Specified by:
getTransformMatrixin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
getTransformMatrixin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
setProjectionMatrix
public void setProjectionMatrix(com.badlogic.gdx.math.Matrix4 projection) - Specified by:
setProjectionMatrixin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
setProjectionMatrixin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
setTransformMatrix
public void setTransformMatrix(com.badlogic.gdx.math.Matrix4 transform) - Specified by:
setTransformMatrixin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
setTransformMatrixin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
flush
public void flush()- Specified by:
flushin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
flushin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
setupMatrices
protected void setupMatrices()- Overrides:
setupMatricesin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
activateTexture
protected int activateTexture(com.badlogic.gdx.graphics.Texture texture) Assigns Texture units and manages the LFU cache.- Parameters:
texture- The texture that shall be loaded into the cache, if it is not already loaded.- Returns:
- The texture slot that has been allocated to the selected texture
-
setShader
public void setShader(com.badlogic.gdx.graphics.glutils.ShaderProgram shader) - Specified by:
setShaderin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
setShaderin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
getShader
public com.badlogic.gdx.graphics.glutils.ShaderProgram getShader()- Specified by:
getShaderin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
getShaderin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
isBlendingEnabled
public boolean isBlendingEnabled()- Specified by:
isBlendingEnabledin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
isBlendingEnabledin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
isDrawing
public boolean isDrawing()- Specified by:
isDrawingin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
isDrawingin classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-
getMaxTextureUnits
public static int getMaxTextureUnits()Queries the number of supported textures in a texture array by trying to create the default shader.
The first call of this method is very expensive, after that it simply returns a cached value.- Returns:
- the number of supported textures in a texture array or zero if this feature is unsupported on this device.
-
createDefaultShader
public static com.badlogic.gdx.graphics.glutils.ShaderProgram createDefaultShader() -
switchTexture
protected void switchTexture(com.badlogic.gdx.graphics.Texture texture) - Overrides:
switchTexturein classcom.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
-