public class FilterBatch
extends java.lang.Object
implements com.badlogic.gdx.graphics.g2d.Batch
SpriteBatch
that filters any colors used to tint text
or images using a FloatFilter
. The filter may have an effect on speed in some cases, but even moderately
complex filters like FloatFilters.YCbCrFilter
seem to perform perfectly well, spiking at above 1000 FPS on
SparseDemo with a filter that changes parameters. This class should be preferred over SpriteBatch when using
SquidLib's style of frequently changing the Batch color; as of libGDX 1.9.9, SpriteBatch is somewhat slower than
FilterBatch when FilterBatch is using the default FloatFilters.identityFilter
. This is because 1.9.9 changed
SpriteBatch to do more work when setting a color, and FilterBatch keeps the older, faster way of color changing. It
may be slower if used for Tiled map renderers in libGDX or for NinePatch
instances, which both need to reset a Color object frequently, but not much else in libGDX specifically needs the
Color object getColor()
returns, and many things do fine with getPackedColor()
, which is faster.
Note that for games that use 2D sprite graphics, there's very low overhead to 1.9.9's SpriteBatch, and it mostly has
issues with overdraw (which every glyph of text drawn over a background contributes towards).
FloatFilters.grayscaleFilter
is a constant FloatFilter that makes
all colors, well, grayscale; you could apply it during things like flashback sequences or when the player is dazed.
FloatFilters.YCwCmFilter
that adds to or subtracts from Cw (chromatic warmth) and may change Y (lightness).
With that same filter, if the protagonist is partially blinded, you could set the multipliers for Cw and Cm
(chromatic mildness; determines whether a color is closer to mild colors like green/yellow or bold colors like
red/blue) to floats between 0.1 and 0.5 or so, which takes even intense colors and makes them diluted and grayish.
You could also change Y to be brighter or darker depending on whether a bright light blinded the protagonist, or some
mud was thrown in their eyes, etc.
Modifier and Type | Field and Description |
---|---|
FloatFilter |
filter |
int |
maxSpritesInBatch
The maximum number of sprites rendered in one batch so far.
|
int |
renderCalls
Number of render calls since the last
begin() . |
int |
totalRenderCalls
Number of rendering calls, ever.
|
Constructor and Description |
---|
FilterBatch()
Constructs a new FilterBatch with a size of 1000, one buffer, the default shader, and no changes in the
color filter.
|
FilterBatch(FloatFilter filter)
Constructs a new FilterBatch with a size of 1000, one buffer, the default shader, and the given
color filter.
|
FilterBatch(int size)
Constructs a FilterBatch with one buffer, the default shader, and no changes in the color filter.
|
FilterBatch(int size,
FloatFilter filter)
Constructs a new FilterBatch with a size of 1000, one buffer, the default shader, and the given
color filter.
|
FilterBatch(int size,
com.badlogic.gdx.graphics.glutils.ShaderProgram defaultShader)
Constructs a new FilterBatch.
|
FilterBatch(int size,
com.badlogic.gdx.graphics.glutils.ShaderProgram defaultShader,
FloatFilter filter)
Constructs a new FilterBatch.
|
Modifier and Type | Method and Description |
---|---|
void |
begin() |
static com.badlogic.gdx.graphics.glutils.ShaderProgram |
createDefaultShader()
Returns a new instance of the default shader used by FilterBatch for GL2 when no shader is specified.
|
void |
disableBlending() |
void |
dispose() |
void |
draw(com.badlogic.gdx.graphics.Texture texture,
float[] spriteVertices,
int offset,
int count) |
void |
draw(com.badlogic.gdx.graphics.Texture texture,
float x,
float y) |
void |
draw(com.badlogic.gdx.graphics.Texture texture,
float x,
float y,
float width,
float height) |
void |
draw(com.badlogic.gdx.graphics.Texture texture,
float x,
float y,
float width,
float height,
float u,
float v,
float u2,
float v2) |
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) |
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) |
void |
draw(com.badlogic.gdx.graphics.Texture texture,
float x,
float y,
int srcX,
int srcY,
int srcWidth,
int srcHeight) |
void |
draw(com.badlogic.gdx.graphics.g2d.TextureRegion region,
float x,
float y) |
void |
draw(com.badlogic.gdx.graphics.g2d.TextureRegion region,
float width,
float height,
com.badlogic.gdx.math.Affine2 transform) |
void |
draw(com.badlogic.gdx.graphics.g2d.TextureRegion region,
float x,
float y,
float width,
float height) |
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) |
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) |
void |
enableBlending() |
void |
end() |
void |
flush() |
int |
getBlendDstFunc() |
int |
getBlendDstFuncAlpha() |
int |
getBlendSrcFunc() |
int |
getBlendSrcFuncAlpha() |
com.badlogic.gdx.graphics.Color |
getColor() |
FloatFilter |
getFilter() |
float |
getPackedColor() |
com.badlogic.gdx.math.Matrix4 |
getProjectionMatrix() |
com.badlogic.gdx.graphics.glutils.ShaderProgram |
getShader() |
com.badlogic.gdx.math.Matrix4 |
getTransformMatrix() |
boolean |
isBlendingEnabled() |
boolean |
isDrawing() |
void |
setBlendFunction(int srcFunc,
int dstFunc) |
void |
setBlendFunctionSeparate(int srcFuncColor,
int dstFuncColor,
int srcFuncAlpha,
int dstFuncAlpha) |
void |
setColor(com.badlogic.gdx.graphics.Color tint) |
void |
setColor(float color) |
void |
setColor(float r,
float g,
float b,
float a) |
void |
setFilter(FloatFilter filter) |
void |
setPackedColor(float color) |
void |
setProjectionMatrix(com.badlogic.gdx.math.Matrix4 projection) |
void |
setShader(com.badlogic.gdx.graphics.glutils.ShaderProgram shader) |
void |
setTransformMatrix(com.badlogic.gdx.math.Matrix4 transform) |
protected void |
switchTexture(com.badlogic.gdx.graphics.Texture texture) |
public FloatFilter filter
public int renderCalls
begin()
.public int totalRenderCalls
public int maxSpritesInBatch
public FilterBatch()
FilterBatch(int, ShaderProgram)
public FilterBatch(FloatFilter filter)
public FilterBatch(int size)
public FilterBatch(int size, FloatFilter filter)
public FilterBatch(int size, com.badlogic.gdx.graphics.glutils.ShaderProgram defaultShader)
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()
.
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 FilterBatch and must be disposed separately.public FilterBatch(int size, com.badlogic.gdx.graphics.glutils.ShaderProgram defaultShader, FloatFilter filter)
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()
.
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 FilterBatch and must be disposed separately.public static com.badlogic.gdx.graphics.glutils.ShaderProgram createDefaultShader()
public void begin()
begin
in interface com.badlogic.gdx.graphics.g2d.Batch
public void end()
end
in interface com.badlogic.gdx.graphics.g2d.Batch
public void setColor(com.badlogic.gdx.graphics.Color tint)
setColor
in interface com.badlogic.gdx.graphics.g2d.Batch
public void setColor(float r, float g, float b, float a)
setColor
in interface com.badlogic.gdx.graphics.g2d.Batch
public void setColor(float color)
public void setPackedColor(float color)
setPackedColor
in interface com.badlogic.gdx.graphics.g2d.Batch
public com.badlogic.gdx.graphics.Color getColor()
getColor
in interface com.badlogic.gdx.graphics.g2d.Batch
public float getPackedColor()
getPackedColor
in interface com.badlogic.gdx.graphics.g2d.Batch
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)
draw
in interface com.badlogic.gdx.graphics.g2d.Batch
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)
draw
in interface com.badlogic.gdx.graphics.g2d.Batch
public void draw(com.badlogic.gdx.graphics.Texture texture, float x, float y, int srcX, int srcY, int srcWidth, int srcHeight)
draw
in interface com.badlogic.gdx.graphics.g2d.Batch
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)
draw
in interface com.badlogic.gdx.graphics.g2d.Batch
public void draw(com.badlogic.gdx.graphics.Texture texture, float x, float y)
draw
in interface com.badlogic.gdx.graphics.g2d.Batch
public void draw(com.badlogic.gdx.graphics.Texture texture, float x, float y, float width, float height)
draw
in interface com.badlogic.gdx.graphics.g2d.Batch
public void draw(com.badlogic.gdx.graphics.Texture texture, float[] spriteVertices, int offset, int count)
draw
in interface com.badlogic.gdx.graphics.g2d.Batch
public void draw(com.badlogic.gdx.graphics.g2d.TextureRegion region, float x, float y)
draw
in interface com.badlogic.gdx.graphics.g2d.Batch
public void draw(com.badlogic.gdx.graphics.g2d.TextureRegion region, float x, float y, float width, float height)
draw
in interface com.badlogic.gdx.graphics.g2d.Batch
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)
draw
in interface com.badlogic.gdx.graphics.g2d.Batch
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)
draw
in interface com.badlogic.gdx.graphics.g2d.Batch
public void draw(com.badlogic.gdx.graphics.g2d.TextureRegion region, float width, float height, com.badlogic.gdx.math.Affine2 transform)
draw
in interface com.badlogic.gdx.graphics.g2d.Batch
public void flush()
flush
in interface com.badlogic.gdx.graphics.g2d.Batch
public void disableBlending()
disableBlending
in interface com.badlogic.gdx.graphics.g2d.Batch
public void enableBlending()
enableBlending
in interface com.badlogic.gdx.graphics.g2d.Batch
public void setBlendFunction(int srcFunc, int dstFunc)
setBlendFunction
in interface com.badlogic.gdx.graphics.g2d.Batch
public void setBlendFunctionSeparate(int srcFuncColor, int dstFuncColor, int srcFuncAlpha, int dstFuncAlpha)
setBlendFunctionSeparate
in interface com.badlogic.gdx.graphics.g2d.Batch
public int getBlendSrcFunc()
getBlendSrcFunc
in interface com.badlogic.gdx.graphics.g2d.Batch
public int getBlendDstFunc()
getBlendDstFunc
in interface com.badlogic.gdx.graphics.g2d.Batch
public int getBlendSrcFuncAlpha()
getBlendSrcFuncAlpha
in interface com.badlogic.gdx.graphics.g2d.Batch
public int getBlendDstFuncAlpha()
getBlendDstFuncAlpha
in interface com.badlogic.gdx.graphics.g2d.Batch
public void dispose()
dispose
in interface com.badlogic.gdx.utils.Disposable
public com.badlogic.gdx.math.Matrix4 getProjectionMatrix()
getProjectionMatrix
in interface com.badlogic.gdx.graphics.g2d.Batch
public com.badlogic.gdx.math.Matrix4 getTransformMatrix()
getTransformMatrix
in interface com.badlogic.gdx.graphics.g2d.Batch
public void setProjectionMatrix(com.badlogic.gdx.math.Matrix4 projection)
setProjectionMatrix
in interface com.badlogic.gdx.graphics.g2d.Batch
public void setTransformMatrix(com.badlogic.gdx.math.Matrix4 transform)
setTransformMatrix
in interface com.badlogic.gdx.graphics.g2d.Batch
protected void switchTexture(com.badlogic.gdx.graphics.Texture texture)
public void setShader(com.badlogic.gdx.graphics.glutils.ShaderProgram shader)
setShader
in interface com.badlogic.gdx.graphics.g2d.Batch
public com.badlogic.gdx.graphics.glutils.ShaderProgram getShader()
getShader
in interface com.badlogic.gdx.graphics.g2d.Batch
public boolean isBlendingEnabled()
isBlendingEnabled
in interface com.badlogic.gdx.graphics.g2d.Batch
public boolean isDrawing()
isDrawing
in interface com.badlogic.gdx.graphics.g2d.Batch
public FloatFilter getFilter()
public void setFilter(FloatFilter filter)
Copyright © Eben Howard 2012–2022. All rights reserved.