com.threerings.opengl.renderer
Class Texture

java.lang.Object
  extended by com.threerings.opengl.renderer.Texture
Direct Known Subclasses:
Texture1D, Texture2D, Texture3D, TextureCubeMap

public abstract class Texture
extends Object

An OpenGL texture object.


Field Summary
protected  Color4f _borderColor
          The border color.
protected  int[] _bytes
          The number of bytes occupied by each mipmap level.
protected  int _compareFunc
          The texture compare function.
protected  int _compareMode
          The texture compare mode.
protected  int _depthMode
          The depth texture mode.
protected  int _format
          The format of the texture.
protected  boolean _generateMipmaps
          Whether or not mipmaps should be automatically generated.
protected  int _id
          The OpenGL identifier for this texture.
protected  int _magFilter
          The current magnification filter.
protected  float _maxAnisotropy
          The maximum degree of anisotropy.
protected  int _minFilter
          The current minification filter.
protected  Renderer _renderer
          The renderer responsible for this texture.
protected  int _target
          The texture target.
protected static FloatBuffer _vbuf
          A buffer for floating point values.
protected  int _wrapR
          The r texture wrap mode.
protected  int _wrapS
          The s texture wrap mode.
protected  int _wrapT
          The t texture wrap mode.
protected static int[] COMPRESSED_FORMATS
          Compressed internal formats for one, two, three, or four color components.
protected static int[] FORMATS
          Formats corresponding to one, two, three, or four color components.
 
Constructor Summary
protected Texture()
          Creates an invalid texture (used by the renderer to force reapplication).
  Texture(Renderer renderer, int target)
          Creates a new texture for the specified renderer.
 
Method Summary
 void delete()
          Deletes this texture, rendering it unusable.
protected  void finalize()
           
 void generateMipmap()
          Generates a set of mipmaps for this texture.
protected static ByteBuffer getData(BufferedImage image, boolean premultiply, int width, int height, boolean rescale)
          Converts (and resizes) an image into a buffer of data to be passed to OpenGL.
 int getDepth()
          Returns the depth of the texture.
 int getFormat()
          Returns the format of this texture.
protected static int getFormat(BufferedImage image)
          Returns the format of the data to be returned by getData(java.awt.image.BufferedImage, boolean, int, int, boolean) for the specified image.
abstract  int getHeight()
          Returns the height of the texture.
 int getId()
          Returns this texture's OpenGL identifier.
protected static int getInternalFormat(BufferedImage image, boolean compress)
          Returns the internal format to use for the given image with optional compression.
 int getTarget()
          Returns the texture's target.
protected  int getTotalBytes()
          Returns the total number of bytes in the texture.
abstract  int getWidth()
          Returns the width of the texture.
protected static BufferedImage halveImage(BufferedImage image)
          Scales the provided image in half by each dimension for use as a mipmap.
 boolean hasAlpha()
          Checks whether this texture has an alpha channel.
 boolean isDepth()
          Determines whether this is a depth texture.
 void setBorderColor(Color4f borderColor)
          Sets the border color.
protected  void setBytes(int level, int bytes)
          Sets the number of bytes occupied by the specified mipmap level.
 void setCompare(int mode, int func)
          Convenience method to set both compare parameters at once.
 void setCompareFunc(int compareFunc)
          Sets the texture compare function.
 void setCompareMode(int compareMode)
          Sets the texture compare mode.
 void setDepthMode(int depthMode)
          Sets the depth texture mode.
 void setFilters(int min, int mag)
          Convenience method to set both the filters at once.
 void setGenerateMipmaps(boolean generate)
          Sets whether or not to generate mipmaps automatically.
 void setMagFilter(int magFilter)
          Sets the texture magnification filter.
 void setMaxAnisotropy(float maxAnisotropy)
          Sets the texture maximum anisotropy.
 void setMinFilter(int minFilter)
          Sets the texture minification filter.
protected  void setMipmapBytes(int bytes, int... dimensions)
          Sets the number of bytes occupied by all mipmap levels.
 void setWrap(int s, int t)
          Convenience method to set the s and t wrap modes at once.
 void setWrap(int s, int t, int r)
          Convenience method to set all the wrap modes at once.
 void setWrapR(int wrap)
          Sets the r texture wrap mode.
 void setWrapS(int wrap)
          Sets the s texture wrap mode.
 void setWrapT(int wrap)
          Sets the t texture wrap mode.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_renderer

protected Renderer _renderer
The renderer responsible for this texture.


_id

protected int _id
The OpenGL identifier for this texture.


_target

protected int _target
The texture target.


_format

protected int _format
The format of the texture.


_minFilter

protected int _minFilter
The current minification filter.


