Class TextureArrayCpuPolygonSpriteBatch
- All Implemented Interfaces:
com.badlogic.gdx.graphics.g2d.Batch,com.badlogic.gdx.graphics.g2d.PolygonBatch,com.badlogic.gdx.utils.Disposable
PolygonSpriteBatch, the transformation matrix optimizations of a CpuSpriteBatch, and optimizations
for Batches that switch between Textures frequently. This can be useful when you need any of: PolygonSpriteBatch
methods for drawing PolygonSprites, scene2d Groups with transform enabled, and/or drawing from multiple Textures.
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. It also uses CpuSpriteBatch's optimizations that avoid flushing when the transform matrix changes.
Use this Batch if you frequently utilize more than a single texture between calling TextureArrayPolygonSpriteBatch.begin() and TextureArrayPolygonSpriteBatch.end(). An
example would be if your Atlas is spread over multiple Textures or if you draw with individual Textures. This can be
a good "default" Batch implementation if you expect to use multiple Textures often, or use scene2d Groups often. In
TextraTypist, typically each Font has its own large Texture, and if you use emoji or icons, those typically use a
different large Texture. Switching between them has a performance cost, which is essentially eliminated by this
Batch. There is more logic in this Batch, and each vertex needs slightly more data, which counterbalances the
performance gains from more efficient Texture swaps. If you only use one Texture and don't use Groups where transform
is enabled, this Batch is expected to perform somewhat worse than a SpriteBatch. Using many Textures or using Group
transformation makes this perform relatively better than SpriteBatch in those cases. This is also a
PolygonSpriteBatch (and it extends PolygonSpriteBatch), which makes it suitable
for Spine animations.
Taken from Hyperlap2D's GitHub repo. Originally licensed under Apache 2.0, like TextraTypist and libGDX.
- See Also:
-
Field Summary
Fields inherited from class com.github.tommyettinger.textra.TextureArrayPolygonSpriteBatch
colorPacked, maxTrianglesInBatch, renderCalls, TEXTURE_INDEX_ATTRIBUTE, totalRenderCallsFields 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 CpuSpriteBatch with a size of 2000 and the default shader.TextureArrayCpuPolygonSpriteBatch(int size) Constructs a CpuSpriteBatch with the default shader.TextureArrayCpuPolygonSpriteBatch(int size, com.badlogic.gdx.graphics.glutils.ShaderProgram defaultShader) Constructs a CpuSpriteBatch with a custom shader. -
Method Summary
Modifier and TypeMethodDescriptionvoiddraw(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) Draws the polygon using the given vertices and triangles.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) voidFlushes the batch and realigns the real matrix on the GPU.com.badlogic.gdx.math.Matrix4voidsetTransformMatrix(com.badlogic.gdx.math.Affine2 transform) Sets the transform matrix to be used by this Batch.voidsetTransformMatrix(com.badlogic.gdx.math.Matrix4 transform) Sets the transform matrix to be used by this Batch.Methods inherited from class com.github.tommyettinger.textra.TextureArrayPolygonSpriteBatch
activateTexture, begin, createDefaultShader, disableBlending, dispose, enableBlending, end, flush, getBlendDstFunc, getBlendDstFuncAlpha, getBlendSrcFunc, getBlendSrcFuncAlpha, getMaxTextureUnits, getPackedColor, getProjectionMatrix, getShader, getTextureLFUCapacity, getTextureLFUSize, getTextureLFUSwaps, isBlendingEnabled, isDrawing, setBlendFunction, setBlendFunctionSeparate, setProjectionMatrix, setShader, setupMatrices, switchTextureMethods inherited from class com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
getColor, setColor, setColor, setPackedColor
-
Constructor Details
-
TextureArrayCpuPolygonSpriteBatch
public TextureArrayCpuPolygonSpriteBatch()Constructs a CpuSpriteBatch with a size of 2000 and the default shader.- See Also:
-
TextureArrayCpuPolygonSpriteBatch
public TextureArrayCpuPolygonSpriteBatch(int size) Constructs a CpuSpriteBatch with the default shader.- See Also:
-
TextureArrayCpuPolygonSpriteBatch
public TextureArrayCpuPolygonSpriteBatch(int size, com.badlogic.gdx.graphics.glutils.ShaderProgram defaultShader) Constructs a CpuSpriteBatch with a custom shader.- See Also:
-
-
Method Details
-
flushAndSyncTransformMatrix
public void flushAndSyncTransformMatrix()Flushes the batch and realigns the real matrix on the GPU. Subsequent draws won't need adjustment and will be slightly faster as long as the transform matrix is not
changed.Note: The real transform matrix must be invertible. If a singular matrix is detected, GdxRuntimeException will be thrown.
- See Also:
-
getTransformMatrix
public com.badlogic.gdx.math.Matrix4 getTransformMatrix()- Specified by:
getTransformMatrixin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
getTransformMatrixin classTextureArrayPolygonSpriteBatch
-
setTransformMatrix
public void setTransformMatrix(com.badlogic.gdx.math.Matrix4 transform) Sets the transform matrix to be used by this Batch. Even if this is called inside aTextureArrayPolygonSpriteBatch.begin()/TextureArrayPolygonSpriteBatch.end()block, the current batch is not flushed to the GPU. Instead, for every subsequent draw() the vertices will be transformed on the CPU to match the original batch matrix. This adjustment must be performed until the matrices are realigned by restoring the original matrix, or by callingflushAndSyncTransformMatrix().- Specified by:
setTransformMatrixin interfacecom.badlogic.gdx.graphics.g2d.Batch- Overrides:
setTransformMatrixin classTextureArrayPolygonSpriteBatch
-
setTransformMatrix
public void setTransformMatrix(com.badlogic.gdx.math.Affine2 transform) Sets the transform matrix to be used by this Batch. Even if this is called inside aTextureArrayPolygonSpriteBatch.begin()/TextureArrayPolygonSpriteBatch.end()block, the current batch is not flushed to the GPU. Instead, for every subsequent draw() the vertices will be transformed on the CPU to match the original batch matrix. This adjustment must be performed until the matrices are realigned by restoring the original matrix, or by callingflushAndSyncTransformMatrix()orTextureArrayPolygonSpriteBatch.end(). -
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 classTextureArrayPolygonSpriteBatch
-
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 classTextureArrayPolygonSpriteBatch
-
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 classTextureArrayPolygonSpriteBatch
-
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 classTextureArrayPolygonSpriteBatch
-
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 classTextureArrayPolygonSpriteBatch
-
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 classTextureArrayPolygonSpriteBatch
-
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 classTextureArrayPolygonSpriteBatch
-
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 classTextureArrayPolygonSpriteBatch
-
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 classTextureArrayPolygonSpriteBatch
-
draw
public void draw(com.badlogic.gdx.graphics.Texture texture, float[] polygonVertices, int verticesOffset, int verticesCount, short[] polygonTriangles, int trianglesOffset, int trianglesCount) Draws the polygon using the given vertices and triangles. Each vertex must be made up of 5 elements in this order: x, y, color, u, v.- Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.PolygonBatch- Overrides:
drawin classTextureArrayPolygonSpriteBatch
-
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 classTextureArrayPolygonSpriteBatch
-
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 classTextureArrayPolygonSpriteBatch
-
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 classTextureArrayPolygonSpriteBatch
-
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 classTextureArrayPolygonSpriteBatch
-
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 classTextureArrayPolygonSpriteBatch
-
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 classTextureArrayPolygonSpriteBatch
-