com.jme.scene.state
Class LightState

java.lang.Object
  extended by com.jme.scene.state.RenderState
      extended by com.jme.scene.state.LightState
All Implemented Interfaces:
Savable
Direct Known Subclasses:
JOGLLightState, LWJGLLightState

public abstract class LightState
extends RenderState

LightState maintains a collection of lights up to the set number of maximum lights allowed. Any subclass of Light can be added to the light state. Each light is processed and used to modify the color of the scene.

Version:
$Id: LightState.java 4336 2009-05-03 20:57:01Z christoph.luder $
Author:
Mark Powell, Joshua Slack - Light state combining and performance enhancements, Three Rings: Local viewer and separate specular

Nested Class Summary
 
Nested classes/interfaces inherited from class com.jme.scene.state.RenderState
RenderState.StateType
 
Field Summary
protected  int backLightMask
           
protected  float[] globalAmbient
           
protected  int lightMask
           
static boolean LIGHTS_ENABLED
          Debug flag for turning off all lighting.
protected  boolean localViewerOn
          When true, the eye position (as opposed to just the view direction) will be taken into account when computing specular reflections.
static int MASK_AMBIENT
          When applied to lightMask, implies ambient light should be set to 0 for this lightstate
static int MASK_DIFFUSE
          When applied to lightMask, implies diffuse light should be set to 0 for this lightstate
static int MASK_GLOBALAMBIENT
          When applied to lightMask, implies global ambient light should be set to 0 for this lightstate
static int MASK_SPECULAR
          When applied to lightMask, implies specular light should be set to 0 for this lightstate
static int MAX_LIGHTS_ALLOWED
          defines the maximum number of lights that are allowed to be maintained at one time.
protected  boolean separateSpecularOn
          When true, specular highlights will be computed separately and added to fragments after texturing.
protected  boolean twoSidedOn
          When true, both sides of the model will be lighted.
protected static java.nio.FloatBuffer zeroBuffer
           
 
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
LightState()
          Constructor instantiates a new LightState object.
 
Method Summary
 boolean attach(Light light)
          attach places a light in the queue to be processed.
 void detach(Light light)
          detach removes a light from the queue for processing.
 void detachAll()
          detachAll clears the queue of all lights to be processed.
 Light get(int i)
          get retrieves a particular light defined by an index.
 java.lang.Class<?> getClassTag()
           
 ColorRGBA getGlobalAmbient()
           
 java.util.ArrayList<Light> getLightList()
          Retrieves all lights handled by this LightState
 int getLightMask()
           
 boolean getLocalViewer()
          Returns the current state of local viewer mode for this LightState.
 int getQuantity()
          getQuantity returns the number of lights currently in the queue.
 boolean getSeparateSpecular()
          Returns the current state of separate specular mode for this LightState.
 RenderState.StateType getStateType()
          getStateType returns the type RenderState.StateType.Light
 boolean getTwoSidedLighting()
          Returns the current state of two sided lighting for this LightState.
 int getType()
          Deprecated. As of 2.0, use RenderState.getStateType() instead.
 void popLightMask()
          Recalls the light mask from a back store or 0 if none was pushed.
 void pushLightMask()
          Saves the light mask to a back store.
 void read(JMEImporter e)
           
 void setGlobalAmbient(ColorRGBA color)
           
 void setLightMask(int lightMask)
          setLightMask sets what attributes of this lightstate to apply as an int comprised of bitwise or'ed values.
 void setLocalViewer(boolean localViewerOn)
          Sets if local viewer mode should be enabled for this LightState.
 void setSeparateSpecular(boolean separateSpecularOn)
          Sets if separate specular mode should be enabled for this LightState.
 void setTwoSidedLighting(boolean twoSidedOn)
          Sets if two sided lighting should be enabled for this LightState.
 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

LIGHTS_ENABLED

public static boolean LIGHTS_ENABLED
Debug flag for turning off all lighting.


MAX_LIGHTS_ALLOWED

public static final int MAX_LIGHTS_ALLOWED
defines the maximum number of lights that are allowed to be maintained at one time.

See Also:
Constant Field Values

MASK_AMBIENT

public static final int MASK_AMBIENT
When applied to lightMask, implies ambient light should be set to 0 for this lightstate

See Also:
Constant Field Values

