edu.mines.jtk.ogl
Class GlTextureName

java.lang.Object
  extended by edu.mines.jtk.ogl.GlTextureName

public class GlTextureName
extends java.lang.Object

An OpenGL texture name. When constructed, a texture name calls glGenTextures to generate a single texture name. When disposed, it calls glDeleteTextures to delete any OpenGL resources bound to that name. If not disposed explicitly, a texture name will dispose itself when finalized during garbage collection.

This class exists to implement the finalize method and thereby reduce the likelihood of OpenGL resource leaks. However, it is not foolproof, for two reasons. First, there is no guarantee that a texture name will ever be finalized. Second, to call glDeleteTextures, a texture name must lock an OpenGL context, and the only context it knows is the one in which it was constructed. That context may have been disposed, but the texture name may have been shared in a different unknown context. In this case, texture resources may be leaked in that unknown context.

Version:
2006.07.08
Author:
Dave Hale, Colorado School of Mines

Constructor Summary
GlTextureName()
          Constructs a texture name in the current OpenGL context.
 
Method Summary
 void dispose()
          Disposes this texture name.
protected  void finalize()
           
 int name()
          Returns the integer name corresponding to this texture name.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GlTextureName

public GlTextureName()
Constructs a texture name in the current OpenGL context. Calls glGenTextures to create one texture object.

Throws:
java.lang.IllegalStateException - if the current OpenGL context is null.
Method Detail

name

public int name()
Returns the integer name corresponding to this texture name.

Returns:
the name; zero, if this texture name has been disposed.

dispose

public void dispose()
Disposes this texture name. When practical, this method should be called explicitly. Otherwise, it will be called when this object is finalized during garbage collection.


finalize

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