Aviatrix3D
2.1.0

org.j3d.aviatrix3d
Class GLSLangShader

java.lang.Object
  extended by org.j3d.aviatrix3d.SceneGraphObject
      extended by org.j3d.aviatrix3d.NodeComponent
          extended by org.j3d.aviatrix3d.Shader
              extended by org.j3d.aviatrix3d.GLSLangShader
All Implemented Interfaces:
java.lang.Comparable, ObjectRenderable, Renderable, ShaderRenderable

public class GLSLangShader
extends Shader
implements ShaderRenderable

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.15 $
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_TIMING_ERR_PROP, updateHandler
 
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.
 ComponentRenderable getArgumentsRenderable()
          Get an object that represents arguments that should be passed along with the shader.
 ShaderArguments getShaderArguments()
          Get the currently set shader arguments instance.
 ShaderProgram getShaderProgram()
          Get the currently set shader program instance.
 ShaderComponentRenderable getShaderRenderable(int type)
          Get the component of this shader, if it has one.
 boolean isValidated()
          Check on the current validation state.
 void postRender(javax.media.opengl.GL gl)
          Restore all openGL state to the given drawable
 void render(javax.media.opengl.GL gl)
          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, numParents, removeParent
 
Methods inherited from class org.j3d.aviatrix3d.SceneGraphObject
checkForCyclicChild, checkForCyclicParent, dataChanged, getAppUpdateWriteTimingMessage, getBoundsWriteTimingMessage, getDataWriteTimingMessage, 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

getArgumentsRenderable

public ComponentRenderable getArgumentsRenderable()
Get an object that represents arguments that should be passed along with the shader. If the shader has a full program component renderable. then it will most likely have arguments too.

Specified by:
getArgumentsRenderable in interface ShaderRenderable
Returns:
An object representing any global argument lists

getShaderRenderable

public ShaderComponentRenderable getShaderRenderable(int type)
Get the component of this shader, if it has one. If the given type is not recognised by this shader, return null.

Specified by:
getShaderRenderable in interface ShaderRenderable
Parameters:
type - One of the _SHADER constants from ShaderComponentRenderable
Returns:
A matching component or null if none

render

public void render(javax.media.opengl.GL gl)
Issue ogl commands needed for this component

Specified by:
render in interface ObjectRenderable
Parameters:
gl - The gl context to draw with

postRender

public void postRender(javax.media.opengl.GL gl)
Restore all openGL state to the given drawable

Specified by:
postRender in interface ObjectRenderable
Parameters:
gl - The gl context to draw with

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

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.

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.

Specified by:
equals in interface Renderable
Overrides:
equals in class java.lang.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 data changed 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 data changed 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 data changed 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.

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
2.1.0

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