org.xith3d.loaders.texture
Class TextureLoader

java.lang.Object
  extended by org.jagatoo.loaders.textures.AbstractTextureLoader
      extended by org.xith3d.loaders.texture.TextureLoader

public class TextureLoader
extends org.jagatoo.loaders.textures.AbstractTextureLoader

Loads Textures from various image resources.

Loading (by name) works in the following order:

The loading stops as soon as a Texture is created.


Nested Class Summary
static class TextureLoader.FlipMode
          The FlipMode defines if Textures are to be vertically flipped at load time.
 
Field Summary
protected static Texture2D fallbackTexture
          Reference to the fallback Texture.
 
Fields inherited from class org.jagatoo.loaders.textures.AbstractTextureLoader
autoDotAddedOnce, fallbackTextureImageFormatLoader, textureFormatLoaders, textureImageFormatLoaders, textureStreamLocators
 
Method Summary
static Texture2D getFallbackTexture()
          Returns the fallback Texture.
static TextureLoader getInstance()
          Returns the singleton instance of the TextureLoader.
 Texture2D getTexture(java.lang.String name)
          Retrieves the Texture with the given name, with mipmap.
 Texture2D getTexture(java.lang.String name, Texture.MipmapMode mipmapMode)
          Retrieves the texture with the given name.
 Texture2D getTexture(java.lang.String name, org.jagatoo.opengl.enums.TextureFormat format)
          Retrieves the texture with the given name.
 Texture2D getTexture(java.lang.String name, org.jagatoo.opengl.enums.TextureFormat format, Texture.MipmapMode mipmapMode)
          Retrieves the texture with the given name.
 Texture2D getTexture(java.lang.String name, TextureLoader.FlipMode flipVertically)
          Retrieves the texture with the given name, with mipmap.
 Texture2D getTexture(java.lang.String name, TextureLoader.FlipMode flipVertically, Texture.MipmapMode mipmapMode)
          Retrieves the texture with the given name.
 Texture2D getTexture(java.lang.String name, TextureLoader.FlipMode flipVertically, org.jagatoo.opengl.enums.TextureFormat format, Texture.MipmapMode mipmapMode)
          Retrieves the requested Texture resource either from the cache or loads it and stores it to the cache.
 Texture2D getTexture(java.lang.String name, TextureLoader.FlipMode flipVertically, org.jagatoo.opengl.enums.TextureFormat format, Texture.MipmapMode mipmapMode, boolean allowStreching)
          Retrieves the requested Texture resource either from the cache or loads it and stores it to the cache.
 Texture2D getTexture(java.lang.String name, TextureLoader.FlipMode flipVertically, org.jagatoo.opengl.enums.TextureFormat format, Texture.MipmapMode mipmapMode, boolean allowStreching, boolean useCache, boolean writeToCache)
          Retrieves the requested Texture resource either from the cache or loads it and stores it to the cache.
 Texture2D getTextureOrNull(java.lang.String textureName)
          This is a convenience method needed many times.
 Texture2D getTextureOrNull(java.lang.String textureName, Texture.MipmapMode mipmapMode)
          This is a convenience method needed many times.
