edu.mines.jtk.opengl
Class GlDisplayList

java.lang.Object
  extended by edu.mines.jtk.opengl.GlDisplayList

public class GlDisplayList
extends java.lang.Object

An OpenGL display list. When constructed, a display list calls glGenLists to generate one or more display lists. When disposed, it calls glDeleteLists to delete any OpenGL resources bound to those lists. If not disposed explicitly, a display list 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 display list will ever be finalized. Second, to call glDeleteLists, a display list 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 display list may have been shared in a different unknown context. In this case, display list resources may be leaked in that unknown context.

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

Constructor Summary
GlDisplayList()
          Constructs a display list in the current OpenGL context.
GlDisplayList(int range)
          Constructs display lists in the current OpenGL context.
 
Method Summary
 void dispose()
          Disposes this display list.
protected  void finalize()
           
 int list()
          Returns the integer index corresponding to this display list.
 int range()
          Returns the number of display lists.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GlDisplayList

public GlDisplayList()
Constructs a display list in the current OpenGL context. Calls glGenLists to create one display list object.

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

GlDisplayList

public GlDisplayList(int range)
Constructs display lists in the current OpenGL context. Calls glGenLists to create the specified number of display list objects.

Parameters:
range - the number of display lists.
Throws:
java.lang.IllegalStateException - if the current OpenGL context is null.
Method Detail

list

public int list()
Returns the integer index corresponding to this display list. If more than one list, this method returns the index of the first list.

Returns:
the index; zero, if this display list has been disposed.

range

public int range()
Returns the number of display lists.

Returns:
the number of display lists; zero, if disposed.

dispose

public void dispose()
Disposes this display list. 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