41package com.jogamp.opengl.util;
43import com.jogamp.common.ExceptionUtils;
44import com.jogamp.common.util.InterruptSource;
45import com.jogamp.common.util.SourcedInterruptedException;
46import com.jogamp.opengl.GLAutoDrawable;
47import com.jogamp.opengl.GLException;
48import com.jogamp.opengl.GLProfile;
65 private ThreadGroup threadGroup;
66 private Runnable runnable;
67 private boolean runAsFastAsPossible;
69 volatile boolean pauseIssued;
70 volatile boolean stopIssued;
162 if(
null != drawable ) {
166 System.err.println(
"Animator created, modeBits 0x"+Integer.toHexString(
modeBits)+
", ThreadGroup: "+threadGroup+
" and "+drawable);
172 return prefix +
"Animator" ;
182 runAsFastAsPossible = runFast;
185 class MainLoop
implements Runnable {
193 ThreadDeath caughtThreadDeath =
null;
194 UncaughtAnimatorException caughtException =
null;
207 while (!stopIssued) {
210 boolean ectCleared =
false;
215 final boolean wasPaused = pauseIssued;
224 }
catch (
final UncaughtAnimatorException dre) {
225 caughtException = dre;
234 }
catch (
final InterruptedException e) {
235 caughtException =
new UncaughtAnimatorException(
null, SourcedInterruptedException.wrap(e));
247 if (!stopIssued && !isAnimating) {
257 if ( !pauseIssued && !stopIssued ) {
260 }
catch (
final UncaughtAnimatorException dre) {
261 caughtException = dre;
265 if ( !runAsFastAsPossible ) {
271 }
catch(
final ThreadDeath td) {
273 ExceptionUtils.dumpThrowable(
"", td);
275 caughtThreadDeath = td;
281 }
catch (
final UncaughtAnimatorException dre) {
282 if(
null == caughtException ) {
283 caughtException = dre;
285 ExceptionUtils.dumpThrowable(
"(setExclusiveContextThread)", dre);
290 boolean throwCaughtException =
false;
294 if(
null != caughtException ) {
295 ExceptionUtils.dumpThrowable(
"", caughtException);
301 if(
null != caughtException ) {
311 if( throwCaughtException ) {
312 throw caughtException;
314 if(
null != caughtThreadDeath ) {
315 throw caughtThreadDeath;
338 throw new GLException(
"Animator already started.");
344 public final synchronized boolean start() {
348 if (runnable ==
null) {
349 runnable =
new MainLoop();
352 final Thread thread =
new InterruptSource.Thread(threadGroup, runnable,
getThreadName()+
"-"+
baseName);
353 thread.setDaemon(
false);
355 final Thread ct = Thread.currentThread();
356 System.err.println(
"Animator "+ct.getName()+
"[daemon "+ct.isDaemon()+
"]: starting "+thread.getName()+
"[daemon "+thread.isDaemon()+
"]");
361 private final Condition waitForStartedCondition =
new Condition() {
363 public boolean eval() {
368 public final synchronized boolean stop() {
375 private final Condition waitForStoppedCondition =
new Condition() {
377 public boolean eval() {
382 public final synchronized boolean pause() {
389 private final Condition waitForPausedCondition =
new Condition() {
391 public boolean eval() {
397 public final synchronized boolean resume() {
404 private final Condition waitForResumeCondition =
new Condition() {
406 public boolean eval() {
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
Base implementation of GLAnimatorControl
static String getThreadName()
static final boolean DEBUG
final synchronized void setDrawablesExclCtxState(final boolean enable)
Should be called at start() and stop() from within the animator thread.
static final int MODE_EXPECT_AWT_RENDERING_THREAD
If present in modeBits field and AWT is available, implementation is aware of the AWT EDT,...
final void display()
Called every frame to cause redrawing of all of the GLAutoDrawables this Animator manages.
final void flushGLRunnables()
Should be called in case of an uncaught exception from within the animator thread to flush all animat...
final synchronized boolean handleUncaughtException(final UncaughtAnimatorException ue)
Should be called in case of an uncaught exception from within the animator thread,...
ArrayList< GLAutoDrawable > drawables
final synchronized boolean finishLifecycleAction(final Condition waitCondition, long pollPeriod)
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
FPSCounterImpl fpsCounter
synchronized boolean isStarted()
Indicates whether this animator has been started.
Animator(final int modeBits)
Creates a new, empty Animator instance with given modeBits.
final synchronized boolean pause()
Pauses this animator.
final synchronized boolean resume()
Resumes animation if paused.
Animator(final ThreadGroup tg, final GLAutoDrawable drawable)
Creates a new Animator w/ an associated ThreadGroup for a particular drawable.
Animator()
Creates a new, empty Animator instance while expecting an AWT rendering thread if AWT is available.
final synchronized void setRunAsFastAsPossible(final boolean runFast)
Sets a flag in this Animator indicating that it is to run as fast as possible.
final synchronized boolean isAnimating()
Indicates whether this animator is started and is not paused.
Animator(final int modeBits, final ThreadGroup tg, final GLAutoDrawable drawable)
Creates a new Animator w/ an associated ThreadGroup for a particular drawable.
Animator(final GLAutoDrawable drawable)
Creates a new Animator for a particular drawable.
final synchronized void setThreadGroup(final ThreadGroup tg)
Set a ThreadGroup for the animation thread.
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean isPaused()
Indicates whether this animator is started and either manually paused or paused automatically due to ...
final String getBaseName(final String prefix)
Animator(final ThreadGroup tg)
Creates a new Animator w/ an associated ThreadGroup.
final synchronized boolean stop()
Stops this animator.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...