jpl.mipl.jade.jadis.agile2d
Class AgileState

java.lang.Object
  extended by jpl.mipl.jade.jadis.agile2d.AgileState

public class AgileState
extends Object

AgileState locally keeps OpenGL state to avoid useless state changes that are very expensive in OpenGL.

Note: AgileGraphics2D uses AgileState to manage all state changes. To interact well with AgileGraphics2D, use AgileState to manage state, or use the AgileGraphics2D.run() method to run code in a safe context. e.g.

    AgileState agileState = AgileState.get(gl);
    ...
    agileState.glEnable(GL.GL_TEXTURE_2D);
    agileState.bindTexture2D(0);
    if (agileState.setState(GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE)) {
          gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE);
    }
    agileState.glDisable(GL.GL_TEXTURE_2D);
 

Version:
$Revision: 1.3 $
Author:
Jean-Daniel Fekete

Constructor Summary
protected AgileState(javax.media.opengl.GL gl)
          AgileState constructor.
 
Method Summary
 void bindTexture1D(int tex)
           
 void bindTexture2D(int tex)
           
protected  void checkError()
           
static AgileState get(javax.media.opengl.GL gl)
          Get/Create a AgileState object for a GL context.
 javax.media.opengl.GL getGL()
          Returns the GL context.
 int getState(int attrib)
          Returns the value currently associated with the specified GL attribute.
 String getVersion()
          Returns a String representing the version of the OpenGL implementation.
 void glColor4f(float r, float g, float b, float a)
           
 void glColor4ub(byte r, byte g, byte b, byte a)
           
 void glDisable(int attrib)
          Equivalent to glDisable but checks the value first and skip the GL function is the value is already set to 0.
 void glDisableClientState(int mode)
           
 void glEnable(int attrib)
          Equivalent to glEnable but checks the value first and skip the GL function is the value is already set to 1.
 void glEnableClientState(int mode)
           
 void glLogicOp(int op)
           
 void glSetShadeModel(int model)
           
 void restore()
          Pops all GL attributes from the GL state stack, using glPopAttrib and glPopClientAttrib.
 void save()
          Pushes all GL attributes onto the GL state stack, using glPushAttrib and glPushClientAttrib.
 boolean setState(int attrib, int value)
          Sets the value currently associated with a specified GL attribute.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AgileState

protected AgileState(javax.media.opengl.GL gl)
AgileState constructor.

Parameters:
gl - the GL context.
Method Detail

get

public static AgileState get(javax.media.opengl.GL gl)
Get/Create a AgileState object for a GL context.

Parameters:
gl - the GL context
Returns:
the associated AgileState

getVersion

public String getVersion()
Returns a String representing the version of the OpenGL implementation.

Returns:
a String representing the version of the OpenGL implementation.

getGL

public javax.media.opengl.GL getGL()
Returns the GL context.

Returns:
the GL context.

getState

public int getState(int attrib)
Returns the value currently associated with the specified GL attribute. If the constant has not been queried before, the GL state is queried first to initialize the local state to the right value.

Parameters:
attrib - the GL attribute
Returns:
the associated value.

setState

public boolean setState(int attrib,
                        int value)
Sets the value currently associated with a specified GL attribute. Returns true if the value is different from the one in the GL state, meaning that a GL primitive should be used to set it. * @param attrib the attribute

Parameters:
value - the value r
Returns:
true if the value is different from the one in the GL state, meaning that a GL primitive should be used to set it.

checkError

protected void checkError()

glEnable

public void glEnable(int attrib)
Equivalent to glEnable but checks the value first and skip the GL function is the value is already set to 1.

Parameters:
attrib - the attribute to set.

glDisable

public void glDisable(int attrib)
Equivalent to glDisable but checks the value first and skip the GL function is the value is already set to 0.

Parameters:
attrib - the attribute to set.

bindTexture1D

public void bindTexture1D(int tex)

bindTexture2D

public void bindTexture2D(int tex)

glSetShadeModel

public void glSetShadeModel(int model)

glEnableClientState

public void glEnableClientState(int mode)

glDisableClientState

public void glDisableClientState(int mode)

glLogicOp

public void glLogicOp(int op)

glColor4ub

public void glColor4ub(byte r,
                       byte g,
                       byte b,
                       byte a)

glColor4f

public void glColor4f(float r,
                      float g,
                      float b,
                      float a)

save

public void save()
Pushes all GL attributes onto the GL state stack, using glPushAttrib and glPushClientAttrib.


restore

public void restore()
Pops all GL attributes from the GL state stack, using glPopAttrib and glPopClientAttrib.