com.sun.opengl.util.glsl
Class ShaderState

java.lang.Object
  extended by com.sun.opengl.util.glsl.ShaderState

public class ShaderState
extends Object


Field Summary
protected  HashMap attribMap2Idx
           
static boolean DEBUG
           
protected  HashSet enabledVertexAttribArraySet
           
protected  ShaderProgram shaderProgram
           
protected  HashMap uniformMap2Data
           
protected  HashMap uniformMap2Idx
           
protected  boolean verbose
           
protected  HashMap vertexAttribMap2Data
           
 
Constructor Summary
ShaderState()
           
 
Method Summary
 void attachShaderProgram(GL2ES2 gl, ShaderProgram prog)
          Attach or switch a shader program Attaching a shader program the first time, as well as switching to another program on the fly, while managing all attribute and uniform data.
 void destroy(GL2ES2 gl)
          Calls release(gl, true, true)
protected  int getAttribLocation(String name)
           
static ShaderState getCurrent()
          Fetches the current shader state from the thread local storage (TLS)
 GLUniformData getUniform(String name)
          Get the uniform data, previously set.
protected  int getUniformLocation(String name)
           
 GLArrayData getVertexAttribPointer(String name)
          Get the vertex attribute data, previously set.
 void glBindAttribLocation(GL2ES2 gl, int index, String name)
          Binds an attribute to the shader.
 void glDisableAllVertexAttributeArrays(GL2ES2 gl, boolean removeFromState)
          Disables all vertex attribute arrays.
 boolean glDisableVertexAttribArray(GL2ES2 gl, String name)
          Disables a vertex attribute array Even if the attribute is not found in the current shader, it is removed from this state.
 boolean glEnableVertexAttribArray(GL2ES2 gl, String name)
          Enable a vertex attribute array Even if the attribute is not found in the current shader, it is stored in this state.
 int glGetAttribLocation(GL2ES2 gl, String name)
          Gets the index of a shader attribute.
protected  int glGetUniformLocation(GL2ES2 gl, String name)
          Gets the index of a shader uniform.
 void glReleaseAllUniforms(GL2ES2 gl)
          Releases all mapped uniform data and loses all indices
 void glReleaseAllVertexAttributes(GL2ES2 gl)
          Releases all mapped vertex attribute data, disables all enabled attributes and loses all indices
 void glResetAllUniforms(GL2ES2 gl)
          Reset all previously mapped uniform data
 void glResetAllVertexAttributes(GL2ES2 gl)
          Reset all previously enabled mapped vertex attribute data, incl enabling them
 boolean glUniform(GL2ES2 gl, GLUniformData data)
          Set the uniform data.
 void glUseProgram(GL2ES2 gl, boolean on)
          Turns the shader program on or off.
Puts this ShaderState to to the thread local storage (TLS), if on is true.
 boolean glVertexAttribPointer(GL2ES2 gl, GLArrayData data)
          Set the vertex attribute data.
 boolean inUse()
           
 boolean isVertexAttribArrayEnabled(String name)
           
 boolean linked()
           
 void release(GL2ES2 gl, boolean releaseProgramToo, boolean releaseShaderToo)
           
 void releaseAllData(GL2ES2 gl)
          Calls release(gl, false, false)
 void setVerbose(boolean v)
           
 ShaderProgram shaderProgram()
           
 String toString()
           
 boolean verbose()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEBUG

public static final boolean DEBUG

verbose

protected boolean verbose

shaderProgram

protected ShaderProgram shaderProgram

attribMap2Idx

protected HashMap attribMap2Idx

enabledVertexAttribArraySet

protected HashSet enabledVertexAttribArraySet

vertexAttribMap2Data

protected HashMap vertexAttribMap2Data

uniformMap2Idx

protected HashMap uniformMap2Idx

uniformMap2Data

protected HashMap uniformMap2Data
Constructor Detail

ShaderState

public ShaderState()
Method Detail

verbose

public boolean verbose()

setVerbose

public void setVerbose(boolean v)

getCurrent

public static ShaderState getCurrent()
Fetches the current shader state from the thread local storage (TLS)

See Also:
javax.media.opengl.glsl.ShaderState#glUseProgram(GL2ES2, boolean), javax.media.opengl.glsl.ShaderState#getCurrent()

glUseProgram

public void glUseProgram(GL2ES2 gl,
                         boolean on)
Turns the shader program on or off.
Puts this ShaderState to to the thread local storage (TLS), if on is true.

See Also:
javax.media.opengl.glsl.ShaderState#glUseProgram(GL2ES2, boolean), javax.media.opengl.glsl.ShaderState#getCurrent()

linked

public boolean linked()

inUse

public boolean inUse()

attachShaderProgram

public void attachShaderProgram(GL2ES2 gl,
                                ShaderProgram prog)
