com.jme.scene.state
Class RenderState

java.lang.Object
  extended by com.jme.scene.state.RenderState
All Implemented Interfaces:
Savable
Direct Known Subclasses:
BlendState, ClipState, ColorMaskState, CullState, FogState, FragmentProgramState, GLSLShaderObjectsState, LightState, MaterialState, ShadeState, StencilState, StippleState, TextureState, VertexProgramState, WireframeState, ZBufferState

public abstract class RenderState
extends java.lang.Object
implements Savable

RenderState is the base class for all states that affect the rendering of a piece of geometry. They aren't created directly, but are created for users from the renderer. The renderstate of a parent affects its children and it is OK to assign to more than one Spatial the same render state.

Version:
$Id: RenderState.java 4137 2009-03-20 18:38:24Z christoph.luder $
Author:
Mark Powell, Joshua Slack, Jack Lindamood (javadoc only)

Nested Class Summary
static class RenderState.StateType
          Enumerates every possible RenderState type.
 
Field Summary
static boolean[] QUICK_COMPARE
          Deprecated. As of 2.0, use RenderState.StateType instead.
static int RS_BLEND
          Deprecated. As of 2.0, use RenderState.StateType.Blend
static int RS_CLIP
          Deprecated. As of 2.0, use RenderState.StateType.Clip
static int RS_COLORMASK_STATE
          Deprecated. As of 2.0, use RenderState.StateType.ColorMask
static int RS_CULL
          Deprecated. As of 2.0, use RenderState.StateType.Cull
static int RS_FOG
          Deprecated. As of 2.0, use RenderState.StateType#fog
static int RS_FRAGMENT_PROGRAM
          Deprecated. As of 2.0, use RenderState.StateType.FragmentProgram
static int RS_GLSL_SHADER_OBJECTS
          Deprecated. As of 2.0, use RenderState.StateType.GLSLShaderObjects
static int RS_LIGHT
          Deprecated. As of 2.0, use RenderState.StateType.Light
static int RS_MATERIAL
          Deprecated. As of 2.0, use RenderState.StateType.Material
static int RS_MAX_STATE
          Deprecated. As of 2.0, use RenderState.StateType
static int RS_SHADE
          Deprecated. As of 2.0, use RenderState.StateType.Shade
static int RS_STENCIL
          Deprecated. As of 2.0, use RenderState.StateType.Stencil
static int RS_TEXTURE
          Deprecated. As of 2.0, use RenderState.StateType.Texture
static int RS_VERTEX_PROGRAM
          Deprecated. As of 2.0, use RenderState.StateType.VertexProgram
static int RS_WIREFRAME
          Deprecated. As of 2.0, use RenderState.StateType.Wireframe
static int RS_ZBUFFER
          Deprecated. As of 2.0, use RenderState.StateType.ZBuffer
 
Constructor Summary
RenderState()
          Construts a new RenderState.
 
Method Summary
abstract  void apply()
          This function is defined in the RenderState that is actually used by the Renderer.
abstract  StateRecord createStateRecord()
           
 RenderState extract(java.util.Stack<? extends RenderState> stack, Spatial spat)
          Extracts from the stack the correct renderstate that should apply to the given spatial.
 java.lang.Class<?> getClassTag()
           
abstract  RenderState.StateType getStateType()
          Defined by the subclass, this returns a StateType value identifying the renderstate.
abstract  int getType()
          Deprecated. Use getStateType() instead.
 boolean isEnabled()
          Returns if this render state is enabled during rendering.
 boolean needsRefresh()
           
 void read(JMEImporter e)
           
 void setEnabled(boolean value)
          Sets if this render state is enabled during rendering.
 void setNeedsRefresh(boolean refresh)
          This should be called by states when it knows internal data has been altered.
static void setQuickCompares(boolean enabled)
           
 void write(JMEExporter e)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RS_BLEND

public static final int RS_BLEND
Deprecated. As of 2.0, use RenderState.StateType.Blend
The value returned by getType() for BlendState.

See Also:
Constant Field Values

RS_FOG

public static final int RS_FOG
Deprecated. As of 2.0, use RenderState.StateType#fog
The value returned by getType() for FogState.

See Also:
Constant Field Values

RS_LIGHT

public static final int RS_LIGHT
Deprecated. As of 2.0, use RenderState.StateType.Light
The value returned by getType() for LightState.

See Also:
Constant Field Values

RS_MATERIAL

public static final int RS_MATERIAL
Deprecated. As of 2.0, use RenderState.StateType.Material
The value returend by getType() for MaterialState.

See Also:
Constant Field Values

RS_SHADE

public static final int RS_SHADE
Deprecated. As of 2.0, use RenderState.StateType.Shade
The value returned by getType() for ShadeState.

See Also:
Constant Field Values

RS_TEXTURE

public static final int RS_TEXTURE
Deprecated. As of 2.0, use RenderState.StateType.Texture
The value returned by getType() for TextureState.

See Also:
Constant Field Values

RS_WIREFRAME