_magFilter

protected int _magFilter
The current magnification filter.


_maxAnisotropy

protected float _maxAnisotropy
The maximum degree of anisotropy.


_wrapS

protected int _wrapS
The s texture wrap mode.


_wrapT

protected int _wrapT
The t texture wrap mode.


_wrapR

protected int _wrapR
The r texture wrap mode.


_borderColor

protected Color4f _borderColor
The border color.


_generateMipmaps

protected boolean _generateMipmaps
Whether or not mipmaps should be automatically generated.


_compareMode

protected int _compareMode
The texture compare mode.


_compareFunc

protected int _compareFunc
The texture compare function.


_depthMode

protected int _depthMode
The depth texture mode.


_bytes

protected int[] _bytes
The number of bytes occupied by each mipmap level.


_vbuf

protected static FloatBuffer _vbuf
A buffer for floating point values.


FORMATS

protected static final int[] FORMATS
Formats corresponding to one, two, three, or four color components.


COMPRESSED_FORMATS

protected static final int[] COMPRESSED_FORMATS
Compressed internal formats for one, two, three, or four color components.

Constructor Detail

Texture

public Texture(Renderer renderer,
               int target)
Creates a new texture for the specified renderer.


Texture

protected Texture()
Creates an invalid texture (used by the renderer to force reapplication).

Method Detail

getId

public final int getId()
Returns this texture's OpenGL identifier.


getTarget

public final int getTarget()
Returns the texture's target.


getFormat

public int getFormat()
Returns the format of this texture.


hasAlpha

public boolean hasAlpha()
Checks whether this texture has an alpha channel.


isDepth

public boolean isDepth()
Determines whether this is a depth texture.


getWidth

public abstract int getWidth()
Returns the width of the texture.


getHeight

public abstract int getHeight()
Returns the height of the texture.


getDepth

public int getDepth()
Returns the depth of the texture.


setFilters

public void setFilters(int min,
                       int mag)
Convenience method to set both the filters at once.


setMinFilter

public void setMinFilter(int minFilter)
Sets the texture minification filter.


setMagFilter

public void setMagFilter(int magFilter)
Sets the texture magnification filter.


setMaxAnisotropy

public void setMaxAnisotropy(float maxAnisotropy)
Sets the texture maximum anisotropy.


setWrap

public void setWrap(int s,
                    int t)
Convenience method to set the s and t wrap modes at once.


setWrap

public void setWrap(int s,
                    int t,
                    int r)
Convenience method to set all the wrap modes at once.


setWrapS

public void setWrapS(int wrap)
Sets the s texture wrap mode.


setWrapT

public void setWrapT(int wrap)
Sets the t texture wrap mode.


setWrapR

public void setWrapR(int wrap)
Sets the r texture wrap mode.


setBorderColor

public void setBorderColor(Color4f borderColor)
Sets the border color.


setGenerateMipmaps

public void setGenerateMipmaps(boolean generate)
Sets whether or not to generate mipmaps automatically.


setCompare

public void setCompare(int mode,
                       int func)
Convenience method to set both compare parameters at once.


setCompareMode

public void setCompareMode(int compareMode)
Sets the texture compare mode.


setCompareFunc

public void setCompareFunc(int compareFunc)
Sets the texture compare function.


setDepthMode

public void setDepthMode(int depthMode)
Sets the depth texture mode.


generateMipmap

public void generateMipmap()
Generates a set of mipmaps for this texture. This relies on the GL_EXT_framebuffer_object extension, so it's really only useful in conjunction with FBOs.


delete

public void delete()
Deletes this texture, rendering it unusable.


finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable

setMipmapBytes

protected void setMipmapBytes(int bytes,
                              int... dimensions)
Sets the number of bytes occupied by all mipmap levels.


setBytes

protected void setBytes(int level,
                        int bytes)
Sets the number of bytes occupied by the specified mipmap level.


getTotalBytes

protected int getTotalBytes()
Returns the total number of bytes in the texture.


getFormat

protected static int getFormat(BufferedImage image)
Returns the format of the data to be returned by getData(java.awt.image.BufferedImage, boolean, int, int, boolean) for the specified image.


getInternalFormat

protected static int getInternalFormat(BufferedImage image,
                                       boolean compress)
Returns the internal format to use for the given image with optional compression.


halveImage

protected static BufferedImage halveImage(BufferedImage image)
Scales the provided image in half by each dimension for use as a mipmap.


getData

protected static ByteBuffer getData(BufferedImage image,
                                    boolean premultiply,
                                    int width,
                                    int height,
                                    boolean rescale)
Converts (and resizes) an image into a buffer of data to be passed to OpenGL.