org.gljava.opengl
Class TextureFactory

java.lang.Object
  extended by org.gljava.opengl.TextureFactory

public class TextureFactory
extends java.lang.Object

Factory for easy loading of Textures.

Version:
$Id: TextureFactory.java,v 1.2 2005/02/02 19:22:28 ivan_ganza Exp $
Author:
Ivan Z. Ganza

Field Summary
(package private)  java.awt.image.ColorModel glAlphaColorModel
          Colour model including alpha for the GL image
(package private)  java.awt.image.ColorModel glColorModel
          colour model for the GL image
(package private) static TextureFactory instance
          Factory instance
(package private)  java.util.HashMap textureCache
          Cache of loaded Textures
(package private)  java.nio.IntBuffer textureIDBuffer
          buffer for texture ID's
 
Constructor Summary
TextureFactory()
          Creates a new TextureFactory instance.
 
Method Summary
(package private)  java.nio.ByteBuffer convertImageData(java.awt.image.BufferedImage bufferedImage, Texture texture)
          Convert the buffered image to byte buffer with the data in appropriate format to pass to opengl
(package private)  int createTextureID(GL gl)
          Create a new texture ID
(package private)  int getClosestGreaterPowerOf2(int target)
          Get the closest greater power of 2
static TextureFactory getFactory()
          initialization
(package private)  java.awt.image.BufferedImage loadImage(java.lang.String path)
          Describe loadImage method here.
(package private)  java.awt.image.BufferedImage loadImage(java.net.URL url)
          Describe loadImage method here.
(package private)  java.awt.image.BufferedImage loadImageResource(java.lang.String resourceName)
          Describe loadImageResource method here.
 Texture loadSubTexture2D(GL gl, java.awt.image.BufferedImage bufferedImage, int target, int dstPixelFormat, int minFilter, int magFilter, int xOffset, int yOffset, int width, int height)
          Describe loadSubTexture method here.
 Texture loadSubTexture2D(GL gl, java.lang.String path, int xOffset, int yOffset, int width, int height)
           
 Texture loadTexture(GL gl, java.awt.image.BufferedImage bufferedImage, int target, int dstPixelFormat, int minFilter, int magFilter)
          Describe loadTexture method here.
 Texture loadTexture(GL gl, java.lang.String path)
          Load a Texture from the filesystem
 Texture loadTexture(GL gl, java.net.URL url)
          Load a Texture from the given URL
 Texture loadTextureResource(GL gl, java.lang.String resourceName)
          Load a Texture as a resource with the given name
 Texture loadTextureResource(GL gl, java.lang.String resourceName, int target, int dstPixelFormat, int minFilter, int magFilter)
          Load a Texture as a resource with the given name
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

static TextureFactory instance
Factory instance


textureCache

java.util.HashMap textureCache
Cache of loaded Textures


glAlphaColorModel

java.awt.image.ColorModel glAlphaColorModel
Colour model including alpha for the GL image


glColorModel

java.awt.image.ColorModel glColorModel
colour model for the GL image


textureIDBuffer

java.nio.IntBuffer textureIDBuffer
buffer for texture ID's

Constructor Detail

TextureFactory

public TextureFactory()
Creates a new TextureFactory instance.

Method Detail

getFactory

public static TextureFactory getFactory()
initialization


createTextureID

int createTextureID(GL gl)
Create a new texture ID

Returns:
A new texture ID

loadTexture

public Texture loadTexture(GL gl,
                           java.lang.String path)
                    throws java.io.IOException
Load a Texture from the filesystem

Parameters:
gl - a GL value
path - The path on the filesystem to the Texture
Returns:
a Texture value
Throws:
java.io.IOException - if an error occurs

loadSubTexture2D

public Texture loadSubTexture2D(GL gl,
                                java.lang.String path,
                                int xOffset,
                                int yOffset,
                                int width,
                                int height)
                         throws java.io.IOException
Throws:
java.io.IOException

loadTexture

public Texture loadTexture(GL gl,
                           java.net.URL url)
                    throws java.io.IOException
Load a Texture from the given URL

Parameters:
gl - a GL value
url - an URL value
Returns:
a Texture value
Throws:
java.io.IOException - if an error occurs

loadTextureResource

public Texture loadTextureResource(GL gl,
                                   java.lang.String resourceName)
                            throws java.io.IOException
Load a Texture as a resource with the given name

Parameters:
gl - a GL value
resourceName - a String value
Returns:
a Texture value
Throws:
java.io.IOException - if an error occurs

loadTextureResource

public Texture loadTextureResource(GL gl,
                                   java.lang.String resourceName,
                                   int target,
                                   int dstPixelFormat,
                                   int minFilter,
                                   int magFilter)
                            throws java.io.IOException
Load a Texture as a resource with the given name

Parameters:
gl - a GL value
resourceName - a String value
target - an int value
dstPixelFormat - an int value
minFilter - an int value
magFilter - an int value
Returns:
a Texture value
Throws:
java.io.IOException - if an error occurs

loadTexture

public Texture loadTexture(GL gl,
                           java.awt.image.BufferedImage bufferedImage,
                           int target,
                           int dstPixelFormat,
                           int minFilter,
                           int magFilter)
                    throws java.io.IOException
Describe loadTexture method here.

Parameters:
gl - a GL value
image - a BufferedImage value
target - an int value
dstPixelFormat - an int value
minFilter - an int value
magFilter - an int value
Returns:
a Texture value
Throws:
java.io.IOException - if an error occurs

loadSubTexture2D

public Texture loadSubTexture2D(GL gl,
                                java.awt.image.BufferedImage bufferedImage,
                                int target,
                                int dstPixelFormat,
                                int minFilter,
                                int magFilter,
                                int xOffset,
                                int yOffset,
                                int width,
                                int height)
                         throws java.io.IOException
Describe loadSubTexture method here.

Parameters:
gl - a GL value
bufferedImage - a BufferedImage value
target - an int value
dstPixelFormat - an int value
minFilter - an int value
magFilter - an int value
width - an int value
height - an int value
Returns:
a Texture value
Throws:
java.io.IOException - if an error occurs

convertImageData

java.nio.ByteBuffer convertImageData(java.awt.image.BufferedImage bufferedImage,
                                     Texture texture)
Convert the buffered image to byte buffer with the data in appropriate format to pass to opengl

Parameters:
bufferedImage - The image to convert to a texture
texture - The texture to store the data into
Returns:
A buffer containing the data

getClosestGreaterPowerOf2

final int getClosestGreaterPowerOf2(int target)
Get the closest greater power of 2

Parameters:
target - The target number
Returns:
The power of 2

loadImage

java.awt.image.BufferedImage loadImage(java.lang.String path)
                                 throws java.io.IOException
Describe loadImage method here.

Parameters:
path - a String value
Returns:
a BufferedImage value
Throws:
java.io.IOException - if an error occurs

loadImage

java.awt.image.BufferedImage loadImage(java.net.URL url)
                                 throws java.io.IOException
Describe loadImage method here.

Parameters:
url - an URL value
Returns:
a BufferedImage value
Throws:
java.io.IOException - if an error occurs

loadImageResource

java.awt.image.BufferedImage loadImageResource(java.lang.String resourceName)
                                         throws java.io.IOException
Describe loadImageResource method here.

Parameters:
url - an URL value
Returns:
a BufferedImage value
Throws:
java.io.IOException - if an error occurs