de.matthiasmann.textureloader
Class Texture

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

public final class Texture
extends java.lang.Object

A texture class. All methods need to be called from the GL thread.


Nested Class Summary
static class Texture.Format
           
 
Constructor Summary
Texture(int width, int height, Texture.Format format)
          Creates an unmanaged texture
 
Method Summary
 void bind()
          Binds the texture for rendering.
 void delete()
          Deletes this texture.
 Texture.Format getFormat()
          Returns the format used to upload texture data of an unmanaged texture.
 int getHeight()
          Retrieves the height of an unmanaged texture.
 int getWidth()
          Retrieves the width of an unmanaged texture.
 boolean isDeleted()
          Returns true when the texture has been deleted
 boolean isManaged()
          Returns true if this texture object was created via TextureManager.getTexture(java.net.URL)
static Texture loadTexture(java.net.URL url)
          Loads an unmanaged texture synchronously
 void upload(int x, int y, int width, int height, java.nio.ByteBuffer bb)
          Uploads texture data.
 void upload(int x, int y, int width, int height, java.nio.IntBuffer ib)
          Uploads texture data.
 void upload(int x, int y, int width, int height, TextureBuffer buf)
          Uploads texture data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Texture

public Texture(int width,
               int height,
               Texture.Format format)
Creates an unmanaged texture

Parameters:
width - the width
height - the height
format - the format of the image data
Method Detail

loadTexture

public static Texture loadTexture(java.net.URL url)
                           throws java.io.IOException
Loads an unmanaged texture synchronously

Parameters:
url - the URL to load
Returns:
the Texture object or null if the URL is not a supported image file
Throws:
java.io.IOException - if an IO or decode error happend

isManaged

public boolean isManaged()
Returns true if this texture object was created via TextureManager.getTexture(java.net.URL)

Returns:
true if this texture object is managed

getWidth

public int getWidth()
Retrieves the width of an unmanaged texture.

Returns:
the width for an unmanaged texture and -1 for a managed texture.

getHeight

public int getHeight()
Retrieves the height of an unmanaged texture.

Returns:
the height for an unmanaged texture and -1 for a managed texture.

getFormat

public Texture.Format getFormat()
Returns the format used to upload texture data of an unmanaged texture.

Returns:
the format for uploading texture data and null for a managed texture.

isDeleted

public boolean isDeleted()
Returns true when the texture has been deleted

Returns:
true when the texture has been deleted
See Also:
delete()

upload

public void upload(int x,
                   int y,
                   int width,
                   int height,
                   java.nio.ByteBuffer bb)
Uploads texture data. Can only be called on unmanaged textures.

Parameters:
x - the horizontal start of the area to modify
y - the vertical start of the area to modify
width - the width of the area to modify
height - the height of the area to modify
bb - the direct ByteBuffer containing the texture data - interpreted as unsigned bytes
Throws:
java.lang.IllegalStateException - when this texture has already been deleted
java.lang.UnsupportedOperationException - when this texture is managed
See Also:
isManaged()

upload

public void upload(int x,
                   int y,
                   int width,
                   int height,
                   java.nio.IntBuffer ib)
Uploads texture data. Can only be called on unmanaged textures.

Parameters:
x - the horizontal start of the area to modify
y - the vertical start of the area to modify
width - the width of the area to modify
height - the height of the area to modify
ib - the direct IntBuffer containing the texture data - interpreted as unsigned bytes
Throws:
java.lang.IllegalStateException - when this texture has already been deleted
java.lang.UnsupportedOperationException - when this texture is managed
See Also:
isManaged()

upload

public void upload(int x,
                   int y,
                   int width,
                   int height,
                   TextureBuffer buf)
Uploads texture data. Can only be called on unmanaged textures.

Parameters:
x - the horizontal start of the area to modify
y - the vertical start of the area to modify
width - the width of the area to modify
height - the height of the area to modify
buf - the TextureBuffer containing the texture data - interpreted as unsigned bytes
Throws:
java.lang.IllegalStateException - when this texture has already been deleted
java.lang.UnsupportedOperationException - when this texture is managed
See Also:
isManaged()

delete

public void delete()
Deletes this texture. Can only be called on unmanaged textures.

Throws:
java.lang.IllegalStateException - when this texture has already been deleted
java.lang.UnsupportedOperationException - when this texture is managed

bind

public void bind()
Binds the texture for rendering. If the texture is managed and not yet loaded then it's loading will be started asynchronously.

Throws:
java.lang.IllegalStateException - when this texture has already been deleted