com.jme.scene.state
Class StencilState

java.lang.Object
  extended by com.jme.scene.state.RenderState
      extended by com.jme.scene.state.StencilState
All Implemented Interfaces:
Savable
Direct Known Subclasses:
JOGLStencilState, LWJGLStencilState

public abstract 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 independantly, the front face values will be used for both sides.

Version:
$Id: StencilState.java 4336 2009-05-03 20:57:01Z christoph.luder $
Author:
Mark Powell, Joshua Slack - two sided, wrap, enums, etc.

Nested Class Summary
static class StencilState.StencilFunction
           
static class StencilState.StencilOperation
           
 
Nested classes/interfaces inherited from class com.jme.scene.state.RenderState
RenderState.StateType
 
Field Summary
protected static boolean stencilWrapSupport
           
protected static boolean twoSidedSupport
           
 
Fields inherited from class com.jme.scene.state.RenderState
QUICK_COMPARE, RS_BLEND, RS_CLIP, RS_COLORMASK_STATE, RS_CULL, RS_FOG, RS_FRAGMENT_PROGRAM, RS_GLSL_SHADER_OBJECTS, RS_LIGHT, RS_MATERIAL, RS_MAX_STATE, RS_SHADE, RS_STENCIL, RS_TEXTURE, RS_VERTEX_PROGRAM, RS_WIREFRAME, RS_ZBUFFER
 
Constructor Summary
StencilState()
           
 
Method Summary
 java.lang.Class<?> getClassTag()
           
 RenderState.StateType getStateType()
          getStateType returns the type RenderState.StateType.Stencil
 int getStencilFuncMaskBack()
           
 int getStencilFuncMaskFront()
           
 StencilState.StencilFunction getStencilFunctionBack()
           
 StencilState.StencilFunction getStencilFunctionFront()
           
 StencilState.StencilOperation getStencilOpFailBack()
           
 StencilState.StencilOperation getStencilOpFailFront()
           
 StencilState.StencilOperation getStencilOpZFailBack()
           
 StencilState.StencilOperation getStencilOpZFailFront()
           
 StencilState.StencilOperation getStencilOpZPassBack()
           
 StencilState.StencilOperation getStencilOpZPassFront()
           
 int getStencilReferenceBack()
           
 int getStencilReferenceFront()
           
 int getStencilWriteMaskBack()
           
 int getStencilWriteMaskFront()
           
 int getType()
          Deprecated. As of 2.0, use RenderState.getStateType() instead.
 boolean isUseTwoSided()
           
 void read(JMEImporter e)
           
 void setStencilFuncMask(int mask)
          Sets the stencil mask to be used during stencil functions for both faces.
 void setStencilFuncMaskBack(int mask)
          Sets the stencil mask to be used during stencil functions for back faces.
 void setStencilFuncMaskFront(int mask)
          Sets the stencil mask to be used during stencil functions for front faces.
 void setStencilFunction(StencilState.StencilFunction function)
          Sets the function that defines if a stencil test passes or not for both faces.
 void setStencilFunctionBack(StencilState.StencilFunction function)
          Sets the function that defines if a stencil test passes or not for back faces.
 void setStencilFunctionFront(StencilState.StencilFunction function)
          Sets the function that defines if a stencil test passes or not for front faces.
 void setStencilMask(int mask)
          Convienence method for setting both types of stencil masks at once for both faces.
 void setStencilMaskBack(int mask)
          Convienence method for setting both types of stencil masks at once for back faces.
 void setStencilMaskFront(int mask)
          Convienence method for setting both types of stencil masks at once for front faces.
 void setStencilOpFail(StencilState.StencilOperation operation)
          Specifies the aciton to take when the stencil test fails for both faces.
 void setStencilOpFailBack(StencilState.StencilOperation operation)
          Specifies the aciton to take when the stencil test fails for back faces.
 void setStencilOpFailFront(StencilState.StencilOperation operation)
          Specifies the aciton to take when the stencil test fails for front faces.
 void setStencilOpZFail(StencilState.StencilOperation operation)
          Specifies stencil action when the stencil test passes, but the depth test fails for both faces.
 void setStencilOpZFailBack(StencilState.StencilOperation operation)
          Specifies stencil action when the stencil test passes, but the depth test fails.
 void setStencilOpZFailFront(StencilState.StencilOperation operation)
          Specifies stencil action when the stencil test passes, but the depth test fails for front faces.
 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.
 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.
 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.
 void setStencilReference(int reference)
          Sets the stencil reference to be used during the stencil function for both faces.
 void setStencilReferenceBack(int reference)
          Sets the stencil reference to be used during the stencil function for back faces.
 void setStencilReferenceFront(int reference)
          Sets the stencil reference to be used during the stencil function for front faces.
 void setStencilWriteMask(int mask)
          Controls which stencil bitplanes are written for both faces.
 void setStencilWriteMaskBack(int mask)
          Controls which stencil bitplanes are written for back faces.
 void setStencilWriteMaskFront(int mask)
          Controls which stencil bitplanes are written for front faces.
 void setUseTwoSided(boolean useTwoSided)
           
static boolean supportsStencilWrap()
           
static boolean supportsTwoSided()
           
 void write(JMEExporter e)
           
 
Methods inherited from class com.jme.scene.state.RenderState
apply, createStateRecord, extract, isEnabled, needsRefresh, setEnabled, setNeedsRefresh, setQuickCompares
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

twoSidedSupport

protected static boolean twoSidedSupport

stencilWrapSupport

protected static boolean stencilWrapSupport
Constructor Detail

StencilState

public StencilState()
Method Detail

supportsTwoSided

public static boolean supportsTwoSided()
Returns:
true if we can handle doing separate operations for front and back facing polys in a single pass.

supportsStencilWrap

public static boolean supportsStencilWrap()
Returns:
true if we can handle wrapping increment/decrement operations.

getType

public int getType()
Deprecated. As of 2.0, use RenderState.getStateType() instead.

Returns RS_STENCIL

Specified by:
getType in class RenderState
Returns:
An int identifying this render state.
See Also:
RenderState.getType()

getStateType

public RenderState.StateType getStateType()
getStateType returns the type RenderState.StateType.Stencil

Specified by:
getStateType in class RenderState
Returns:
RenderState.StateType.Stencil
See Also:
RenderState.getStateType()

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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.IllegalArgumentException - if operation is null

getStencilOpZPassBack

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

write

public void write(JMEExporter e)
           throws java.io.IOException
Specified by:
write in interface Savable
Overrides:
write in class RenderState
Throws:
java.io.IOException

read

public void read(JMEImporter e)
          throws java.io.IOException
Specified by:
read in interface Savable
Overrides:
read in class RenderState
Throws:
java.io.IOException

getClassTag

public java.lang.Class<?> getClassTag()
Specified by:
getClassTag in interface Savable
Overrides:
getClassTag in class RenderState

isUseTwoSided

public boolean isUseTwoSided()

setUseTwoSided

public void setUseTwoSided(boolean useTwoSided)