static boolean isFallbackTexture(Texture tex)
          Checks whether the given Texture is a fallback Texture.
 Texture2D loadTexture(java.io.InputStream in)
          Loads the requested Texture resource.
 Texture2D loadTexture(java.io.InputStream in, Texture.MipmapMode mipmapMode)
          Loads the requested Texture resource.
 Texture2D loadTexture(java.io.InputStream in, org.jagatoo.opengl.enums.TextureFormat format)
          Loads the requested Texture resource.
 Texture2D loadTexture(java.io.InputStream in, org.jagatoo.opengl.enums.TextureFormat format, Texture.MipmapMode mipmapMode)
          Loads the requested Texture resource.
 Texture2D loadTexture(java.io.InputStream in, TextureLoader.FlipMode flipVertically)
          Loads the requested Texture resource.
 Texture2D loadTexture(java.io.InputStream in, TextureLoader.FlipMode flipVertically, Texture.MipmapMode mipmapMode)
          Loads the requested Texture resource.
 Texture2D loadTexture(java.io.InputStream in, TextureLoader.FlipMode flipVertically, org.jagatoo.opengl.enums.TextureFormat format, Texture.MipmapMode mipmapMode)
          Loads the requested Texture resource.
 Texture2D loadTexture(java.io.InputStream in, TextureLoader.FlipMode flipVertically, org.jagatoo.opengl.enums.TextureFormat format, Texture.MipmapMode mipmapMode, boolean allowStreching)
          Loads the requested Texture resource.
 Texture2D loadTexture(java.net.URL imageURL)
          Loads the texture with the given URL, with mipmap.
 Texture2D loadTexture(java.net.URL imageURL, Texture.MipmapMode mipmapMode)
          Loads the texture with the given URL.
 Texture2D loadTexture(java.net.URL imageURL, org.jagatoo.opengl.enums.TextureFormat format)
          Loads the texture with the given URL.
 Texture2D loadTexture(java.net.URL imageURL, org.jagatoo.opengl.enums.TextureFormat format, Texture.MipmapMode mipmapMode)
          Loads the texture with the given URL.
 Texture2D loadTexture(java.net.URL imageURL, TextureLoader.FlipMode flipVertically)
          Loads the texture with the given URL, with mipmap.
 Texture2D loadTexture(java.net.URL imageURL, TextureLoader.FlipMode flipVertically, Texture.MipmapMode mipmapMode)
          Loads the texture with the given URL.
 Texture2D loadTexture(java.net.URL imageURL, TextureLoader.FlipMode flipVertically, org.jagatoo.opengl.enums.TextureFormat format, Texture.MipmapMode mipmapMode)
          Loads the requested Texture resource.
 Texture2D loadTexture(java.net.URL imageURL, TextureLoader.FlipMode flipVertically, org.jagatoo.opengl.enums.TextureFormat format, Texture.MipmapMode mipmapMode, boolean allowStreching)
          Loads the requested Texture resource.
 Texture3D loadTexture3D(java.lang.String[] names)
          Loads the requested Texture3D resource.
 Texture3D loadTexture3D(java.lang.String[] names, org.jagatoo.opengl.enums.TextureFormat format)
          Loads the requested Texture3D resource.
 Texture3D loadTexture3D(java.lang.String[] names, TextureLoader.FlipMode flipVertically, org.jagatoo.opengl.enums.TextureFormat format)
          Loads the requested Texture3D resource.
 TextureImage2D loadTextureImage(java.lang.String name)
          Loads a TextureImage.
 TextureImage2D loadTextureImage(java.lang.String name, org.jagatoo.opengl.enums.TextureFormat format)
          Loads a TextureImage.
 TextureImage2D loadTextureImage(java.lang.String name, TextureLoader.FlipMode flipVertically, org.jagatoo.opengl.enums.TextureFormat format)
          Loads a TextureImage.
 TextureImage2D loadTextureImage(java.lang.String name, TextureLoader.FlipMode flipVertically, org.jagatoo.opengl.enums.TextureFormat format, boolean allowStreching)
          Loads a TextureImage.
protected  void onTextureLoaded(org.jagatoo.loaders.textures.AbstractTexture texture, java.lang.String resourceName)
          
 
Methods inherited from class org.jagatoo.loaders.textures.AbstractTextureLoader
addTextureFormatLoader, addTextureImageFormatLoader, addTextureStreamLocator, addTextureStreamLocator, addTextureStreamLocator, addTextureStreamLocator, addTextureStreamLocator, checkCache, createTextureFromTextureImage, generateCacheKey, getCache, getFallbackTextureImageFormatLoader, getInputStream, initStandardFormatLoaders, loadOrGetTexture, loadTextureFromStream, loadTextureFromURL, loadTextureImage, loadTextureImageFromStream, removeTextureFormatLoader, removeTextureImageFormatLoader, removeTextureStreamLocator, setCache, setFallbackTextureImageFormatLoader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fallbackTexture

