com.jme.scene.state
Class TextureState

java.lang.Object
  extended by com.jme.scene.state.RenderState
      extended by com.jme.scene.state.TextureState
All Implemented Interfaces:
Savable
Direct Known Subclasses:
JOGLTextureState, LWJGLTextureState

public abstract class TextureState
extends RenderState

TextureState maintains a texture state for a given node and it's children. The number of states that a TextureState can maintain at one time is equal to the number of texture units available on the GPU. It is not within the scope of this class to generate the texture, and is recommended that TextureManager be used to create the Texture objects.

Version:
$Id: TextureState.java,v 1.43 2007/10/05 22:39:48 nca Exp $
Author:
Mark Powell, Joshua Slack, Tijl Houtbeckers - TextureID cache / Shader texture units, Vekas Arpad - Shader Texture units
See Also:
TextureManager

Nested Class Summary
static class TextureState.CorrectionType
           
 
Field Summary
 
Fields inherited from class com.jme.scene.state.RenderState
QUICK_COMPARE, RS_BLEND, RS_CLIP, RS_COLORMASK_STATE, RS_CULL, RS_FOG, RS_FRAGMENT_PROGRAM, RS_GLSL_SHADER_OBJECTS, RS_LIGHT, RS_MATERIAL, RS_MAX_STATE, RS_SHADE, RS_STENCIL, RS_TEXTURE, RS_VERTEX_PROGRAM, RS_WIREFRAME, RS_ZBUFFER
 
Constructor Summary
TextureState()
          Constructor instantiates a new TextureState object.
 
Method Summary
 void clearTextures()
          Removes all textures in this texture state.
abstract  void delete(int unit)
          Removes the texture of the given unit.
abstract  void deleteAll()
          Removes all Texture set in this TextureState.
abstract  void deleteAll(boolean removeFromCache)
          Removes all Texture set in this TextureState.
 void deleteTextureId(int textureId)
           
 Class<? extends TextureState> getClassTag()
           
 TextureState.CorrectionType getCorrectionType()
          getCorrectionType returns the correction mode for the texture state.
static Texture getDefaultTexture()
           
static Image getDefaultTextureImage()
           
 float getMaxAnisotropic()
          Returns the maximum anisotropic filter.
static int getNumberOfFixedUnits()
          getNumberOfFixedUnits returns the number of texture units the computer's graphics card supports, for use in the fixed pipeline.
static int getNumberOfFragmentTexCoordUnits()
          getNumberOfFragmentTexCoordUnits returns the number of texture coordinate sets available that this graphics card supports.
static int getNumberOfFragmentUnits()
          getNumberOfFragmentUnits returns the number of texture units available to a fragment shader that this graphics card supports.
 int getNumberOfSetTextures()
          Returns the number of textures this texture manager is maintaining.
static int getNumberOfTotalUnits()
          getNumberOfTotalUnits returns the number texture units the computer's graphics card supports.
static int getNumberOfVertexUnits()
          getNumberOfVertexUnits returns the number of texture units available to a vertex shader that this graphics card supports.
 Texture getTexture()
          getTexture gets the texture that is assigned to the first texture unit.
 Texture getTexture(int textureUnit)
          getTexture retrieves the texture being used by the state in a particular texture unit.
 int getTextureCoordinateOffset()
          setTextureCoordinateOffset gets the offset value used to determine which coordinates to use for texturing Geometry.
 int getTextureID(int textureUnit)
          Fast access for retrieving a Texture ID.
static int getTotalNumberOfUnits()
          getTotalNumberOfUnits returns the total number of texture units the computer's graphics card supports.
 int getType()
          getType returns this type of render state.
static boolean isAnisoSupported()
           
 boolean isAutomaticMipmapsSupported()
          Returns if AutomaticMipmap generation is available for textures.
static boolean isEnvCombineSupported()
           
static boolean isEnvDot3Supported()
           
static boolean isMultiTextureSupported()
           
static boolean isNonPowerOfTwoTextureSupported()
           
static boolean isRectangularTextureSupported()
           
 boolean isS3TCSupported()
          Returns if S3TC compression is available for textures.
 boolean isTexture3DSupported()
          Returns if Texture3D is available for textures.
 boolean isTextureCubeMapSupported()
          Returns if TextureCubeMap is available for textures.
 void load()
          Loads our textures into the underlying rendering system, generating mip maps if appropriate.
abstract  void load(int unit)
          Loads the texture for the given unit into the underlying rendering system, generating mip maps if appropriate.
static void overrideAnisoSupport(boolean use)
          Overide setting of support for Anisotropic texture filtering.
static void overrideAutomaticMipmapsSupport(boolean use)
          Overide setting of AutomaticMipmap generation support.
static void overrideEnvCombineSupport(boolean use)
          Overide support for combine environment texture settings
static void overrideEnvDot3Support(boolean use)
          Overide support for dot3 environment texture settings
static void overrideMultiTextureSupport(boolean use)
          Overide setting of fixed function multi-texturing support.
static void overrideNonPowerOfTwoTextureSupport(boolean use)
          Overide setting of support for non-pow2 texture sizes.
static void overrideRectangularTextureSupport(boolean use)
          Overide auto-detected setting of support for rectangular texture sizes (width != height).
static void overrideS3TCSupport(boolean use)
          Overide setting of S3TC compression support.
static void overrideTexture3DSupport(boolean use)
          Overide setting of Texture3D support.
static void overrideTextureCubeMapSupport(boolean use)
          Overide setting of TextureCubeMap support.
 void read(JMEImporter e)
           
 boolean removeTexture(int textureUnit)
           
 boolean removeTexture(Texture tex)
           
static void resetAnisoSupport()
          Reset dot3 environment texture support to driver-detected setting.
static void resetAutomaticMipmapsSupport()
          Reset AutomaticMipmap generation support to driver-detected setting.
static void resetEnvCombineSupport()
          Reset combine environment texture support to driver-detected setting.
static void resetEnvDot3Support()
          Reset dot3 environment texture support to driver-detected setting.
static void resetMultiTextureSupport()
          Reset fixed function multi-texturing support to driver-detected setting.
static void resetNonPowerOfTwoTextureSupport()
          Reset support for non-pow2 texture sizes to driver-detected setting.
static void resetRectangularTextureSupport()
          Reset support for rectangular texture sizes to driver-detected setting.
static void resetS3TCSupport()
          Reset dot3 environment texture support to driver-detected setting.
static void resetTexture3DSupport()
          Reset Texture3D support to driver-detected setting.
static void resetTextureCubeMapSupport()
          Reset TextureCubeMap support to driver-detected setting.
 void setCorrectionType(TextureState.CorrectionType type)
          setCorrectionType sets the image correction type for this texture state.
 void setTexture(Texture texture)
          setTexture sets a single texture to the first texture unit.
 void setTexture(Texture texture, int textureUnit)
          setTexture sets the texture object to be used by the state.
 void setTextureCoordinateOffset(int offset)
          setTextureCoordinateOffset sets the offset value used to determine which coordinates to use for texturing Geometry.
 void write(JMEExporter e)
           
 
Methods inherited from class com.jme.scene.state.RenderState
apply, createStateRecord, extract, isEnabled, needsRefresh, setEnabled, setNeedsRefresh, setQuickCompares
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextureState

public TextureState()
Constructor instantiates a new TextureState object.

Method Detail

getType

public int getType()
getType returns this type of render state. (RS_TEXTURE).

Specified by:
getType in class RenderState
Returns:
An int identifying this render state.
See Also:
RenderState.getType()

setTexture

public void setTexture(Texture texture)
setTexture sets a single texture to the first texture unit.

Parameters:
texture - the texture to set.

getTexture

public Texture getTexture()
getTexture gets the texture that is assigned to the first texture unit.

Returns:
the texture in the first texture unit.

setTexture

public void setTexture(Texture texture,
                       int textureUnit)
setTexture sets the texture object to be used by the state. The texture unit that this texture uses is set, if the unit is not valid, i.e. less than zero or greater than the number of texture units supported by the graphics card, it is ignored.

Parameters:
texture - the texture to be used by the state.
textureUnit - the texture unit this texture will fill.

getTexture

public Texture getTexture(int textureUnit)
getTexture retrieves the texture being used by the state in a particular texture unit.

Parameters:
textureUnit - the texture unit to retrieve the texture from.
Returns:
the texture being used by the state. If the texture unit is invalid, null is returned.

removeTexture

public boolean removeTexture(Texture tex)

removeTexture

public boolean removeTexture(int textureUnit)

clearTextures

public void clearTextures()
Removes all textures in this texture state. Does not delete them from the graphics card.


setCorrectionType

public void setCorrectionType(TextureState.CorrectionType type)
setCorrectionType sets the image correction type for this texture state.

Parameters:
type - the correction type for this texture.
Throws:
IllegalArgumentException - if type is null

getCorrectionType

public TextureState.CorrectionType getCorrectionType()
getCorrectionType returns the correction mode for the texture state.

Returns:
the correction type for the texture state.

getTotalNumberOfUnits

public static int getTotalNumberOfUnits()
getTotalNumberOfUnits returns the total number of texture units the computer's graphics card supports.

Returns:
the total number of texture units supported by the graphics card.

getNumberOfFixedUnits

public static int getNumberOfFixedUnits()
getNumberOfFixedUnits returns the number of texture units the computer's graphics card supports, for use in the fixed pipeline.

Returns:
the number units.

getNumberOfVertexUnits

public static int getNumberOfVertexUnits()
getNumberOfVertexUnits returns the number of texture units available to a vertex shader that this graphics card supports.

Returns:
the number of units.

getNumberOfFragmentUnits

public static int getNumberOfFragmentUnits()
getNumberOfFragmentUnits returns the number of texture units available to a fragment shader that this graphics card supports.

Returns:
the number of units.

getNumberOfFragmentTexCoordUnits

public static int getNumberOfFragmentTexCoordUnits()
getNumberOfFragmentTexCoordUnits returns the number of texture coordinate sets available that this graphics card supports.

Returns:
the number of units.

getNumberOfTotalUnits

public static int getNumberOfTotalUnits()
getNumberOfTotalUnits returns the number texture units the computer's graphics card supports.

Returns:
the number of units.

getNumberOfSetTextures

public int getNumberOfSetTextures()
Returns the number of textures this texture manager is maintaining.

Returns:
the number of textures.

getTextureID

public final int getTextureID(int textureUnit)
Fast access for retrieving a Texture ID. A return is guaranteed when textureUnit is any number under or equal to the highest textureunit currently in use. This value can be retrieved with getNumberOfSetTextures. A higher value might result in unexpected behaviour such as an exception being thrown.

Parameters:
textureUnit - The texture unit from which to retrieve the ID.
Returns:
the textureID, or 0 if there is none.

setTextureCoordinateOffset

public void setTextureCoordinateOffset(int offset)
setTextureCoordinateOffset sets the offset value used to determine which coordinates to use for texturing Geometry.

Parameters:
offset - the offset (default 0).

getTextureCoordinateOffset

public int getTextureCoordinateOffset()
setTextureCoordinateOffset gets the offset value used to determine which coordinates to use for texturing Geometry.

Returns:
the offset (default 0).

load

public void load()
Loads our textures into the underlying rendering system, generating mip maps if appropriate.


load

public abstract void load(int unit)
Loads the texture for the given unit into the underlying rendering system, generating mip maps if appropriate.


delete

public abstract void delete(int unit)
Removes the texture of the given unit.

Parameters:
unit - The unit of the Texture to remove.

deleteAll

public abstract void deleteAll()
Removes all Texture set in this TextureState. Does not also remove from TextureManager's cache.


deleteAll

public abstract void deleteAll(boolean removeFromCache)
Removes all Texture set in this TextureState. Also removes the textures from the TextureManager cache if passed boolean is true.


getMaxAnisotropic

public float getMaxAnisotropic()
Returns the maximum anisotropic filter.

Returns:
The maximum anisotropic filter.

isMultiTextureSupported

public static boolean isMultiTextureSupported()
Returns:
true if multi-texturing is supported in fixed function

overrideMultiTextureSupport

public static void overrideMultiTextureSupport(boolean use)
Overide setting of fixed function multi-texturing support.

Parameters:
use -

resetMultiTextureSupport

public static void resetMultiTextureSupport()
Reset fixed function multi-texturing support to driver-detected setting.


isEnvDot3Supported

public static boolean isEnvDot3Supported()
Returns:
true we support dot3 environment texture settings

overrideEnvDot3Support

public static void overrideEnvDot3Support(boolean use)
Overide support for dot3 environment texture settings

Parameters:
use -

resetEnvDot3Support

