Package com.prineside.tdi2.utils
Class ParallelBatch
java.lang.Object
com.prineside.tdi2.utils.ParallelBatch
- All Implemented Interfaces:
com.badlogic.gdx.graphics.g2d.Batch,com.badlogic.gdx.utils.Disposable
Implementation of Batch which does not draw anything.
Instead it caches every call into its internal buffers and can replay all of the method calls into a regular Batch.
Can be used on a separate (not-rendering) thread. Should only be used from a single thread.
Not blocking.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic com.badlogic.gdx.graphics.Mesh.VertexDataTypeDeprecated.booleanstatic final float[]intThe maximum number of sprites rendered in one batch so far.intNumber of render calls since the lastbegin().intNumber 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 new SpriteBatch with a size of 1000, one buffer, and the default shader.ParallelBatch(int size) Constructs a SpriteBatch with one buffer and the default shader.ParallelBatch(int size, com.badlogic.gdx.graphics.glutils.ShaderProgram defaultShader) Constructs a new SpriteBatch. -
Method Summary
Modifier and TypeMethodDescriptionvoidbegin()Sets up the Batch for drawing.voidDisables blending for drawing sprites.voiddispose()Releases all resources of this object.voiddraw(com.badlogic.gdx.graphics.g2d.TextureRegion region, float x, float y) Draws a rectangle with the bottom left corner at x,y having the width and height of the region.voiddraw(com.badlogic.gdx.graphics.g2d.TextureRegion region, float x, float y, float width, float height) Draws a rectangle with the bottom left corner at x,y and stretching the region to cover the given width and 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) Draws a rectangle with the bottom left corner at x,y and stretching the region to cover the given width and 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, boolean clockwise) Draws a rectangle with the texture coordinates rotated 90 degrees.voiddraw(com.badlogic.gdx.graphics.g2d.TextureRegion region, float width, float height, com.badlogic.gdx.math.Affine2 transform) Draws a rectangle transformed by the given matrix.voiddraw(com.badlogic.gdx.graphics.Texture texture, float[] spriteVertices, int offset, int count) Draws a rectangle using the given vertices.voiddraw(com.badlogic.gdx.graphics.Texture texture, float x, float y) Draws a rectangle with the bottom left corner at x,y having the width and height of the texture.voiddraw(com.badlogic.gdx.graphics.Texture texture, float x, float y, float width, float height) Draws a rectangle with the bottom left corner at x,y and stretching the region to cover the given width and height.voiddraw(com.badlogic.gdx.graphics.Texture texture, float x, float y, float width, float height, float u, float v, float u2, float v2) Draws a rectangle with the bottom left corner at x,y having the given width and height in pixels.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) Draws a rectangle with the bottom left corner at x,y having the given width and height in pixels.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) Draws a rectangle with the bottom left corner at x,y having the given width and height in pixels.voiddraw(com.badlogic.gdx.graphics.Texture texture, float x, float y, int srcX, int srcY, int srcWidth, int srcHeight) Draws a rectangle with the bottom left corner at x,y having the given width and height in pixels.voidEnables blending for drawing sprites.voidend()Finishes off rendering.voidflush()Causes any pending sprites to be rendered, without ending the Batch.intintintintcom.badlogic.gdx.graphics.ColorgetColor()floatcom.badlogic.gdx.math.Matrix4Returns the current projection matrix.com.badlogic.gdx.graphics.glutils.ShaderProgramcom.badlogic.gdx.math.Matrix4Returns the current transform matrix.booleanbooleanvoidrender(com.badlogic.gdx.graphics.Mesh mesh) voidreset()voidsetBlendFunction(int srcFunc, int dstFunc) Sets the blending function to be used when rendering sprites.voidsetBlendFunctionSeparate(int srcFuncColor, int dstFuncColor, int srcFuncAlpha, int dstFuncAlpha) Sets separate (color/alpha) blending function to be used when rendering sprites.voidsetColor(float r, float g, float b, float a) voidsetColor(com.badlogic.gdx.graphics.Color tint) Sets the color used to tint images when they are added to the Batch.voidsetPackedColor(float packedColor) Sets the rendering color of this Batch, expanding the alpha from 0-254 to 0-255.voidsetProjectionMatrix(com.badlogic.gdx.math.Matrix4 projection) Sets the projection matrix to be used by this Batch.voidsetShader(com.badlogic.gdx.graphics.glutils.ShaderProgram shader) Sets the shader to be used in a GLES 2.0 environment.voidsetTransformMatrix(com.badlogic.gdx.math.Matrix4 transform) Sets the transform matrix to be used by this Batch.
-
Field Details
-
defaultVertexDataType
Deprecated. -
FLUSH_VERTICES
public static final float[] FLUSH_VERTICES -
drawing
public boolean drawing -
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. -
maxSpritesInBatch
public int maxSpritesInBatchThe maximum number of sprites rendered in one batch so far.
-
-
Constructor Details
-
ParallelBatch
public ParallelBatch()Constructs a new SpriteBatch with a size of 1000, one buffer, and the default shader.- See Also:
-
SpriteBatch(int, ShaderProgram)
-
ParallelBatch
public ParallelBatch(int size) Constructs a SpriteBatch with one buffer and the default shader.- See Also:
-
SpriteBatch(int, ShaderProgram)
-
ParallelBatch
public ParallelBatch(int size, com.badlogic.gdx.graphics.glutils.ShaderProgram defaultShader) Constructs a new SpriteBatch. 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 than the ones expect for shaders set with
setShader(ShaderProgram). See createDefaultShader().- Parameters:
size- The max number of sprites in a single batch. Max of 8191.defaultShader- The default shader to use. This is not owned by the SpriteBatch and must be disposed separately.
-
-
Method Details
-
reset
public void reset() -
render
public void render(com.badlogic.gdx.graphics.Mesh mesh) -
begin
public void begin()Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchSets up the Batch for drawing. This will disable depth buffer writing. It enables blending and texturing. If you have more texture units enabled than the first one you have to disable them before calling this. Uses a screen coordinate system by default where everything is given in pixels. You can specify your own projection and modelview matrices viaBatch.setProjectionMatrix(Matrix4)andBatch.setTransformMatrix(Matrix4).- Specified by:
beginin interfacecom.badlogic.gdx.graphics.g2d.Batch
-
end
public void end()Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchFinishes off rendering. Enables depth writes, disables blending and texturing. Must always be called after a call toBatch.begin()- Specified by:
endin interfacecom.badlogic.gdx.graphics.g2d.Batch
-
setColor
public void setColor(com.badlogic.gdx.graphics.Color tint) Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchSets the color used to tint images when they are added to the Batch. Default isColor.WHITE.- Specified by:
setColorin interfacecom.badlogic.gdx.graphics.g2d.Batch
-
setColor
public void setColor(float r, float g, float b, float a) - Specified by:
setColorin interfacecom.badlogic.gdx.graphics.g2d.Batch- See Also:
-
Batch.setColor(Color)
-
getColor
public com.badlogic.gdx.graphics.Color getColor()- Specified by:
getColorin interfacecom.badlogic.gdx.graphics.g2d.Batch- Returns:
- the rendering color of this Batch. If the returned instance is manipulated,
Batch.setColor(Color)must be called afterward.
-
setPackedColor
public void setPackedColor(float packedColor) Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchSets the rendering color of this Batch, expanding the alpha from 0-254 to 0-255.- Specified by:
setPackedColorin interfacecom.badlogic.gdx.graphics.g2d.Batch- See Also:
-
Batch.setColor(Color)Color.toFloatBits()
-
getPackedColor
public float getPackedColor()- Specified by:
getPackedColorin interfacecom.badlogic.gdx.graphics.g2d.Batch- Returns:
- the rendering color of this Batch in vertex format (alpha compressed to 0-254)
- See Also:
-
Color.toFloatBits()
-
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) Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchDraws a rectangle with the bottom left corner at x,y having the given width and height in pixels. The rectangle is offset by originX, originY relative to the origin. Scale specifies the scaling factor by which the rectangle should be scaled around originX, originY. Rotation specifies the angle of counter clockwise rotation of the rectangle around originX, originY. The portion of theTexturegiven by srcX, srcY and srcWidth, srcHeight is used. These coordinates and sizes are given in texels. FlipX and flipY specify whether the texture portion should be flipped horizontally or vertically.- Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batchx- the x-coordinate in screen spacey- the y-coordinate in screen spaceoriginX- the x-coordinate of the scaling and rotation origin relative to the screen space coordinatesoriginY- the y-coordinate of the scaling and rotation origin relative to the screen space coordinateswidth- the width in pixelsheight- the height in pixelsscaleX- the scale of the rectangle around originX/originY in xscaleY- the scale of the rectangle around originX/originY in yrotation- the angle of counter clockwise rotation of the rectangle around originX/originYsrcX- the x-coordinate in texel spacesrcY- the y-coordinate in texel spacesrcWidth- the source with in texelssrcHeight- the source height in texelsflipX- whether to flip the sprite horizontallyflipY- whether to flip the sprite vertically
-
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) Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchDraws a rectangle with the bottom left corner at x,y having the given width and height in pixels. The portion of theTexturegiven by srcX, srcY and srcWidth, srcHeight is used. These coordinates and sizes are given in texels. FlipX and flipY specify whether the texture portion should be flipped horizontally or vertically.- Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batchx- the x-coordinate in screen spacey- the y-coordinate in screen spacewidth- the width in pixelsheight- the height in pixelssrcX- the x-coordinate in texel spacesrcY- the y-coordinate in texel spacesrcWidth- the source with in texelssrcHeight- the source height in texelsflipX- whether to flip the sprite horizontallyflipY- whether to flip the sprite vertically
-
draw
public void draw(com.badlogic.gdx.graphics.Texture texture, float x, float y, int srcX, int srcY, int srcWidth, int srcHeight) Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchDraws a rectangle with the bottom left corner at x,y having the given width and height in pixels. The portion of theTexturegiven by srcX, srcY and srcWidth, srcHeight are used. These coordinates and sizes are given in texels.- Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batchx- the x-coordinate in screen spacey- the y-coordinate in screen spacesrcX- the x-coordinate in texel spacesrcY- the y-coordinate in texel spacesrcWidth- the source with in texelssrcHeight- the source height in texels
-
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) Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchDraws a rectangle with the bottom left corner at x,y having the given width and height in pixels. The portion of theTexturegiven by u, v and u2, v2 are used. These coordinates and sizes are given in texture size percentage. The rectangle will have the given tintColor.- Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batchx- the x-coordinate in screen spacey- the y-coordinate in screen spacewidth- the width in pixelsheight- the height in pixels
-
draw
public void draw(com.badlogic.gdx.graphics.Texture texture, float x, float y) Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchDraws a rectangle with the bottom left corner at x,y having the width and height of the texture.- Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batchx- the x-coordinate in screen spacey- the y-coordinate in screen space
-
draw
public void draw(com.badlogic.gdx.graphics.Texture texture, float x, float y, float width, float height) Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchDraws a rectangle with the bottom left corner at x,y and stretching the region to cover the given width and height.- Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batch
-
draw
public void draw(com.badlogic.gdx.graphics.Texture texture, float[] spriteVertices, int offset, int count) Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchDraws a rectangle using the given vertices. There must be 4 vertices, each made up of 5 elements in this order: x, y, color, u, v. TheBatch.getColor()from the Batch is not applied.- Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batch
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.TextureRegion region, float x, float y) Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchDraws a rectangle with the bottom left corner at x,y having the width and height of the region.- Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batch
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.TextureRegion region, float x, float y, float width, float height) Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchDraws a rectangle with the bottom left corner at x,y and stretching the region to cover the given width and height.- Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batch
-
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) Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchDraws a rectangle with the bottom left corner at x,y and stretching the region to cover the given width and height. The rectangle is offset by originX, originY relative to the origin. Scale specifies the scaling factor by which the rectangle should be scaled around originX, originY. Rotation specifies the angle of counter clockwise rotation of the rectangle around originX, originY.- Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batch
-
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) Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchDraws a rectangle with the texture coordinates rotated 90 degrees. The bottom left corner at x,y and stretching the region to cover the given width and height. The rectangle is offset by originX, originY relative to the origin. Scale specifies the scaling factor by which the rectangle should be scaled around originX, originY. Rotation specifies the angle of counter clockwise rotation of the rectangle around originX, originY.- Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batchclockwise- If true, the texture coordinates are rotated 90 degrees clockwise. If false, they are rotated 90 degrees counter clockwise.
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.TextureRegion region, float width, float height, com.badlogic.gdx.math.Affine2 transform) Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchDraws a rectangle transformed by the given matrix.- Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batch
-
flush
public void flush()Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchCauses any pending sprites to be rendered, without ending the Batch.- Specified by:
flushin interfacecom.badlogic.gdx.graphics.g2d.Batch
-
disableBlending
public void disableBlending()Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchDisables blending for drawing sprites. Calling this withinBatch.begin()/Batch.end()will flush the batch.- Specified by:
disableBlendingin interfacecom.badlogic.gdx.graphics.g2d.Batch
-
enableBlending
public void enableBlending()Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchEnables blending for drawing sprites. Calling this withinBatch.begin()/Batch.end()will flush the batch.- Specified by:
enableBlendingin interfacecom.badlogic.gdx.graphics.g2d.Batch
-
setBlendFunction
public void setBlendFunction(int srcFunc, int dstFunc) Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchSets the blending function to be used when rendering sprites.- Specified by:
setBlendFunctionin interfacecom.badlogic.gdx.graphics.g2d.Batch- Parameters:
srcFunc- the source function, e.g. GL20.GL_SRC_ALPHA. If set to -1, Batch won't change the blending function.dstFunc- the destination function, e.g. GL20.GL_ONE_MINUS_SRC_ALPHA
-
setBlendFunctionSeparate
public void setBlendFunctionSeparate(int srcFuncColor, int dstFuncColor, int srcFuncAlpha, int dstFuncAlpha) Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchSets separate (color/alpha) blending function to be used when rendering sprites.- Specified by:
setBlendFunctionSeparatein interfacecom.badlogic.gdx.graphics.g2d.Batch- Parameters:
srcFuncColor- the source color function, e.g. GL20.GL_SRC_ALPHA. If set to -1, Batch won't change the blending function.dstFuncColor- the destination color function, e.g. GL20.GL_ONE_MINUS_SRC_ALPHA.srcFuncAlpha- the source alpha function, e.g. GL20.GL_SRC_ALPHA.dstFuncAlpha- the destination alpha function, e.g. GL20.GL_ONE_MINUS_SRC_ALPHA.
-
getBlendSrcFunc
public int getBlendSrcFunc()- Specified by:
getBlendSrcFuncin interfacecom.badlogic.gdx.graphics.g2d.Batch
-
getBlendDstFunc
public int getBlendDstFunc()- Specified by:
getBlendDstFuncin interfacecom.badlogic.gdx.graphics.g2d.Batch
-
getBlendSrcFuncAlpha
public int getBlendSrcFuncAlpha()- Specified by:
getBlendSrcFuncAlphain interfacecom.badlogic.gdx.graphics.g2d.Batch
-
getBlendDstFuncAlpha
public int getBlendDstFuncAlpha()- Specified by:
getBlendDstFuncAlphain interfacecom.badlogic.gdx.graphics.g2d.Batch
-
dispose
public void dispose()Description copied from interface:com.badlogic.gdx.utils.DisposableReleases all resources of this object.- Specified by:
disposein interfacecom.badlogic.gdx.utils.Disposable
-
getProjectionMatrix
public com.badlogic.gdx.math.Matrix4 getProjectionMatrix()Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchReturns the current projection matrix. Changing this withinBatch.begin()/Batch.end()results in undefined behaviour.- Specified by:
getProjectionMatrixin interfacecom.badlogic.gdx.graphics.g2d.Batch
-
getTransformMatrix
public com.badlogic.gdx.math.Matrix4 getTransformMatrix()Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchReturns the current transform matrix. Changing this withinBatch.begin()/Batch.end()results in undefined behaviour.- Specified by:
getTransformMatrixin interfacecom.badlogic.gdx.graphics.g2d.Batch
-
setProjectionMatrix
public void setProjectionMatrix(com.badlogic.gdx.math.Matrix4 projection) Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchSets the projection matrix to be used by this Batch. If this is called inside aBatch.begin()/Batch.end()block, the current batch is flushed to the gpu.- Specified by:
setProjectionMatrixin interfacecom.badlogic.gdx.graphics.g2d.Batch
-
setTransformMatrix
public void setTransformMatrix(com.badlogic.gdx.math.Matrix4 transform) Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchSets the transform matrix to be used by this Batch.- Specified by:
setTransformMatrixin interfacecom.badlogic.gdx.graphics.g2d.Batch
-
setShader
public void setShader(com.badlogic.gdx.graphics.glutils.ShaderProgram shader) Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchSets the shader to be used in a GLES 2.0 environment. Vertex position attribute is called "a_position", the texture coordinates attribute is called "a_texCoord0", the color attribute is called "a_color". SeeShaderProgram.POSITION_ATTRIBUTE,ShaderProgram.COLOR_ATTRIBUTEandShaderProgram.TEXCOORD_ATTRIBUTEwhich gets "0" appended to indicate the use of the first texture unit. The combined transform and projection matrx is uploaded via a mat4 uniform called "u_projTrans". The texture sampler is passed via a uniform called "u_texture".Call this method with a null argument to use the default shader.
This method will flush the batch before setting the new shader, you can call it in between
Batch.begin()andBatch.end().- Specified by:
setShaderin interfacecom.badlogic.gdx.graphics.g2d.Batch- Parameters:
shader- theShaderProgramor null to use the default shader.
-
getShader
public com.badlogic.gdx.graphics.glutils.ShaderProgram getShader()- Specified by:
getShaderin interfacecom.badlogic.gdx.graphics.g2d.Batch- Returns:
- the current
ShaderProgramset byBatch.setShader(ShaderProgram)or the defaultShader
-
isBlendingEnabled
public boolean isBlendingEnabled()- Specified by:
isBlendingEnabledin interfacecom.badlogic.gdx.graphics.g2d.Batch- Returns:
- true if blending for sprites is enabled
-
isDrawing
public boolean isDrawing()- Specified by:
isDrawingin interfacecom.badlogic.gdx.graphics.g2d.Batch- Returns:
- true if currently between begin and end.
-