Aviatrix3D 1.0

org.j3d.aviatrix3d
Class TextureUnit

java.lang.Object
  extended byorg.j3d.aviatrix3d.SceneGraphObject
      extended byorg.j3d.aviatrix3d.NodeComponent
          extended byorg.j3d.aviatrix3d.TextureUnit
All Implemented Interfaces:
java.lang.Comparable, Renderable, RenderableComponent

public class TextureUnit
extends NodeComponent
implements RenderableComponent, java.lang.Comparable

Describes a texture stage and its associated texture and attributes.

The external data passed to the RenderableComponent calls shall be an Integer instance that represents the GL texture unit of the this instance is working with. If the value is -1, then only a single texture is being used, so the class does not need to make use of the glActiveTexture() call.

Version:
$Revision: 1.37 $
Author:
Justin Couch, Alan Hudson

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
TextureUnit()
          Constructs a Texture Unit with default values.
TextureUnit(Texture t, TextureAttributes attrs, TexCoordGeneration tcg)
          Construct a Texture Unit with the specified texture, attributes and coordinate generation.
 
Method Summary
protected  void checkForCyclicChild(SceneGraphObject parent)
          Check to see if this node is the same reference as the passed node that is a parent of this node.
 int compareTo(java.lang.Object o)
          Compares this object with the specified object for order.
 int compareTo(TextureUnit tu)
          Compares this object with the specified object for order.
 boolean equals(java.lang.Object o)
          Compare this object for equality to the given object.
 boolean equals(TextureUnit tu)
          Compares this object with the specified object to check for equivalence.
 TexCoordGeneration getTexCoordGeneration()
          Get the currently set texture.
 Texture getTexture()
          Get the currently set texture.
 TextureAttributes getTextureAttributes()
          Get the currently set texture attributes.
 void getTextureTransform(javax.vecmath.Matrix4f mat)
          Get the current local texture transformation maxtix.
 boolean isMultiTextureAllowed()
          Convenience method to check if this code has detected the prescense of multitexture extensions.
 void postRender(net.java.games.jogl.GL gl, net.java.games.jogl.GLU glu, java.lang.Object stageId)
          Restore all openGL state to the given drawable.
 void render(net.java.games.jogl.GL gl, net.java.games.jogl.GLU glu, java.lang.Object stageId)
          Issue ogl commands needed for this component
protected  void setLive(boolean state)
          Notification that this object is live now.
 void setTexCoordGeneration(TexCoordGeneration tcg)
          Set the texture coordinate generation for this stage.
 void setTexture(Texture tex)
          Set the texture for this stage.
 void setTextureAttributes(TextureAttributes attrs)
          Set the texture attributes for this stage.
 void setTextureTransform(javax.vecmath.Matrix4f mat)
          Set the current texture transform matrix.
protected  void setUpdateHandler(NodeUpdateHandler handler)
          Set the scenegraph update handler for this node.
 
Methods inherited from class org.j3d.aviatrix3d.NodeComponent
addParent, getParents, hasChanged, numParents, removeParent
 
Methods inherited from class org.j3d.aviatrix3d.SceneGraphObject
checkForCyclicParent, dataChanged, getUserData, isLive, setUserData
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextureUnit

public TextureUnit()
Constructs a Texture Unit with default values.


TextureUnit

public TextureUnit(Texture t,
                   TextureAttributes attrs,
                   TexCoordGeneration tcg)
Construct a Texture Unit with the specified texture, attributes and coordinate generation.

Parameters:
t - The texture instance to use
attrs - Attributes used to control the visual appearance
tcg - Automated texture coordinate generation, if needed
Method Detail

checkForCyclicChild

protected void checkForCyclicChild(SceneGraphObject parent)
                            throws CyclicSceneGraphStructureException
Check to see if this node is the same reference as the passed node that is a parent of this node. This is the downwards check to ensure that there is no cyclic scene graph structures at the point where someone adds a node to the scenegraph. When the reference and this are the same, an exception is generated. Since each class may have different lists of child node setups, this should be overriden by any class that can take children, and have the call passed along to the children.

Overrides:
checkForCyclicChild in class SceneGraphObject
Parameters:
parent - The reference to check against this class
Throws:
CyclicSceneGraphStructureException - Equal parent and child

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,
                   java.lang.Object stageId)
Issue ogl commands needed for this component

Specified by:
render in interface RenderableComponent
Parameters:
gl - The gl context to draw with
glu - The utility context to draw with
stageId - The ID of the texture stage we're reading

postRender

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

Specified by:
postRender in interface RenderableComponent
Parameters:
gl - The gl context to draw with
glu - The utility context to draw with
stageId - The ID of the texture stage we're reading

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 object 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

setTexture

public void setTexture(Texture tex)
                throws InvalidWriteTimingException
Set the texture for this stage. Passing a value of null will disable this stage from being passed to the rendering APIs.

Parameters:
tex - The texture to be used or null
Throws:
InvalidWriteTimingException - An attempt was made to write outside of the NodeUpdateListener callback method

getTexture

public Texture getTexture()
Get the currently set texture. If none is set, return null.

Returns:
The current texture instance or null

setTextureAttributes

public void setTextureAttributes(TextureAttributes attrs)
                          throws InvalidWriteTimingException
Set the texture attributes for this stage.

Parameters:
attrs - The texture attributes. Null clears.
Throws:
InvalidWriteTimingException - An attempt was made to write outside of the NodeUpdateListener callback method

getTextureAttributes

public TextureAttributes getTextureAttributes()
Get the currently set texture attributes. If none is set, return null.

Returns:
The current texture attributes instance or null

setTexCoordGeneration

public void setTexCoordGeneration(TexCoordGeneration tcg)
                           throws InvalidWriteTimingException
Set the texture coordinate generation for this stage.

Parameters:
tcg - The texture coordinate generation. Null clears.
Throws:
InvalidWriteTimingException - An attempt was made to write outside of the NodeUpdateListener callback method

getTexCoordGeneration

public TexCoordGeneration getTexCoordGeneration()
Get the currently set texture. If none is set, return null.

Returns:
The current texture instance or null

setTextureTransform

public void setTextureTransform(javax.vecmath.Matrix4f mat)
                         throws InvalidWriteTimingException
Set the current texture transform matrix. A value of null will reset the matrix back to the default identity matrix. A copy of this matrix is made.

Parameters:
mat - The matrix to modify textures by, or null
Throws:
InvalidWriteTimingException

getTextureTransform

public void getTextureTransform(javax.vecmath.Matrix4f mat)
Get the current local texture transformation maxtix. If no matrix is currently set, it will set the value to an identity matrix.

Parameters:
mat - The matrix to copy the current values into

compareTo

public int compareTo(TextureUnit tu)
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:
tu - The texture unit instance to be compared
Returns:
-1, 0 or 1 depending on order

equals

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

Parameters:
tu - The texture unit instance to be compared
Returns:
true if the objects represent identical values

isMultiTextureAllowed

public boolean isMultiTextureAllowed()
Convenience method to check if this code has detected the prescense of multitexture extensions. If none are found, this will return null. However, one node instance has to have passed through the rendering cycle for this to have detected it. A better option would be to make use of the appropriate callbacks on the DrawableSurface APIs to detect before you get to this point.

Returns:
true if multitexture is allowed

Aviatrix3D 1.0

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