com.rugl.gl
Class State

java.lang.Object
  extended by com.rugl.gl.State
All Implemented Interfaces:
java.lang.Comparable<State>

public class State
extends java.lang.Object
implements java.lang.Comparable<State>

Represents a rendering state

Author:
ryanm

Field Summary
 AlphaTest alphaTest
          Alpha test function
 Blend blend
          Blend function
 DepthTest depthTest
          Depth test
 PolygonMode polyMode
          Polygon rasterisation mode
 PolygonOffset polyOffset
          Polygon offset
 TextureState texture
          Texture state
 
Constructor Summary
State(boolean texture, boolean alphaTest, boolean blend, boolean depthTest, boolean polyMode, boolean polyOffset)
          Constructs a state that controls some facets of OpenGL state.
 
Method Summary
 void apply()
          Applies this rendering state to OpenGL
 State cloneInstance()
          Gets a clone of this state.
 int compareTo(State o)
           
static void compile(State... states)
          Compiles a set of states so that compiledState.compareTo( otherCompiledState ) is fast: a simple int comparison rather than a traversal of the entire state tree.
 boolean equals(java.lang.Object o)
           
 int getCompilationBatch()
          Comparisons based on getCompiledIndex() between states with different getCompilationBatch() values are invalid
 int getCompiledIndex()
          Gets the index that this state achieved in its compilation batch.
 void set(State state)
          Copies the values of the supplied State to this one.
 void setShader(ShaderProgram shader)
          Sets the shader program
static void stateReset()
          The State class mirrors the OpenGL state as much as possible, so don't change it outside of State, and call this when the OpenGL State is refreshed e.g.: when the display has been (re)created
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

texture

public final TextureState texture
Texture state


alphaTest

public final AlphaTest alphaTest
Alpha test function


blend

public final Blend blend
Blend function


depthTest

public final DepthTest depthTest
Depth test


polyMode

public final PolygonMode polyMode
Polygon rasterisation mode


polyOffset

public final PolygonOffset polyOffset
Polygon offset

Constructor Detail

State

public State(boolean texture,
             boolean alphaTest,
             boolean blend,
             boolean depthTest,
             boolean polyMode,
             boolean polyOffset)
Constructs a state that controls some facets of OpenGL state. Controlling fewer facets will speed up state comparison and transition.

Parameters:
texture -
alphaTest -
blend -
depthTest -
polyMode -
polyOffset -
Method Detail

stateReset

public static void stateReset()
The State class mirrors the OpenGL state as much as possible, so don't change it outside of State, and call this when the OpenGL State is refreshed e.g.: when the display has been (re)created


compile

public static void compile(State... states)
Compiles a set of states so that compiledState.compareTo( otherCompiledState ) is fast: a simple int comparison rather than a traversal of the entire state tree. On the other hand, changes to a compiled state will cause assertion errors as you've probably messed up the order.

Parameters:
states -

setShader

public void setShader(ShaderProgram shader)
Sets the shader program

Parameters:
shader - the new shader, or null for fixed-function

cloneInstance

public State cloneInstance()
Gets a clone of this state. Note that compilation status is not copied - there is very little point in having two separate but identical instances of a compiled state

Returns:
an identical rendering state

set

public void set(State state)
Copies the values of the supplied State to this one. Note that compilation status is not copied - there is very little point in having two separate but identical instances of a compiled state

Parameters:
state - the state to copy

apply

public void apply()
Applies this rendering state to OpenGL


getCompilationBatch

public int getCompilationBatch()
Comparisons based on getCompiledIndex() between states with different getCompilationBatch() values are invalid

Returns:
the batch number of the compilation of this State, or -1 if this state has not been compiled

getCompiledIndex

public int getCompiledIndex()
Gets the index that this state achieved in its compilation batch. Remember that states compiled in different batches can have the same compiled index

Returns:
The index of this state in its compilation batch, or -1 if the state has not been compiled

compareTo

public int compareTo(State o)
Specified by:
compareTo in interface java.lang.Comparable<State>

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object