jme.texture
Class TextureManager

java.lang.Object
  extended byjme.texture.TextureManager

public class TextureManager
extends java.lang.Object

TextureManager maintains all textures within the running application. It is a singleton class, and therefore can be used anywhere in the program. TextureManager maintains a list of texture id's with the name of the file as the key.

To create a new texture invoke the loadTexture method with the file name and the filter parameters. It takes a boolean value of as the last parameter to determine to use mipmapping or not. If the file is already loaded, the texture is NOT reloaded, but the corresponding id is returned instead.

TextureManager also takes care of retrieving id's, binding a texture and deleting textures.

The supported texture types are: PNG, JPG, GIF, TGA(Uncompressed), BMP

Version:
0.1.0
Author:
Mark Powell

Method Summary
 void batchLoad(java.util.ArrayList keys)
          batchLoad loads a collection of textures defined by an ArrayList.
 void batchLoad(java.util.ArrayList keys, boolean flipped)
          batchLoad loads a collection of textures defined by an ArrayList.
 void bind(int id)
          bind binds a texture based on a given id.
 boolean bind(java.lang.String file)
          bind sets the current texture to that defined by the filename key.
 void deleteAll()
          deleteAll removes all textures from the video memory as well as the TextureManager list.
 boolean deleteTexture(java.lang.String file)
          deleteTexture removes the texture from video memory.
 int getNumberOfTextures()
          getNumberOfTextures returns how many textures are currently being maintained by the TextureManager.
 int getTexture(java.lang.String file)
          getTexture retrieves a texture id based on the filename.
static TextureManager getTextureManager()
          getTextureManager retrieves the instance of TextureManager.
 int loadTexture(javax.swing.ImageIcon image, int minFilter, int magFilter, boolean isMipMapped)
          loadTexture loads a new texture defined by a loaded ImageIcon.
 int loadTexture(javax.swing.ImageIcon image, int minFilter, int magFilter, boolean isMipmapped, boolean flipped)
          loadTexture loads a new texture defined by a loaded ImageIcon.
 int loadTexture(java.lang.String file, int minFilter, int magFilter, boolean isMipMapped)
          loadTexture loads a new texture defined by the parameter string.
 int loadTexture(java.lang.String file, int minFilter, int magFilter, boolean isMipmapped, boolean flipped)
          loadTexture loads a new texture defined by the parameter string.
 void reload()
          reload reloads all loaded textures after making a call to saveKeys.
 void reload(boolean flipped)
          reload reloads all loaded textures after making a call to saveKeys.
static void reset()
          reset clears all textures from the list and sets the instance to null.
 java.util.ArrayList saveKeys()
          saveKeys makes a copy of all the texture keys (file names).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

reload

public void reload()
reload reloads all loaded textures after making a call to saveKeys. This is useful for reloading textures if the GL object has been recreated.


reload

public void reload(boolean flipped)
reload reloads all loaded textures after making a call to saveKeys. This is useful for reloading textures if the GL object has been recreated.

Parameters:
flipped - true flips the bits of the image, false does not. True by default.

batchLoad

public void batchLoad(java.util.ArrayList keys)
batchLoad loads a collection of textures defined by an ArrayList.

Parameters:
keys - the list of files to open.

batchLoad

public void batchLoad(java.util.ArrayList keys,
                      boolean flipped)
batchLoad loads a collection of textures defined by an ArrayList.

Parameters:
keys - the list of files to open.
flipped - true flips the bits of the image, false does not. True by default.

saveKeys

public java.util.ArrayList saveKeys()
saveKeys makes a copy of all the texture keys (file names). This is useful for reloading prior to deleting all textures.

Returns:
an ArrayList of the keys.

loadTexture

public int loadTexture(javax.swing.ImageIcon image,
                       int minFilter,
                       int magFilter,
                       boolean isMipMapped)
loadTexture loads a new texture defined by a loaded ImageIcon. If a texture with the same filename has previously been loaded, that id is returned rather than reloading. Filter parameters are used to define the filtering of the texture. Whether the texture is to be mipmapped or not is denoted by the isMipmapped boolean flag. If there is an error loading the file, -1 is returned.

Parameters:
image - the ImageIcon of the texture image.
minFilter - the filter for the near values.
magFilter - the filter for the far values.
Returns:
an integer for the loaded texture id. If there is a problem loading the texture -1 is returned.

