org.jrabbit.base.data.thread
Class WatchableGLThread

java.lang.Object
  extended by java.lang.Thread
      extended by org.jrabbit.base.data.thread.WatchableThread
          extended by org.jrabbit.base.data.thread.WatchableGLThread
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
ImageLoadingThread, ResourceLoadingThread, SoundLoadingThread

public abstract class WatchableGLThread
extends WatchableThread

This class attempts to do the same thing as a WatchableThread, but it allows you to alter OpenGL resources while doing so. Attempting to do so in the default WatchableThread will not work, since the two threads have separate OpenGL contexts. To mingle contexts, the Thread instantiates a SharedDrawable to mingle contexts with that of the Display (i.e., the main OpenGL context). Unfortunately, this functionality is not universally supported on all graphics cards, and so this has a chance to fail. If the attempt fails, a flag is set, and external operations can check for success or failure.

Author:
Chris Molini

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static int CONTEXT_SHARING_FAILURE
          Indicates that context sharing failed, and the thread has been unable to process events.
static int CONTEXT_SHARING_SUCCESS
          Indicates that context sharing has been a success.
static int CONTEXT_SHARING_UNDECIDED
          Indicates that the Thread has not come to the point where it can determine success or failure.
private  int contextSharingResult
          The current indicator of that status of context sharing.
protected  org.lwjgl.opengl.SharedDrawable sharedDrawable
          The object used to share contexts.
 
Fields inherited from class org.jrabbit.base.data.thread.WatchableThread
progress, total
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
WatchableGLThread()
           
 
Method Summary
 boolean contextSharingFailed()
          Checks if context sharing failed.
 int contextSharingResult()
          Accesses the context sharing flag.
 boolean contextSharingSuccess()
          Checks if context sharing succeeded.
protected  void releaseContext()
          Gets rid of the shared context if it is not present any more.
 void run()
          First attempts to share contexts with the Display.
protected  void shareContext()
          Attempts to share contexts, settings the flag on either success or failure.
 
Methods inherited from class org.jrabbit.base.data.thread.WatchableThread
act, complete, percentComplete
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CONTEXT_SHARING_UNDECIDED

public static final int CONTEXT_SHARING_UNDECIDED
Indicates that the Thread has not come to the point where it can determine success or failure.

See Also:
Constant Field Values

CONTEXT_SHARING_SUCCESS

public static final int CONTEXT_SHARING_SUCCESS
Indicates that context sharing has been a success.

See Also:
Constant Field Values

CONTEXT_SHARING_FAILURE

public static final int CONTEXT_SHARING_FAILURE
Indicates that context sharing failed, and the thread has been unable to process events.

See Also:
Constant Field Values

sharedDrawable

protected org.lwjgl.opengl.SharedDrawable sharedDrawable
The object used to share contexts.


contextSharingResult

private int contextSharingResult
The current indicator of that status of context sharing.

Constructor Detail

WatchableGLThread

public WatchableGLThread()
Method Detail

run

public void run()
First attempts to share contexts with the Display. If context sharing fails, the Thread doesn't attempt to process act(), but instead exits immediately.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class WatchableThread

shareContext

protected void shareContext()
Attempts to share contexts, settings the flag on either success or failure.


releaseContext

protected void releaseContext()
Gets rid of the shared context if it is not present any more.


contextSharingResult

public int contextSharingResult()
Accesses the context sharing flag.

Returns:
The current value of the flag. This will be either CONTEXT_SHARING_UNDECIDED, CONTEXT_SHARING_SUCCESS, or CONTEXT_SHARING_FAILURE.

contextSharingSuccess

public boolean contextSharingSuccess()
Checks if context sharing succeeded.

Returns:
True if the context sharing succeeded and events are being processed as planned.

contextSharingFailed

public boolean contextSharingFailed()
Checks if context sharing failed.

Returns:
True if the context sharing failed and events cannot be processed.