protected static Texture2D fallbackTexture
Reference to the fallback Texture.

Method Detail

getFallbackTexture

public static Texture2D getFallbackTexture()
Returns the fallback Texture.

Returns:
the fallback Texture to return

isFallbackTexture

public static boolean isFallbackTexture(Texture tex)
Checks whether the given Texture is a fallback Texture.

Parameters:
tex - the sample Texture to check
Returns:
true if the sample Texture IS the fallback Texture; false otherwise

getInstance

public static TextureLoader getInstance()
Returns the singleton instance of the TextureLoader.

Returns:
the singleton instance

loadTextureImage

public TextureImage2D loadTextureImage(java.lang.String name,
                                       TextureLoader.FlipMode flipVertically,
                                       org.jagatoo.opengl.enums.TextureFormat format,
                                       boolean allowStreching)
Loads a TextureImage.

Parameters:
name - the texture resource name
flipVertically - whether to flip the texture vertically
format - the texture format to use
allowStreching - whether to allow stretching
Returns:
the TextureImage loaded

loadTextureImage

public final TextureImage2D loadTextureImage(java.lang.String name,
                                             TextureLoader.FlipMode flipVertically,
                                             org.jagatoo.opengl.enums.TextureFormat format)
Loads a TextureImage.

Parameters:
name - the texture resource name
flipVertically - whether to flip the texture vertically
format - the texture format to use
Returns:
the TextureImage loaded

loadTextureImage

public final TextureImage2D loadTextureImage(java.lang.String name,
                                             org.jagatoo.opengl.enums.TextureFormat format)
Loads a TextureImage.

Parameters:
name - the texture resource name
format - the texture format to use
Returns:
the TextureImage loaded

loadTextureImage

public final TextureImage2D loadTextureImage(java.lang.String name)
Loads a TextureImage.

Parameters:
name - the texture resource name
Returns:
the TextureImage loaded

onTextureLoaded

protected void onTextureLoaded(org.jagatoo.loaders.textures.AbstractTexture texture,
                               java.lang.String resourceName)

Specified by:
onTextureLoaded in class org.jagatoo.loaders.textures.AbstractTextureLoader

getTexture

public Texture2D getTexture(java.lang.String name,
                            TextureLoader.FlipMode flipVertically,
                            org.jagatoo.opengl.enums.TextureFormat format,
                            Texture.MipmapMode mipmapMode,
                            boolean allowStreching,
                            boolean useCache,
                            boolean writeToCache)
Retrieves the requested Texture resource either from the cache or loads it and stores it to the cache.

Parameters:
name - The name of the texture
flipVertically - whether to flip the texture vertically
format - The desired texture format. The returned texture format may differ from this format
mipmapMode - Should the texture contain mipmaps?
allowStreching - whether to allow stretching
useCache - whether to use the cache
writeToCache - whether to write to the cache (ignored if useCache is false)
Returns:
The Texture object (or the fallback texture if it was not found)

getTexture

public Texture2D getTexture(java.lang.String name,
                            TextureLoader.FlipMode flipVertically,
                            org.jagatoo.opengl.enums.TextureFormat format,
                            Texture.MipmapMode mipmapMode,
                            boolean allowStreching)
Retrieves the requested Texture resource either from the cache or loads it and stores it to the cache.

Parameters:
name - The name of the texture
flipVertically - whether to flip the texture vertically
format - The desired texture format. The returned texture format may differ from this format
mipmapMode - Should the texture contain mipmaps?
allowStreching - whether to allow stretching
Returns:
The Texture object (or the fallback texture if it was not found)

