NASA World Wind

gov.nasa.worldwind.render
Class BasicWWTexture

java.lang.Object
  extended by gov.nasa.worldwind.render.BasicWWTexture
All Implemented Interfaces:
WWTexture
Direct Known Subclasses:
WebViewTexture

public class BasicWWTexture
extends Object
implements WWTexture

Basic implementation of a texture derived from an image source such as an image file or a BufferedImage.

The interface contains a method, isTextureInitializationFailed() to determine whether the instance failed to convert an image source to a texture. If such a failure occurs, the method returns true and no further attempts are made to create the texture.

This class retrieves its image source immediately during a call to bind(DrawContext) or applyInternalTransform(DrawContext).

See Also:
LazilyLoadedTexture

Field Summary
protected  Integer height
           
protected  TextureCoords texCoords
           
protected  boolean textureInitializationFailed
           
protected  Integer width
           
 
Constructor Summary
BasicWWTexture(Object imageSource)
          Constructs a texture object.
BasicWWTexture(Object imageSource, boolean useMipMaps)
          Constructs a texture object from an image source.
 
Method Summary
 void applyInternalTransform(DrawContext dc)
          Applies any necessary transformations to the texture prior to its being rendered.
 boolean bind(DrawContext dc)
          Makes this texture the current texture for rendering.
 int getHeight(DrawContext dc)
          Returns the texture's height
 Object getImageSource()
          Returns the texture's image source.
 TextureCoords getTexCoords()
          Returns the texture's texture coordinates, which may be other than [0,0],[1,1] if the texture size is not a power of two or the texture must be flipped when rendered.
protected  Texture getTexture(DrawContext dc, boolean initialize)
           
protected  Texture getTextureFromCache(DrawContext dc)
           
 int getWidth(DrawContext dc)
          Returns the texture's width.
protected  void initialize(Object imageSource, boolean useMipMaps)
           
protected  Texture initializeTexture(DrawContext dc, Object imageSource)
           
 boolean isTextureCurrent(DrawContext dc)
          Indicates whether the texture is currently available for use without regenerating it from its image source.
 boolean isTextureInitializationFailed()
          Indicates whether an attempt to initialize the texture failed, which occurs when the image source is a non-existent image file or for other reasons specific to the image source.
 boolean isUseAnisotropy()
          Indicates whether texture anisotropy is applied to the texture when rendered.
 boolean isUseMipMaps()
          Indicates whether the texture creates and uses mipmaps.
 void setUseAnisotropy(boolean useAnisotropy)
          Specifies whether texture anisotropy is applied to the texture when rendered.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

height

protected Integer height

texCoords

protected TextureCoords texCoords

textureInitializationFailed

protected boolean textureInitializationFailed

width

protected Integer width
Constructor Detail

BasicWWTexture

public BasicWWTexture(Object imageSource)
Constructs a texture object.

The texture's image source is opened, if a file, only when the texture is displayed. If the texture is not displayed the image source is not read.

Parameters:
imageSource - the source of the image, either a file path String or a BufferedImage.
Throws:
IllegalArgumentException - if the imageSource is null.

BasicWWTexture

public BasicWWTexture(Object imageSource,
                      boolean useMipMaps)
Constructs a texture object from an image source.

The texture's image source is opened, if a file, only when the texture is displayed. If the texture is not displayed the image source is not read.

Parameters:
imageSource - the source of the image, either a file path String or a BufferedImage.
useMipMaps - Indicates whether to generate and use mipmaps for the image.
Throws:
IllegalArgumentException - if the imageSource is null.
Method Detail

applyInternalTransform

public void applyInternalTransform(DrawContext dc)
Description copied from interface: WWTexture
Applies any necessary transformations to the texture prior to its being rendered. A common transformation is mapping texture coordinates from a flipped or non-square state to conventionally oriented OpenGL values.

Specified by:
applyInternalTransform in interface WWTexture
Parameters:
dc - the current draw context.

bind

public boolean bind(DrawContext dc)
Description copied from interface: WWTexture
Makes this texture the current texture for rendering.

If the implementing instance's internal texture has not been created from its image source, the implementing class determines when the texture is retrieved and available.

If a texture cannot be created from its image source it cannot be bound. This method returns an indication of whether the texture was bound or was not bound due to a failure during creation.

Specified by:
bind in interface WWTexture
Parameters:
dc - the current draw context.
Returns:
true if the texture was bound, otherwise false.

getHeight

public int getHeight(DrawContext dc)
Description copied from interface: WWTexture
Returns the texture's height

Specified by:
getHeight in interface WWTexture
Parameters:
dc - the current draw context
Returns:
the texture's height, or 0 if the texture's size is currently unknown.

getImageSource

public Object getImageSource()
Description copied from interface: WWTexture
Returns the texture's image source.

Specified by:
getImageSource in interface WWTexture
Returns:
the texture's image source.

getTexCoords

public TextureCoords getTexCoords()
Description copied from interface: WWTexture
Returns the texture's texture coordinates, which may be other than [0,0],[1,1] if the texture size is not a power of two or the texture must be flipped when rendered.

Specified by:
getTexCoords in interface WWTexture
Returns:
returns the texture's texture coordinates.

getTexture

protected Texture getTexture(DrawContext dc,
                             boolean initialize)

getTextureFromCache

protected Texture getTextureFromCache(DrawContext dc)

getWidth

public int getWidth(DrawContext dc)
Description copied from interface: WWTexture
Returns the texture's width.

Specified by:
getWidth in interface WWTexture
Parameters:
dc - the current draw context
Returns:
the texture's width, or 0 if the texture's size is currently unknown.

initialize

protected void initialize(Object imageSource,
                          boolean useMipMaps)

initializeTexture

protected Texture initializeTexture(DrawContext dc,
                                    Object imageSource)

isTextureCurrent

public boolean isTextureCurrent(DrawContext dc)
Description copied from interface: WWTexture
Indicates whether the texture is currently available for use without regenerating it from its image source.

Specified by:
isTextureCurrent in interface WWTexture
Parameters:
dc - the current draw context
Returns:
true if the texture is available and consistent with its image source, otherwise false.

isTextureInitializationFailed

public boolean isTextureInitializationFailed()
Description copied from interface: WWTexture
Indicates whether an attempt to initialize the texture failed, which occurs when the image source is a non-existent image file or for other reasons specific to the image source.

Specified by:
isTextureInitializationFailed in interface WWTexture
Returns:
true if texture initialization failed, otherwise false.

isUseAnisotropy

public boolean isUseAnisotropy()
Indicates whether texture anisotropy is applied to the texture when rendered.

Returns:
useAnisotropy true if anisotropy is to be applied, otherwise false.

isUseMipMaps

public boolean isUseMipMaps()
Indicates whether the texture creates and uses mipmaps.

Returns:
true if mipmaps are used, false if not.

setUseAnisotropy

public void setUseAnisotropy(boolean useAnisotropy)
Specifies whether texture anisotropy is applied to the texture when rendered.

Parameters:
useAnisotropy - true if anisotropy is to be applied, otherwise false.

NASA World Wind