Skip to main content

FlixelShaderable

View source

interface

org.flixelgdx.functional.FlixelShaderable

public interface FlixelShaderable

Marks an object that can have a FlixelShader applied to it.

Implemented by both FlixelSprite (per-sprite batch interruption) and FlixelCamera (full-scene FBO post-processing). Both follow the same ownership contract: the shader is NOT owned by the implementing object. The caller is responsible for calling FlixelShader.destroy() when the shader is no longer needed.

Performance note

The cost differs significantly between the two implementations.

  • Camera shader: one FBO capture and one composite draw call per camera per frame, regardless of how many sprites the camera contains. Suitable for full-screen scene effects.
  • Sprite shader: each shader transition in draw order costs one GPU batch flush (all buffered vertices are submitted before the new shader can take over). Sprites that share the same shader instance and are drawn consecutively batch together for free. Mixing many different shaders in draw order causes many flushes and can significantly hurt performance on low-end hardware. Give players the option to turn off shaders if your game targets weak devices.

See Also: FlixelSprite, FlixelCamera

Methods

setShader(FlixelShader)

public void setShader(FlixelShader shader)

Assigns a shader to this object, or removes it by passing null.

The shader is NOT owned by this object. Destroy it yourself by calling FlixelShader.destroy() when it is no longer needed.

Parameters:

NameDescription
shaderThe shader to apply, or null to remove the current shader.

getShader()

public FlixelShader getShader()

Returns the shader currently assigned to this object, or null if none is set.

Returns: The active FlixelShader, or null.