loadTexture

public int loadTexture(javax.swing.ImageIcon image,
                       int minFilter,
                       int magFilter,
                       boolean isMipmapped,
                       boolean flipped)
loadTexture loads a new texture defined by a loaded ImageIcon. If a texture with the same filename has previously been loaded, that id is returned rather than reloading. Filter parameters are used to define the filtering of the texture. Whether the texture is to be mipmapped or not is denoted by the isMipmapped boolean flag. If there is an error loading the file, -1 is returned.

Parameters:
image - the ImageIcon of the texture image.
minFilter - the filter for the near values.
magFilter - the filter for the far values.
isMipmapped - determines if we will load the texture mipmapped or not. True load the texture mipmapped, false do not.
flipped - true flips the bits of the image, false does not. True by default.
Returns:
an integer for the loaded texture id. If there is a problem loading the texture -1 is returned.

loadTexture

public int loadTexture(java.lang.String file,
                       int minFilter,
                       int magFilter,
                       boolean isMipMapped)
loadTexture loads a new texture defined by the parameter string. If a texture with the same filename has previously been loaded, that id is returned rather than reloading. Filter parameters are used to define the filtering of the texture. Whether the texture is to be mipmapped or not is denoted by the isMipmapped boolean flag. If there is an error loading the file, -1 is returned.

Parameters:
file - the filename of the texture image.
minFilter - the filter for the near values.
magFilter - the filter for the far values.
Returns:
an integer for the loaded texture id. If there is a problem loading the texture -1 is returned.

loadTexture

public int loadTexture(java.lang.String file,
                       int minFilter,
                       int magFilter,
                       boolean isMipmapped,
                       boolean flipped)
loadTexture loads a new texture defined by the parameter string. If a texture with the same filename has previously been loaded, that id is returned rather than reloading. Filter parameters are used to define the filtering of the texture. Whether the texture is to be mipmapped or not is denoted by the isMipmapped boolean flag. If there is an error loading the file, -1 is returned.

Parameters:
file - the filename of the texture image.
minFilter - the filter for the near values.
magFilter - the filter for the far values.
isMipmapped - determines if we will load the texture mipmapped or not. True load the texture mipmapped, false do not.
Returns:
an integer for the loaded texture id. If there is a problem loading the texture -1 is returned.

getTexture

public int getTexture(java.lang.String file)
getTexture retrieves a texture id based on the filename. Use this method if you are certain that the file has previously been loaded using loadTexture. If the texture has not been loaded previously -1 is returned as the id.

Parameters:
file - the filename to retrieve the id of.
Returns:
the id of the given filename. If the given filename is not loaded, -1 is returned.

bind

public boolean bind(java.lang.String file)
bind sets the current texture to that defined by the filename key. The filename must have been previously loaded using the loadTexture method. If the texture is bound correctly, true is returned, otherwise false is returned.

Parameters:
file - the filename key to bind.
Returns:
true is the bind was successful false otherwise.

bind

public void bind(int id)
bind binds a texture based on a given id. It is up to the client to insure that the id is valid. If unsure about the id value, use bind(String) with the texture filename as the key. If the id is valid, the texture is bound, otherwise it is not. There is not success check.

Parameters:
id - the texture id to bind.

deleteTexture

public boolean deleteTexture(java.lang.String file)
deleteTexture removes the texture from video memory. The texture removed is defined by the filename key. If the texture file has not been loaded or has previously been deleted false is returned. True is returned if the texture was successfully removed.

Parameters:
file - the texture filename to remove.
Returns:
true is successful false otherwise.

deleteAll

public void deleteAll()
deleteAll removes all textures from the video memory as well as the TextureManager list. This effectively "resets" the manager.


getNumberOfTextures

public int getNumberOfTextures()
getNumberOfTextures returns how many textures are currently being maintained by the TextureManager.

Returns:
the number of textures being maintained.

getTextureManager

public static TextureManager getTextureManager()
getTextureManager retrieves the instance of TextureManager.

Returns:
the single instance of TextureManager.

reset

public static void reset()
reset clears all textures from the list and sets the instance to null. This will guarantee that the next call to getTexutreManager will create a new instance of TextureManager