Aviatrix3D 1.0

org.j3d.aviatrix3d
Class GLSLangShader

java.lang.Object
  extended byorg.j3d.aviatrix3d.SceneGraphObject
      extended byorg.j3d.aviatrix3d.NodeComponent
          extended byorg.j3d.aviatrix3d.Shader
              extended byorg.j3d.aviatrix3d.GLSLangShader
All Implemented Interfaces:
java.lang.Comparable, Renderable, RenderableObject

public class GLSLangShader
extends Shader
implements java.lang.Comparable

Shader handler for shaders written with the OpenGL GLSLang 1.0 shader language.

A shader consists of the compiled program source and a set of arguments. The compiled source is represented by the ShaderProgram class. Uniform variable arguments are provided through the ShaderArguments class, while attribute variable values are directly provided as part of the VertexGeometry.

This allows a single program to be used multiple times and just change the argument values depending on the object to be rendered, without needing two completely separate sets of shaders.

Version:
$Revision: 1.9 $
Author:
Justin Couch

Field Summary
 
Fields inherited from class org.j3d.aviatrix3d.NodeComponent
lastParent, liveCount, parentList
 
Fields inherited from class org.j3d.aviatrix3d.SceneGraphObject
alive, LISTENER_SET_NOT_LIVE_MESSAGE, updateHandler, WRITE_TIMING_MSG
 
Constructor Summary
GLSLangShader()
          Constructs a shader with nothing set.
 
Method Summary
 int compareTo(GLSLangShader sh)
          Compares this object with the specified object for order.
 int compareTo(java.lang.Object o)
          Compares this object with the specified object for order.
 boolean equals(GLSLangShader sh)
          Compares this object with the specified object to check for equivalence.
 boolean equals(java.lang.Object o)
          Compare this object for equality to the given object.
 ShaderArguments getShaderArguments()
          Get the currently set shader arguments instance.
 ShaderProgram getShaderProgram()
          Get the currently set shader program instance.
 boolean isValidated()
          Check on the current validation state.
 void postRender(net.java.games.jogl.GL gl, net.java.games.jogl.GLU glu)
          Restore all openGL state to the given drawable
 void render(net.java.games.jogl.GL gl, net.java.games.jogl.GLU glu)
          Issue ogl commands needed for this component
protected  void setLive(boolean state)
          Notification that this object is live now.
 void setShaderArguments(ShaderArguments arg)
          Set the shader arguments to be used on this object.
 void setShaderProgram(ShaderProgram prog)
          Set the shader program to be used on this object.
protected  void setUpdateHandler(NodeUpdateHandler handler)
          Set the scenegraph update handler for this node.
 void validate()
          Request that the shader validate it's code at the next available oppourtunity.
 
Methods inherited from class org.j3d.aviatrix3d.NodeComponent
addParent, getParents, hasChanged, numParents, removeParent
 
Methods inherited from class org.j3d.aviatrix3d.SceneGraphObject
checkForCyclicChild, checkForCyclicParent, dataChanged, getUserData, isLive, setUserData
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GLSLangShader

public GLSLangShader()
Constructs a shader with nothing set. When used, it will have no effect.

Method Detail

setUpdateHandler

protected void setUpdateHandler(NodeUpdateHandler handler)
Set the scenegraph update handler for this node. It will notify all its children of the value. A null value will clear the current handler.

Overrides:
setUpdateHandler in class SceneGraphObject
Parameters:
handler - The instance to use as a handler

setLive

protected void setLive(boolean state)
Notification that this object is live now. Overridden to make sure that the live state of the nodes represents the same state as the parent scene graph.

Overrides:
setLive in class SceneGraphObject
Parameters:
state - true if this should be marked as live now

render

public void render(net.java.games.jogl.GL gl,
                   net.java.games.jogl.GLU glu)
Issue ogl commands needed for this component

Specified by:
render in interface RenderableObject
Parameters:
gl - The gl context to draw with
glu - The utility context to draw with

postRender

public void postRender(net.java.games.jogl.GL gl,
                       net.java.games.jogl.GLU glu)
Restore all openGL state to the given drawable

Specified by:
postRender in interface RenderableObject
Parameters:
gl - The gl context to draw with
glu - The utility context to draw with

compareTo

public int compareTo(java.lang.Object o)
              throws java.lang.ClassCastException
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Derived classes should extend this one to add the extra comparisons needed.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - The objec to be compared
Returns:
-1, 0 or 1 depending on order
Throws:
java.lang.ClassCastException - The specified object's type prevents it from being compared to this Object

equals

public boolean equals(java.lang.Object o)
Compare this object for equality to the given object.

Parameters:
o - The object to be compared
Returns:
True if these represent the same values

setShaderProgram

public void setShaderProgram(ShaderProgram prog)
                      throws InvalidWriteTimingException
Set the shader program to be used on this object. Program instances may be shared between multiple primitives. A value of null will remove the currently set shader from being used.

Parameters:
prog - The program instance to use or null
Throws:
InvalidWriteTimingException - An attempt was made to write outside of the NodeUpdateListener callback method

getShaderProgram

public ShaderProgram getShaderProgram()
Get the currently set shader program instance. If none is set, this will return null.

Returns:
The current instance or null

setShaderArguments

public void setShaderArguments(ShaderArguments arg)
                        throws InvalidWriteTimingException
Set the shader arguments to be used on this object. Argument instances may be shared between multiple primitives. A value of null will remove the currently set arguments, returning them to their default values which are the last set values according to the OGL spec).

Parameters:
arg - The argument instance to use or null
Throws:
InvalidWriteTimingException - An attempt was made to write outside of the NodeUpdateListener callback method

getShaderArguments

public ShaderArguments getShaderArguments()
Get the currently set shader arguments instance. If none is set, this will return null.

Returns:
The current instance or null

validate

public void validate()
              throws InvalidWriteTimingException
Request that the shader validate it's code at the next available oppourtunity. Note that this is purely a debugging capability provided for shader programs and you should not be calling this in production code. It will cause severe performance impacts.

Also note that the validation can only take place in the course of the normal runtime processing of the render loop as it validates whether the shader can execute given the current complete OpenGL state. If the shader is currently on a primitive that is not visible on screen, it will not be validated until it is visible.

Throws:
InvalidWriteTimingException - An attempt was made to write outside of the NodeUpdateListener callback method

isValidated

public boolean isValidated()
Check on the current validation state. This will always return true unless the user asks for explicit validation via the validate() method.

Returns:
true always unless the user requests explicit validation

compareTo

public int compareTo(GLSLangShader sh)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Derived classes should extend this one to add the extra comparisons needed.

Parameters:
sh - The shader instances to be compared
Returns:
-1, 0 or 1 depending on order

equals

public boolean equals(GLSLangShader sh)
Compares this object with the specified object to check for equivalence.

Parameters:
sh - The shader instance to be compared
Returns:
true if the objects represent identical values

Aviatrix3D 1.0

Latest Info from http://aviatrix3d.j3d.org/
Copyright © 2003 - 2005 j3d.org