Class Stencil
A SpriteBatch
can support many types of stencil effects. Classic
stencil effects including clipping (limiting drawing to a specific region)
or masking (prohibiting drawing to a specific region).
In particular, stencil effects are designed to support simple constructive area geometry operations. You can union, intersect, or subtract stencil regions to produce the relevant effects. However, this is only used for drawing and does not actually construct the associated geometries.
To support the CAG operations, the sprite batch stencil buffer has two
areas: low and high. Operations can be applied to one or both of these
regions. All binary operations are operations between these two regions.
For example, Stencil.Effect.CLIP_MASK
will restrict all drawing to
the stencil region defined in the low buffer, while also prohibiting any
drawing to the stencil region in the high buffer. This has the visible
effect of "subtracting" the high buffer from the low buffer.
The CAG operations are only supported at the binary level, as we only have
two halves of the stencil buffer. However, using non-drawing effects like
Stencil.Effect.CLIP_WIPE
or Stencil.Effect.CLIP_CARVE
, it is possible to
produce more interesting nested expressions.
Note that when using split-buffer operations, only one of the operations
will modify the stencil buffer. That is why there no effects such as
FILL_WIPE
or CLAMP_STAMP
.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
An enum enumerating all of the supported stencil effects. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Both buffersstatic final int
Lower bufferstatic final int
Neither stencil effect bufferstatic final int
Upper buffer -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
applyEffect
(Stencil.Effect effect) Configures the OpenGL settings to apply the given effect.static void
clearBuffer
(int buffer) Clears the stencil buffer specified
-
Field Details
-
STENCIL_NONE
public static final int STENCIL_NONENeither stencil effect buffer- See Also:
-
STENCIL_LOWER
public static final int STENCIL_LOWERLower buffer- See Also:
-
STENCIL_UPPER
public static final int STENCIL_UPPERUpper buffer- See Also:
-
STENCIL_BOTH
public static final int STENCIL_BOTHBoth buffers- See Also:
-
-
Constructor Details
-
Stencil
public Stencil()
-
-
Method Details
-
clearBuffer
public static void clearBuffer(int buffer) Clears the stencil buffer specified- Parameters:
buffer
- The stencil buffer (lower, upper, both)
-
applyEffect
Configures the OpenGL settings to apply the given effect.- Parameters:
effect
- The stencil effect
-