getTexture

public final Texture2D getTexture(java.lang.String name,
                                  TextureLoader.FlipMode flipVertically,
                                  org.jagatoo.opengl.enums.TextureFormat format,
                                  Texture.MipmapMode mipmapMode)
Retrieves the requested Texture resource either from the cache or loads it and stores it to the cache.

Parameters:
name - The name of the texture
format - The desired texture format. The returned texture format may differ from this format
mipmapMode - Should the texture contain mipmaps?
Returns:
The Texture object (or the fallback texture if it was not found)

getTexture

public Texture2D getTexture(java.lang.String name,
                            TextureLoader.FlipMode flipVertically)
Retrieves the texture with the given name, with mipmap.

Parameters:
name - the name of the texture
flipVertically - whether to flip the texture vertically
Returns:
The Texture object (or the fallback texture if it was not found)

getTexture

public Texture2D getTexture(java.lang.String name)
Retrieves the Texture with the given name, with mipmap.

Parameters:
name - the name of the texture
Returns:
The Texture object (or the fallback texture if it was not found)

getTexture

public Texture2D getTexture(java.lang.String name,
                            TextureLoader.FlipMode flipVertically,
                            Texture.MipmapMode mipmapMode)
Retrieves the texture with the given name.

Parameters:
name - The name of the texture
flipVertically - whether to flip the texture vertically
mipmapMode - Should the texture contain mipmaps?
Returns:
The Texture object (or the fallback texture if it was not found)

getTexture

public Texture2D getTexture(java.lang.String name,
                            org.jagatoo.opengl.enums.TextureFormat format)
Retrieves the texture with the given name.

Parameters:
name - The name of the texture
format - the format to use: Texture.RGB or Texture.RGBA
Returns:
The Texture object (or the fallback texture if it was not found)

getTexture

public Texture2D getTexture(java.lang.String name,
                            Texture.MipmapMode mipmapMode)
Retrieves the texture with the given name.

Parameters:
name - The name of the texture
mipmapMode - Should the texture contain mipmaps?
Returns:
The Texture object (or the fallback texture if it was not found)

getTexture

public Texture2D getTexture(java.lang.String name,
                            org.jagatoo.opengl.enums.TextureFormat format,
                            Texture.MipmapMode mipmapMode)
Retrieves the texture with the given name. Loading works in the following order:
If the texture was already loaded and is still in the cache then the existing texture is returned. So don't modify textures returned by this method.
All TextureLocator are tried in the order in which they are registered.
All TextureStreamLocatorZip are tried in the order in which they are registered.
If a stream was found then the following is tried on the stream:
All TextureStreamLoader are tried in the order in which they are registered.
All TextureImageFormatLoader are tried in the order in which they are registered. A texture is then created with this AbstractTextureImage (mipmaps are currently not implemented).
At last ImageIO.read() is tried. From this a Texture with optional mipmaps is created.
The loading stops as soon as a Texture is created.

Parameters:
name - The name of the texture
format - The desired texture format. The returned texture format may differ from this format
mipmapMode - Should the texture contain mipmaps?
Returns:
The Texture object (or the fallback texture if it was not found)

getTextureOrNull

public Texture2D getTextureOrNull(java.lang.String textureName,
                                  Texture.MipmapMode mipmapMode)
This is a convenience method needed many times.
It loads the Texture by resource name and with or without alpha channel. If the given textureName is null or an empty string, null is returned.

Parameters:
textureName - the requested Texture's name or null
mipmapMode - the MipmapMode to use
Returns:
the loaded Texture or null

getTextureOrNull

public Texture2D getTextureOrNull(java.lang.String textureName)
This is a convenience method needed many times.
It loads the Texture by resource name and with or without alpha channel. If the given textureName is null or an empty string, null is returned.

Parameters:
textureName - the requested Texture name
Returns:
the loaded Texture or null

loadTexture

