Class StencilMask

java.lang.Object
lol.trq.helios.state.StencilMask

public final class StencilMask extends Object
Clips drawing to an arbitrary shape with the stencil buffer: draw a mask, then draw content only inside it (or only outside it).
helios.stencil().clip(
        () -> helios.shapes().begin(pixel).circle(50, 50, 30, Paint.solid(-1)).end(),
        true,
        () -> drawAvatar());

The bound framebuffer needs a stencil buffer: pooled framebuffers made with depthStencil, or on Minecraft the main framebuffer after MinecraftHelios.enableStencil(). Mask fragments with alpha at or below one half are dropped, so the mask edge is not anti-aliased; the content inside it is. Masks do not nest: a clip clears the stencil buffer.

  • Constructor Details

    • StencilMask

      public StencilMask(GlBackend gl, GlStateCache cache, ShapeBatch batch)
      Creates the helper.
      Parameters:
      gl - the backend
      cache - the host's state cache
      batch - the batch the mask is drawn with; its alpha cutoff is raised while the mask draws
  • Method Details

    • clip

      public void clip(Runnable mask, boolean inside, Runnable content)
      Draws content clipped to a mask.
      Parameters:
      mask - draws the mask shape with the batch given to the constructor; nothing reaches the colour buffer
      inside - keep the content inside the mask, or outside it
      content - draws the clipped content
      Throws:
      IllegalStateException - if the bound framebuffer has no stencil buffer