public static final int RS_WIREFRAME
Deprecated. As of 2.0, use RenderState.StateType.Wireframe
The value returned by getType() for WireframeState.

See Also:
Constant Field Values

RS_ZBUFFER

public static final int RS_ZBUFFER
Deprecated. As of 2.0, use RenderState.StateType.ZBuffer
The value returned by getType() for ZBufferState.

See Also:
Constant Field Values

RS_CULL

public static final int RS_CULL
Deprecated. As of 2.0, use RenderState.StateType.Cull
The value returned by getType() for CullState.

See Also:
Constant Field Values

RS_VERTEX_PROGRAM

public static final int RS_VERTEX_PROGRAM
Deprecated. As of 2.0, use RenderState.StateType.VertexProgram
The value returned by getType() for VertexProgramState.

See Also:
Constant Field Values

RS_FRAGMENT_PROGRAM

public static final int RS_FRAGMENT_PROGRAM
Deprecated. As of 2.0, use RenderState.StateType.FragmentProgram
The value returned by getType() for FragmentProgramState.

See Also:
Constant Field Values

RS_STENCIL

public static final int RS_STENCIL
Deprecated. As of 2.0, use RenderState.StateType.Stencil
The value returned by getType() for StencilState.

See Also:
Constant Field Values

RS_GLSL_SHADER_OBJECTS

public static final int RS_GLSL_SHADER_OBJECTS
Deprecated. As of 2.0, use RenderState.StateType.GLSLShaderObjects
The value returned by getType() for GLSLShaderObjectsState.

See Also:
Constant Field Values

RS_COLORMASK_STATE

public static final int RS_COLORMASK_STATE
Deprecated. As of 2.0, use RenderState.StateType.ColorMask
The value returned by getType() for ColorMaskState.

See Also:
Constant Field Values

RS_CLIP

public static final int RS_CLIP
Deprecated. As of 2.0, use RenderState.StateType.Clip
The value returned by getType() for ClipState.

See Also:
Constant Field Values

RS_MAX_STATE

public static final int RS_MAX_STATE
Deprecated. As of 2.0, use RenderState.StateType
The total number of diffrent types of RenderState.

See Also:
Constant Field Values

QUICK_COMPARE

public static boolean[] QUICK_COMPARE
Deprecated. As of 2.0, use RenderState.StateType instead.

If false, each renderstate of that type is always applied in the renderer and only field by field checks are done to minimize jni overhead. This is slower than setting to true, but relieves the programmer from situations where he has to remember to update the needsRefresh field of a state.

If true, each renderstate of that type is checked for == with the last applied renderstate of the same type. If same and the state's needsRefresh method returns false, then application of the renderstate is skipped. This can be much faster than setting false, but in certain circumstances, the programmer must manually set needsRefresh (for example, in a FogState, if you call getFogColor().set(....) to change the color, the fogstate will not set the needsRefresh field. In non-quick compare mode, this is not a problem because it will go into the apply method and do an actual check of the current fog color in opengl vs. the color in the state being applied.)

DEFAULTS:

Constructor Detail

RenderState

public RenderState()
Construts a new RenderState. The state is enabled by default.

Method Detail

getType

public abstract int getType()
Deprecated. Use getStateType() instead.

Defined by the subclass, this returns an int identifying the renderstate. For example, RS_CULL or RS_TEXTURE.

Returns:
An int identifying this render state.

getStateType

public abstract RenderState.StateType getStateType()
Defined by the subclass, this returns a StateType value identifying the renderstate. For example, StateType.Cull or StateType.Texture.

Returns:
A StateType value identifying this render state.

isEnabled

public boolean isEnabled()
Returns if this render state is enabled during rendering. Disabled states are ignored.

Returns:
True if this state is enabled.

setEnabled

public void setEnabled(boolean value)
Sets if this render state is enabled during rendering. Disabled states are ignored.

Parameters:
value - False if the state is to be disabled, true otherwise.

apply

public abstract void apply()
This function is defined in the RenderState that is actually used by the Renderer. It contains the code that, when executed, applies the render state for the given render system. This should only be called internally and not by users directly.


extract

public RenderState extract(java.util.Stack<? extends RenderState> stack,
                           Spatial spat)
Extracts from the stack the correct renderstate that should apply to the given spatial. This is mainly used for RenderStates that can be cumulative such as TextureState or LightState. By default, the top of the static is returned. This function should not be called by users directly.

Parameters:
stack - The stack to extract render states from.
spat - The spatial to apply the render states too.
Returns:
The render state to use.

write

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

read

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

getClassTag

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

createStateRecord

public abstract StateRecord createStateRecord()

needsRefresh

public boolean needsRefresh()
Returns:
true if we should apply this state even if we think it is the current state of its type in the current context. Is reset to false after apply is finished.

setNeedsRefresh

public void setNeedsRefresh(boolean refresh)
This should be called by states when it knows internal data has been altered.

Parameters:
refresh - true if we should apply this state even if we think it is the current state of its type in the current context.

setQuickCompares

public static void setQuickCompares(boolean enabled)
Parameters:
enabled -
See Also:
QUICK_COMPARE