edu.mines.jtk.opengl
Class GlContext

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

public class GlContext
extends java.lang.Object

An OpenGL context. All OpenGL rendering is performed using the current OpenGL context. A thread sets the current context by locking it. After rendering, that thread unlocks the context. At any time, a single thread may hold the lock to no more than one context. Multiple threads cannot simultaneously hold the lock to one context. Therefore, contexts should be unlocked sometime after they are locked.

To ensure that each call to lock() is paired with a call to unlock(), perform the latter in a finally block, as in this example:


   context.lock();
   try {
     // ...
     // render using various OpenGL methods
     // ...
     context.swapBuffers();
   } finally {
     context.unlock();
   }
 

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

Constructor Summary
GlContext(java.awt.Canvas canvas)
          Constructs an OpenGL context for the specified canvas.
 
Method Summary
 void dispose()
          Dispose this context.
protected  void finalize()
           
 boolean isDisposed()
          Determines whether this context has been disposed.
 boolean isLocked()
          Determines whether the current thread has this context locked.
 void lock()
          Locks this context.
 void swapBuffers()
          Swaps the front and back buffers for this context.
 void unlock()
          Unlocks this context.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GlContext

public GlContext(java.awt.Canvas canvas)
Constructs an OpenGL context for the specified canvas.

Parameters:
canvas - the canvas.
Method Detail

lock

public void lock()
Locks this context. If another thread has locked this context, this method waits until that lock is released.

Throws:
java.lang.IllegalStateException - if the current thread already has another OpenGL context locked.

unlock

public void unlock()
Unlocks this context.

Throws:
java.lang.IllegalStateException - if the current thread does not already have this OpenGL context locked.

isLocked

public boolean isLocked()
Determines whether the current thread has this context locked. Used only for debugging, not for synchronization.

Returns:
true, if locked; false, otherwise.

swapBuffers

public void swapBuffers()
Swaps the front and back buffers for this context.


dispose

public void dispose()
Dispose this context.


isDisposed

public boolean isDisposed()
Determines whether this context has been disposed.

Returns:
true, if disposed; false, otherwise.

finalize

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