Class StencilState

java.lang.Object
com.ardor3d.renderer.state.RenderState
com.ardor3d.renderer.state.StencilState
All Implemented Interfaces:
Savable

public class StencilState extends RenderState
The StencilState RenderState allows the user to set the attributes of the stencil buffer of the renderer. The Stenciling is similar to Z-Buffering in that it allows enabling and disabling drawing on a per pixel basis. You can use the stencil plane to mask out portions of the rendering to create special effects, such as outlining or planar shadows. Our stencil state supports setting operations for front and back facing polygons separately. If your card does not support setting faces independently, the front face values will be used for both sides.
  • Constructor Details

    • StencilState

      public StencilState()
  • Method Details

    • getType

      public RenderState.StateType getType()
      Specified by:
      getType in class RenderState
      Returns:
      An statetype enum value for the subclass.
      See Also:
    • setStencilFunction

      public void setStencilFunction(StencilState.StencilFunction function)
      Sets the function that defines if a stencil test passes or not for both faces.
      Parameters:
      function - The new stencil function for both faces.
      Throws:
      IllegalArgumentException - if function is null
    • setStencilReference

      public void setStencilReference(int reference)
      Sets the stencil reference to be used during the stencil function for both faces.
      Parameters:
      reference - The new stencil reference for both faces.
    • setStencilMask

      public void setStencilMask(int mask)
      Convienence method for setting both types of stencil masks at once for both faces.
      Parameters:
      mask - The new stencil write and func mask for both faces.
    • setStencilWriteMask

      public void setStencilWriteMask(int mask)
      Controls which stencil bitplanes are written for both faces.
      Parameters:
      mask - The new stencil write mask for both faces.
    • setStencilFuncMask

      public void setStencilFuncMask(int mask)
      Sets the stencil mask to be used during stencil functions for both faces.
      Parameters:
      mask - The new stencil function mask for both faces.
    • setStencilOpFail

      public void setStencilOpFail(StencilState.StencilOperation operation)
      Specifies the aciton to take when the stencil test fails for both faces.
      Parameters:
      operation - The new stencil operation for both faces.
      Throws:
      IllegalArgumentException - if operation is null
    • setStencilOpZFail

      public void setStencilOpZFail(StencilState.StencilOperation operation)
      Specifies stencil action when the stencil test passes, but the depth test fails for both faces.
      Parameters:
      operation - The Z test operation to set for both faces.
      Throws:
      IllegalArgumentException - if operation is null
    • setStencilOpZPass

      public void setStencilOpZPass(StencilState.StencilOperation operation)
      Specifies stencil action when both the stencil test and the depth test pass, or when the stencil test passes and either there is no depth buffer or depth testing is not enabled.
      Parameters:
      operation - The new Z test pass operation to set for both faces.
      Throws:
      IllegalArgumentException - if operation is null
    • setStencilFunctionFront

      public void setStencilFunctionFront(StencilState.StencilFunction function)
      Sets the function that defines if a stencil test passes or not for front faces.
      Parameters:
      function - The new stencil function for front faces.
      Throws:
      IllegalArgumentException - if function is null
    • getStencilFunctionFront

      public StencilState.StencilFunction getStencilFunctionFront()
      Returns:
      The current stencil function for front faces. Default is StencilFunction.Always
    • setStencilReferenceFront

      public void setStencilReferenceFront(int reference)
      Sets the stencil reference to be used during the stencil function for front faces.
      Parameters:
      reference - The new stencil reference for front faces.
    • getStencilReferenceFront

      public int getStencilReferenceFront()
      Returns:
      The current stencil reference for front faces. Default is 0
    • setStencilMaskFront

      public void setStencilMaskFront(int mask)
      Convienence method for setting both types of stencil masks at once for front faces.
      Parameters:
      mask - The new stencil write and func mask for front faces.
    • setStencilWriteMaskFront

      public void setStencilWriteMaskFront(int mask)
      Controls which stencil bitplanes are written for front faces.
      Parameters:
      mask - The new stencil write mask for front faces.
    • getStencilWriteMaskFront

      public int getStencilWriteMaskFront()
      Returns:
      The current stencil write mask for front faces. Default is all 1's (~0)
    • setStencilFuncMaskFront

      public void setStencilFuncMaskFront(int mask)
      Sets the stencil mask to be used during stencil functions for front faces.
      Parameters:
      mask - The new stencil function mask for front faces.
    • getStencilFuncMaskFront

      public int getStencilFuncMaskFront()
      Returns:
      The current stencil function mask for front faces. Default is all 1's (~0)
    • setStencilOpFailFront

      public void setStencilOpFailFront(StencilState.StencilOperation operation)
      Specifies the aciton to take when the stencil test fails for front faces.
      Parameters:
      operation - The new stencil operation for front faces.
      Throws:
      IllegalArgumentException - if operation is null
    • getStencilOpFailFront

      public StencilState.StencilOperation getStencilOpFailFront()
      Returns:
      The current stencil operation for front faces. Default is StencilOperation.Keep
    • setStencilOpZFailFront

      public void setStencilOpZFailFront(StencilState.StencilOperation operation)
      Specifies stencil action when the stencil test passes, but the depth test fails for front faces.
      Parameters:
      operation - The Z test operation to set for front faces.
      Throws:
      IllegalArgumentException - if operation is null
    • getStencilOpZFailFront

      public StencilState.StencilOperation getStencilOpZFailFront()
      Returns:
      The current Z op fail function for front faces. Default is StencilOperation.Keep
    • setStencilOpZPassFront

      public void setStencilOpZPassFront(StencilState.StencilOperation operation)
      Specifies stencil action when both the stencil test and the depth test pass, or when the stencil test passes and either there is no depth buffer or depth testing is not enabled.
      Parameters:
      operation - The new Z test pass operation to set for front faces.
      Throws:
      IllegalArgumentException - if operation is null
    • getStencilOpZPassFront

      public StencilState.StencilOperation getStencilOpZPassFront()
      Returns:
      The current Z op pass function for front faces. Default is StencilOperation.Keep
    • setStencilFunctionBack

      public void setStencilFunctionBack(StencilState.StencilFunction function)
      Sets the function that defines if a stencil test passes or not for back faces.
      Parameters:
      function - The new stencil function for back faces.
      Throws:
      IllegalArgumentException - if function is null
    • getStencilFunctionBack

      public StencilState.StencilFunction getStencilFunctionBack()
      Returns:
      The current stencil function for back faces. Default is StencilFunction.Always
    • setStencilReferenceBack

      public void setStencilReferenceBack(int reference)
      Sets the stencil reference to be used during the stencil function for back faces.
      Parameters:
      reference - The new stencil reference for back faces.
    • getStencilReferenceBack

      public int getStencilReferenceBack()
      Returns:
      The current stencil reference for back faces. Default is 0
    • setStencilMaskBack

      public void setStencilMaskBack(int mask)
      Convienence method for setting both types of stencil masks at once for back faces.
      Parameters:
      mask - The new stencil write and func mask for back faces.
    • setStencilWriteMaskBack

      public void setStencilWriteMaskBack(int mask)
      Controls which stencil bitplanes are written for back faces.
      Parameters:
      mask - The new stencil write mask for back faces.
    • getStencilWriteMaskBack

      public int getStencilWriteMaskBack()
      Returns:
      The current stencil write mask for back faces. Default is all 1's (~0)
    • setStencilFuncMaskBack

      public void setStencilFuncMaskBack(int mask)
      Sets the stencil mask to be used during stencil functions for back faces.
      Parameters:
      mask - The new stencil function mask for back faces.
    • getStencilFuncMaskBack

      public int getStencilFuncMaskBack()
      Returns:
      The current stencil function mask for back faces. Default is all 1's (~0)
    • setStencilOpFailBack

      public void setStencilOpFailBack(StencilState.StencilOperation operation)
      Specifies the aciton to take when the stencil test fails for back faces.
      Parameters:
      operation - The new stencil operation for back faces.
      Throws:
      IllegalArgumentException - if operation is null
    • getStencilOpFailBack

      public StencilState.StencilOperation getStencilOpFailBack()
      Returns:
      The current stencil operation for back faces. Default is StencilOperation.Keep
    • setStencilOpZFailBack

      public void setStencilOpZFailBack(StencilState.StencilOperation operation)
      Specifies stencil action when the stencil test passes, but the depth test fails.
      Parameters:
      operation - The Z test operation to set for back faces.
      Throws:
      IllegalArgumentException - if operation is null
    • getStencilOpZFailBack

      public StencilState.StencilOperation getStencilOpZFailBack()
      Returns:
      The current Z op fail function for back faces. Default is StencilOperation.Keep
    • setStencilOpZPassBack

      public void setStencilOpZPassBack(StencilState.StencilOperation operation)
      Specifies stencil action when both the stencil test and the depth test pass, or when the stencil test passes and either there is no depth buffer or depth testing is not enabled.
      Parameters:
      operation - The new Z test pass operation to set for back faces.
      Throws:
      IllegalArgumentException - if operation is null
    • getStencilOpZPassBack

      public StencilState.StencilOperation getStencilOpZPassBack()
      Returns:
      The current Z op pass function for back faces. Default is StencilOperation.Keep
    • isUseTwoSided

      public boolean isUseTwoSided()
    • setUseTwoSided

      public void setUseTwoSided(boolean useTwoSided)
    • write

      public void write(OutputCapsule capsule) throws IOException
      Specified by:
      write in interface Savable
      Overrides:
      write in class RenderState
      Throws:
      IOException
    • read

      public void read(InputCapsule capsule) throws IOException
      Specified by:
      read in interface Savable
      Overrides:
      read in class RenderState
      Throws:
      IOException
    • createStateRecord

      public StateRecord createStateRecord(ContextCapabilities caps)
      Specified by:
      createStateRecord in class RenderState