Attach or switch a shader program Attaching a shader program the first time, as well as switching to another program on the fly, while managing all attribute and uniform data.


shaderProgram

public ShaderProgram shaderProgram()

destroy

public void destroy(GL2ES2 gl)
Calls release(gl, true, true)

See Also:
glReleaseAllVertexAttributes(javax.media.opengl.GL2ES2), glReleaseAllUniforms(javax.media.opengl.GL2ES2), release(GL2ES2, boolean, boolean)

releaseAllData

public void releaseAllData(GL2ES2 gl)
Calls release(gl, false, false)

See Also:
glReleaseAllVertexAttributes(javax.media.opengl.GL2ES2), glReleaseAllUniforms(javax.media.opengl.GL2ES2), release(GL2ES2, boolean, boolean)

release

public void release(GL2ES2 gl,
                    boolean releaseProgramToo,
                    boolean releaseShaderToo)
See Also:
glReleaseAllVertexAttributes(javax.media.opengl.GL2ES2), glReleaseAllUniforms(javax.media.opengl.GL2ES2), ShaderProgram.release(GL2ES2, boolean)

glBindAttribLocation

public void glBindAttribLocation(GL2ES2 gl,
                                 int index,
                                 String name)
Binds an attribute to the shader. This must be done before the program is linked ! n name - 1 idx, where name is a uniq key

Throws:
GLException - is the program is already linked
See Also:
glBindAttribLocation(javax.media.opengl.GL2ES2, int, java.lang.String), GL2ES2.glBindAttribLocation(int, int, java.lang.String), glGetAttribLocation(javax.media.opengl.GL2ES2, java.lang.String), GL2ES2.glGetAttribLocation(int, java.lang.String), getAttribLocation(java.lang.String), #glReplaceShader

glGetAttribLocation

public int glGetAttribLocation(GL2ES2 gl,
                               String name)
Gets the index of a shader attribute. This must be done after the program is linked !

Returns:
-1 if there is no such attribute available, otherwise >= 0
Throws:
GLException - is the program is not linked
See Also:
glBindAttribLocation(javax.media.opengl.GL2ES2, int, java.lang.String), GL2ES2.glBindAttribLocation(int, int, java.lang.String), glGetAttribLocation(javax.media.opengl.GL2ES2, java.lang.String), GL2ES2.glGetAttribLocation(int, java.lang.String), getAttribLocation(java.lang.String), #glReplaceShader

getAttribLocation

protected int getAttribLocation(String name)

glEnableVertexAttribArray

public boolean glEnableVertexAttribArray(GL2ES2 gl,
                                         String name)
Enable a vertex attribute array Even if the attribute is not found in the current shader, it is stored in this state.

Throws:
GLException - if the program is not in use
See Also:
glEnableVertexAttribArray(javax.media.opengl.GL2ES2, java.lang.String), glDisableVertexAttribArray(javax.media.opengl.GL2ES2, java.lang.String), glVertexAttribPointer(javax.media.opengl.GL2ES2, javax.media.opengl.GLArrayData), #getVertexAttributePointer, glReleaseAllVertexAttributes(javax.media.opengl.GL2ES2), glResetAllVertexAttributes(javax.media.opengl.GL2ES2), #glReplaceShader

isVertexAttribArrayEnabled

public boolean isVertexAttribArrayEnabled(String name)

glDisableVertexAttribArray

public boolean glDisableVertexAttribArray(GL2ES2 gl,
                                          String name)
Disables a vertex attribute array Even if the attribute is not found in the current shader, it is removed from this state.

Throws:
GLException - if the program is not in use
See Also:
glEnableVertexAttribArray(javax.media.opengl.GL2ES2, java.lang.String), glDisableVertexAttribArray(javax.media.opengl.GL2ES2, java.lang.String), glVertexAttribPointer(javax.media.opengl.GL2ES2, javax.media.opengl.GLArrayData), #getVertexAttributePointer, glReleaseAllVertexAttributes(javax.media.opengl.GL2ES2), glResetAllVertexAttributes(javax.media.opengl.GL2ES2), #glReplaceShader

glVertexAttribPointer

public boolean glVertexAttribPointer(GL2ES2 gl,
                                     GLArrayData data)
Set the vertex attribute data. Enable the attribute, if it is not enabled yet. Even if the attribute is not found in the current shader, it is stored in this state.

Parameters:
data - the GLArrayData's name must match the attributes one, it's index will be set with the attribute's location, if found.
Throws:
GLException - if the program is not in use
See Also:
glEnableVertexAttribArray(javax.media.opengl.GL2ES2, java.lang.String), glDisableVertexAttribArray(javax.media.opengl.GL2ES2, java.lang.String), glVertexAttribPointer(javax.media.opengl.GL2ES2, javax.media.opengl.GLArrayData), #getVertexAttributePointer, glReleaseAllVertexAttributes(javax.media.opengl.GL2ES2), glResetAllVertexAttributes(javax.media.opengl.GL2ES2), #glReplaceShader

