de.matthiasmann.textureloader
Class TextureManager

java.lang.Object
  extended by de.matthiasmann.textureloader.TextureManager

public class TextureManager
extends java.lang.Object

A texture manager which will load texture asynchronous on damand and also unloads them when not used for a certain amount of time.

Example main loop:

// before main loop
AsyncExecution async = new AsyncExecution();
TextureManager tm = new TextureManager(async);
...
// main loop
while(!Display.isCloseRequested()) {
   GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

   async.executeQueuedJobs();
   tm.nextFrame();

   handleInput();
   renderStuff();

   Display.update();
}


Constructor Summary
TextureManager(AsyncExecution asyncExecution)
          Creates a texture manager which uses a single threaded ExecutorService to perform async loading of textures.
TextureManager(AsyncExecution asyncExecution, java.util.concurrent.ExecutorService executor)
          Creates a texture manager which uses the specified ExecutorService to perform async loading of textures.
 
Method Summary
static TextureLoader createTextureLoader(java.net.URL url)
          Constructs a TextureLoader for the given URL.
 Texture getTexture(java.net.URL url)
          Creates a managed texture instance for the specified URL.
 void nextFrame()
          Checks for textures which have not been bound for a certain amount of time and unloads them.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextureManager

public TextureManager(AsyncExecution asyncExecution)
Creates a texture manager which uses a single threaded ExecutorService to perform async loading of textures.

It is important to call AsyncExecution.executeQueuedJobs() on the main thread at least once per frame.

Parameters:
asyncExecution - the AsyncExecution instance used to bridge threads
Throws:
java.lang.NullPointerException - when asyncExecution is null

TextureManager

public TextureManager(AsyncExecution asyncExecution,
                      java.util.concurrent.ExecutorService executor)
Creates a texture manager which uses the specified ExecutorService to perform async loading of textures.

It is important to call AsyncExecution.executeQueuedJobs() on the main thread at least once per frame.

Parameters:
asyncExecution - the AsyncExecution instance used to bridge threads
executor - the ExecutorService used to load textures asynchronous to the GL thread
Throws:
java.lang.NullPointerException - when one of the arguments is null
Method Detail

getTexture

public Texture getTexture(java.net.URL url)
Creates a managed texture instance for the specified URL.

Textures are cached using their URL.toString() as a key.

The texture is not loaded until it is first used.

Parameters:
url - the URL to load
Returns:
the managed texture object

nextFrame

public void nextFrame()
Checks for textures which have not been bound for a certain amount of time and unloads them. Only a limited number of textures are unloaded per frame.


createTextureLoader

public static TextureLoader createTextureLoader(java.net.URL url)
Constructs a TextureLoader for the given URL.

The file extension is used to select which subclass to use.

The following file extensions are supported: PNG, JPG, TGA and BMP

Parameters:
url -
Returns: