diff options
author | Sven Gothel <[email protected]> | 2011-04-23 06:20:45 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-04-23 06:20:45 +0200 |
commit | ea819ff768d507c37a981c1ab0bdc0cad32c6a87 (patch) | |
tree | 769f0b3c394fb93da235cd7abf6bdd7f642be42a /src/jogl/classes/com/jogamp/opengl/util | |
parent | f5e0656fe20925d8c921d1b4cc70acd02dfbf9fd (diff) |
New FPSCounter, impl. by GLWindow and GLAnimatorControl (fps perf related API change)
- Don't fetch System.currentTimeMillis() by default and for every frame (performance)
- Default behavior is FPSCounter switched off
- Enable by frame interval, ie measure each 60 frames.
- FPSCounterImpl is default impl. used by impl. FPSCounter class (reduce code/redundancy)
- Might be promoted to GLAutoDrawable ?!
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/util')
3 files changed, 45 insertions, 32 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/Animator.java b/src/jogl/classes/com/jogamp/opengl/util/Animator.java index 4fbd0e478..e7fbc4d58 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/Animator.java +++ b/src/jogl/classes/com/jogamp/opengl/util/Animator.java @@ -125,7 +125,7 @@ public class Animator extends AnimatorBase { class MainLoop implements Runnable { public String toString() { - return "[started "+isStartedImpl()+", animating "+isAnimatingImpl()+", paused "+isPausedImpl()+", frames "+getTotalFrames()+", drawable "+drawables.size()+"]"; + return "[started "+isStartedImpl()+", animating "+isAnimatingImpl()+", paused "+isPausedImpl()+", drawable "+drawables.size()+"]"; } public void run() { @@ -134,11 +134,7 @@ public class Animator extends AnimatorBase { if(DEBUG) { System.err.println("Animator start:" + Thread.currentThread() + ": " + toString()); } - - startTime = System.currentTimeMillis(); - curTime = startTime; - totalFrames = 0; - + fpsCounter.resetFPSCounter(); animThread = Thread.currentThread(); setIsAnimatingSynced(false); // barrier Animator.this.notifyAll(); @@ -161,9 +157,7 @@ public class Animator extends AnimatorBase { if (wasPaused) { // resume from pause -> reset counter - startTime = System.currentTimeMillis(); - curTime = startTime; - totalFrames = 0; + fpsCounter.resetFPSCounter(); if (DEBUG) { System.err.println("Animator resume:" + Thread.currentThread() + ": " + toString()); } @@ -269,7 +263,7 @@ public class Animator extends AnimatorBase { if (runnable == null) { runnable = new MainLoop(); } - resetCounter(); + fpsCounter.resetFPSCounter(); String threadName = Thread.currentThread().getName()+"-"+baseName; Thread thread; if(null==threadGroup) { diff --git a/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java b/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java index 01c2ea664..a6ba74665 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java +++ b/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java @@ -30,7 +30,12 @@ package com.jogamp.opengl.util; import com.jogamp.common.util.locks.RecursiveLock; import jogamp.opengl.Debug; +import jogamp.opengl.FPSCounterImpl; + +import java.io.PrintStream; import java.util.ArrayList; + +import javax.media.opengl.FPSCounter; import javax.media.opengl.GLAnimatorControl; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLProfile; @@ -61,9 +66,7 @@ public abstract class AnimatorBase implements GLAnimatorControl { protected Thread animThread; protected boolean ignoreExceptions; protected boolean printExceptions; - protected long startTime; - protected long curTime; - protected int totalFrames; + protected FPSCounterImpl fpsCounter = new FPSCounterImpl(); protected RecursiveLock stateSync = new RecursiveLock(); /** Creates a new, empty Animator. */ @@ -83,7 +86,6 @@ public abstract class AnimatorBase implements GLAnimatorControl { baseName = baseName.concat("-"+animatorCount); drawablesEmpty = true; } - resetCounter(); } protected abstract String getBaseName(String prefix); @@ -138,25 +140,48 @@ public abstract class AnimatorBase implements GLAnimatorControl { lightweight widgets are continually being redrawn. */ protected void display() { impl.display(drawables, ignoreExceptions, printExceptions); - curTime = System.currentTimeMillis(); - totalFrames++; + fpsCounter.tickFPS(); + } + + public final void setUpdateFPSFrames(int frames, PrintStream out) { + fpsCounter.setUpdateFPSFrames(frames, out); + } + + public final void resetFPSCounter() { + fpsCounter.resetFPSCounter(); } - public long getCurrentTime() { - return curTime; + public final int getUpdateFPSFrames() { + return fpsCounter.getUpdateFPSFrames(); + } + + public final long getFPSStartTime() { + return fpsCounter.getFPSStartTime(); } - public long getDuration() { - return curTime - startTime; + public final long getLastFPSUpdateTime() { + return fpsCounter.getLastFPSUpdateTime(); } - public long getStartTime() { - return startTime; + public final long getLastFPSPeriod() { + return fpsCounter.getLastFPSPeriod(); + } + + public final float getLastFPS() { + return fpsCounter.getLastFPS(); + } + + public final int getTotalFPSFrames() { + return fpsCounter.getTotalFPSFrames(); } - public int getTotalFrames() { - return totalFrames; + public final long getTotalFPSDuration() { + return fpsCounter.getTotalFPSDuration(); } + + public final float getTotalFPS() { + return fpsCounter.getTotalFPS(); + } public final Thread getThread() { stateSync.lock(); @@ -167,12 +192,6 @@ public abstract class AnimatorBase implements GLAnimatorControl { } } - public synchronized void resetCounter() { - startTime = System.currentTimeMillis(); // overwrite startTime to real init one - curTime = startTime; - totalFrames = 0; - } - /** 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. */ @@ -189,6 +208,6 @@ public abstract class AnimatorBase implements GLAnimatorControl { } public String toString() { - return getClass().getName()+"[started "+isStarted()+", animating "+isAnimating()+", paused "+isPaused()+", frames "+getTotalFrames()+", drawable "+drawables.size()+"]"; + return getClass().getName()+"[started "+isStarted()+", animating "+isAnimating()+", paused "+isPaused()+", drawable "+drawables.size()+"]"; } } diff --git a/src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java b/src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java index f59351ad8..f7fc58160 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java +++ b/src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java @@ -130,7 +130,7 @@ public class FPSAnimator extends AnimatorBase { } }; - resetCounter(); + fpsCounter.resetFPSCounter(); shouldRun = true; if (scheduleAtFixedRate) { |