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:
DummyRenderer.TextureStateN, 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 4336 2009-05-03 20:57:01Z christoph.luder $
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
           
 
Nested classes/interfaces inherited from class com.jme.scene.state.RenderState
RenderState.StateType
 
Field Summary
protected static boolean automaticMipMaps
          True if non-GLU mipmap generation (part of FBO) is supported.
protected static boolean automaticMipMapsDetected
           
protected static Texture defaultTexture
           
protected  int firstTexture
           
protected  int[] idCache
           
protected  int lastTexture
           
protected static float maxAnisotropic
           
protected static int numFixedTexUnits
          The number of texture units availible for fixed functionality
protected static int numFragmentTexCoordUnits
          The number of texture coordinate sets available
protected static int numFragmentTexUnits
          The number of texture units availible to fragment shader
protected static int numTotalTexUnits
          The total number of supported texture units.
protected static int numVertexTexUnits
          The number of texture units availible to vertex shader
protected  int offset
          offset is used to denote where to begin access of texture coordinates.
protected static boolean supportsAniso
          True if anisofiltering is supported.
protected static boolean supportsAnisoDetected
           
protected static boolean supportsDepthTexture
          True if depth textures are supported
protected static boolean supportsEnvCombine
          True if combine dot3 is supported.
protected static boolean supportsEnvCombineDetected
           
protected static boolean supportsEnvDot3
          True if combine dot3 is supported.
protected static boolean supportsEnvDot3Detected
           
protected static boolean supportsMultiTexture
          True if multitexturing is supported.
protected static boolean supportsMultiTextureDetected
           
protected static boolean supportsNonPowerTwo
          True if non pow 2 texture sizes are supported.
protected static boolean supportsNonPowerTwoDetected
           
protected static boolean supportsRectangular
          True if rectangular textures are supported (vs.
protected static boolean supportsRectangularDetected
           
protected static boolean supportsS3TCCompression
          True if S3TC compression is supported.
protected static boolean supportsS3TCCompressionDetected
           
protected static boolean supportsShadow
          True if shadow mapping supported
protected static boolean supportsTexture3D
          True if Texture3D is supported.
protected static boolean supportsTexture3DDetected
           
protected static boolean supportsTextureCubeMap
          True if TextureCubeMap is supported.
protected static boolean supportsTextureCubeMapDetected
           
protected  java.util.ArrayList<Texture> texture
          The texture(s).
 
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)
           
 java.lang.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.
 RenderState.StateType getStateType()
          getStateType returns the type RenderState.StateType.Texture
 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()
          Deprecated. As of 2.0, use RenderState.getStateType() instead.
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.
protected  void resetFirstLast()
          Updates firstTexture to be the first non-null Texture, and lastTexture to be the last non-null texture.
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultTexture

protected static Texture defaultTexture

texture

protected transient java.util.ArrayList<Texture> texture
The texture(s).


numTotalTexUnits

protected static int numTotalTexUnits
The total number of supported texture units.


numFixedTexUnits

protected static int numFixedTexUnits
The number of texture units availible for fixed functionality


numVertexTexUnits

protected static int numVertexTexUnits
The number of texture units availible to vertex shader


numFragmentTexUnits

protected static int numFragmentTexUnits
The number of texture units availible to fragment shader


numFragmentTexCoordUnits

protected static int numFragmentTexCoordUnits
The number of texture coordinate sets available


maxAnisotropic

protected static float maxAnisotropic

supportsMultiTexture

protected static boolean supportsMultiTexture
True if multitexturing is supported.


supportsMultiTextureDetected

protected static boolean supportsMultiTextureDetected

supportsEnvDot3

protected static boolean supportsEnvDot3
True if combine dot3 is supported.


supportsEnvDot3Detected

protected static boolean supportsEnvDot3Detected

supportsEnvCombine

protected static boolean supportsEnvCombine
True if combine dot3 is supported.


supportsEnvCombineDetected

protected static boolean supportsEnvCombineDetected

supportsAniso

protected static boolean supportsAniso
True if anisofiltering is supported.


supportsAnisoDetected

protected static boolean supportsAnisoDetected

supportsNonPowerTwo

protected static boolean supportsNonPowerTwo
True if non pow 2 texture sizes are supported.


supportsNonPowerTwoDetected

protected static boolean supportsNonPowerTwoDetected

supportsRectangular

protected static boolean supportsRectangular
True if rectangular textures are supported (vs. only square textures)


supportsRectangularDetected

protected static boolean supportsRectangularDetected

supportsS3TCCompression

protected static boolean supportsS3TCCompression
True if S3TC compression is supported.


supportsS3TCCompressionDetected

protected static boolean supportsS3TCCompressionDetected

supportsTexture3D

protected static boolean supportsTexture3D
True if Texture3D is supported.


supportsTexture3DDetected

protected static boolean supportsTexture3DDetected

supportsTextureCubeMap

protected static boolean supportsTextureCubeMap
True if TextureCubeMap is supported.


supportsTextureCubeMapDetected

protected static boolean supportsTextureCubeMapDetected

automaticMipMaps

protected static boolean automaticMipMaps
True if non-GLU mipmap generation (part of FBO) is supported.


automaticMipMapsDetected

protected static boolean automaticMipMapsDetected

supportsDepthTexture

protected static boolean supportsDepthTexture
True if depth textures are supported


supportsShadow

protected static boolean supportsShadow
True if shadow mapping supported


firstTexture

protected transient int firstTexture

lastTexture

protected transient int lastTexture

offset

protected int offset
offset is used to denote where to begin access of texture coordinates. 0 default


idCache

protected transient int[] idCache
Constructor Detail

TextureState

public TextureState()
Constructor instantiates a new TextureState object.

Method Detail

getType

public int getType()
Deprecated. As of 2.0, use RenderState.getStateType() instead.

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()

getStateType

public RenderState.StateType getStateType()
getStateType returns the type RenderState.StateType.Texture

Specified by:
getStateType in class RenderState
Returns:
RenderState.StateType.Texture
See Also:
RenderState.getStateType()

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:
java.lang.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.

resetFirstLast

protected void resetFirstLast()
Updates firstTexture to be the first non-null Texture, and lastTexture to be the last non-null texture.


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 java.io.IOException
Specified by:
write in interface Savable
Overrides:
write in class RenderState
Throws:
java.io.IOException

read

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

getClassTag

public java.lang.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()