public class LazilyLoadedTexture extends AVListImpl implements WWTexture
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 performs lazy retrieval and loading of an image source, attempting to retrieve and load the image source
only when the bind(DrawContext)
or applyInternalTransform(DrawContext)
methods are called. If the
image source is a BufferedImage
the associated Texture
object is created and available immediately
when bind
or applyInternalTransform
are called. If the image source is a local file or
remote stream (URL), retrieval and loading is performed on a separate thread from the EDT.Modifier and Type | Class and Description |
---|---|
protected static class |
LazilyLoadedTexture.RequestTask
Attempts to find this texture's image file locally, and if that fails attempts to find it remotely.
|
Modifier and Type | Field and Description |
---|---|
protected Object |
fileLock
Provides a semaphore to synchronize access to the texture file if duplicate request tasks are active.
|
protected FileStore |
fileStore
Identifies the
FileStore of the supporting file cache for this model. |
protected boolean |
hasMipmapData
Indicates whether the image read from the image source has mip-map data.
|
protected Integer |
height
The texture height, if the height is known.
|
protected Object |
imageSource
The original image source specified at construction.
|
protected PropertyChangeListener |
listener
The object to notify when an image is eventually loaded in memory.
|
protected TextureCoords |
texCoords
The texture's texture coordinates, as determined by JOGL when the texture is created.
|
protected TextureData |
textureData
The texture data created as the image source is read.
|
protected boolean |
textureInitializationFailed
Indicates that texture initialization failed.
|
protected boolean |
useAnisotropy
The current anisotropy flag.
|
protected boolean |
useMipMaps
The mip-map flag specified at construction.
|
protected Integer |
width
The texture width, if the width is known.
|
Constructor and Description |
---|
LazilyLoadedTexture(Object imageSource)
Constructs a texture object for a specified image source.
|
LazilyLoadedTexture(Object imageSource,
boolean useMipMaps)
Constructs a texture object for a specified image source.
|
Modifier and Type | Method and Description |
---|---|
void |
applyInternalTransform(DrawContext dc)
Applies any necessary transformations to the texture prior to its being rendered.
|
boolean |
bind(DrawContext dc)
Binds this instance's
Texture to the GLContext if the texture has been created, otherwise
initiates image source retrieval and texture creation in a separate thread. |
protected Runnable |
createRequestTask()
Returns an object that implements the Runnable interface, and who's
run method retrieves and loads
this texture's image source. |
boolean |
equals(Object o) |
int |
getHeight()
Indicates the texture's height, which is the same as the image source's height.
|
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)
Returns the
Texture associated with this instance. |
protected TextureData |
getTextureData()
Returns this texture's texture data if it has been retrieved but a
Texture has not yet been created
for it. |
int |
getWidth()
Indicates the texture's width, which is the same as the image source's width.
|
int |
getWidth(DrawContext dc)
Returns the texture's width.
|
int |
hashCode() |
protected void |
initialize(Object imageSource,
boolean useMipMaps,
PropertyChangeListener listener)
Initializes this object's fields during construction.
|
protected boolean |
isBufferedImageSource()
Indicates whether the image source is a
BufferedImage |
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 was made to retrieve and read the texture but it failed.
|
boolean |
isUseAnisotropy()
Indicates whether texture anisotropy is applied to the texture when rendered.
|
boolean |
isUseMipMaps()
Indicates whether the texture should use mip-maps.
|
protected boolean |
loadTextureData(URL fileUrl)
Loads the image from disk into memory.
|
protected Texture |
makeBufferedImageTexture(DrawContext dc)
Creates this instance's
Texture if the image source is a BufferedImage |
protected Texture |
makeTextureFromTextureData(DrawContext dc)
|
protected void |
notifyTextureLoaded() |
protected TextureData |
readImage(URL fileUrl)
Reads and returns a
TextureData for an image from a specified file URL. |
protected Texture |
requestTexture(DrawContext dc)
If this instance's image source is a
BufferedImage , creates and returns the texture, otherwise
creates a task in a separate thread to retrieve it from its local or remote location. |
protected void |
setTextureData(TextureData textureData)
Specifies texture data for the tile.
|
protected void |
setTextureParameters(DrawContext dc,
Texture texture)
Sets a specified texture's OpenGL
Texture parameters. |
void |
setUseAnisotropy(boolean useAnisotropy)
Specifies whether texture anisotropy is applied to the texture when rendered.
|
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getBooleanValue, getBooleanValue, getChangeSupport, getDoubleValue, getDoubleValue, getEntries, getIntegerValue, getIntegerValue, getLongValue, getLongValue, getRestorableStateForAVPair, getStringValue, getStringValue, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
protected final Object fileLock
protected FileStore fileStore
FileStore
of the supporting file cache for this model.protected boolean hasMipmapData
protected Integer height
protected Object imageSource
protected PropertyChangeListener listener
protected TextureCoords texCoords
protected volatile TextureData textureData
volatile
in order to synchronize atomic access among threads. This field is not used if the
image source is BufferedImage
.protected boolean textureInitializationFailed
protected boolean useAnisotropy
protected boolean useMipMaps
protected Integer width
public LazilyLoadedTexture(Object imageSource)
imageSource
- the source of the image, either a file path String
or a BufferedImage
.IllegalArgumentException
- if the imageSource
is null.public LazilyLoadedTexture(Object imageSource, boolean useMipMaps)
imageSource
- the source of the image, either a file path String
or a BufferedImage
.useMipMaps
- Indicates whether to generate and use mip-maps for the image.IllegalArgumentException
- if the imageSource
is null.public void applyInternalTransform(DrawContext dc)
WWTexture
applyInternalTransform
in interface WWTexture
dc
- the current draw context.public boolean bind(DrawContext dc)
Texture
to the GLContext
if the texture has been created, otherwise
initiates image source retrieval and texture creation in a separate thread.protected Runnable createRequestTask()
run
method retrieves and loads
this texture's image source.public int getHeight()
TextureData
. It's value is -1
until then.public int getHeight(DrawContext dc)
getHeight()
. The DrawContext
argument is not used.public Object getImageSource()
WWTexture
getImageSource
in interface WWTexture
public TextureCoords getTexCoords()
WWTexture
getTexCoords
in interface WWTexture
protected Texture getTexture(DrawContext dc)
Texture
associated with this instance.dc
- the current draw context.protected TextureData getTextureData()
Texture
has not yet been created
for it.
If this object's texture data field is non-null, a new texture is created from the texture data when the tile is
next bound or otherwise initialized. This object's texture data field is then set to null.public int getWidth()
TextureData
. It's value is -1 until
then.public int getWidth(DrawContext dc)
getWidth()
. The DrawContext
argument is not used.protected void initialize(Object imageSource, boolean useMipMaps, PropertyChangeListener listener)
imageSource
- the image source.useMipMaps
- the mip-map flag.listener
- the change listener.IllegalArgumentException
- if the image source is null.protected boolean isBufferedImageSource()
BufferedImage
BufferedImage
, otherwise false.public boolean isTextureCurrent(DrawContext dc)
WWTexture
isTextureCurrent
in interface WWTexture
dc
- the current draw contextpublic boolean isTextureInitializationFailed()
isTextureInitializationFailed
in interface WWTexture
public boolean isUseAnisotropy()
public boolean isUseMipMaps()
protected boolean loadTextureData(URL fileUrl)
getTextureData()
.fileUrl
- the URL of the image file.protected Texture makeBufferedImageTexture(DrawContext dc)
Texture
if the image source is a BufferedImage.
dc
- the current draw context.IllegalStateException
- if the image source is null or not a BufferedImage
.protected Texture makeTextureFromTextureData(DrawContext dc)
dc
- the current draw context.TextureData
or if texture
creation failed.protected void notifyTextureLoaded()
protected TextureData readImage(URL fileUrl)
TextureData
for an image from a specified file URL.fileUrl
- the URL of the image file to read.TextureData
instance for the image.protected Texture requestTexture(DrawContext dc)
BufferedImage
, creates and returns the texture, otherwise
creates a task in a separate thread to retrieve it from its local or remote location.dc
- the current draw context.protected void setTextureData(TextureData textureData)
textureData
- the texture data, which may be null.protected void setTextureParameters(DrawContext dc, Texture texture)
Texture
parameters.dc
- the current draw context.texture
- the texture whose parameters to set.public void setUseAnisotropy(boolean useAnisotropy)
useAnisotropy
- true if anisotropy is to be applied, otherwise false.