public static void resetEnvDot3Support()
Reset dot3 environment texture support to driver-detected setting.


isEnvCombineSupported

public static boolean isEnvCombineSupported()
Returns:
true we support combine environment texture settings

overrideEnvCombineSupport

public static void overrideEnvCombineSupport(boolean use)
Overide support for combine environment texture settings

Parameters:
use -

resetEnvCombineSupport

public static void resetEnvCombineSupport()
Reset combine environment texture support to driver-detected setting.


isS3TCSupported

public boolean isS3TCSupported()
Returns if S3TC compression is available for textures.

Returns:
true if S3TC is available.

overrideS3TCSupport

public static void overrideS3TCSupport(boolean use)
Overide setting of S3TC compression support.

Parameters:
use -

resetS3TCSupport

public static void resetS3TCSupport()
Reset dot3 environment texture support to driver-detected setting.


isTexture3DSupported

public boolean isTexture3DSupported()
Returns if Texture3D is available for textures.

Returns:
true if Texture3D is available.

overrideTexture3DSupport

public static void overrideTexture3DSupport(boolean use)
Overide setting of Texture3D support.

Parameters:
use -

resetTexture3DSupport

public static void resetTexture3DSupport()
Reset Texture3D support to driver-detected setting.


isTextureCubeMapSupported

public boolean isTextureCubeMapSupported()
Returns if TextureCubeMap is available for textures.

Returns:
true if TextureCubeMap is available.

overrideTextureCubeMapSupport

public static void overrideTextureCubeMapSupport(boolean use)
Overide setting of TextureCubeMap support.

Parameters:
use -

resetTextureCubeMapSupport

public static void resetTextureCubeMapSupport()
Reset TextureCubeMap support to driver-detected setting.


isAutomaticMipmapsSupported

public boolean isAutomaticMipmapsSupported()
Returns if AutomaticMipmap generation is available for textures.

Returns:
true if AutomaticMipmap generation is available.

overrideAutomaticMipmapsSupport

public static void overrideAutomaticMipmapsSupport(boolean use)
Overide setting of AutomaticMipmap generation support.

Parameters:
use -

resetAutomaticMipmapsSupport

public static void resetAutomaticMipmapsSupport()
Reset AutomaticMipmap generation support to driver-detected setting.


isAnisoSupported

public static boolean isAnisoSupported()
Returns:
if Anisotropic texture filtering is supported

overrideAnisoSupport

public static void overrideAnisoSupport(boolean use)
Overide setting of support for Anisotropic texture filtering.

Parameters:
use -

resetAnisoSupport

public static void resetAnisoSupport()
Reset dot3 environment texture support to driver-detected setting.


isNonPowerOfTwoTextureSupported

public static boolean isNonPowerOfTwoTextureSupported()
Returns:
true if non pow 2 texture sizes are supported

overrideNonPowerOfTwoTextureSupport

public static void overrideNonPowerOfTwoTextureSupport(boolean use)
Overide setting of support for non-pow2 texture sizes.

Parameters:
use -

resetNonPowerOfTwoTextureSupport

public static void resetNonPowerOfTwoTextureSupport()
Reset support for non-pow2 texture sizes to driver-detected setting.


isRectangularTextureSupported

public static boolean isRectangularTextureSupported()
Returns:
if rectangular texture sizes are supported (width != height)

overrideRectangularTextureSupport

public static void overrideRectangularTextureSupport(boolean use)
Overide auto-detected setting of support for rectangular texture sizes (width != height).

Parameters:
use -

resetRectangularTextureSupport

public static void resetRectangularTextureSupport()
Reset support for rectangular texture sizes to driver-detected setting.


write

public void write(JMEExporter e)
           throws IOException
Specified by:
write in interface Savable
Overrides:
write in class RenderState
Throws:
IOException

read

public void read(JMEImporter e)
          throws IOException
Specified by:
read in interface Savable
Overrides:
read in class RenderState
Throws:
IOException

getClassTag

public Class<? extends TextureState> getClassTag()
Specified by:
getClassTag in interface Savable
Overrides:
getClassTag in class RenderState

deleteTextureId

public void deleteTextureId(int textureId)

getDefaultTextureImage

public static Image getDefaultTextureImage()

getDefaultTexture

public static Texture getDefaultTexture()