From ea819ff768d507c37a981c1ab0bdc0cad32c6a87 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 23 Apr 2011 06:20:45 +0200 Subject: 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 ?! --- .../junit/graph/demos/GPURegionNewtDemo01.java | 4 +- .../junit/graph/demos/GPURegionNewtDemo02.java | 4 +- .../graph/demos/GPURendererListenerBase01.java | 6 +- .../test/junit/graph/demos/GPUTextNewtDemo01.java | 6 +- .../test/junit/graph/demos/GPUTextNewtDemo02.java | 8 +- .../graph/demos/GPUTextRendererListenerBase01.java | 4 +- .../junit/graph/demos/ui/UIListenerBase01.java | 2 +- .../test/junit/graph/demos/ui/UINewtDemo01.java | 4 +- .../junit/jogl/acore/TestSharedContextListAWT.java | 4 +- .../jogl/acore/TestSharedContextListNEWT.java | 5 +- .../junit/jogl/demos/gl2/gears/TestGearsAWT.java | 4 +- .../jogl/demos/gl2/gears/TestGearsGLJPanelAWT.java | 4 +- .../gl2/gears/TestGearsGLJPanelAWTBug450.java | 3 +- .../jogl/demos/gl2/gears/newt/TestGearsNEWT.java | 5 +- .../gl2/gears/newt/TestGearsNewtAWTWrapper.java | 4 +- .../test/junit/jogl/glsl/GLSLMiscHelper.java | 22 +++- .../junit/jogl/glsl/TestGLSLShaderState01NEWT.java | 15 +-- .../junit/jogl/glsl/TestGLSLShaderState02NEWT.java | 21 ++-- .../test/junit/jogl/glsl/TestGLSLSimple01NEWT.java | 4 +- .../jogl/glsl/TestShaderCompilationBug459AWT.java | 4 +- .../offscreen/TestOffscreen01GLPBufferNEWT.java | 6 +- .../jogl/offscreen/TestOffscreen02BitmapNEWT.java | 2 +- .../test/junit/jogl/offscreen/WindowUtilNEWT.java | 2 +- .../junit/newt/TestDisplayLifecycle01NEWT.java | 36 +++--- .../junit/newt/TestDisplayLifecycle02NEWT.java | 52 ++++----- .../test/junit/newt/TestFocus01SwingAWTRobot.java | 6 +- .../test/junit/newt/TestFocus02SwingAWTRobot.java | 6 +- .../test/junit/newt/TestGLWindows01NEWT.java | 20 ++-- .../junit/newt/TestGLWindows02NEWTAnimated.java | 15 ++- .../test/junit/newt/TestListenerCom01AWT.java | 3 +- .../test/junit/newt/TestRemoteGLWindows01NEWT.java | 4 +- .../junit/newt/parenting/TestParenting01NEWT.java | 127 ++++++++++----------- .../junit/newt/parenting/TestParenting01aAWT.java | 18 ++- .../newt/parenting/TestParenting01cSwingAWT.java | 19 +-- .../junit/newt/parenting/TestParenting03AWT.java | 18 +-- .../junit/newt/parenting/TestParenting03bAWT.java | 20 +--- 36 files changed, 246 insertions(+), 241 deletions(-) (limited to 'src/test/com/jogamp') diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java index e2ed5f0d0..a7534dc01 100755 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java @@ -28,6 +28,7 @@ package com.jogamp.opengl.test.junit.graph.demos; +import javax.media.opengl.FPSCounter; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; @@ -69,11 +70,12 @@ public class GPURegionNewtDemo01 { regionGLListener.attachInputListenerTo(window); window.addGLEventListener(regionGLListener); - window.enablePerfLog(true); + window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); window.setVisible(true); //FPSAnimator animator = new FPSAnimator(60); Animator animator = new Animator(); + animator.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); animator.add(window); animator.start(); } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java index 678a40c29..9353e0c06 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java @@ -28,6 +28,7 @@ package com.jogamp.opengl.test.junit.graph.demos; +import javax.media.opengl.FPSCounter; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; @@ -69,11 +70,12 @@ public class GPURegionNewtDemo02 { regionGLListener.attachInputListenerTo(window); window.addGLEventListener(regionGLListener); - window.enablePerfLog(true); + window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); window.setVisible(true); //FPSAnimator animator = new FPSAnimator(60); Animator animator = new Animator(); + animator.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); animator.add(window); animator.start(); } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java index 17e0a06d2..b173c1f06 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java @@ -31,6 +31,7 @@ import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; +import javax.media.opengl.FPSCounter; import javax.media.opengl.GL; import javax.media.opengl.GL2ES2; import javax.media.opengl.GLAnimatorControl; @@ -228,7 +229,10 @@ public abstract class GPURendererListenerBase01 implements GLEventListener { gl.setSwapInterval(i); final GLAnimatorControl a = drawable.getAnimator(); if( null != a ) { - a.resetCounter(); + a.resetFPSCounter(); + } + if(drawable instanceof FPSCounter) { + ((FPSCounter)drawable).resetFPSCounter(); } System.err.println("Swap Interval: "+i); } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java index ff22a920e..219438146 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java @@ -28,6 +28,7 @@ package com.jogamp.opengl.test.junit.graph.demos; +import javax.media.opengl.FPSCounter; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; @@ -61,11 +62,12 @@ public class GPUTextNewtDemo01 { GPUTextGLListener0A textGLListener = new GPUTextGLListener0A(rs, Region.SINGLE_PASS, 0, DEBUG, TRACE); textGLListener.attachInputListenerTo(window); window.addGLEventListener(textGLListener); - - window.enablePerfLog(true); + + window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); window.setVisible(true); // FPSAnimator animator = new FPSAnimator(10); Animator animator = new Animator(); + animator.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); animator.add(window); animator.start(); } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java index 067d45b73..cbe597508 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java @@ -27,6 +27,7 @@ */ package com.jogamp.opengl.test.junit.graph.demos; +import javax.media.opengl.FPSCounter; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; @@ -72,11 +73,12 @@ public class GPUTextNewtDemo02 { // ((TextRenderer)textGLListener.getRenderer()).setCacheLimit(32); textGLListener.attachInputListenerTo(window); window.addGLEventListener(textGLListener); - - window.enablePerfLog(true); + + window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); window.setVisible(true); // FPSAnimator animator = new FPSAnimator(60); - Animator animator = new Animator(); + Animator animator = new Animator(); + animator.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); animator.add(window); animator.start(); } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java index 7199226f9..119b38584 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java @@ -137,11 +137,11 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB final int width = drawable.getWidth(); final int height = drawable.getHeight(); final GLAnimatorControl animator = drawable.getAnimator(); - final boolean _drawFPS = drawFPS && null != animator && animator.getTotalFrames()>10; + final boolean _drawFPS = drawFPS && null != animator && animator.getTotalFPSFrames()>10; textRenderer.reshapeOrtho(null, width, height, 0.1f, 7000.0f); if(_drawFPS) { - final float fps = ( animator.getTotalFrames() * 1000.0f ) / (float) animator.getDuration() ; + final float fps = ( animator.getTotalFPSFrames() * 1000.0f ) / (float) animator.getTotalFPSDuration() ; final String fpsS = String.valueOf(fps); final int fpsSp = fpsS.indexOf('.'); textRenderer.resetModelview(null); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIListenerBase01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIListenerBase01.java index f854d8195..c74d11f0d 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIListenerBase01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIListenerBase01.java @@ -294,7 +294,7 @@ public abstract class UIListenerBase01 implements GLEventListener { gl.setSwapInterval(i); final GLAnimatorControl a = drawable.getAnimator(); if( null != a ) { - a.resetCounter(); + a.resetFPSCounter(); } System.err.println("Swap Interval: "+i); } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java index e2aff5793..7d0ad83fa 100755 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java @@ -28,6 +28,7 @@ package com.jogamp.opengl.test.junit.graph.demos.ui; +import javax.media.opengl.FPSCounter; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; @@ -67,10 +68,11 @@ public class UINewtDemo01 { uiGLListener.attachInputListenerTo(window); window.addGLEventListener(uiGLListener); - window.enablePerfLog(true); + window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); window.setVisible(true); Animator animator = new Animator(); + animator.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); animator.add(window); animator.start(); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListAWT.java index bf4c493bc..10c4bce42 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListAWT.java @@ -28,6 +28,7 @@ package com.jogamp.opengl.test.junit.jogl.acore; +import javax.media.opengl.FPSCounter; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLDrawableFactory; import javax.media.opengl.GLPbuffer; @@ -119,8 +120,9 @@ public class TestSharedContextListAWT extends UITestCase { GLCanvas glc2 = runTestGL(f2, animator, width, 0, true); GLCanvas glc3 = runTestGL(f3, animator, 0, height, false); + animator.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); animator.start(); - while(animator.isAnimating() && animator.getDuration() X11 Display). diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows02NEWTAnimated.java b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows02NEWTAnimated.java index 6582a96c0..f7aab9efa 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows02NEWTAnimated.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows02NEWTAnimated.java @@ -118,8 +118,9 @@ public class TestGLWindows02NEWTAnimated extends UITestCase { Assert.assertNotNull(caps); GLWindow window = createWindow(null, caps, width, height, true /* onscreen */, false /* undecorated */); Animator animator = new Animator(window); + animator.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); Assert.assertTrue(animator.start()); - while(animator.isAnimating() && animator.getDuration() glWindow1: compatible Assert.assertEquals(true, glWindow2.isVisible()); - System.err.println("Frames(1) "+glWindow2.getTotalFrames()); + System.err.println("Frames(1) "+glWindow2.getTotalFPSFrames()); reparentAction = glWindow2.reparentWindow(glWindow1, reparentRecreate); - System.err.println("Frames(2) "+glWindow2.getTotalFrames()); + System.err.println("Frames(2) "+glWindow2.getTotalFPSFrames()); Assert.assertTrue(Window.ReparentAction.ACTION_INVALID < reparentAction); Assert.assertEquals(true, glWindow2.isVisible()); Assert.assertEquals(true, glWindow2.isNativeValid()); Assert.assertSame(glWindow1,glWindow2.getParent()); - System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B2: "+glWindow2.getTotalFrames()); - Assert.assertTrue(0 < glWindow2.getTotalFrames()); + System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B2: "+glWindow2.getTotalFPSFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFPSFrames()); Assert.assertEquals(1,display1.getReferenceCount()); Assert.assertEquals(true,display1.isNativeValid()); @@ -425,8 +419,8 @@ public class TestParenting01NEWT extends UITestCase { Assert.assertEquals(true, glWindow2.isVisible()); Assert.assertEquals(true, glWindow2.isNativeValid()); Assert.assertNull(glWindow2.getParent()); - System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B3: "+glWindow2.getTotalFrames()); - Assert.assertTrue(0 < glWindow2.getTotalFrames()); + System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B3: "+glWindow2.getTotalFPSFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFPSFrames()); Assert.assertEquals(1,display1.getReferenceCount()); Assert.assertEquals(true,display1.isNativeValid()); @@ -519,11 +513,6 @@ public class TestParenting01NEWT extends UITestCase { } protected void testWindowParenting03ReparentWin2TopImpl(boolean reparentRecreate) throws InterruptedException { - int x = 0; - int y = 0; - - NEWTEventFiFo eventFifo = new NEWTEventFiFo(); - Assert.assertEquals(0,Display.getActiveDisplayNumber()); Display display1 = null; Screen screen1 = null; @@ -566,12 +555,12 @@ public class TestParenting01NEWT extends UITestCase { Assert.assertSame(screen1,glWindow2.getScreen()); Assert.assertSame(display1,glWindow2.getScreen().getDisplay()); - Assert.assertEquals(0, glWindow1.getTotalFrames()); - Assert.assertEquals(0, glWindow2.getTotalFrames()); + Assert.assertEquals(0, glWindow1.getTotalFPSFrames()); + Assert.assertEquals(0, glWindow2.getTotalFPSFrames()); glWindow1.setVisible(true); - System.err.println("Frames for setVisible(): A1: "+glWindow1.getTotalFrames()+", B1: "+glWindow2.getTotalFrames()); - Assert.assertTrue(0 < glWindow2.getTotalFrames()); - Assert.assertTrue(0 < glWindow1.getTotalFrames()); + System.err.println("Frames for setVisible(): A1: "+glWindow1.getTotalFPSFrames()+", B1: "+glWindow2.getTotalFPSFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFPSFrames()); + Assert.assertTrue(0 < glWindow1.getTotalFPSFrames()); Assert.assertEquals(1,display1.getReferenceCount()); Assert.assertEquals(true,display1.isNativeValid()); @@ -584,13 +573,15 @@ public class TestParenting01NEWT extends UITestCase { Assert.assertEquals(1,Display.getActiveDisplayNumber()); Animator animator1 = new Animator(glWindow1); + animator1.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); animator1.start(); Animator animator2 = new Animator(glWindow2); + animator2.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); animator2.start(); int state = 0; int reparentAction; - while(animator1.isAnimating() && animator1.getDuration()<3*durationPerTest) { + while(animator1.isAnimating() && animator1.getTotalFPSDuration()<3*durationPerTest) { Thread.sleep(durationPerTest); switch(state) { case 0: @@ -599,8 +590,8 @@ public class TestParenting01NEWT extends UITestCase { Assert.assertTrue(Window.ReparentAction.ACTION_INVALID < reparentAction); Assert.assertEquals(true, glWindow2.isVisible()); Assert.assertEquals(true, glWindow2.isNativeValid()); - System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B2: "+glWindow2.getTotalFrames()); - Assert.assertTrue(0 < glWindow2.getTotalFrames()); + System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B2: "+glWindow2.getTotalFPSFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFPSFrames()); Assert.assertNull(glWindow2.getParent()); Assert.assertSame(screen1,glWindow2.getScreen()); Assert.assertSame(display1,glWindow2.getScreen().getDisplay()); @@ -612,8 +603,8 @@ public class TestParenting01NEWT extends UITestCase { Assert.assertTrue(Window.ReparentAction.ACTION_INVALID < reparentAction); Assert.assertEquals(true, glWindow2.isVisible()); Assert.assertEquals(true, glWindow2.isNativeValid()); - System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B3 "+glWindow2.getTotalFrames()); - Assert.assertTrue(0 < glWindow2.getTotalFrames()); + System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B3 "+glWindow2.getTotalFPSFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFPSFrames()); Assert.assertSame(glWindow1,glWindow2.getParent()); Assert.assertSame(screen1,glWindow2.getScreen()); Assert.assertSame(display1,glWindow2.getScreen().getDisplay()); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01aAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01aAWT.java index 424fff0e2..3046eb061 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01aAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01aAWT.java @@ -123,8 +123,9 @@ public class TestParenting01aAWT extends UITestCase { Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); Animator animator1 = new Animator(glWindow1); + animator1.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); animator1.start(); - while(animator1.isAnimating() && animator1.getDuration()