MASK_DIFFUSE

public static final int MASK_DIFFUSE
When applied to lightMask, implies diffuse light should be set to 0 for this lightstate

See Also:
Constant Field Values

MASK_SPECULAR

public static final int MASK_SPECULAR
When applied to lightMask, implies specular light should be set to 0 for this lightstate

See Also:
Constant Field Values

MASK_GLOBALAMBIENT

public static final int MASK_GLOBALAMBIENT
When applied to lightMask, implies global ambient light should be set to 0 for this lightstate

See Also:
Constant Field Values

lightMask

protected int lightMask

backLightMask

protected int backLightMask

twoSidedOn

protected boolean twoSidedOn
When true, both sides of the model will be lighted.


globalAmbient

protected float[] globalAmbient

zeroBuffer

protected static java.nio.FloatBuffer zeroBuffer

localViewerOn

protected boolean localViewerOn
When true, the eye position (as opposed to just the view direction) will be taken into account when computing specular reflections.


separateSpecularOn

protected boolean separateSpecularOn
When true, specular highlights will be computed separately and added to fragments after texturing.

Constructor Detail

LightState

public LightState()
Constructor instantiates a new LightState object. Initially there are no lights set.

Method Detail

getType

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

getType returns the type of render state this is. (RS_LIGHT).

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.Light

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

attach

public boolean attach(Light light)
attach places a light in the queue to be processed. If there are already eight lights placed in the queue, the light is ignored and false is returned. Otherwise, true is returned to indicate success.

Parameters:
light - the light to add to the queue.
Returns:
true if the light was added successfully, false if there are already eight lights in the queue.

detach

public void detach(Light light)
detach removes a light from the queue for processing.

Parameters:
light - the light to be removed.

detachAll

public void detachAll()
detachAll clears the queue of all lights to be processed.


getLightList

public java.util.ArrayList<Light> getLightList()
Retrieves all lights handled by this LightState

Returns:
List of lights handled

get

public Light get(int i)
get retrieves a particular light defined by an index. If there exists no light at a particular index, null is returned.

Parameters:
i - the index to retrieve the light from the queue.
Returns:
the light at the given index, null if no light exists at this index.

getQuantity

public int getQuantity()
getQuantity returns the number of lights currently in the queue.

Returns:
the number of lights currently in the queue.

setTwoSidedLighting

public void setTwoSidedLighting(boolean twoSidedOn)
Sets if two sided lighting should be enabled for this LightState.

Parameters:
twoSidedOn - If true, two sided lighting is enabled.

getTwoSidedLighting

public boolean getTwoSidedLighting()
Returns the current state of two sided lighting for this LightState. By default, it is off.

Returns:
True if two sided lighting is enabled.

setLocalViewer

public void setLocalViewer(boolean localViewerOn)
Sets if local viewer mode should be enabled for this LightState.

Parameters:
localViewerOn - If true, local viewer mode is enabled.

getLocalViewer

public boolean getLocalViewer()
Returns the current state of local viewer mode for this LightState. By default, it is off.

Returns:
True if local viewer mode is enabled.

setSeparateSpecular

public void setSeparateSpecular(boolean separateSpecularOn)
Sets if separate specular mode should be enabled for this LightState.

Parameters:
separateSpecularOn - If true, separate specular mode is enabled.

getSeparateSpecular

public boolean getSeparateSpecular()
Returns the current state of separate specular mode for this LightState. By default, it is off.

Returns:
True if separate specular mode is enabled.

setGlobalAmbient

public void setGlobalAmbient(ColorRGBA color)

getGlobalAmbient

public ColorRGBA getGlobalAmbient()

getLightMask

public int getLightMask()
Returns:
Returns the lightMask - default is 0 or not masked.

setLightMask

public void setLightMask(int lightMask)
setLightMask sets what attributes of this lightstate to apply as an int comprised of bitwise or'ed values.

Parameters:
lightMask - The lightMask to set.

pushLightMask

public void pushLightMask()
Saves the light mask to a back store. That backstore is recalled with popLightMask. Despite the name, this is not a stack and additional pushes will simply overwrite the backstored value.


popLightMask

public void popLightMask()
Recalls the light mask from a back store or 0 if none was pushed.

See Also:
pushLightMask()

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