org.xith3d.render.states
Class StateMap

java.lang.Object
  extended by org.xith3d.render.states.StateMap

public class StateMap
extends java.lang.Object

A state map is used to map objects to state id's. This is based on the assumption that many state objects (like materials) are different objects but are actually the same values. This class provides a way to assign unique id's to unique combinations of objects and then map all the other objects to the same id. This allows for efficient state sorting and state changes. The weakness is that it will keep a pointer one more frame than it would normally be kept, since reference count would not go to zero until the next frame render.


Constructor Summary
StateMap()
           
 
Method Summary
 void assignState(StateTrackable<?> trackable)
          Ok this is a little tricky.
static int newStateType()
          Used to get an integer ID which uniquely defined a state type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StateMap

public StateMap()
Method Detail

newStateType

public static int newStateType()
Used to get an integer ID which uniquely defined a state type. Shaders should initialize their state type in a static constant in their class definitions.

Returns:
the state type ID

assignState

public void assignState(StateTrackable<?> trackable)
Ok this is a little tricky. When a state trackable item comes in, we check to see if there is a state node already assigned. If there is then we are all set. If there isn't then what we have is this item which is a unique object, but probably is the same as one we have already seen.

So we take the item and use it as a key into a TreeMap. The state trackable items have to implement Comparable, so we we can use it as a key. Now this can be expensive since some shader components have many sub-items which will have to be compared. But if the comparators are written properly we can quickly match against the tree state in log(n) compares, which is very few.

If we find and entry then we just assign that state node to the state trackable item. If we do not then we create a new node. This node copies the statetrackable item, assigns it a unique id and inserts it into the tree.

Parameters:
trackable -