getVertexAttribPointer

public GLArrayData getVertexAttribPointer(String name)
Get the vertex attribute data, previously set.

See Also:
glEnableVertexAttribArray(javax.media.opengl.GL2ES2, java.lang.String), glDisableVertexAttribArray(javax.media.opengl.GL2ES2, java.lang.String), glVertexAttribPointer(javax.media.opengl.GL2ES2, javax.media.opengl.GLArrayData), #getVertexAttributePointer, glReleaseAllVertexAttributes(javax.media.opengl.GL2ES2), glResetAllVertexAttributes(javax.media.opengl.GL2ES2), #glReplaceShader

glReleaseAllVertexAttributes

public void glReleaseAllVertexAttributes(GL2ES2 gl)
Releases all mapped vertex attribute data, disables all enabled attributes and loses all indices

Throws:
GLException - is the program is not in use but the shaderProgram is set
See Also:
glEnableVertexAttribArray(javax.media.opengl.GL2ES2, java.lang.String), glDisableVertexAttribArray(javax.media.opengl.GL2ES2, java.lang.String), glVertexAttribPointer(javax.media.opengl.GL2ES2, javax.media.opengl.GLArrayData), #getVertexAttributePointer, glReleaseAllVertexAttributes(javax.media.opengl.GL2ES2), glResetAllVertexAttributes(javax.media.opengl.GL2ES2), glResetAllVertexAttributes(javax.media.opengl.GL2ES2), #glReplaceShader

glDisableAllVertexAttributeArrays

public void glDisableAllVertexAttributeArrays(GL2ES2 gl,
                                              boolean removeFromState)
Disables all vertex attribute arrays. Their enabled stated will be removed from this state only if 'removeFromState' is true. This method purpose is more for debugging.

Throws:
GLException - is the program is not in use but the shaderProgram is set
See Also:
glEnableVertexAttribArray(javax.media.opengl.GL2ES2, java.lang.String), glDisableVertexAttribArray(javax.media.opengl.GL2ES2, java.lang.String), glVertexAttribPointer(javax.media.opengl.GL2ES2, javax.media.opengl.GLArrayData), #getVertexAttributePointer, glReleaseAllVertexAttributes(javax.media.opengl.GL2ES2), glResetAllVertexAttributes(javax.media.opengl.GL2ES2), glResetAllVertexAttributes(javax.media.opengl.GL2ES2), #glReplaceShader

glResetAllVertexAttributes

public void glResetAllVertexAttributes(GL2ES2 gl)
Reset all previously enabled mapped vertex attribute data, incl enabling them

Throws:
GLException - is the program is not in use
See Also:
glEnableVertexAttribArray(javax.media.opengl.GL2ES2, java.lang.String), glDisableVertexAttribArray(javax.media.opengl.GL2ES2, java.lang.String), glVertexAttribPointer(javax.media.opengl.GL2ES2, javax.media.opengl.GLArrayData), #getVertexAttributePointer, glReleaseAllVertexAttributes(javax.media.opengl.GL2ES2), glResetAllVertexAttributes(javax.media.opengl.GL2ES2), #glReplaceShader

glGetUniformLocation

protected int glGetUniformLocation(GL2ES2 gl,
                                   String name)
Gets the index of a shader uniform. This must be done when the program is in use !

Returns:
-1 if there is no such attribute available, otherwise >= 0
Throws:
GLException - is the program is not linked
See Also:
glGetUniformLocation(javax.media.opengl.GL2ES2, java.lang.String), GL2ES2.glGetUniformLocation(int, java.lang.String), getUniformLocation(java.lang.String), #glReplaceShader

getUniformLocation

protected int getUniformLocation(String name)

glUniform

public boolean glUniform(GL2ES2 gl,
                         GLUniformData data)
Set the uniform data. Even if the uniform is not found in the current shader, it is stored in this state.

Parameters:
data - the GLUniforms's name must match the uniform one, it's index will be set with the uniforms's location, if found.
Throws:
GLException - if the program is not in use
See Also:
glGetUniformLocation(javax.media.opengl.GL2ES2, java.lang.String), GL2ES2.glGetUniformLocation(int, java.lang.String), getUniformLocation(java.lang.String), #glReplaceShader

getUniform

public GLUniformData getUniform(String name)
Get the uniform data, previously set.


glReleaseAllUniforms

public void glReleaseAllUniforms(GL2ES2 gl)
Releases all mapped uniform data and loses all indices

Throws:
GLException - is the program is not in use

glResetAllUniforms

public void glResetAllUniforms(GL2ES2 gl)
Reset all previously mapped uniform data

Throws:
GLException - is the program is not in use

toString

public String toString()
Overrides:
toString in class Object


Copyright 2005 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.