Class Animator
- java.lang.Object
-
- com.jogamp.opengl.util.AnimatorBase
-
- com.jogamp.opengl.util.Animator
-
- All Implemented Interfaces:
FPSCounter
,GLAnimatorControl
public class Animator extends AnimatorBase
An Animator can be attached to one or more
GLAutoDrawable
s to drive their display() methods in a loop.The Animator class creates a background thread in which the calls to
display()
are performed. After each drawable has been redrawn, a brief pause is performed to avoid swamping the CPU, unlesssetRunAsFastAsPossible(boolean)
has been called.The Animator execution thread does not run as a daemon thread, so it is able to keep an application from terminating.
Callstop()
to terminate the animation and it's execution thread.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.jogamp.opengl.util.AnimatorBase
AnimatorBase.AnimatorImpl, AnimatorBase.UncaughtAnimatorException
-
Nested classes/interfaces inherited from interface com.jogamp.opengl.GLAnimatorControl
GLAnimatorControl.UncaughtExceptionHandler
-
-
Field Summary
-
Fields inherited from class com.jogamp.opengl.util.AnimatorBase
MODE_EXPECT_AWT_RENDERING_THREAD
-
Fields inherited from interface com.jogamp.opengl.FPSCounter
DEFAULT_FRAMES_PER_INTERVAL
-
-
Constructor Summary
Constructors Constructor Description Animator()
Creates a new, empty Animator instance while expecting an AWT rendering thread if AWT is available.Animator(int modeBits)
Creates a new, empty Animator instance with given modeBits.Animator(int modeBits, ThreadGroup tg, GLAutoDrawable drawable)
Creates a new Animator w/ an associated ThreadGroup for a particular drawable.Animator(GLAutoDrawable drawable)
Creates a new Animator for a particular drawable.Animator(ThreadGroup tg)
Creates a new Animator w/ an associated ThreadGroup.Animator(ThreadGroup tg, GLAutoDrawable drawable)
Creates a new Animator w/ an associated ThreadGroup for a particular drawable.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isAnimating()
Indicates whether this animatoris started
andis not paused
.boolean
isPaused()
Indicates whether this animatoris started
and eithermanually paused
or paused automatically due to noadded
GLAutoDrawable
s.boolean
pause()
Pauses this animator.boolean
resume()
Resumes animation if paused.void
setRunAsFastAsPossible(boolean runFast)
Sets a flag in this Animator indicating that it is to run as fast as possible.void
setThreadGroup(ThreadGroup tg)
Set aThreadGroup
for theanimation thread
.boolean
start()
Starts this animator, if not running.boolean
stop()
Stops this animator.-
Methods inherited from class com.jogamp.opengl.util.AnimatorBase
add, getExclusiveContextThread, getFPSStartTime, getLastFPS, getLastFPSPeriod, getLastFPSUpdateTime, getModeBits, getThread, getTotalFPS, getTotalFPSDuration, getTotalFPSFrames, getUncaughtExceptionHandler, getUpdateFPSFrames, isExclusiveContextEnabled, isStarted, remove, resetFPSCounter, setExclusiveContext, setExclusiveContext, setIgnoreExceptions, setModeBits, setPrintExceptions, setUncaughtExceptionHandler, setUpdateFPSFrames, toString
-
-
-
-
Constructor Detail
-
Animator
public Animator()
Creates a new, empty Animator instance while expecting an AWT rendering thread if AWT is available.
-
Animator
public Animator(int modeBits)
Creates a new, empty Animator instance with given modeBits.Passing
AnimatorBase.MODE_EXPECT_AWT_RENDERING_THREAD
is considered default. However, passing0
is recommended if not using AWT in your application.
-
Animator
public Animator(ThreadGroup tg)
Creates a new Animator w/ an associated ThreadGroup.This ctor variant expects an AWT rendering thread if AWT is available.
-
Animator
public Animator(GLAutoDrawable drawable)
Creates a new Animator for a particular drawable.This ctor variant expects an AWT rendering thread if AWT is available.
-
Animator
public Animator(ThreadGroup tg, GLAutoDrawable drawable)
Creates a new Animator w/ an associated ThreadGroup for a particular drawable.This ctor variant expects an AWT rendering thread if AWT is available.
-
Animator
public Animator(int modeBits, ThreadGroup tg, GLAutoDrawable drawable)
Creates a new Animator w/ an associated ThreadGroup for a particular drawable.Passing
AnimatorBase.MODE_EXPECT_AWT_RENDERING_THREAD
is considered default. However, passing0
is recommended if not using AWT in your application.- Parameters:
modeBits
- passAnimatorBase.MODE_EXPECT_AWT_RENDERING_THREAD
if an AWT rendering thread is expected, otherwise0
.tg
- desiredThreadGroup
ornull
drawable
-added
GLAutoDrawable
ornull
- See Also:
AnimatorBase.MODE_EXPECT_AWT_RENDERING_THREAD
,GLProfile.isAWTAvailable()
,AnimatorBase.setModeBits(boolean, int)
-
-
Method Detail
-
setRunAsFastAsPossible
public final void setRunAsFastAsPossible(boolean runFast)
Sets a flag in this Animator indicating that it is to run as fast as possible. By default there is a brief pause in the animation loop which prevents the CPU from getting swamped. This method may not have an effect on subclasses.
-
isAnimating
public final boolean isAnimating()
Description copied from interface:GLAnimatorControl
Indicates whether this animatoris started
andis not paused
.
-
isPaused
public final boolean isPaused()
Description copied from interface:GLAnimatorControl
Indicates whether this animatoris started
and eithermanually paused
or paused automatically due to noadded
GLAutoDrawable
s.
-
setThreadGroup
public final void setThreadGroup(ThreadGroup tg) throws GLException
Set aThreadGroup
for theanimation thread
.- Parameters:
tg
- theThreadGroup
- Throws:
GLException
- if the animator has already been started
-
start
public final boolean start()
Description copied from interface:GLAnimatorControl
Starts this animator, if not running.In most situations this method blocks until completion, except when called from the animation thread itself or in some cases from an implementation-internal thread like the AWT event queue thread.
Note that an animator w/o
added drawables
will be paused automatically.If started, all counters (time, frames, ..) are reset to zero.
- Returns:
- true is started due to this call, otherwise false, ie started already or unable to start.
- See Also:
GLAnimatorControl.stop()
,GLAnimatorControl.isAnimating()
,GLAnimatorControl.isPaused()
,GLAnimatorControl.getThread()
-
stop
public final boolean stop()
Description copied from interface:GLAnimatorControl
Stops this animator.In most situations this method blocks until completion, except when called from the animation thread itself or in some cases from an implementation-internal thread like the AWT event queue thread.
- Returns:
- true is stopped due to this call, otherwise false, ie not started or unable to stop.
- See Also:
GLAnimatorControl.start()
,GLAnimatorControl.isAnimating()
,GLAnimatorControl.getThread()
-
pause
public final boolean pause()
Description copied from interface:GLAnimatorControl
Pauses this animator.In most situations this method blocks until completion, except when called from the animation thread itself or in some cases from an implementation-internal thread like the AWT event queue thread.
- Returns:
- false if not started, already paused or failed to pause, otherwise true
- See Also:
GLAnimatorControl.resume()
,GLAnimatorControl.isAnimating()
-
resume
public final boolean resume()
Description copied from interface:GLAnimatorControl
Resumes animation if paused.In most situations this method blocks until completion, except when called from the animation thread itself or in some cases from an implementation-internal thread like the AWT event queue thread.
If resumed, all counters (time, frames, ..) are reset to zero.
- Returns:
- false if not started, not paused or unable to resume, otherwise true
- See Also:
GLAnimatorControl.pause()
,GLAnimatorControl.isAnimating()
-
-