Class AnimatorBase
- All Implemented Interfaces:
FPSCounter
,GLAnimatorControl
- Direct Known Subclasses:
Animator
,FPSAnimator
The change synchronization is done via synchronized blocks on the AnimatorBase instance.
Status get / set activity is synced with a RecursiveLock, used as a memory barrier.
This is suitable, since all change requests are allowed to be expensive
as they are not expected to be called at every frame.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
static class
Nested classes/interfaces inherited from interface com.jogamp.opengl.GLAnimatorControl
GLAnimatorControl.UncaughtExceptionHandler
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
If present inmodeBits
field andAWT is available
, implementation is aware of the AWT EDT, otherwise not.Fields inherited from interface com.jogamp.opengl.FPSCounter
DEFAULT_FRAMES_PER_INTERVAL
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new, empty Animator instance while expecting an AWT rendering thread if AWT is available. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
add
(GLAutoDrawable drawable) Adds a drawable to this animator's list of rendering drawables.final Thread
Returns the exclusive context thread ifisExclusiveContextEnabled()
andisStarted()
, otherwisenull
.final long
Returns the time of the first display call in milliseconds after enabling this feature viaFPSCounter.setUpdateFPSFrames(int, PrintStream)
.
This value is reset viaFPSCounter.resetFPSCounter()
.final float
final long
final long
Returns the time of the last update interval in milliseconds, if this feature is enabled viaFPSCounter.setUpdateFPSFrames(int, PrintStream)
.
This value is reset viaFPSCounter.resetFPSCounter()
.int
final Thread
final float
final long
final int
Returns theGLAnimatorControl.UncaughtExceptionHandler
invoked when thisanimator
abruptlystops
due to an uncaught exception from one of itsGLAutoDrawable
s.final int
final boolean
Returnstrue
, if the exclusive context thread is enabled, otherwisefalse
.boolean
Indicates whether this animator has beenstarted
.final void
remove
(GLAutoDrawable drawable) Removes a drawable from the animator's list of rendering drawables.final void
Reset all performance counter (startTime, currentTime, frame number)final boolean
setExclusiveContext
(boolean enable) Dedicate allGLAutoDrawable
's context to this animator thread.final Thread
Dedicate allGLAutoDrawable
's context to the given exclusive context thread.final void
setIgnoreExceptions
(boolean ignoreExceptions) Sets a flag causing this Animator to ignore exceptions produced while redrawing the drawables.final void
setModeBits
(boolean enable, int bitValues) Enables or disables the givenbitValues
in this AnimatorsmodeBits
.final void
setPrintExceptions
(boolean printExceptions) Sets a flag indicating that when exceptions are being ignored by this Animator (seesetIgnoreExceptions(boolean)
), to print the exceptions' stack traces for diagnostic information.final void
Set the handler invoked when thisanimator
abruptlystops
due to an uncaught exception from one of itsGLAutoDrawable
s.final void
setUpdateFPSFrames
(int frames, PrintStream out) toString()
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.jogamp.opengl.GLAnimatorControl
isAnimating, isPaused, pause, resume, start, stop
-
Field Details
-
MODE_EXPECT_AWT_RENDERING_THREAD
public static final int MODE_EXPECT_AWT_RENDERING_THREADIf present inmodeBits
field andAWT is available
, implementation is aware of the AWT EDT, otherwise not.This is the default.
-
-
Constructor Details
-
AnimatorBase
public AnimatorBase()Creates a new, empty Animator instance while expecting an AWT rendering thread if AWT is available.- See Also:
-
-
Method Details
-
setModeBits
Enables or disables the givenbitValues
in this AnimatorsmodeBits
.- Parameters:
enable
-bitValues
-- Throws:
GLException
- if Animator isisStarted()
andMODE_EXPECT_AWT_RENDERING_THREAD
about to change- See Also:
-
getModeBits
public int getModeBits() -
add
Description copied from interface:GLAnimatorControl
Adds a drawable to this animator's list of rendering drawables.This allows the animator thread to become
animating
, in case the first drawable is added and the animatoris started
.- Specified by:
add
in interfaceGLAnimatorControl
- Parameters:
drawable
- the drawable to be added
-
remove
Description copied from interface:GLAnimatorControl
Removes a drawable from the animator's list of rendering drawables.This method should get called in case a drawable becomes invalid, and will not be recovered.
This allows the animator thread to become
not animating
, in case the last drawable has been removed.- Specified by:
remove
in interfaceGLAnimatorControl
- Parameters:
drawable
- the drawable to be removed
-
setExclusiveContext
Dedicate allGLAutoDrawable
's context to the given exclusive context thread.The given thread will be exclusive to all
GLAutoDrawable
's context whileGLAnimatorControl.isAnimating()
.If already started and disabling, method waits until change is propagated to all
GLAutoDrawable
if not called from the animator thread orexclusive context thread
.Note: Utilizing this feature w/ AWT could lead to an AWT-EDT deadlock, depending on the AWT implementation. Hence it is advised not to use it with native AWT GLAutoDrawable like GLCanvas.
- Parameters:
enable
-- Returns:
- previous value
- See Also:
-
setExclusiveContext
public final boolean setExclusiveContext(boolean enable) Dedicate allGLAutoDrawable
's context to this animator thread.The given thread will be exclusive to all
GLAutoDrawable
's context whileGLAnimatorControl.isAnimating()
.If already started and disabling, method waits until change is propagated to all
GLAutoDrawable
if not called from the animator thread orexclusive context thread
.Note: Utilizing this feature w/ AWT could lead to an AWT-EDT deadlock, depending on the AWT implementation. Hence it is advised not to use it with native AWT GLAutoDrawable like GLCanvas.
- Parameters:
enable
-- Returns:
- previous value
- See Also:
-
isExclusiveContextEnabled
public final boolean isExclusiveContextEnabled()Returnstrue
, if the exclusive context thread is enabled, otherwisefalse
. -
getExclusiveContextThread
Returns the exclusive context thread ifisExclusiveContextEnabled()
andisStarted()
, otherwisenull
.If exclusive context is enabled via
setExclusiveContext(boolean)
theanimator thread
is returned if above conditions are met.If exclusive context is enabled via
setExclusiveContext(Thread)
the user passed thread is returned if above conditions are met. -
getThread
- Specified by:
getThread
in interfaceGLAnimatorControl
- Returns:
- The animation thread if running, otherwise null.
- See Also:
-
setUpdateFPSFrames
- Specified by:
setUpdateFPSFrames
in interfaceFPSCounter
- Parameters:
frames
- Update interval in frames.
At every rendered frames interval the currentTime and fps values are updated. If the frames interval is <= 0, no update will be issued, ie the FPSCounter feature is turned off. You may chooseFPSCounter.DEFAULT_FRAMES_PER_INTERVAL
.out
- optional print stream where the fps values gets printed if not null at every frames interval
-
resetFPSCounter
public final void resetFPSCounter()Description copied from interface:FPSCounter
Reset all performance counter (startTime, currentTime, frame number)- Specified by:
resetFPSCounter
in interfaceFPSCounter
-
getUpdateFPSFrames
public final int getUpdateFPSFrames()- Specified by:
getUpdateFPSFrames
in interfaceFPSCounter
- Returns:
- update interval in frames
- See Also:
-
getFPSStartTime
public final long getFPSStartTime()Description copied from interface:FPSCounter
Returns the time of the first display call in milliseconds after enabling this feature viaFPSCounter.setUpdateFPSFrames(int, PrintStream)
.
This value is reset viaFPSCounter.resetFPSCounter()
.- Specified by:
getFPSStartTime
in interfaceFPSCounter
- See Also:
-
getLastFPSUpdateTime
public final long getLastFPSUpdateTime()Description copied from interface:FPSCounter
Returns the time of the last update interval in milliseconds, if this feature is enabled viaFPSCounter.setUpdateFPSFrames(int, PrintStream)
.
This value is reset viaFPSCounter.resetFPSCounter()
.- Specified by:
getLastFPSUpdateTime
in interfaceFPSCounter
- See Also:
-
getLastFPSPeriod
public final long getLastFPSPeriod()- Specified by:
getLastFPSPeriod
in interfaceFPSCounter
- Returns:
- Duration of the last update interval in milliseconds.
- See Also:
-
getLastFPS
public final float getLastFPS()- Specified by:
getLastFPS
in interfaceFPSCounter
- Returns:
- Last update interval's frames per seconds,
FPSCounter.getUpdateFPSFrames()
/FPSCounter.getLastFPSPeriod()
- See Also:
-
getTotalFPSFrames
public final int getTotalFPSFrames()- Specified by:
getTotalFPSFrames
in interfaceFPSCounter
- Returns:
- Number of frame rendered since
FPSCounter.getFPSStartTime()
up toFPSCounter.getLastFPSUpdateTime()
- See Also:
-
getTotalFPSDuration
public final long getTotalFPSDuration()- Specified by:
getTotalFPSDuration
in interfaceFPSCounter
- Returns:
- Total duration in milliseconds,
FPSCounter.getLastFPSUpdateTime()
-FPSCounter.getFPSStartTime()
- See Also:
-
getTotalFPS
public final float getTotalFPS()- Specified by:
getTotalFPS
in interfaceFPSCounter
- Returns:
- Total frames per seconds,
FPSCounter.getTotalFPSFrames()
/FPSCounter.getTotalFPSDuration()
- See Also:
-
setIgnoreExceptions
public final void setIgnoreExceptions(boolean ignoreExceptions) Sets a flag causing this Animator to ignore exceptions produced while redrawing the drawables. By default this flag is set to false, causing any exception thrown to halt the Animator. -
setPrintExceptions
public final void setPrintExceptions(boolean printExceptions) Sets a flag indicating that when exceptions are being ignored by this Animator (seesetIgnoreExceptions(boolean)
), to print the exceptions' stack traces for diagnostic information. Defaults to false. -
getUncaughtExceptionHandler
Description copied from interface:GLAnimatorControl
Returns theGLAnimatorControl.UncaughtExceptionHandler
invoked when thisanimator
abruptlystops
due to an uncaught exception from one of itsGLAutoDrawable
s.Default is
null
.- Specified by:
getUncaughtExceptionHandler
in interfaceGLAnimatorControl
-
setUncaughtExceptionHandler
Description copied from interface:GLAnimatorControl
Set the handler invoked when thisanimator
abruptlystops
due to an uncaught exception from one of itsGLAutoDrawable
s.- Specified by:
setUncaughtExceptionHandler
in interfaceGLAnimatorControl
- Parameters:
handler
- theGLAnimatorControl.UncaughtExceptionHandler
to use as thisanimator
's uncaught exception handler. Passnull
to unset the handler.- See Also:
-
isStarted
public boolean isStarted()Description copied from interface:GLAnimatorControl
Indicates whether this animator has beenstarted
.- Specified by:
isStarted
in interfaceGLAnimatorControl
- See Also:
-
toString
-