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/newt/classes/com | |
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/newt/classes/com')
-rw-r--r-- | src/newt/classes/com/jogamp/newt/opengl/GLWindow.java | 98 |
1 files changed, 38 insertions, 60 deletions
diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java index 48531fcf8..2dcb6345e 100644 --- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java +++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java @@ -34,6 +34,7 @@ package com.jogamp.newt.opengl; +import java.io.PrintStream; import java.util.List; import com.jogamp.common.GlueGenVersion; @@ -48,6 +49,7 @@ import javax.media.nativewindow.util.Point; import javax.media.nativewindow.util.Insets; import javax.media.opengl.*; +import jogamp.opengl.FPSCounterImpl; import jogamp.opengl.GLDrawableHelper; import com.jogamp.opengl.JoglVersion; @@ -64,14 +66,14 @@ import com.jogamp.opengl.JoglVersion; * via {@link #invoke(boolean, javax.media.opengl.GLRunnable)} to the OpenGL command stream.<br> * <p> */ -public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer { +public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer, FPSCounter { private WindowImpl window; /** * Constructor. Do not call this directly -- use {@link #create()} instead. */ protected GLWindow(Window window) { - resetCounter(); + resetFPSCounter(); this.window = (WindowImpl) window; ((WindowImpl)this.window).setHandleDestroyNotify(false); window.addWindowListener(new WindowAdapter() { @@ -365,7 +367,7 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer { if(Window.DEBUG_WINDOW_EVENT || Window.DEBUG_IMPLEMENTATION) { System.err.println("GLWindow.resetCounter() "+Thread.currentThread()); } - GLWindow.this.resetCounter(); + GLWindow.this.resetFPSCounter(); } public synchronized void setVisibleActionPost(boolean visible, boolean nativeWindowCreated) { @@ -433,9 +435,7 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer { // To make reshape events be sent immediately before a display event private boolean sendReshape=false; private boolean sendDestroy=false; - private boolean perfLog = false; - private long startTime, curTime, lastCheck; - private int totalFrames, lastFrames; + private FPSCounterImpl fpsCounter = new FPSCounterImpl(); public GLDrawableFactory getFactory() { return factory; @@ -507,12 +507,6 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer { return null; } - public boolean getPerfLogEnabled() { return perfLog; } - - public void enablePerfLog(boolean v) { - perfLog = v; - } - public void invoke(boolean wait, GLRunnable glRunnable) { if(null!=helper) { helper.invoke(this, wait, glRunnable); @@ -577,7 +571,7 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer { public final void run() { // Lock: Locked Surface/Window by MakeCurrent/Release helper.init(GLWindow.this); - resetCounter(); + resetFPSCounter(); } } private InitAction initAction = new InitAction(); @@ -592,66 +586,50 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer { helper.display(GLWindow.this); - curTime = System.currentTimeMillis(); - totalFrames++; - - if(perfLog) { - long dt0, dt1; - lastFrames++; - dt0 = curTime-lastCheck; - if ( dt0 > 5000 ) { - dt1 = curTime-startTime; - System.err.println(dt0/1000 +"s: "+ lastFrames + "f, " + (lastFrames*1000)/dt0 + " fps, "+dt0/lastFrames+" ms/f; "+ - "total: "+ dt1/1000+"s, "+(totalFrames*1000)/dt1 + " fps, "+dt1/totalFrames+" ms/f"); - lastCheck=curTime; - lastFrames=0; - } - } + fpsCounter.tickFPS(); } } private DisplayAction displayAction = new DisplayAction(); - /** - * @return Time of the first display call in milliseconds. - * This value is reset if becoming visible again or reparenting. - */ - public final long getStartTime() { - return startTime; + public final void setUpdateFPSFrames(int frames, PrintStream out) { + fpsCounter.setUpdateFPSFrames(frames, out); + } + + public final void resetFPSCounter() { + fpsCounter.resetFPSCounter(); } - /** - * @return Time of the last display call in milliseconds. - * This value is reset if becoming visible again or reparenting. - */ - public final long getCurrentTime() { - return curTime; + public final int getUpdateFPSFrames() { + return fpsCounter.getUpdateFPSFrames(); + } + + public final long getFPSStartTime() { + return fpsCounter.getFPSStartTime(); } - /** - * @return Duration <code>getCurrentTime() - getStartTime()</code>. - * - * @see #getStartTime() - * @see #getCurrentTime() - */ - public final long getDuration() { - return getCurrentTime()-getStartTime(); + public final long getLastFPSUpdateTime() { + return fpsCounter.getLastFPSUpdateTime(); } - /** - * @return Number of frames displayed since the first display call, ie <code>getStartTime()</code>. - * This value is reset if becoming visible again or reparenting. - */ - public final int getTotalFrames() { - return totalFrames; + public final long getLastFPSPeriod() { + return fpsCounter.getLastFPSPeriod(); + } + + public final float getLastFPS() { + return fpsCounter.getLastFPS(); + } + + public final int getTotalFPSFrames() { + return fpsCounter.getTotalFPSFrames(); } - /** Reset all counter (startTime, currentTime, frame number) */ - public final synchronized void resetCounter() { - startTime = System.currentTimeMillis(); // overwrite startTime to real init one - curTime = startTime; - lastCheck = startTime; - totalFrames = 0; lastFrames = 0; + public final long getTotalFPSDuration() { + return fpsCounter.getTotalFPSDuration(); } + + public final float getTotalFPS() { + return fpsCounter.getTotalFPS(); + } private class SwapBuffersAction implements Runnable { public final void run() { |