public Texture2D loadTexture(java.net.URL imageURL,
                             TextureLoader.FlipMode flipVertically,
                             org.jagatoo.opengl.enums.TextureFormat format,
                             Texture.MipmapMode mipmapMode,
                             boolean allowStreching)
Loads the requested Texture resource. (Doesn't check the cache!)

Parameters:
imageURL - The URL pointing to the texture image
flipVertically - whether to flip the texture vertically
format - The desired texture format. The returned texture format may differ from this format
mipmapMode - Should the texture contain mipmaps?
allowStreching - whether to allow stretching
Returns:
The Texture object (or the fallback texture if it was not found)

loadTexture

public Texture2D loadTexture(java.net.URL imageURL,
                             TextureLoader.FlipMode flipVertically,
                             org.jagatoo.opengl.enums.TextureFormat format,
                             Texture.MipmapMode mipmapMode)
Loads the requested Texture resource. (Doesn't check the cache!)

Parameters:
imageURL - The URL pointing to the texture image
flipVertically - whether to flip the texture vertically
format - The desired texture format. The returned texture format may differ from this format
mipmapMode - Should the texture contain mipmaps?
Returns:
The Texture object (or the fallback texture if it was not found)

loadTexture

public Texture2D loadTexture(java.net.URL imageURL,
                             TextureLoader.FlipMode flipVertically)
Loads the texture with the given URL, with mipmap.

Parameters:
imageURL - The URL pointing to the texture image
flipVertically - whether to flip the texture vertically
Returns:
The Texture object (or the fallback texture if it was not found)

loadTexture

public Texture2D loadTexture(java.net.URL imageURL)
Loads the texture with the given URL, with mipmap.

Parameters:
imageURL - The URL pointing to the texture image
Returns:
The Texture object (or the fallback texture if it was not found)

loadTexture

public Texture2D loadTexture(java.net.URL imageURL,
                             Texture.MipmapMode mipmapMode)
Loads the texture with the given URL.

Parameters:
imageURL - The URL pointing to the texture image
mipmapMode - Should the texture contain mipmaps?
Returns:
The Texture object (or the fallback texture if it was not found)

loadTexture

public Texture2D loadTexture(java.net.URL imageURL,
                             org.jagatoo.opengl.enums.TextureFormat format)
Loads the texture with the given URL.

Parameters:
imageURL - The URL pointing to the texture image
format - the format to use: Texture.RGB or Texture.RGBA
Returns:
The Texture object (or the fallback texture if it was not found)

loadTexture

public Texture2D loadTexture(java.net.URL imageURL,
                             TextureLoader.FlipMode flipVertically,
                             Texture.MipmapMode mipmapMode)
Loads the texture with the given URL.

Parameters:
imageURL - The URL pointing to the texture image
flipVertically - whether to flip the texture vertically
mipmapMode - Should the texture contain mipmaps?
Returns:
The Texture object (or the fallback texture if it was not found)

loadTexture

public Texture2D loadTexture(java.net.URL imageURL,
                             org.jagatoo.opengl.enums.TextureFormat format,
                             Texture.MipmapMode mipmapMode)
Loads the texture with the given URL.

Parameters:
imageURL - The URL pointing to the texture image
format - The desired texture format. The returned texture format may differ from this format
mipmapMode - Should the texture contain mipmaps?
Returns:
The Texture object (or the fallback texture if it was not found)

loadTexture

public Texture2D loadTexture(java.io.InputStream in,
                             TextureLoader.FlipMode flipVertically,
                             org.jagatoo.opengl.enums.TextureFormat format,
                             Texture.MipmapMode mipmapMode,
                             boolean allowStreching)
Loads the requested Texture resource. (Doesn't check the cache!)

Parameters:
in - An InputStream for the texture resource
flipVertically - whether to flip the texture vertically
format - The desired texture format. The returned texture format may differ from this format
mipmapMode - Should the texture contain mipmaps?
allowStreching - whether to allow stretching
Returns:
The Texture object (or the fallback texture if it was not found)

loadTexture

public Texture2D loadTexture(java.io.InputStream in,
                             TextureLoader.FlipMode flipVertically,
                             org.jagatoo.opengl.enums.TextureFormat format,
                             Texture.MipmapMode mipmapMode)
Loads the requested Texture resource. (Doesn't check the cache!)

Parameters:
in - An InputStream for the texture resource
flipVertically - whether to flip the texture vertically
format - The desired texture format. The returned texture format may differ from this format
mipmapMode - Should the texture contain mipmaps?
Returns:
The Texture object (or the fallback texture if it was not found)

loadTexture

public Texture2D loadTexture(java.io.InputStream in,
                             TextureLoader.FlipMode flipVertically)
Loads the requested Texture resource. (Doesn't check the cache!)

Parameters:
in - An InputStream for the texture resource
flipVertically - whether to flip the texture vertically
Returns:
The Texture object (or the fallback texture if it was not found)

loadTexture

public Texture2D loadTexture(java.io.InputStream in)
Loads the requested Texture resource. (Doesn't check the cache!)

Parameters:
in - An InputStream for the texture resource
Returns:
The Texture object (or the fallback texture if it was not found)

loadTexture

public Texture2D loadTexture(java.io.InputStream in,
                             Texture.MipmapMode mipmapMode)
Loads the requested Texture resource. (Doesn't check the cache!)

Parameters:
in - An InputStream for the texture resource
mipmapMode - Should the texture contain mipmaps?
Returns:
The Texture object (or the fallback texture if it was not found)

loadTexture

public Texture2D loadTexture(java.io.InputStream in,
                             org.jagatoo.opengl.enums.TextureFormat format)
Loads the requested Texture resource. (Doesn't check the cache!)

Parameters:
in - An InputStream for the texture resource
format - the format to use: Texture.RGB or Texture.RGBA
Returns:
The Texture object (or the fallback texture if it was not found)

loadTexture

public Texture2D loadTexture(java.io.InputStream in,
                             TextureLoader.FlipMode flipVertically,
                             Texture.MipmapMode mipmapMode)
Loads the requested Texture resource. (Doesn't check the cache!)

Parameters:
in - An InputStream for the texture resource
flipVertically - whether to flip the texture vertically
mipmapMode - Should the texture contain mipmaps?
Returns:
The Texture object (or the fallback texture if it was not found)

loadTexture

public Texture2D loadTexture(java.io.InputStream in,
                             org.jagatoo.opengl.enums.TextureFormat format,
                             Texture.MipmapMode mipmapMode)
Loads the requested Texture resource. (Doesn't check the cache!)

Parameters:
in - An InputStream for the texture resource
format - The desired texture format. The returned texture format may differ from this format
mipmapMode - Should the texture contain mipmaps?
Returns:
The Texture object (or a dummy texture if it was not found).

loadTexture3D

public Texture3D loadTexture3D(java.lang.String[] names,
                               TextureLoader.FlipMode flipVertically,
                               org.jagatoo.opengl.enums.TextureFormat format)
Loads the requested Texture3D resource.

Parameters:
names - names of the texture image resources
flipVertically - whether to flip the texture vertically
format - The desired texture format. The returned texture format may differ from this format
Returns:
The Texture object (or null).

loadTexture3D

public final Texture3D loadTexture3D(java.lang.String[] names,
                                     org.jagatoo.opengl.enums.TextureFormat format)
Loads the requested Texture3D resource.

Parameters:
names - names of the texture image resources
format - The desired texture format. The returned texture format may differ from this format
Returns:
The Texture object (or null).

loadTexture3D

public final Texture3D loadTexture3D(java.lang.String[] names)
Loads the requested Texture3D resource.

Parameters:
names - names of the texture image resources
Returns:
The Texture object (or null).