net.java.joglutils.msg.nodes
Class Texture2

java.lang.Object
  extended by net.java.joglutils.msg.nodes.Node
      extended by net.java.joglutils.msg.nodes.Texture2

public class Texture2
extends Node

Represents a two-dimensional texture which can be set up from all of the image sources supported by the JOGL TextureIO classes or the JOGL TextureRenderer. If set up with a texture, supports updating of the texture as well. Supports switching between use of a TextureRenderer and a Texture.


Field Summary
static int BLEND
          Represents the OpenGL BLEND texture environment mode.
static int DECAL
          Represents the OpenGL DECAL texture environment mode.
static int MODULATE
          Represents the OpenGL MODULATE texture environment mode.
static int REPLACE
          Represents the OpenGL REPLACE texture environment mode.
 
Constructor Summary
Texture2()
           
 
Method Summary
 void dispose()
          Disposes of the OpenGL texture and/or TextureRenderer this Texture2 node refers to.
 void doAction(Action action)
          Performs the "typical" operation for this node when an action is applied to it.
 int getHeight()
          Returns the height of the texture or TextureRenderer this Texture2 node is referencing, or 0 if it has not been set up yet.
 int getTexEnvMode()
          Returns the texture environment mode: one of MODULATE, DECAL, BLEND, or REPLACE.
 com.sun.opengl.util.texture.Texture getTexture()
          Fetches the Texture object associated with this Texture2 node, refreshing its content if necessary.
 com.sun.opengl.util.j2d.TextureRenderer getTextureRenderer()
          Returns the TextureRenderer, if one has been set, that is associated with this Texture2 node.
 int getWidth()
          Returns the width of the texture or TextureRenderer this Texture2 node is referencing, or 0 if it has not been set up yet.
 void initTextureRenderer(int width, int height, boolean alpha)
          Initializes this node to operate upon a TextureRenderer of the specified width, height, and presence of an alpha channel.
 void resetGL(GLResetAction action)
          Resets the OpenGL state of this node without explicitly disposing of any resources.
 void setTexEnvMode(int mode)
          Sets the texture environment mode.
 void setTexture(BufferedImage image, boolean mipmap)
          Initializes this texture from the given BufferedImage.
 void setTexture(File file, boolean mipmap, String fileSuffix)
          Initializes this texture from the given file.
 void setTexture(InputStream stream, boolean mipmap, String fileSuffix)
          Initializes this texture from the given InputStream.
 void setTexture(com.sun.opengl.util.texture.TextureData data)
          Initializes this texture from the given TextureData.
 void setTexture(URL url, boolean mipmap, String fileSuffix)
          Initializes this texture from the given URL.
 void updateSubImage(com.sun.opengl.util.texture.TextureData data, int mipmapLevel, int dstx, int dsty, int srcx, int srcy, int width, int height)
          Updates a subregion of the content area of this texture using the specified sub-region of the given data.
 
Methods inherited from class net.java.joglutils.msg.nodes.Node
rayPick, render
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODULATE

public static final int MODULATE
Represents the OpenGL MODULATE texture environment mode.

See Also:
Constant Field Values

DECAL

public static final int DECAL
Represents the OpenGL DECAL texture environment mode.

See Also:
Constant Field Values

BLEND

public static final int BLEND
Represents the OpenGL BLEND texture environment mode.

See Also:
Constant Field Values

REPLACE

public static final int REPLACE
Represents the OpenGL REPLACE texture environment mode.

See Also:
Constant Field Values
Constructor Detail

Texture2

public Texture2()
Method Detail

setTexture

public void setTexture(File file,
                       boolean mipmap,
                       String fileSuffix)
                throws IOException
Initializes this texture from the given file. No OpenGL work is done during this call; it is done lazily when the Texture is fetched.

Throws:
IOException

setTexture

public void setTexture(InputStream stream,
                       boolean mipmap,
                       String fileSuffix)
                throws IOException
Initializes this texture from the given InputStream. No OpenGL work is done during this call; it is done lazily when the Texture is fetched.

