JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
com.jogamp.opengl.util.FPSAnimator Class Reference

An Animator subclass which attempts to achieve a target frames-per-second rate to avoid using all CPU time. More...

Inheritance diagram for com.jogamp.opengl.util.FPSAnimator:
Collaboration diagram for com.jogamp.opengl.util.FPSAnimator:

Classes

class  MainTask
 

Public Member Functions

 FPSAnimator (final int fps)
 Creates an FPSAnimator with a given target frames-per-second value. More...
 
 FPSAnimator (final int modeBits, final int fps)
 Creates an FPSAnimator with modeBits, see AnimatorBase#AnimatorBase(int) and a given target frames-per-second value. More...
 
 FPSAnimator (final int fps, final boolean scheduleAtFixedRate)
 Creates an FPSAnimator with a given target frames-per-second value and a flag indicating whether to use fixed-rate scheduling. More...
 
 FPSAnimator (final GLAutoDrawable drawable, final int fps)
 Creates an FPSAnimator with a given target frames-per-second value and an initial drawable to animate. More...
 
 FPSAnimator (final GLAutoDrawable drawable, final int fps, final 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. More...
 
 FPSAnimator (final int modeBits, final GLAutoDrawable drawable, final int fps, final boolean scheduleAtFixedRate)
 Creates an FPSAnimator with modeBits, see AnimatorBase#AnimatorBase(int), a given target frames-per-second value, an initial drawable to animate, and a flag indicating whether to use fixed-rate scheduling. More...
 
final void setFPS (final int fps) throws GLException
 
final int getFPS ()
 
final synchronized boolean isAnimating ()
 Indicates whether this animator is started and is not paused. More...
 
final synchronized boolean isPaused ()
 Indicates whether this animator is started and either manually paused or paused automatically due to no added GLAutoDrawables. More...
 
final synchronized boolean start ()
 Starts this animator, if not running. More...
 
final synchronized boolean stop ()
 Stops this FPSAnimator. More...
 
final synchronized boolean pause ()
 Pauses this animator. More...
 
final synchronized boolean resume ()
 Resumes animation if paused. More...
 
- Public Member Functions inherited from com.jogamp.opengl.util.AnimatorBase
 AnimatorBase ()
 Creates a new, empty Animator instance while expecting an AWT rendering thread if AWT is available. More...
 
 AnimatorBase (final int modeBits)
 Creates a new, empty Animator instance with given modeBits. More...
 
final synchronized void setModeBits (final boolean enable, final int bitValues) throws GLException
 Enables or disables the given bitValues in this Animators modeBits. More...
 
synchronized int getModeBits ()
 
final synchronized void add (final GLAutoDrawable drawable)
 Adds a drawable to this animator's list of rendering drawables. More...
 
final synchronized void remove (final GLAutoDrawable drawable)
 Removes a drawable from the animator's list of rendering drawables. More...
 
final synchronized Thread setExclusiveContext (final Thread t)
 Dedicate all GLAutoDrawable's context to the given exclusive context thread. More...
 
final boolean setExclusiveContext (final boolean enable)
 Dedicate all GLAutoDrawable's context to this animator thread. More...
 
final synchronized boolean isExclusiveContextEnabled ()
 Returns true, if the exclusive context thread is enabled, otherwise false. More...
 
final synchronized Thread getExclusiveContextThread ()
 Returns the exclusive context thread if isExclusiveContextEnabled() and isStarted(), otherwise null. More...
 
final synchronized Thread getThread ()
 
final void setUpdateFPSFrames (final int frames, final PrintStream out)
 
final void resetFPSCounter ()
 Reset all performance counter (startTime, currentTime, frame number) More...
 
final int getUpdateFPSFrames ()
 
final long getFPSStartTime ()
 Returns the time of the first display call in milliseconds after enabling this feature via setUpdateFPSFrames(int, PrintStream). More...
 
final long getLastFPSUpdateTime ()
 Returns the time of the last update interval in milliseconds, if this feature is enabled via setUpdateFPSFrames(int, PrintStream). More...
 
final long getLastFPSPeriod ()
 
final float getLastFPS ()
 
final int getTotalFPSFrames ()
 
final long getTotalFPSDuration ()
 
final float getTotalFPS ()
 
final void setIgnoreExceptions (final boolean ignoreExceptions)
 Sets a flag causing this Animator to ignore exceptions produced while redrawing the drawables. More...
 
final void setPrintExceptions (final boolean printExceptions)
 Sets a flag indicating that when exceptions are being ignored by this Animator (see setIgnoreExceptions), to print the exceptions' stack traces for diagnostic information. More...
 
final UncaughtExceptionHandler getUncaughtExceptionHandler ()
 Returns the UncaughtExceptionHandler invoked when this animator abruptly stops due to an uncaught exception from one of its GLAutoDrawables. More...
 
final void setUncaughtExceptionHandler (final UncaughtExceptionHandler handler)
 Set the handler invoked when this animator abruptly stops due to an uncaught exception from one of its GLAutoDrawables. More...
 
synchronized boolean isStarted ()
 Indicates whether this animator has been started. More...
 
String toString ()
 
boolean isStarted ()
 Indicates whether this animator has been started. More...
 
boolean isAnimating ()
 Indicates whether this animator is started and is not paused. More...
 
boolean isPaused ()
 Indicates whether this animator is started and either manually paused or paused automatically due to no added GLAutoDrawables. More...
 
Thread getThread ()
 
boolean start ()
 Starts this animator, if not running. More...
 
boolean stop ()
 Stops this animator. More...
 
boolean pause ()
 Pauses this animator. More...
 
boolean resume ()
 Resumes animation if paused. More...
 
void add (GLAutoDrawable drawable)
 Adds a drawable to this animator's list of rendering drawables. More...
 
void remove (GLAutoDrawable drawable)
 Removes a drawable from the animator's list of rendering drawables. More...
 
UncaughtExceptionHandler getUncaughtExceptionHandler ()
 Returns the UncaughtExceptionHandler invoked when this animator abruptly stops due to an uncaught exception from one of its GLAutoDrawables. More...
 
void setUncaughtExceptionHandler (final UncaughtExceptionHandler handler)
 Set the handler invoked when this animator abruptly stops due to an uncaught exception from one of its GLAutoDrawables. More...
 
void setUpdateFPSFrames (int frames, PrintStream out)
 
void resetFPSCounter ()
 Reset all performance counter (startTime, currentTime, frame number) More...
 
int getUpdateFPSFrames ()
 
long getFPSStartTime ()
 Returns the time of the first display call in milliseconds after enabling this feature via setUpdateFPSFrames(int, PrintStream). More...
 
long getLastFPSUpdateTime ()
 Returns the time of the last update interval in milliseconds, if this feature is enabled via setUpdateFPSFrames(int, PrintStream). More...
 
long getLastFPSPeriod ()
 
float getLastFPS ()
 
int getTotalFPSFrames ()
 
long getTotalFPSDuration ()
 
float getTotalFPS ()
 

Protected Member Functions

String getBaseName (final String prefix)
 
- Protected Member Functions inherited from com.jogamp.opengl.util.AnimatorBase
final synchronized void initImpl (final boolean force)
 Initializes implementation details post setup, invoked at add(GLAutoDrawable), start(), . More...
 
abstract String getBaseName (String prefix)
 
final synchronized void setDrawablesExclCtxState (final boolean enable)
 Should be called at start() and stop() from within the animator thread. More...
 
final boolean validateDrawablesExclCtxState (final Thread expected)
 
final void display () throws UncaughtAnimatorException
 Called every frame to cause redrawing of all of the GLAutoDrawables this Animator manages. More...
 
final synchronized boolean handleUncaughtException (final UncaughtAnimatorException ue)
 Should be called in case of an uncaught exception from within the animator thread, throws given exception if no handler has been installed. More...
 
final void flushGLRunnables ()
 Should be called in case of an uncaught exception from within the animator thread to flush all animator. More...
 
final synchronized boolean finishLifecycleAction (final Condition waitCondition, long pollPeriod)
 

Additional Inherited Members

- Static Public Attributes inherited from com.jogamp.opengl.util.AnimatorBase
static final int MODE_EXPECT_AWT_RENDERING_THREAD = 1 << 0
 If present in modeBits field and AWT is available, implementation is aware of the AWT EDT, otherwise not. More...
 
- Static Public Attributes inherited from com.jogamp.opengl.FPSCounter
static final int DEFAULT_FRAMES_PER_INTERVAL = 5*60
 
- Static Protected Member Functions inherited from com.jogamp.opengl.util.AnimatorBase
static String getThreadName ()
 
- Protected Attributes inherited from com.jogamp.opengl.util.AnimatorBase
int modeBits
 
AnimatorImpl impl
 
String baseName
 
ArrayList< GLAutoDrawabledrawables = new ArrayList<GLAutoDrawable>()
 
boolean drawablesEmpty
 
Thread animThread
 
boolean ignoreExceptions
 
boolean printExceptions
 
boolean exclusiveContext
 
Thread userExclusiveContextThread
 
UncaughtExceptionHandler uncaughtExceptionHandler
 
FPSCounterImpl fpsCounter = new FPSCounterImpl()
 
- Static Protected Attributes inherited from com.jogamp.opengl.util.AnimatorBase
static final boolean DEBUG = Debug.debug("Animator")
 
static final long TO_WAIT_FOR_FINISH_LIFECYCLE_ACTION = 1000
 A 1s timeout while waiting for a native action response, limiting finishLifecycleAction(Condition, long). More...
 
static final long POLLP_WAIT_FOR_FINISH_LIFECYCLE_ACTION = 32
 

Detailed Description

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.
Call stop() to terminate the animation and it's execution thread.

Definition at line 60 of file FPSAnimator.java.

Constructor & Destructor Documentation

◆ FPSAnimator() [1/6]

com.jogamp.opengl.util.FPSAnimator.FPSAnimator ( final int  fps)

Creates an FPSAnimator with a given target frames-per-second value.

Equivalent to FPSAnimator(null, fps).

This ctor variant expects an AWT rendering thread if AWT is available.

See also
AnimatorBase::MODE_EXPECT_AWT_RENDERING_THREAD
FPSAnimator(int, GLAutoDrawable, int, boolean)
GLProfile::isAWTAvailable()
AnimatorBase::setModeBits(boolean, int)

Definition at line 85 of file FPSAnimator.java.

◆ FPSAnimator() [2/6]

com.jogamp.opengl.util.FPSAnimator.FPSAnimator ( final int  modeBits,
final int  fps 
)

Creates an FPSAnimator with modeBits, see AnimatorBase#AnimatorBase(int) and a given target frames-per-second value.

See also
AnimatorBase::MODE_EXPECT_AWT_RENDERING_THREAD
FPSAnimator(int, GLAutoDrawable, int, boolean)
GLProfile::isAWTAvailable()
AnimatorBase::setModeBits(boolean, int)

Definition at line 98 of file FPSAnimator.java.

◆ FPSAnimator() [3/6]

com.jogamp.opengl.util.FPSAnimator.FPSAnimator ( final int  fps,
final boolean  scheduleAtFixedRate 
)

Creates an FPSAnimator with a given target frames-per-second value and a flag indicating whether to use fixed-rate scheduling.

Equivalent to FPSAnimator(null, fps, scheduleAtFixedRate).

This ctor variant expects an AWT rendering thread if AWT is available.

See also
AnimatorBase::MODE_EXPECT_AWT_RENDERING_THREAD
FPSAnimator(int, GLAutoDrawable, int, boolean)
GLProfile::isAWTAvailable()
AnimatorBase::setModeBits(boolean, int)

Definition at line 115 of file FPSAnimator.java.

◆ FPSAnimator() [4/6]

com.jogamp.opengl.util.FPSAnimator.FPSAnimator ( final GLAutoDrawable  drawable,
final int  fps 
)

Creates an FPSAnimator with a given target frames-per-second value and an initial drawable to animate.

Equivalent to FPSAnimator(null, fps, false).

This ctor variant expects an AWT rendering thread if AWT is available.

See also
AnimatorBase::MODE_EXPECT_AWT_RENDERING_THREAD
FPSAnimator(int, GLAutoDrawable, int, boolean)
GLProfile::isAWTAvailable()
AnimatorBase::setModeBits(boolean, int)

Definition at line 131 of file FPSAnimator.java.

◆ FPSAnimator() [5/6]

com.jogamp.opengl.util.FPSAnimator.FPSAnimator ( final GLAutoDrawable  drawable,
final int  fps,
final 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.

This ctor variant expects an AWT rendering thread if AWT is available.

See also
AnimatorBase::MODE_EXPECT_AWT_RENDERING_THREAD
FPSAnimator(int, GLAutoDrawable, int, boolean)
GLProfile::isAWTAvailable()
AnimatorBase::setModeBits(boolean, int)

Definition at line 147 of file FPSAnimator.java.

◆ FPSAnimator() [6/6]

com.jogamp.opengl.util.FPSAnimator.FPSAnimator ( final int  modeBits,
final GLAutoDrawable  drawable,
final int  fps,
final boolean  scheduleAtFixedRate 
)

Creates an FPSAnimator with modeBits, see AnimatorBase#AnimatorBase(int), a given target frames-per-second value, an initial drawable to animate, and a flag indicating whether to use fixed-rate scheduling.

Parameters
modeBitspass AnimatorBase#MODE_EXPECT_AWT_RENDERING_THREAD if an AWT rendering thread is expected, otherwise 0.
drawableadded GLAutoDrawable or null
fpstarget frames per seconds
scheduleAtFixedRateflag indicating fixed rate scheduling
See also
AnimatorBase::MODE_EXPECT_AWT_RENDERING_THREAD
FPSAnimator(int, GLAutoDrawable, int, boolean)
GLProfile::isAWTAvailable()
AnimatorBase::setModeBits(boolean, int)

Definition at line 165 of file FPSAnimator.java.

Here is the call graph for this function:

Member Function Documentation

◆ getBaseName()

String com.jogamp.opengl.util.FPSAnimator.getBaseName ( final String  prefix)
protected

Reimplemented from com.jogamp.opengl.util.AnimatorBase.

Definition at line 70 of file FPSAnimator.java.

◆ getFPS()

final int com.jogamp.opengl.util.FPSAnimator.getFPS ( )

Definition at line 184 of file FPSAnimator.java.

◆ isAnimating()

final synchronized boolean com.jogamp.opengl.util.FPSAnimator.isAnimating ( )

Indicates whether this animator is started and is not paused.

See also
start()
stop()
pause()
resume()

Implements com.jogamp.opengl.GLAnimatorControl.

Definition at line 331 of file FPSAnimator.java.

◆ isPaused()

final synchronized boolean com.jogamp.opengl.util.FPSAnimator.isPaused ( )

Indicates whether this animator is started and either manually paused or paused automatically due to no added GLAutoDrawables.

See also
start()
stop()
pause()
resume()

Implements com.jogamp.opengl.GLAnimatorControl.

Definition at line 336 of file FPSAnimator.java.

◆ pause()

final synchronized boolean com.jogamp.opengl.util.FPSAnimator.pause ( )

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
resume()
#isAnimating()

Implements com.jogamp.opengl.GLAnimatorControl.

Definition at line 417 of file FPSAnimator.java.

Here is the call graph for this function:

◆ resume()

final synchronized boolean com.jogamp.opengl.util.FPSAnimator.resume ( )

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
pause()
#isAnimating()

Implements com.jogamp.opengl.GLAnimatorControl.

Definition at line 450 of file FPSAnimator.java.

Here is the call graph for this function:

◆ setFPS()

final void com.jogamp.opengl.util.FPSAnimator.setFPS ( final int  fps) throws GLException
Parameters
fps
Exceptions
GLExceptionif the animator has already been started

Definition at line 178 of file FPSAnimator.java.

Here is the call graph for this function:

◆ start()

final synchronized boolean com.jogamp.opengl.util.FPSAnimator.start ( )

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
stop()
#isAnimating()
isPaused()
getThread()

Implements com.jogamp.opengl.GLAnimatorControl.

Definition at line 343 of file FPSAnimator.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stop()

final synchronized boolean com.jogamp.opengl.util.FPSAnimator.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.

Implements com.jogamp.opengl.GLAnimatorControl.

Definition at line 380 of file FPSAnimator.java.

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following file: