Class FPSAnimator
- java.lang.Object
-
- com.jogamp.opengl.util.AnimatorBase
-
- com.jogamp.opengl.util.FPSAnimator
-
- All Implemented Interfaces:
FPSCounter
,GLAnimatorControl
public class FPSAnimator extends AnimatorBase
An Animator subclass which attempts to achieve a target frames-per-second rate to avoid using all CPU time. The target FPS is only an estimate and is not guaranteed.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 FPSAnimator(int fps)
Creates an FPSAnimator with a given target frames-per-second value.FPSAnimator(int fps, boolean scheduleAtFixedRate)
Creates an FPSAnimator with a given target frames-per-second value and a flag indicating whether to use fixed-rate scheduling.FPSAnimator(GLAutoDrawable drawable, int fps)
Creates an FPSAnimator with a given target frames-per-second value and an initial drawable to animate.FPSAnimator(GLAutoDrawable drawable, int fps, boolean scheduleAtFixedRate)
Creates an FPSAnimator with a given target frames-per-second value, an initial drawable to animate, and a flag indicating whether to use fixed-rate scheduling.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getFPS()
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
setFPS(int fps)
boolean
start()
Starts this animator, if not running.boolean
stop()
Stops this FPSAnimator.-
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
-
FPSAnimator
public FPSAnimator(int fps)
Creates an FPSAnimator with a given target frames-per-second value. Equivalent toFPSAnimator(null, fps)
.
-
FPSAnimator
public FPSAnimator(int fps, boolean scheduleAtFixedRate)
Creates an FPSAnimator with a given target frames-per-second value and a flag indicating whether to use fixed-rate scheduling. Equivalent toFPSAnimator(null, fps, scheduleAtFixedRate)
.
-
FPSAnimator
public FPSAnimator(GLAutoDrawable drawable, int fps)
Creates an FPSAnimator with a given target frames-per-second value and an initial drawable to animate. Equivalent toFPSAnimator(null, fps, false)
.
-
FPSAnimator
public FPSAnimator(GLAutoDrawable drawable, int fps, boolean scheduleAtFixedRate)
Creates an FPSAnimator with a given target frames-per-second value, an initial drawable to animate, and a flag indicating whether to use fixed-rate scheduling.
-
-
Method Detail
-
setFPS
public final void setFPS(int fps) throws GLException
- Parameters:
fps
-- Throws:
GLException
- if the animator has already been started
-
getFPS
public final int getFPS()
-
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.
-
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()
Stops this FPSAnimator. Due to the implementation of the FPSAnimator it is not guaranteed that the FPSAnimator will be completely stopped by the time this method returns.- 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()
-
-