Throws:
IOException

setTexture

public void setTexture(URL url,
                       boolean mipmap,
                       String fileSuffix)
                throws IOException
Initializes this texture from the given URL. No OpenGL work is done during this call; it is done lazily when the Texture is fetched.

Throws:
IOException

setTexture

public void setTexture(BufferedImage image,
                       boolean mipmap)
Initializes this texture from the given BufferedImage. No OpenGL work is done during this call; it is done lazily when the Texture is fetched.


setTexture

public void setTexture(com.sun.opengl.util.texture.TextureData data)
Initializes this texture from the given TextureData. No OpenGL work is done during this call; it is done lazily when the Texture is fetched.


getWidth

public int getWidth()
Returns the width of the texture or TextureRenderer this Texture2 node is referencing, or 0 if it has not been set up yet.


getHeight

public int getHeight()
Returns the height of the texture or TextureRenderer this Texture2 node is referencing, or 0 if it has not been set up yet.


updateSubImage

public void updateSubImage(com.sun.opengl.util.texture.TextureData data,
                           int mipmapLevel,
                           int dstx,
                           int dsty,
                           int srcx,
                           int srcy,
                           int width,
                           int height)
Updates a subregion of the content area of this texture using the specified sub-region of the given data. Only updates the specified mipmap level and does not re-generate mipmaps if they were originally produced or loaded. This method is only supported for uncompressed TextureData sources, and may only be called if a TextureRenderer has not been set up for this Texture2 node.

Parameters:
data - the image data to be uploaded to this texture
mipmapLevel - the mipmap level of the texture to set. If this is non-zero and the TextureData contains mipmap data, the appropriate mipmap level will be selected.
dstx - the x offset (in pixels) relative to the lower-left corner of this texture where the update will be applied
dsty - the y offset (in pixels) relative to the lower-left corner of this texture where the update will be applied
srcx - the x offset (in pixels) relative to the lower-left corner of the supplied TextureData from which to fetch the update rectangle
srcy - the y offset (in pixels) relative to the lower-left corner of the supplied TextureData from which to fetch the update rectangle
width - the width (in pixels) of the rectangle to be updated
height - the height (in pixels) of the rectangle to be updated

initTextureRenderer

public void initTextureRenderer(int width,
                                int height,
                                boolean alpha)
Initializes this node to operate upon a TextureRenderer of the specified width, height, and presence of an alpha channel. Updates to the TextureRenderer are automatically propagated to the texture as long as TextureRenderer.markDirty() is used properly.


getTextureRenderer

public com.sun.opengl.util.j2d.TextureRenderer getTextureRenderer()
Returns the TextureRenderer, if one has been set, that is associated with this Texture2 node.


getTexture

public com.sun.opengl.util.texture.Texture getTexture()
                                               throws javax.media.opengl.GLException
Fetches the Texture object associated with this Texture2 node, refreshing its content if necessary. It is required to call this each frame during rendering. An OpenGL context must be current at the time this method is called or a GLException will be thrown.

Throws:
javax.media.opengl.GLException

setTexEnvMode

public void setTexEnvMode(int mode)
Sets the texture environment mode. Default is MODULATE.


getTexEnvMode

public int getTexEnvMode()
Returns the texture environment mode: one of MODULATE, DECAL, BLEND, or REPLACE.


doAction

public void doAction(Action action)
Description copied from class: Node
Performs the "typical" operation for this node when an action is applied to it. The default implementation does nothing.

Overrides:
doAction in class Node

dispose

public void dispose()
             throws javax.media.opengl.GLException
Disposes of the OpenGL texture and/or TextureRenderer this Texture2 node refers to. An OpenGL context must be current at the point this method is called.

Throws:
javax.media.opengl.GLException

resetGL

public void resetGL(GLResetAction action)
Resets the OpenGL state of this node without explicitly disposing of any resources. This should only be called when you know you are using this Texture2 node across the destruction and re-creation of OpenGL contexts and know how to re-initialize the Texture2 from its previous state.