Class Stencil

java.lang.Object
edu.cornell.gdiac.graphics.Stencil

public class Stencil extends Object
A class to support stenciling effects.

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.

  • Field Details

  • 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

      public static void applyEffect(Stencil.Effect effect)
      Configures the OpenGL settings to apply the given effect.
      Parameters:
      effect - The stencil effect