diff options
Diffstat (limited to 'src/test')
25 files changed, 960 insertions, 475 deletions
diff --git a/src/test/com/jogamp/opengl/test/android/MovieCubeActivityLauncher0.java b/src/test/com/jogamp/opengl/test/android/MovieCubeActivityLauncher0.java index fb7faf90b..1e0d6067f 100644 --- a/src/test/com/jogamp/opengl/test/android/MovieCubeActivityLauncher0.java +++ b/src/test/com/jogamp/opengl/test/android/MovieCubeActivityLauncher0.java @@ -58,7 +58,7 @@ public class MovieCubeActivityLauncher0 extends LauncherUtil.BaseActivityLaunche // props.setProperty("jogl.debug.GLProfile", "true"); // props.setProperty("jogl.debug.GLDrawable", "true"); // props.setProperty("jogl.debug.GLContext", "true"); - // props.setProperty("jogl.debug.GLMediaPlayer", "true"); + props.setProperty("jogl.debug.GLMediaPlayer", "true"); props.setProperty("jogl.debug.GLSLCode", "true"); // props.setProperty("jogl.debug.CapabilitiesChooser", "true"); // props.setProperty("jogl.debug.GLSLState", "true"); diff --git a/src/test/com/jogamp/opengl/test/android/MovieCubeActivityLauncher1a.java b/src/test/com/jogamp/opengl/test/android/MovieCubeActivityLauncher1a.java index 79b8b210d..c4eea084a 100644 --- a/src/test/com/jogamp/opengl/test/android/MovieCubeActivityLauncher1a.java +++ b/src/test/com/jogamp/opengl/test/android/MovieCubeActivityLauncher1a.java @@ -57,7 +57,7 @@ public class MovieCubeActivityLauncher1a extends LauncherUtil.BaseActivityLaunch // props.setProperty("jogl.debug.GLProfile", "true"); // props.setProperty("jogl.debug.GLDrawable", "true"); // props.setProperty("jogl.debug.GLContext", "true"); - // props.setProperty("jogl.debug.GLMediaPlayer", "true"); + props.setProperty("jogl.debug.GLMediaPlayer", "true"); props.setProperty("jogl.debug.GLSLCode", "true"); // props.setProperty("jogl.debug.CapabilitiesChooser", "true"); // props.setProperty("jogl.debug.GLSLState", "true"); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestShutdownCompleteAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestShutdownCompleteAWT.java index 4e2e91320..9f367ef0b 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestShutdownCompleteAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestShutdownCompleteAWT.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,12 +20,12 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ - + package com.jogamp.opengl.test.junit.jogl.acore; import java.awt.Frame; @@ -36,11 +36,14 @@ import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; import javax.media.opengl.awt.GLCanvas; +import org.junit.AfterClass; import org.junit.Assert; import org.junit.Test; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; +import com.jogamp.common.os.Platform; +import com.jogamp.opengl.JoglVersion; import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; import com.jogamp.opengl.test.junit.util.UITestCase; import com.jogamp.opengl.util.Animator; @@ -49,7 +52,7 @@ import com.jogamp.opengl.util.Animator; public class TestShutdownCompleteAWT extends UITestCase { static long duration = 300; // ms - + protected void runTestGL() throws InterruptedException, InvocationTargetException { final Frame frame = new Frame("Gears AWT Test"); Assert.assertNotNull(frame); @@ -67,8 +70,8 @@ public class TestShutdownCompleteAWT extends UITestCase { frame.setSize(256, 256); frame.setVisible(true); }}); - - animator.setUpdateFPSFrames(60, System.err); + + animator.setUpdateFPSFrames(60, System.err); animator.start(); Assert.assertEquals(true, animator.isAnimating()); Assert.assertEquals(true, glCanvas.isVisible()); @@ -93,37 +96,70 @@ public class TestShutdownCompleteAWT extends UITestCase { }}); } - protected void oneLife() throws InterruptedException, InvocationTargetException { - long t0 = System.nanoTime(); + @AfterClass + public static void afterAll() { + if(waitForKey) { + UITestCase.waitForKey("Exit"); + } + } + + protected void oneLife(boolean glInfo) throws InterruptedException, InvocationTargetException { + final long t0 = Platform.currentTimeMicros(); GLProfile.initSingleton(); - long t1 = System.nanoTime(); - runTestGL(); - long t2 = System.nanoTime(); - GLProfile.shutdown(); - long t3 = System.nanoTime(); - System.err.println("Total: "+ (t3-t0)/1e6 +"ms"); - System.err.println(" GLProfile.initSingleton(): "+ (t1-t0)/1e6 +"ms"); - System.err.println(" Demo Code: "+ (t2-t1)/1e6 +"ms"); - System.err.println(" GLProfile.shutdown(): "+ (t3-t2)/1e6 +"ms"); + final long t1 = Platform.currentTimeMicros(); + if(!initOnly) { + runTestGL(); + } + final long t2 = Platform.currentTimeMicros(); + if(glInfo) { + System.err.println(JoglVersion.getDefaultOpenGLInfo(null, null, false).toString()); + } + final long t3 = Platform.currentTimeMicros(); + GLProfile.shutdown(); + final long t4 = Platform.currentTimeMicros(); + System.err.println("Total: "+ (t4-t0)/1e3 +"ms"); + System.err.println(" GLProfile.initSingleton(): "+ (t1-t0)/1e3 +"ms"); + System.err.println(" Demo Code: "+ (t2-t1)/1e3 +"ms"); + System.err.println(" GLInfo: "+ (t3-t2)/1e3 +"ms"); + System.err.println(" GLProfile.shutdown(): "+ (t4-t3)/1e3 +"ms"); } - + @Test public void test01OneLife() throws InterruptedException, InvocationTargetException { - oneLife(); + oneLife(false); + } + + @Test + public void test02AnotherLifeWithGLInfo() throws InterruptedException, InvocationTargetException { + oneLife(true); } @Test - public void test01AnotherLife() throws InterruptedException, InvocationTargetException { - oneLife(); + public void test03AnotherLife() throws InterruptedException, InvocationTargetException { + oneLife(true); } - + @Test - public void test01TwoLifes() throws InterruptedException, InvocationTargetException { - oneLife(); - oneLife(); + public void test03TwoLifes() throws InterruptedException, InvocationTargetException { + oneLife(false); + oneLife(false); } - + + static boolean initOnly = false; + static boolean waitForKey = false; + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-wait")) { + waitForKey = true; + } else if(args[i].equals("-initOnly")) { + initOnly = true; + } + } + + if(waitForKey) { + UITestCase.waitForKey("Start"); + } String tstname = TestShutdownCompleteAWT.class.getName(); org.junit.runner.JUnitCore.main(tstname); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestShutdownCompleteNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestShutdownCompleteNEWT.java index 881d6c8de..e7d1cb8e9 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestShutdownCompleteNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestShutdownCompleteNEWT.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,26 +20,26 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ - + package com.jogamp.opengl.test.junit.jogl.acore; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStreamReader; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; +import org.junit.AfterClass; import org.junit.Assert; import org.junit.Test; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; +import com.jogamp.common.os.Platform; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.JoglVersion; import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; @@ -50,12 +50,12 @@ import com.jogamp.opengl.util.Animator; public class TestShutdownCompleteNEWT extends UITestCase { static long duration = 300; // ms - + protected void runTestGL(boolean onscreen) throws InterruptedException { GLCapabilities caps = new GLCapabilities(GLProfile.getGL2ES2()); caps.setOnscreen(onscreen); caps.setPBuffer(!onscreen); - + GLWindow glWindow = GLWindow.create(caps); Assert.assertNotNull(glWindow); glWindow.setTitle("Gears NEWT Test"); @@ -81,59 +81,63 @@ public class TestShutdownCompleteNEWT extends UITestCase { glWindow.destroy(); } + @AfterClass + public static void afterAll() { + if(waitForKey) { + UITestCase.waitForKey("Exit"); + } + } + protected void oneLife(boolean glInfo) throws InterruptedException { if(waitForEach) { - waitForEnter(); + UITestCase.waitForKey("Start One Life"); } - long t0 = System.nanoTime(); + final long t0 = Platform.currentTimeMicros(); GLProfile.initSingleton(); - long t1 = System.nanoTime(); + final long t1 = Platform.currentTimeMicros(); if(!initOnly) { runTestGL(true); } - long t2 = System.nanoTime(); + final long t2 = Platform.currentTimeMicros(); if(glInfo) { System.err.println(JoglVersion.getDefaultOpenGLInfo(null, null, false).toString()); } - long t3 = System.nanoTime(); - GLProfile.shutdown(); - long t4 = System.nanoTime(); - System.err.println("Total: "+ (t3-t0)/1e6 +"ms"); - System.err.println(" GLProfile.initSingleton(): "+ (t1-t0)/1e6 +"ms"); - System.err.println(" Demo Code: "+ (t2-t1)/1e6 +"ms"); - System.err.println(" GLProfile.shutdown(): "+ (t4-t3)/1e6 +"ms"); + final long t3 = Platform.currentTimeMicros(); + GLProfile.shutdown(); + final long t4 = Platform.currentTimeMicros(); + System.err.println("Total: "+ (t4-t0)/1e3 +"ms"); + System.err.println(" GLProfile.initSingleton(): "+ (t1-t0)/1e3 +"ms"); + System.err.println(" Demo Code: "+ (t2-t1)/1e3 +"ms"); + System.err.println(" GLInfo: "+ (t3-t2)/1e3 +"ms"); + System.err.println(" GLProfile.shutdown(): "+ (t4-t3)/1e3 +"ms"); } - + @Test public void test01OneLife() throws InterruptedException { + oneLife(false); + } + + @Test + public void test02AnotherLifeWithGLInfo() throws InterruptedException { oneLife(true); } @Test - public void test01AnotherLife() throws InterruptedException { - oneLife(false); + public void test03AnotherLife() throws InterruptedException { + oneLife(true); } - + @Test - public void test01TwoLifes() throws InterruptedException { + public void test03TwoLifes() throws InterruptedException { oneLife(false); oneLife(false); } - + static boolean initOnly = false; static boolean waitForEach = false; - - static void waitForEnter() { - BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); - System.err.println("Press enter to continue"); - try { - System.err.println(stdin.readLine()); - } catch (IOException e) { } - } - + static boolean waitForKey = false; + public static void main(String args[]) throws IOException { - boolean waitForKey = false; - for(int i=0; i<args.length; i++) { if(args[i].equals("-wait")) { waitForKey = true; @@ -144,11 +148,11 @@ public class TestShutdownCompleteNEWT extends UITestCase { initOnly = true; } } - + if(waitForKey) { - waitForEnter(); + UITestCase.waitForKey("Start"); } - + String tstname = TestShutdownCompleteNEWT.class.getName(); org.junit.runner.JUnitCore.main(tstname); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/RedSquareES1.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/RedSquareES1.java index 811e91886..5891bce0d 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/RedSquareES1.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/RedSquareES1.java @@ -23,10 +23,11 @@ public class RedSquareES1 implements GLEventListener, TileRendererBase.TileRende private boolean debug = false ; private boolean trace = false ; private int swapInterval = 0; - private float aspect = 1.0f; + private final float aspect = 1.0f; private boolean doRotate = true; private TileRendererBase tileRendererInUse = null; private boolean doRotateBeforePrinting; + private boolean flipVerticalInGLOrientation = false; long startTime = 0; long curTime = 0; @@ -38,17 +39,17 @@ public class RedSquareES1 implements GLEventListener, TileRendererBase.TileRende public RedSquareES1() { this.swapInterval = 1; } - + @Override public void addTileRendererNotify(TileRendererBase tr) { tileRendererInUse = tr; doRotateBeforePrinting = doRotate; - setDoRotation(false); + setDoRotation(false); } @Override public void removeTileRendererNotify(TileRendererBase tr) { tileRendererInUse = null; - setDoRotation(doRotateBeforePrinting); + setDoRotation(doRotateBeforePrinting); } @Override public void startTileRendering(TileRendererBase tr) { @@ -58,7 +59,7 @@ public class RedSquareES1 implements GLEventListener, TileRendererBase.TileRende public void endTileRendering(TileRendererBase tr) { System.err.println("RedSquareES1.endTileRendering: "+tr); } - + public void setDoRotation(boolean rotate) { this.doRotate = rotate; } public void setForceFFPEmu(boolean forceFFPEmu, boolean verboseFFPEmu, boolean debugFFPEmu, boolean traceFFPEmu) { this.forceFFPEmu = forceFFPEmu; @@ -66,7 +67,8 @@ public class RedSquareES1 implements GLEventListener, TileRendererBase.TileRende this.debugFFPEmu = debugFFPEmu; this.traceFFPEmu = traceFFPEmu; } - + public void setFlipVerticalInGLOrientation(boolean v) { flipVerticalInGLOrientation=v; } + // FIXME: we must add storage of the pointers in the GL state to // the GLImpl classes. The need for this can be seen by making // these variables method local instead of instance members. The @@ -93,12 +95,12 @@ public class RedSquareES1 implements GLEventListener, TileRendererBase.TileRende trace = false; } GL2ES1 gl = FixedFuncUtil.wrapFixedFuncEmul(_gl, ShaderSelectionMode.AUTO, null, forceFFPEmu, verboseFFPEmu); - + if(debug) { try { // Debug .. gl = (GL2ES1) gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Debug", GL2ES1.class, gl, null) ); - } catch (Exception e) {e.printStackTrace();} + } catch (Exception e) {e.printStackTrace();} } if(trace) { try { @@ -139,34 +141,37 @@ public class RedSquareES1 implements GLEventListener, TileRendererBase.TileRende @Override public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) { final GL2ES1 gl = glad.getGL().getGL2ES1(); - if(-1 != swapInterval) { + if(-1 != swapInterval) { gl.setSwapInterval(swapInterval); } reshapeImpl(gl, x, y, width, height, width, height); } - + @Override public void reshapeTile(TileRendererBase tr, - int tileX, int tileY, int tileWidth, int tileHeight, + int tileX, int tileY, int tileWidth, int tileHeight, int imageWidth, int imageHeight) { final GL2ES1 gl = tr.getAttachedDrawable().getGL().getGL2ES1(); gl.setSwapInterval(0); reshapeImpl(gl, tileX, tileY, tileWidth, tileHeight, imageWidth, imageHeight); } - + void reshapeImpl(GL2ES1 gl, int tileX, int tileY, int tileWidth, int tileHeight, int imageWidth, int imageHeight) { System.err.println(Thread.currentThread()+" RedSquareES1.reshape "+tileX+"/"+tileY+" "+tileWidth+"x"+tileHeight+" of "+imageWidth+"x"+imageHeight+", swapInterval "+swapInterval+", drawable 0x"+Long.toHexString(gl.getContext().getGLDrawable().getHandle())+", tileRendererInUse "+tileRendererInUse); - + // Set location in front of camera gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); gl.glLoadIdentity(); - + if( flipVerticalInGLOrientation && gl.getContext().getGLDrawable().isGLOriented() ) { + gl.glScalef(1f, -1f, 1f); + } + // compute projection parameters 'normal' perspective final float fovy=45f; final float aspect2 = ( (float) imageWidth / (float) imageHeight ) / aspect; final float zNear=1f; final float zFar=100f; - + // compute projection parameters 'normal' frustum final float top=(float)Math.tan(fovy*((float)Math.PI)/360.0f)*zNear; final float bottom=-1.0f*top; @@ -174,18 +179,22 @@ public class RedSquareES1 implements GLEventListener, TileRendererBase.TileRende final float right=aspect2*top; final float w = right - left; final float h = top - bottom; - + // compute projection parameters 'tiled' final float l = left + tileX * w / imageWidth; final float r = l + tileWidth * w / imageWidth; final float b = bottom + tileY * h / imageHeight; final float t = b + tileHeight * h / imageHeight; - + gl.glFrustumf(l, r, b, t, zNear, zFar); // gl.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f); + + gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); + gl.glLoadIdentity(); + System.err.println(Thread.currentThread()+" RedSquareES1.reshape FIN"); } - + @Override public void display(GLAutoDrawable drawable) { curTime = System.currentTimeMillis(); @@ -201,11 +210,9 @@ public class RedSquareES1 implements GLEventListener, TileRendererBase.TileRende gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); gl.glLoadIdentity(); gl.glTranslatef(0, 0, -10); - if(doRotate) { - float ang = ((float) (curTime - startTime) * 360.0f) / 4000.0f; - gl.glRotatef(ang, 0, 0, 1); - gl.glRotatef(ang, 0, 1, 0); - } + float ang = doRotate ? ((curTime - startTime) * 360.0f) / 4000.0f : 1f; + gl.glRotatef(ang, 0, 0, 1); + gl.glRotatef(ang, 0, 1, 0); // Draw a square gl.glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java index ff5de7cb0..d85d38618 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java @@ -356,8 +356,6 @@ public class GearsES2 implements GLEventListener, TileRendererBase.TileRendererL } st.useProgram(gl, true); - pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION); - pmvMatrix.glLoadIdentity(); // compute projection parameters 'normal' float left, right, bottom, top; @@ -386,17 +384,19 @@ public class GearsES2 implements GLEventListener, TileRendererBase.TileRendererL final float _w = r - l; final float _h = t - b; if(verbose) { - System.err.println(">> angle "+sid()+" "+angle+", [l "+left+", r "+right+", b "+bottom+", t "+top+"] "+w+"x"+h+" -> [l "+l+", r "+r+", b "+b+", t "+t+"] "+_w+"x"+_h); + System.err.println(">> GearsES2 "+sid()+", angle "+angle+", [l "+left+", r "+right+", b "+bottom+", t "+top+"] "+w+"x"+h+" -> [l "+l+", r "+r+", b "+b+", t "+t+"] "+_w+"x"+_h+", v-flip "+flipVerticalInGLOrientation); } + pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION); + pmvMatrix.glLoadIdentity(); + if( flipVerticalInGLOrientation && gl.getContext().getGLDrawable().isGLOriented() ) { + pmvMatrix.glScalef(1f, -1f, 1f); + } pmvMatrix.glFrustumf(l, r, b, t, 5.0f, 200.0f); pmvMatrix.glMatrixMode(PMVMatrix.GL_MODELVIEW); pmvMatrix.glLoadIdentity(); pmvMatrix.glTranslatef(0.0f, 0.0f, -40.0f); - if(flipVerticalInGLOrientation && gl.getContext().getGLDrawable().isGLOriented() ) { - pmvMatrix.glRotatef(180f, 1.0f, 0.0f, 0.0f); - } st.uniform(gl, pmvMatrixUniform); st.useProgram(gl, false); @@ -490,15 +490,18 @@ public class GearsES2 implements GLEventListener, TileRendererBase.TileRendererL return; } - gl.glEnable(GL.GL_CULL_FACE); + // Only possible if we do not flip the projection matrix + final boolean enableCullFace = ! ( flipVerticalInGLOrientation && gl.getContext().getGLDrawable().isGLOriented() ); + if( enableCullFace ) { + gl.glEnable(GL.GL_CULL_FACE); + } st.useProgram(gl, true); pmvMatrix.glPushMatrix(); pmvMatrix.glTranslatef(panX, panY, panZ); - final float flipVF = ( flipVerticalInGLOrientation && drawable.isGLOriented() ) ? -1f : 1f; - pmvMatrix.glRotatef(flipVF*view_rotx, 1.0f, 0.0f, 0.0f); - pmvMatrix.glRotatef(flipVF*view_roty, 0.0f, 1.0f, 0.0f); - pmvMatrix.glRotatef(flipVF*view_rotz, 0.0f, 0.0f, 1.0f); + pmvMatrix.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f); + pmvMatrix.glRotatef(view_roty, 0.0f, 1.0f, 0.0f); + pmvMatrix.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f); gear1.draw(gl, -3.0f, -2.0f, 1f * angle - 0f); gear2.draw(gl, 3.1f, -2.0f, -2f * angle - 9.0f); @@ -506,7 +509,9 @@ public class GearsES2 implements GLEventListener, TileRendererBase.TileRendererL pmvMatrix.glPopMatrix(); st.useProgram(gl, false); - gl.glDisable(GL.GL_CULL_FACE); + if( enableCullFace ) { + gl.glDisable(GL.GL_CULL_FACE); + } } @Override diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java index 8f27e19c4..c1ccf7c39 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java @@ -153,7 +153,7 @@ public class MovieCube implements GLEventListener { return; } System.err.println("MC "+e); - int pts0 = mPlayer.getVideoPTS(); + final int pts0 = GLMediaPlayer.STREAM_ID_NONE != mPlayer.getVID() ? mPlayer.getVideoPTS() : mPlayer.getAudioPTS(); int pts1 = 0; switch(e.getKeyCode()) { case KeyEvent.VK_RIGHT: pts1 = pts0 + 1000; break; diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java index 1a9914bb7..ddf5c709c 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java @@ -150,7 +150,8 @@ public class MovieSimple implements GLEventListener { if(y>winHeight/2) { final float dp = (float)(x-prevMouseX)/(float)winWidth; - mPlayer.seek(mPlayer.getVideoPTS() + (int) (mPlayer.getDuration() * dp)); + final int pts0 = GLMediaPlayer.STREAM_ID_NONE != mPlayer.getVID() ? mPlayer.getVideoPTS() : mPlayer.getAudioPTS(); + mPlayer.seek(pts0 + (int) (mPlayer.getDuration() * dp)); } else { mPlayer.play(); rotate = 1; @@ -174,7 +175,7 @@ public class MovieSimple implements GLEventListener { return; } System.err.println("MC "+e); - int pts0 = mPlayer.getVideoPTS(); + final int pts0 = GLMediaPlayer.STREAM_ID_NONE != mPlayer.getVID() ? mPlayer.getVideoPTS() : mPlayer.getAudioPTS(); int pts1 = 0; switch(e.getKeyCode()) { case KeyEvent.VK_RIGHT: pts1 = pts0 + 1000; break; @@ -372,9 +373,7 @@ public class MovieSimple implements GLEventListener { if( GLMediaPlayer.State.Uninitialized == mPlayer.getState() ) { throw new IllegalStateException("mPlayer in uninitialized state: "+mPlayer); } - if( GLMediaPlayer.STREAM_ID_NONE == mPlayer.getVID() ) { - throw new IllegalStateException("mPlayer has no VID/stream selected: "+mPlayer); - } + final boolean hasVideo = GLMediaPlayer.STREAM_ID_NONE != mPlayer.getVID(); resetGLState = false; zoom0 = orthoProjection ? 0f : -2.5f; @@ -397,10 +396,20 @@ public class MovieSimple implements GLEventListener { } System.out.println("p1 "+mPlayer+", shared "+mPlayerShared); final TextureFrame frame = mPlayer.getLastTexture(); - if( null == frame ) { - throw new InternalError("XXX: "+mPlayer); + if( null != frame ) { + if( !hasVideo ) { + throw new InternalError("XXX: "+mPlayer); + } + tex = frame.getTexture(); + if( null == tex ) { + throw new InternalError("XXX: "+mPlayer); + } + } else { + tex = null; + if( hasVideo ) { + throw new InternalError("XXX: "+mPlayer); + } } - tex = mPlayer.getLastTexture().getTexture(); if(!mPlayerShared) { mPlayer.setTextureMinMagFilter( new int[] { GL.GL_NEAREST, GL.GL_LINEAR } ); } @@ -413,74 +422,76 @@ public class MovieSimple implements GLEventListener { throw new GLException(glex); } - initShader(gl); + if( hasVideo ) { + initShader(gl); - // Push the 1st uniform down the path - st.useProgram(gl, true); + // Push the 1st uniform down the path + st.useProgram(gl, true); - int[] viewPort = new int[] { 0, 0, drawable.getWidth(), drawable.getHeight()}; - pmvMatrix = new PMVMatrix(); - reshapePMV(viewPort[2], viewPort[3]); - pmvMatrixUniform = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()); - if(!st.uniform(gl, pmvMatrixUniform)) { - throw new GLException("Error setting PMVMatrix in shader: "+st); - } - if(!st.uniform(gl, new GLUniformData("mgl_ActiveTexture", mPlayer.getTextureUnit()))) { - throw new GLException("Error setting mgl_ActiveTexture in shader: "+st); - } + int[] viewPort = new int[] { 0, 0, drawable.getWidth(), drawable.getHeight()}; + pmvMatrix = new PMVMatrix(); + reshapePMV(viewPort[2], viewPort[3]); + pmvMatrixUniform = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()); + if(!st.uniform(gl, pmvMatrixUniform)) { + throw new GLException("Error setting PMVMatrix in shader: "+st); + } + if(!st.uniform(gl, new GLUniformData("mgl_ActiveTexture", mPlayer.getTextureUnit()))) { + throw new GLException("Error setting mgl_ActiveTexture in shader: "+st); + } - float dWidth = drawable.getWidth(); - float dHeight = drawable.getHeight(); - float mWidth = mPlayer.getWidth(); - float mHeight = mPlayer.getHeight(); - float mAspect = mWidth/mHeight; - System.err.println("XXX0: mov aspect: "+mAspect); - float xs, ys; - if(orthoProjection) { - if(mPlayerScaleOrig && mWidth < dWidth && mHeight < dHeight) { - xs = mWidth/2f; ys = xs / mAspect; + float dWidth = drawable.getWidth(); + float dHeight = drawable.getHeight(); + float mWidth = mPlayer.getWidth(); + float mHeight = mPlayer.getHeight(); + float mAspect = mWidth/mHeight; + System.err.println("XXX0: mov aspect: "+mAspect); + float xs, ys; + if(orthoProjection) { + if(mPlayerScaleOrig && mWidth < dWidth && mHeight < dHeight) { + xs = mWidth/2f; ys = xs / mAspect; + } else { + xs = dWidth/2f; ys = xs / mAspect; // w>h + } } else { - xs = dWidth/2f; ys = xs / mAspect; // w>h + if(mPlayerScaleOrig && mWidth < dWidth && mHeight < dHeight) { + xs = mAspect * ( mWidth / dWidth ) ; ys = xs / mAspect ; + } else { + xs = mAspect; ys = 1f; // b>h + } } - } else { - if(mPlayerScaleOrig && mWidth < dWidth && mHeight < dHeight) { - xs = mAspect * ( mWidth / dWidth ) ; ys = xs / mAspect ; - } else { - xs = mAspect; ys = 1f; // b>h + verts = new float[] { -1f*xs, -1f*ys, 0f, // LB + 1f*xs, 1f*ys, 0f // RT + }; + { + System.err.println("XXX0: pixel LB: "+verts[0]+", "+verts[1]+", "+verts[2]); + System.err.println("XXX0: pixel RT: "+verts[3]+", "+verts[4]+", "+verts[5]); + float[] winLB = new float[3]; + float[] winRT = new float[3]; + pmvMatrix.gluProject(verts[0], verts[1], verts[2], viewPort, 0, winLB, 0); + pmvMatrix.gluProject(verts[3], verts[4], verts[5], viewPort, 0, winRT, 0); + System.err.println("XXX0: win LB: "+winLB[0]+", "+winLB[1]+", "+winLB[2]); + System.err.println("XXX0: win RT: "+winRT[0]+", "+winRT[1]+", "+winRT[2]); } - } - verts = new float[] { -1f*xs, -1f*ys, 0f, // LB - 1f*xs, 1f*ys, 0f // RT - }; - { - System.err.println("XXX0: pixel LB: "+verts[0]+", "+verts[1]+", "+verts[2]); - System.err.println("XXX0: pixel RT: "+verts[3]+", "+verts[4]+", "+verts[5]); - float[] winLB = new float[3]; - float[] winRT = new float[3]; - pmvMatrix.gluProject(verts[0], verts[1], verts[2], viewPort, 0, winLB, 0); - pmvMatrix.gluProject(verts[3], verts[4], verts[5], viewPort, 0, winRT, 0); - System.err.println("XXX0: win LB: "+winLB[0]+", "+winLB[1]+", "+winLB[2]); - System.err.println("XXX0: win RT: "+winRT[0]+", "+winRT[1]+", "+winRT[2]); - } - interleavedVBO = GLArrayDataServer.createGLSLInterleaved(3+4+2, GL.GL_FLOAT, false, 3*4, GL.GL_STATIC_DRAW); - { - interleavedVBO.addGLSLSubArray("mgl_Vertex", 3, GL.GL_ARRAY_BUFFER); - interleavedVBO.addGLSLSubArray("mgl_Color", 4, GL.GL_ARRAY_BUFFER); - interleavedVBO.addGLSLSubArray("mgl_MultiTexCoord", 2, GL.GL_ARRAY_BUFFER); - } - updateInterleavedVBO(gl, tex); + interleavedVBO = GLArrayDataServer.createGLSLInterleaved(3+4+2, GL.GL_FLOAT, false, 3*4, GL.GL_STATIC_DRAW); + { + interleavedVBO.addGLSLSubArray("mgl_Vertex", 3, GL.GL_ARRAY_BUFFER); + interleavedVBO.addGLSLSubArray("mgl_Color", 4, GL.GL_ARRAY_BUFFER); + interleavedVBO.addGLSLSubArray("mgl_MultiTexCoord", 2, GL.GL_ARRAY_BUFFER); + } + updateInterleavedVBO(gl, tex); - st.ownAttribute(interleavedVBO, true); - gl.glClearColor(0.3f, 0.3f, 0.3f, 0.3f); + st.ownAttribute(interleavedVBO, true); + gl.glClearColor(0.3f, 0.3f, 0.3f, 0.3f); - gl.glEnable(GL2ES2.GL_DEPTH_TEST); + gl.glEnable(GL2ES2.GL_DEPTH_TEST); - st.useProgram(gl, false); + st.useProgram(gl, false); - // Let's show the completed shader state .. - System.out.println("iVBO: "+interleavedVBO); - System.out.println(st); + // Let's show the completed shader state .. + System.out.println("iVBO: "+interleavedVBO); + System.out.println(st); + } if(!mPlayerShared) { mPlayer.play(); @@ -697,6 +708,7 @@ public class MovieSimple implements GLEventListener { int textureCount = 3; // default - threaded boolean ortho = true; boolean zoom = false; + boolean _loopEOS = false; boolean forceES2 = false; boolean forceES3 = false; @@ -742,6 +754,8 @@ public class MovieSimple implements GLEventListener { ortho=false; } else if(args[i].equals("-zoom")) { zoom=true; + } else if(args[i].equals("-loop")) { + _loopEOS=true; } else if(args[i].equals("-url")) { i++; url_s = args[i]; @@ -757,6 +771,7 @@ public class MovieSimple implements GLEventListener { } origSize = _origSize; } + final boolean loopEOS = _loopEOS; final URI streamLoc; if( null != url_s ) { streamLoc = new URI(url_s); @@ -827,6 +842,7 @@ public class MovieSimple implements GLEventListener { System.err.println("MovieSimple AttributesChanges: events_mask 0x"+Integer.toHexString(event_mask)+", when "+when); System.err.println("MovieSimple State: "+mp); if( 0 != ( GLMediaEventListener.EVENT_CHANGE_SIZE & event_mask ) ) { + System.err.println("MovieSimple State: CHANGE_SIZE"); if( origSize ) { window.setSize(mp.getWidth(), mp.getHeight()); } @@ -834,11 +850,14 @@ public class MovieSimple implements GLEventListener { ms.resetGLState(); } if( 0 != ( GLMediaEventListener.EVENT_CHANGE_INIT & event_mask ) ) { - if( GLMediaPlayer.STREAM_ID_NONE != ms.mPlayer.getVID() ) { - window.addGLEventListener(ms); - anim.setUpdateFPSFrames(60, System.err); - anim.resetFPSCounter(); - } else { + System.err.println("MovieSimple State: INIT"); + // Use GLEventListener in all cases [A+V, V, A] + window.addGLEventListener(ms); + anim.setUpdateFPSFrames(60, System.err); + anim.resetFPSCounter(); + /** + * Kick off player w/o GLEventListener, i.e. for audio only. + * try { ms.mPlayer.initGL(null); } catch (Exception e) { @@ -848,12 +867,38 @@ public class MovieSimple implements GLEventListener { } ms.mPlayer.play(); System.out.println("play.1 "+ms.mPlayer); + */ + } + boolean destroy = false; + Throwable err = null; + + if( 0 != ( GLMediaEventListener.EVENT_CHANGE_EOS & event_mask ) ) { + err = ms.mPlayer.getStreamException(); + if( null != err ) { + System.err.println("MovieSimple State: EOS + Exception"); + destroy = true; + } else { + System.err.println("MovieSimple State: EOS"); + if( loopEOS ) { + ms.mPlayer.seek(0); + ms.mPlayer.play(); + } else { + destroy = true; + } + } + } + if( 0 != ( GLMediaEventListener.EVENT_CHANGE_ERR & event_mask ) ) { + err = ms.mPlayer.getStreamException(); + if( null != err ) { + System.err.println("MovieSimple State: ERR + Exception"); + } else { + System.err.println("MovieSimple State: ERR"); } + destroy = true; } - if( 0 != ( ( GLMediaEventListener.EVENT_CHANGE_ERR | GLMediaEventListener.EVENT_CHANGE_EOS ) & event_mask ) ) { - final StreamException se = ms.mPlayer.getStreamException(); - if( null != se ) { - se.printStackTrace(); + if( destroy ) { + if( null != err ) { + err.printStackTrace(); } destroyWindow(); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java index 3a9cf8f98..46e39bebf 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,12 +20,12 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ - + package com.jogamp.opengl.test.junit.jogl.demos.es2.awt; import java.awt.AWTException; @@ -63,12 +63,14 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { static Dimension wsize, rwsize=null; static boolean forceES2 = false; static boolean forceGL3 = false; + static boolean forceGLFFP = false; static boolean shallUsePBuffer = false; static boolean shallUseBitmap = false; static boolean useMSAA = false; static int swapInterval = 0; static boolean useAnimator = true; static boolean manualTest = false; + static boolean skipGLOrientationVerticalFlip = false; @BeforeClass public static void initClass() { @@ -93,9 +95,9 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { } catch( Throwable throwable ) { throwable.printStackTrace(); Assume.assumeNoException( throwable ); - } + } } - + protected void runTestGL(GLCapabilities caps) throws AWTException, InterruptedException, InvocationTargetException { @@ -104,13 +106,18 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { final GLJPanel glJPanel = new GLJPanel(caps); Assert.assertNotNull(glJPanel); + glJPanel.setSkipGLOrientationVerticalFlip(skipGLOrientationVerticalFlip); glJPanel.setMinimumSize(wsize); glJPanel.setPreferredSize(wsize); glJPanel.setSize(wsize); - if( caps.isBitmap() ) { - glJPanel.addGLEventListener(new Gears(swapInterval)); + if( caps.isBitmap() || caps.getGLProfile().isGL2() ) { + final Gears gears = new Gears(swapInterval); + gears.setFlipVerticalInGLOrientation(skipGLOrientationVerticalFlip); + glJPanel.addGLEventListener(gears); } else { - glJPanel.addGLEventListener(new GearsES2(swapInterval)); + final GearsES2 gears = new GearsES2(swapInterval); + gears.setFlipVerticalInGLOrientation(skipGLOrientationVerticalFlip); + glJPanel.addGLEventListener(gears); } final SnapshotGLEventListener snap = new SnapshotGLEventListener(); glJPanel.addGLEventListener(snap); @@ -135,17 +142,17 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { new AWTKeyAdapter(new TraceKeyAdapter(quitAdapter)).addTo(glJPanel); new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter)).addTo(frame); - + snap.setMakeSnapshot(); - + if( null != rwsize ) { - Thread.sleep(500); // 500ms delay + Thread.sleep(500); // 500ms delay setFrameSize(frame, true, rwsize); System.err.println("window resize pos/siz: "+glJPanel.getX()+"/"+glJPanel.getY()+" "+glJPanel.getWidth()+"x"+glJPanel.getHeight()); } - + snap.setMakeSnapshot(); - + final long t0 = System.currentTimeMillis(); long t1 = t0; boolean triggerSnap = false; @@ -187,6 +194,8 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { glp = GLProfile.get(GLProfile.GL3); } else if(forceES2) { glp = GLProfile.get(GLProfile.GLES2); + } else if(forceGLFFP) { + glp = GLProfile.getMaxFixedFunc(true); } else { glp = GLProfile.getGL2ES2(); } @@ -216,7 +225,7 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { caps.setSampleBuffers(true); runTestGL(caps); } - + @Test public void test03_PbufferNorm() throws AWTException, InterruptedException, InvocationTargetException @@ -228,7 +237,7 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { caps.setPBuffer(true); runTestGL(caps); } - + @Test public void test04_PbufferMsaa() throws AWTException, InterruptedException, InvocationTargetException @@ -242,7 +251,7 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { caps.setPBuffer(true); runTestGL(caps); } - + @Test public void test05_BitmapNorm() throws AWTException, InterruptedException, InvocationTargetException @@ -254,7 +263,7 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { caps.setBitmap(true); runTestGL(caps); } - + @Test public void test06_BitmapMsaa() throws AWTException, InterruptedException, InvocationTargetException @@ -268,7 +277,7 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { caps.setBitmap(true); runTestGL(caps); } - + @Test public void test20_GLES2() throws AWTException, InterruptedException, InvocationTargetException @@ -276,7 +285,7 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { if( manualTest ) { return; } - + if( !GLProfile.isAvailable(GLProfile.GLES2) ) { System.err.println("GLES2 n/a"); return; @@ -285,7 +294,7 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { final GLCapabilities caps = new GLCapabilities( glp ); runTestGL(caps); } - + @Test public void test30_GL3() throws AWTException, InterruptedException, InvocationTargetException @@ -293,7 +302,7 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { if( manualTest ) { return; } - + if( !GLProfile.isAvailable(GLProfile.GL3) ) { System.err.println("GL3 n/a"); return; @@ -302,12 +311,12 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { final GLCapabilities caps = new GLCapabilities( glp ); runTestGL(caps); } - + static long duration = 500; // ms public static void main(String args[]) { int w=640, h=480, rw=-1, rh=-1; - + for(int i=0; i<args.length; i++) { if(args[i].equals("-time")) { i++; @@ -316,6 +325,8 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { forceES2 = true; } else if(args[i].equals("-gl3")) { forceGL3 = true; + } else if(args[i].equals("-glFFP")) { + forceGLFFP = true; } else if(args[i].equals("-width")) { i++; w = MiscUtils.atoi(args[i], w); @@ -328,6 +339,8 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { } else if(args[i].equals("-rheight")) { i++; rh = MiscUtils.atoi(args[i], rh); + } else if(args[i].equals("-userVFlip")) { + skipGLOrientationVerticalFlip = true; } else if(args[i].equals("-vsync")) { i++; swapInterval = MiscUtils.atoi(args[i], swapInterval); @@ -347,18 +360,20 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { if( 0 < rw && 0 < rh ) { rwsize = new Dimension(rw, rh); } - + System.err.println("size "+wsize); System.err.println("resize "+rwsize); + System.err.println("userVFlip "+skipGLOrientationVerticalFlip); System.err.println("swapInterval "+swapInterval); System.err.println("forceES2 "+forceES2); System.err.println("forceGL3 "+forceGL3); + System.err.println("forceGLFFP "+forceGLFFP); System.err.println("useMSAA "+useMSAA); System.err.println("useAnimator "+useAnimator); System.err.println("shallUsePBuffer "+shallUsePBuffer); System.err.println("shallUseBitmap "+shallUseBitmap); System.err.println("manualTest "+manualTest); - + org.junit.runner.JUnitCore.main(TestGearsES2GLJPanelAWT.class.getName()); } } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Gears.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Gears.java index 031d6a1c1..0d71c7ad0 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Gears.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Gears.java @@ -27,17 +27,19 @@ import com.jogamp.opengl.util.TileRendererBase; * This version is equal to Brian Paul's version 1.2 1999/10/21 */ public class Gears implements GLEventListener, TileRendererBase.TileRendererListener { - private float view_rotx = 20.0f, view_roty = 30.0f, view_rotz = 0.0f; + private float view_rotx = 20.0f, view_roty = 30.0f; + private final float view_rotz = 0.0f; private int gear1=0, gear2=0, gear3=0; private float angle = 0.0f; private boolean doRotate = true; - private int swapInterval; - private MouseListener gearsMouse = new GearsMouseAdapter(); - private KeyListener gearsKeys = new GearsKeyAdapter(); + private final int swapInterval; + private final MouseListener gearsMouse = new GearsMouseAdapter(); + private final KeyListener gearsKeys = new GearsKeyAdapter(); private TileRendererBase tileRendererInUse = null; private boolean doRotateBeforePrinting; private boolean verbose = true; - + private boolean flipVerticalInGLOrientation = false; + // private boolean mouseRButtonDown = false; private int prevMouseX, prevMouseY; @@ -48,17 +50,17 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList public Gears() { this.swapInterval = 1; } - + @Override public void addTileRendererNotify(TileRendererBase tr) { tileRendererInUse = tr; doRotateBeforePrinting = doRotate; - setDoRotation(false); + setDoRotation(false); } @Override public void removeTileRendererNotify(TileRendererBase tr) { tileRendererInUse = null; - setDoRotation(doRotateBeforePrinting); + setDoRotation(doRotateBeforePrinting); } @Override public void startTileRendering(TileRendererBase tr) { @@ -68,10 +70,11 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList public void endTileRendering(TileRendererBase tr) { System.err.println("Gears.endTileRendering: "+tr); } - + public void setDoRotation(boolean rotate) { doRotate = rotate; } public void setVerbose(boolean v) { verbose = v; } - + public void setFlipVerticalInGLOrientation(boolean v) { flipVerticalInGLOrientation=v; } + public void setGears(int g1, int g2, int g3) { gear1 = g1; gear2 = g2; @@ -98,24 +101,24 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList GL2 gl = drawable.getGL().getGL2(); init(gl); - + final Object upstreamWidget = drawable.getUpstreamWidget(); - if (upstreamWidget instanceof Window) { + if (upstreamWidget instanceof Window) { final Window window = (Window) upstreamWidget; window.addMouseListener(gearsMouse); window.addKeyListener(gearsKeys); } else if (GLProfile.isAWTAvailable() && upstreamWidget instanceof java.awt.Component) { final java.awt.Component comp = (java.awt.Component) upstreamWidget; new AWTMouseAdapter(gearsMouse).addTo(comp); - new AWTKeyAdapter(gearsKeys).addTo(comp); + new AWTKeyAdapter(gearsKeys).addTo(comp); } } - + public void init(GL2 gl) { - float pos[] = { 5.0f, 5.0f, 10.0f, 0.0f }; - float red[] = { 0.8f, 0.1f, 0.0f, 0.7f }; - float green[] = { 0.0f, 0.8f, 0.2f, 0.7f }; - float blue[] = { 0.2f, 0.2f, 1.0f, 0.7f }; + final float lightPos[] = { 5.0f, 5.0f, 10.0f, 0.0f }; + final float red[] = { 0.8f, 0.1f, 0.0f, 0.7f }; + final float green[] = { 0.0f, 0.8f, 0.2f, 0.7f }; + final float blue[] = { 0.2f, 0.2f, 1.0f, 0.7f }; System.err.println(Thread.currentThread()+" Gears.init: tileRendererInUse "+tileRendererInUse); if(verbose) { @@ -124,13 +127,16 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList System.err.println("INIT GL IS: " + gl.getClass().getName()); System.err.println(JoglVersion.getGLStrings(gl, null, false).toString()); } - - gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, pos, 0); - gl.glEnable(GL2.GL_CULL_FACE); + + gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, lightPos, 0); + if( ! ( flipVerticalInGLOrientation && gl.getContext().getGLDrawable().isGLOriented() ) ) { + // Only possible if we do not flip the projection matrix + gl.glEnable(GL2.GL_CULL_FACE); + } gl.glEnable(GL2.GL_LIGHTING); gl.glEnable(GL2.GL_LIGHT0); gl.glEnable(GL2.GL_DEPTH_TEST); - + /* make the gears */ if(0>=gear1) { gear1 = gl.glGenLists(1); @@ -142,7 +148,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList } else { System.err.println("gear1 list reused: "+gear1); } - + if(0>=gear2) { gear2 = gl.glGenLists(1); gl.glNewList(gear2, GL2.GL_COMPILE); @@ -153,7 +159,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList } else { System.err.println("gear2 list reused: "+gear2); } - + if(0>=gear3) { gear3 = gl.glGenLists(1); gl.glNewList(gear3, GL2.GL_COMPILE); @@ -164,14 +170,14 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList } else { System.err.println("gear3 list reused: "+gear3); } - + gl.glEnable(GL2.GL_NORMALIZE); } - + @Override public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) { final GL2 gl = glad.getGL().getGL2(); - if(-1 != swapInterval) { + if(-1 != swapInterval) { gl.setSwapInterval(swapInterval); } reshape(gl, x, y, width, height, width, height); @@ -179,7 +185,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList @Override public void reshapeTile(TileRendererBase tr, - int tileX, int tileY, int tileWidth, int tileHeight, + int tileX, int tileY, int tileWidth, int tileHeight, int imageWidth, int imageHeight) { final GL2 gl = tr.getAttachedDrawable().getGL().getGL2(); gl.setSwapInterval(0); @@ -193,13 +199,9 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList if( msaa ) { gl.glEnable(GL.GL_MULTISAMPLE); } - - gl.glMatrixMode(GL2.GL_PROJECTION); - gl.glLoadIdentity(); - // compute projection parameters 'normal' - float left, right, bottom, top; + float left, right, bottom, top; if( imageHeight > imageWidth ) { float a = (float)imageHeight / (float)imageWidth; left = -1.0f; @@ -215,24 +217,31 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList } final float w = right - left; final float h = top - bottom; - + // compute projection parameters 'tiled' final float l = left + tileX * w / imageWidth; final float r = l + tileWidth * w / imageWidth; + final float b = bottom + tileY * h / imageHeight; final float t = b + tileHeight * h / imageHeight; final float _w = r - l; final float _h = t - b; if(verbose) { - System.err.println(">> angle "+angle+", [l "+left+", r "+right+", b "+bottom+", t "+top+"] "+w+"x"+h+" -> [l "+l+", r "+r+", b "+b+", t "+t+"] "+_w+"x"+_h); + System.err.println(">> Gears angle "+angle+", [l "+left+", r "+right+", b "+bottom+", t "+top+"] "+w+"x"+h+" -> [l "+l+", r "+r+", b "+b+", t "+t+"] "+_w+"x"+_h+", v-flip "+flipVerticalInGLOrientation); + } + + gl.glMatrixMode(GL2.GL_PROJECTION); + gl.glLoadIdentity(); + if( flipVerticalInGLOrientation && gl.getContext().getGLDrawable().isGLOriented() ) { + gl.glScalef(1f, -1f, 1f); } gl.glFrustum(l, r, b, t, 5.0f, 60.0f); - gl.glMatrixMode(GL2.GL_MODELVIEW); + gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); gl.glTranslatef(0.0f, 0.0f, -40.0f); - + if( msaa ) { gl.glDisable(GL.GL_MULTISAMPLE); } @@ -243,7 +252,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList System.err.println(Thread.currentThread()+" Gears.dispose: tileRendererInUse "+tileRendererInUse); try { final Object upstreamWidget = drawable.getUpstreamWidget(); - if (upstreamWidget instanceof Window) { + if (upstreamWidget instanceof Window) { final Window window = (Window) upstreamWidget; window.removeMouseListener(gearsMouse); window.removeKeyListener(gearsKeys); @@ -261,7 +270,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList if( msaa ) { gl.glEnable(GL.GL_MULTISAMPLE); } - + if( null == tileRendererInUse ) { gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); } else { @@ -270,7 +279,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList // Special handling for the case where the GLJPanel is translucent // and wants to be composited with other Java 2D content - if (GLProfile.isAWTAvailable() && + if (GLProfile.isAWTAvailable() && (drawable instanceof javax.media.opengl.awt.GLJPanel) && !((javax.media.opengl.awt.GLJPanel) drawable).isOpaque() && ((javax.media.opengl.awt.GLJPanel) drawable).shouldPreserveColorBufferIfTranslucent()) { @@ -310,31 +319,31 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList gl.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f); gl.glRotatef(view_roty, 0.0f, 1.0f, 0.0f); gl.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f); - + // Place the first gear and call its display list gl.glPushMatrix(); gl.glTranslatef(-3.0f, -2.0f, 0.0f); gl.glRotatef(angle, 0.0f, 0.0f, 1.0f); gl.glCallList(gear1); gl.glPopMatrix(); - + // Place the second gear and call its display list gl.glPushMatrix(); gl.glTranslatef(3.1f, -2.0f, 0.0f); gl.glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f); gl.glCallList(gear2); gl.glPopMatrix(); - + // Place the third gear and call its display list gl.glPushMatrix(); gl.glTranslatef(-3.1f, 4.2f, 0.0f); gl.glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f); gl.glCallList(gear3); gl.glPopMatrix(); - + // Remember that every push needs a pop; this one is paired with // rotating the entire gear assembly - gl.glPopMatrix(); + gl.glPopMatrix(); } public static void gear(GL2 gl, @@ -352,9 +361,9 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList r0 = inner_radius; r1 = outer_radius - tooth_depth / 2.0f; r2 = outer_radius + tooth_depth / 2.0f; - + da = 2.0f * (float) Math.PI / teeth / 4.0f; - + gl.glShadeModel(GL2.GL_FLAT); gl.glNormal3f(0.0f, 0.0f, 1.0f); @@ -385,7 +394,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList gl.glVertex3f(r1 * (float)Math.cos(angle + 3.0f * da), r1 * (float)Math.sin(angle + 3.0f * da), width * 0.5f); } gl.glEnd(); - + /* draw back face */ gl.glBegin(GL2.GL_QUAD_STRIP); for (i = 0; i <= teeth; i++) @@ -397,7 +406,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f); } gl.glEnd(); - + /* draw back sides of teeth */ gl.glBegin(GL2.GL_QUADS); for (i = 0; i < teeth; i++) @@ -409,7 +418,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f); } gl.glEnd(); - + /* draw outward faces of teeth */ gl.glBegin(GL2.GL_QUAD_STRIP); for (i = 0; i < teeth; i++) @@ -438,9 +447,9 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList gl.glVertex3f(r1 * (float)Math.cos(0), r1 * (float)Math.sin(0), width * 0.5f); gl.glVertex3f(r1 * (float)Math.cos(0), r1 * (float)Math.sin(0), -width * 0.5f); gl.glEnd(); - + gl.glShadeModel(GL2.GL_SMOOTH); - + /* draw inside radius cylinder */ gl.glBegin(GL2.GL_QUAD_STRIP); for (i = 0; i <= teeth; i++) @@ -453,7 +462,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList gl.glEnd(); } - class GearsKeyAdapter extends KeyAdapter { + class GearsKeyAdapter extends KeyAdapter { public void keyPressed(KeyEvent e) { int kc = e.getKeyCode(); if(KeyEvent.VK_LEFT == kc) { @@ -467,7 +476,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList } } } - + class GearsMouseAdapter extends MouseAdapter { public void mousePressed(MouseEvent e) { prevMouseX = e.getX(); @@ -476,13 +485,13 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList // mouseRButtonDown = true; } } - + public void mouseReleased(MouseEvent e) { if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0) { // mouseRButtonDown = false; } } - + public void mouseDragged(MouseEvent e) { int x = e.getX(); int y = e.getY(); @@ -501,7 +510,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList } float thetaY = 360.0f * ( (float)(x-prevMouseX)/(float)width); float thetaX = 360.0f * ( (float)(prevMouseY-y)/(float)height); - + prevMouseX = x; prevMouseY = y; diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT.java index e0d0e00dc..3dd3a83c8 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT.java @@ -100,11 +100,12 @@ public class TestTiledPrintingGearsSwingAWT extends TiledPrintingAWTBase { public static void releaseClass() { } - protected void runTestGL(GLCapabilities caps, boolean layered) throws InterruptedException, InvocationTargetException { + protected void runTestGL(GLCapabilities caps, boolean layered, boolean skipGLOrientationVerticalFlip) throws InterruptedException, InvocationTargetException { final int layerStepX = width/6, layerStepY = height/6; final Dimension glc_sz = new Dimension(layered ? width - 2*layerStepX : width/2, layered ? height - 2*layerStepY : height); final GLJPanel glJPanel1 = new GLJPanel(caps); Assert.assertNotNull(glJPanel1); + glJPanel1.setSkipGLOrientationVerticalFlip(skipGLOrientationVerticalFlip); glJPanel1.setMinimumSize(glc_sz); glJPanel1.setPreferredSize(glc_sz); if( layered ) { @@ -112,10 +113,15 @@ public class TestTiledPrintingGearsSwingAWT extends TiledPrintingAWTBase { } else { glJPanel1.setBounds(0, 0, glc_sz.width, glc_sz.height); } - glJPanel1.addGLEventListener(new Gears()); + { + final Gears demo = new Gears(); + demo.setFlipVerticalInGLOrientation(skipGLOrientationVerticalFlip); + glJPanel1.addGLEventListener(demo); + } final GLJPanel glJPanel2 = new GLJPanel(caps); Assert.assertNotNull(glJPanel2); + glJPanel2.setSkipGLOrientationVerticalFlip(skipGLOrientationVerticalFlip); glJPanel2.setMinimumSize(glc_sz); glJPanel2.setPreferredSize(glc_sz); if( layered ) { @@ -123,8 +129,11 @@ public class TestTiledPrintingGearsSwingAWT extends TiledPrintingAWTBase { } else { glJPanel2.setBounds(0, 0, glc_sz.width, glc_sz.height); } - glJPanel2.addGLEventListener(new RedSquareES1()); - // glJPanel2.addGLEventListener(new Gears()); + { + final RedSquareES1 demo = new RedSquareES1(); + demo.setFlipVerticalInGLOrientation(skipGLOrientationVerticalFlip); + glJPanel2.addGLEventListener(demo); + } final JComponent demoPanel; if( layered ) { @@ -293,43 +302,83 @@ public class TestTiledPrintingGearsSwingAWT extends TiledPrintingAWTBase { } @Test - public void test01_aa0() throws InterruptedException, InvocationTargetException { + public void test01_flip1_aa0() throws InterruptedException, InvocationTargetException { + GLCapabilities caps = new GLCapabilities(glp); + runTestGL(caps, false, false); + } + + @Test + public void test01_flip1_aa0_layered() throws InterruptedException, InvocationTargetException { + GLCapabilities caps = new GLCapabilities(glp); + caps.setAlphaBits(8); + runTestGL(caps, true, false); + } + + @Test + public void test01_flip1_aa0_bitmap() throws InterruptedException, InvocationTargetException { + if( Platform.OSType.WINDOWS == Platform.getOSType() ) { + GLCapabilities caps = new GLCapabilities(glp); + caps.setBitmap(true); + runTestGL(caps, false, false); + } // issues w/ AMD catalyst driver and pixmap surface .. + } + + @Test + public void test01_flip1_aa0_bitmap_layered() throws InterruptedException, InvocationTargetException { + if( Platform.OSType.WINDOWS == Platform.getOSType() ) { + GLCapabilities caps = new GLCapabilities(glp); + caps.setBitmap(true); + caps.setAlphaBits(8); + runTestGL(caps, true, false); + } // issues w/ AMD catalyst driver and pixmap surface .. + } + + @Test + public void test02_flip1_aa8() throws InterruptedException, InvocationTargetException { + GLCapabilities caps = new GLCapabilities(glp); + caps.setSampleBuffers(true); + caps.setNumSamples(8); + runTestGL(caps, false, false); + } + + @Test + public void test11_flip0_aa0() throws InterruptedException, InvocationTargetException { GLCapabilities caps = new GLCapabilities(glp); - runTestGL(caps, false); + runTestGL(caps, false, true); } @Test - public void test01_aa0_layered() throws InterruptedException, InvocationTargetException { + public void test11_flip0_aa0_layered() throws InterruptedException, InvocationTargetException { GLCapabilities caps = new GLCapabilities(glp); caps.setAlphaBits(8); - runTestGL(caps, true); + runTestGL(caps, true, true); } @Test - public void test01_aa0_bitmap() throws InterruptedException, InvocationTargetException { + public void test11_flip0_aa0_bitmap() throws InterruptedException, InvocationTargetException { if( Platform.OSType.WINDOWS == Platform.getOSType() ) { GLCapabilities caps = new GLCapabilities(glp); caps.setBitmap(true); - runTestGL(caps, false); + runTestGL(caps, false, true); } // issues w/ AMD catalyst driver and pixmap surface .. } @Test - public void test01_aa0_bitmap_layered() throws InterruptedException, InvocationTargetException { + public void test11_flip0_aa0_bitmap_layered() throws InterruptedException, InvocationTargetException { if( Platform.OSType.WINDOWS == Platform.getOSType() ) { GLCapabilities caps = new GLCapabilities(glp); caps.setBitmap(true); caps.setAlphaBits(8); - runTestGL(caps, true); + runTestGL(caps, true, true); } // issues w/ AMD catalyst driver and pixmap surface .. } @Test - public void test02_aa8() throws InterruptedException, InvocationTargetException { + public void test12_flip0_aa8() throws InterruptedException, InvocationTargetException { GLCapabilities caps = new GLCapabilities(glp); caps.setSampleBuffers(true); caps.setNumSamples(8); - runTestGL(caps, false); + runTestGL(caps, false, true); } static long duration = 500; // ms diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT2.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT2.java index 2d4973d6b..29bf8a6c3 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT2.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT2.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,12 +20,12 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ - + package com.jogamp.opengl.test.junit.jogl.tile; import java.awt.BorderLayout; @@ -77,7 +77,7 @@ public class TestTiledPrintingGearsSwingAWT2 extends TiledPrintingAWTBase { static boolean waitForKey = false; static GLProfile glp; static int width, height; - + @BeforeClass public static void initClass() { if(GLProfile.isAvailable(GLProfile.GL2)) { @@ -95,16 +95,21 @@ public class TestTiledPrintingGearsSwingAWT2 extends TiledPrintingAWTBase { @AfterClass public static void releaseClass() { } - - protected void runTestGL(GLCapabilities caps, final boolean addLayout, boolean layered, boolean useAnim) throws InterruptedException, InvocationTargetException { + + protected void runTestGL(GLCapabilities caps, final boolean addLayout, boolean layered, boolean skipGLOrientationVerticalFlip, boolean useAnim) throws InterruptedException, InvocationTargetException { final Dimension glc_sz = new Dimension(width, height); final GLJPanel glJPanel1 = new GLJPanel(caps); - Assert.assertNotNull(glJPanel1); + Assert.assertNotNull(glJPanel1); + glJPanel1.setSkipGLOrientationVerticalFlip(skipGLOrientationVerticalFlip); glJPanel1.setMinimumSize(glc_sz); glJPanel1.setPreferredSize(glc_sz); glJPanel1.setBounds(0, 0, glc_sz.width, glc_sz.height); - glJPanel1.addGLEventListener(new Gears()); - + { + final Gears demo = new Gears(); + demo.setFlipVerticalInGLOrientation(skipGLOrientationVerticalFlip); + glJPanel1.addGLEventListener(demo); + } + final JComponent tPanel, demoPanel; if( layered ) { glJPanel1.setOpaque(true); @@ -133,13 +138,13 @@ public class TestTiledPrintingGearsSwingAWT2 extends TiledPrintingAWTBase { demoPanel = new JPanel(); demoPanel.add(glJPanel1); } else { - demoPanel = glJPanel1; + demoPanel = glJPanel1; } } - + final JFrame frame = new JFrame("Swing Print"); Assert.assertNotNull(frame); - + final ActionListener print72DPIAction = new ActionListener() { public void actionPerformed(ActionEvent e) { doPrintManual(frame, 72, 0, -1, -1); @@ -158,7 +163,7 @@ public class TestTiledPrintingGearsSwingAWT2 extends TiledPrintingAWTBase { print150DPIButton.addActionListener(print150DPIAction); final Button print300DPIButton = new Button("300dpi"); print300DPIButton.addActionListener(print300DPIAction); - + final JPanel printPanel = new JPanel(); printPanel.add(print72DPIButton); printPanel.add(print150DPIButton); @@ -169,7 +174,7 @@ public class TestTiledPrintingGearsSwingAWT2 extends TiledPrintingAWTBase { eastPanel.add(new Label("East")); final JPanel westPanel = new JPanel(); westPanel.add(new Label("West")); - + final Animator animator = useAnim ? new Animator() : null; if( null != animator ) { animator.add(glJPanel1); @@ -181,7 +186,7 @@ public class TestTiledPrintingGearsSwingAWT2 extends TiledPrintingAWTBase { SwingUtilities.invokeAndWait(new Runnable() { public void run() { - final Container fcont = frame.getContentPane(); + final Container fcont = frame.getContentPane(); if( addLayout ) { fcont.setLayout(new BorderLayout()); fcont.add(printPanel, BorderLayout.NORTH); @@ -201,12 +206,12 @@ public class TestTiledPrintingGearsSwingAWT2 extends TiledPrintingAWTBase { } frame.setVisible(true); } } ) ; - + Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true)); Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glJPanel1, true)); - + if( null != animator ) { - animator.setUpdateFPSFrames(60, System.err); + animator.setUpdateFPSFrames(60, System.err); animator.start(); Assert.assertEquals(true, animator.isAnimating()); } @@ -226,11 +231,11 @@ public class TestTiledPrintingGearsSwingAWT2 extends TiledPrintingAWTBase { } t1 = System.currentTimeMillis(); } - + Assert.assertNotNull(frame); Assert.assertNotNull(glJPanel1); - if( null != animator ) { + if( null != animator ) { animator.stop(); Assert.assertEquals(false, animator.isAnimating()); } @@ -248,69 +253,133 @@ public class TestTiledPrintingGearsSwingAWT2 extends TiledPrintingAWTBase { } @Test - public void test01_norm_layout0_layered0() throws InterruptedException, InvocationTargetException { + public void test001_flip1_norm_layout0_layered0() throws InterruptedException, InvocationTargetException { GLCapabilities caps = new GLCapabilities(glp); - runTestGL(caps, false /* addLayout */, false /* layered */, false /* useAnim */); + runTestGL(caps, false /* addLayout */, false /* layered */, false /* skipGLOrientationVerticalFlip */, false /* useAnim */); } - + @Test - public void test02_norm_layout1_layered0() throws InterruptedException, InvocationTargetException { + public void test002_flip1_norm_layout1_layered0() throws InterruptedException, InvocationTargetException { GLCapabilities caps = new GLCapabilities(glp); - runTestGL(caps, true /* addLayout */, false /* layered */, false /* useAnim */); + runTestGL(caps, true /* addLayout */, false /* layered */, false /* skipGLOrientationVerticalFlip */, false /* useAnim */); } - + @Test - public void test03_norm_layout0_layered1() throws InterruptedException, InvocationTargetException { + public void test003_flip1_norm_layout0_layered1() throws InterruptedException, InvocationTargetException { GLCapabilities caps = new GLCapabilities(glp); - runTestGL(caps, false /* addLayout */, true /* layered */, false /* useAnim */); + runTestGL(caps, false /* addLayout */, true /* layered */, false /* skipGLOrientationVerticalFlip */, false /* useAnim */); } - + @Test - public void test04_norm_layout1_layered1() throws InterruptedException, InvocationTargetException { + public void test004_flip1_norm_layout1_layered1() throws InterruptedException, InvocationTargetException { GLCapabilities caps = new GLCapabilities(glp); - runTestGL(caps, true /* addLayout */, true /* layered */, false /* useAnim */); + runTestGL(caps, true /* addLayout */, true /* layered */, false /* skipGLOrientationVerticalFlip */, false /* useAnim */); } - + @Test - public void test11_bitm_layout0_layered0() throws InterruptedException, InvocationTargetException { + public void test011_flip1_bitm_layout0_layered0() throws InterruptedException, InvocationTargetException { if( Platform.OSType.WINDOWS != Platform.getOSType() ) { return; } GLCapabilities caps = new GLCapabilities(glp); caps.setBitmap(true); - runTestGL(caps, false /* addLayout */, false /* layered */, false /* useAnim */); + runTestGL(caps, false /* addLayout */, false /* layered */, false /* skipGLOrientationVerticalFlip */, false /* useAnim */); } - + @Test - public void test12_bitm_layout1_layered0() throws InterruptedException, InvocationTargetException { + public void test012_flip1_bitm_layout1_layered0() throws InterruptedException, InvocationTargetException { if( Platform.OSType.WINDOWS != Platform.getOSType() ) { return; } GLCapabilities caps = new GLCapabilities(glp); caps.setBitmap(true); - runTestGL(caps, true /* addLayout */, false /* layered */, false /* useAnim */); + runTestGL(caps, true /* addLayout */, false /* layered */, false /* skipGLOrientationVerticalFlip */, false /* useAnim */); } - + @Test - public void test13_bitm_layout0_layered1() throws InterruptedException, InvocationTargetException { + public void test013_flip1_bitm_layout0_layered1() throws InterruptedException, InvocationTargetException { if( Platform.OSType.WINDOWS != Platform.getOSType() ) { return; } GLCapabilities caps = new GLCapabilities(glp); caps.setBitmap(true); - runTestGL(caps, false /* addLayout */, true /* layered */, false /* useAnim */); + runTestGL(caps, false /* addLayout */, true /* layered */, false /* skipGLOrientationVerticalFlip */, false /* useAnim */); } - + @Test - public void test14_bitm_layout1_layered1() throws InterruptedException, InvocationTargetException { + public void test014_flip1_bitm_layout1_layered1() throws InterruptedException, InvocationTargetException { if( Platform.OSType.WINDOWS != Platform.getOSType() ) { return; } GLCapabilities caps = new GLCapabilities(glp); caps.setBitmap(true); - runTestGL(caps, true /* addLayout */, true /* layered */, false /* useAnim */); + runTestGL(caps, true /* addLayout */, true /* layered */, false /* skipGLOrientationVerticalFlip */, false /* useAnim */); + } + + @Test + public void test101_flip1_norm_layout0_layered0() throws InterruptedException, InvocationTargetException { + GLCapabilities caps = new GLCapabilities(glp); + runTestGL(caps, false /* addLayout */, false /* layered */, true /* skipGLOrientationVerticalFlip */, false /* useAnim */); + } + + @Test + public void test102_flip1_norm_layout1_layered0() throws InterruptedException, InvocationTargetException { + GLCapabilities caps = new GLCapabilities(glp); + runTestGL(caps, true /* addLayout */, false /* layered */, true /* skipGLOrientationVerticalFlip */, false /* useAnim */); + } + + @Test + public void test103_flip1_norm_layout0_layered1() throws InterruptedException, InvocationTargetException { + GLCapabilities caps = new GLCapabilities(glp); + runTestGL(caps, false /* addLayout */, true /* layered */, true /* skipGLOrientationVerticalFlip */, false /* useAnim */); } - + + @Test + public void test104_flip1_norm_layout1_layered1() throws InterruptedException, InvocationTargetException { + GLCapabilities caps = new GLCapabilities(glp); + runTestGL(caps, true /* addLayout */, true /* layered */, true /* skipGLOrientationVerticalFlip */, false /* useAnim */); + } + + @Test + public void test111_flip1_bitm_layout0_layered0() throws InterruptedException, InvocationTargetException { + if( Platform.OSType.WINDOWS != Platform.getOSType() ) { + return; + } + GLCapabilities caps = new GLCapabilities(glp); + caps.setBitmap(true); + runTestGL(caps, false /* addLayout */, false /* layered */, true /* skipGLOrientationVerticalFlip */, false /* useAnim */); + } + + @Test + public void test112_flip1_bitm_layout1_layered0() throws InterruptedException, InvocationTargetException { + if( Platform.OSType.WINDOWS != Platform.getOSType() ) { + return; + } + GLCapabilities caps = new GLCapabilities(glp); + caps.setBitmap(true); + runTestGL(caps, true /* addLayout */, false /* layered */, true /* skipGLOrientationVerticalFlip */, false /* useAnim */); + } + + @Test + public void test113_flip1_bitm_layout0_layered1() throws InterruptedException, InvocationTargetException { + if( Platform.OSType.WINDOWS != Platform.getOSType() ) { + return; + } + GLCapabilities caps = new GLCapabilities(glp); + caps.setBitmap(true); + runTestGL(caps, false /* addLayout */, true /* layered */, true /* skipGLOrientationVerticalFlip */, false /* useAnim */); + } + + @Test + public void test114_flip1_bitm_layout1_layered1() throws InterruptedException, InvocationTargetException { + if( Platform.OSType.WINDOWS != Platform.getOSType() ) { + return; + } + GLCapabilities caps = new GLCapabilities(glp); + caps.setBitmap(true); + runTestGL(caps, true /* addLayout */, true /* layered */, true /* skipGLOrientationVerticalFlip */, false /* useAnim */); + } + static long duration = 500; // ms public static void main(String args[]) { diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java index 4bf1f95c3..f7fbc7332 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,7 +20,7 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. @@ -42,24 +42,24 @@ public class NewtAWTReparentingKeyAdapter extends KeyAdapter { final NewtCanvasAWT newtCanvasAWT; final GLWindow glWindow; final QuitAdapter quitAdapter; - + public NewtAWTReparentingKeyAdapter(Frame frame, NewtCanvasAWT newtCanvasAWT, GLWindow glWindow, QuitAdapter quitAdapter) { this.frame = frame; this.newtCanvasAWT = newtCanvasAWT; this.glWindow = glWindow; this.quitAdapter = quitAdapter; } - + public void keyReleased(KeyEvent e) { if( !e.isPrintableKey() || e.isAutoRepeat() ) { return; - } + } if( e.getKeySymbol() == KeyEvent.VK_I ) { System.err.println(glWindow); } else if( e.getKeySymbol() == KeyEvent.VK_L ) { javax.media.nativewindow.util.Point p0 = newtCanvasAWT.getNativeWindow().getLocationOnScreen(null); javax.media.nativewindow.util.Point p1 = glWindow.getLocationOnScreen(null); - System.err.println("NewtCanvasAWT position: "+p0+", "+p1); + System.err.println("NewtCanvasAWT position: "+p0+", "+p1); } else if( e.getKeySymbol() == KeyEvent.VK_D ) { glWindow.setUndecorated(!glWindow.isUndecorated()); } else if( e.getKeySymbol() == KeyEvent.VK_S ) { @@ -68,7 +68,7 @@ public class NewtAWTReparentingKeyAdapter extends KeyAdapter { glWindow.setPosition(100, 100); } else { System.err.println("XXX glWin to 0/0"); - glWindow.setPosition(0, 0); + glWindow.setPosition(0, 0); } } else if( e.getKeySymbol() == KeyEvent.VK_F ) { if( null != quitAdapter ) { @@ -92,8 +92,8 @@ public class NewtAWTReparentingKeyAdapter extends KeyAdapter { if(glWindow.getAnimator().isPaused()) { glWindow.getAnimator().resume(); } else { - glWindow.getAnimator().pause(); - } + glWindow.getAnimator().pause(); + } } }.run(); } else if( e.getKeySymbol() == KeyEvent.VK_R ) { @@ -105,7 +105,7 @@ public class NewtAWTReparentingKeyAdapter extends KeyAdapter { final Thread t = glWindow.setExclusiveContextThread(null); if(glWindow.getParent()==null) { System.err.println("XXX glWin to HOME"); - glWindow.reparentWindow(newtCanvasAWT.getNativeWindow()); + glWindow.reparentWindow(newtCanvasAWT.getNativeWindow(), -1, -1, 0 /* hints */); } else { if( null != frame ) { final InsetsImmutable nInsets = glWindow.getInsets(); @@ -121,10 +121,10 @@ public class NewtAWTReparentingKeyAdapter extends KeyAdapter { final int topLevelX = frame.getX()+frame.getWidth()+dx; final int topLevelY = frame.getY()+dy; System.err.println("XXX glWin to TOP.1 "+topLevelX+"/"+topLevelY+" - insets " + nInsets + ", " + aInsets); - glWindow.reparentWindow(null, topLevelX, topLevelY, false); + glWindow.reparentWindow(null, topLevelX, topLevelY, 0 /* hint */); } else { System.err.println("XXX glWin to TOP.0"); - glWindow.reparentWindow(null); + glWindow.reparentWindow(null, -1, -1, 0 /* hints */); } } glWindow.requestFocus(); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01NEWT.java index 1f19241d8..7beceb291 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01NEWT.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,12 +20,12 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ - + package com.jogamp.opengl.test.junit.newt.parenting; @@ -62,7 +62,7 @@ public class TestParenting01NEWT extends UITestCase { } @Test - public void testWindowParenting01CreateVisibleDestroy() throws InterruptedException { + public void test01CreateVisibleDestroy() throws InterruptedException { Assert.assertEquals(0,Display.getActiveDisplayNumber()); Display display = null; Screen screen = null; @@ -82,7 +82,7 @@ public class TestParenting01NEWT extends UITestCase { Assert.assertEquals(false,screen.isNativeValid()); Assert.assertEquals(0,Display.getActiveDisplayNumber()); - glWindow1.setTitle("testWindowParenting01CreateVisibleDestroy"); + glWindow1.setTitle("test01CreateVisibleDestroy"); glWindow1.setSize(640, 480); GLEventListener demo1 = new RedSquareES2(); setDemoFields(demo1, glWindow1, false); @@ -151,13 +151,13 @@ public class TestParenting01NEWT extends UITestCase { glWindow1.resetFPSCounter(); glWindow2.resetFPSCounter(); Animator animator1 = new Animator(glWindow1); - animator1.setUpdateFPSFrames(1, null); + animator1.setUpdateFPSFrames(1, null); animator1.start(); Assert.assertEquals(true, animator1.isAnimating()); Assert.assertEquals(false, animator1.isPaused()); Assert.assertNotNull(animator1.getThread()); Animator animator2 = new Animator(glWindow2); - animator2.setUpdateFPSFrames(1, null); + animator2.setUpdateFPSFrames(1, null); animator2.start(); Assert.assertEquals(true, animator2.isAnimating()); Assert.assertEquals(false, animator2.isPaused()); @@ -286,25 +286,27 @@ public class TestParenting01NEWT extends UITestCase { } @Test - public void testWindowParenting02ReparentTop2WinReparentRecreate() throws InterruptedException { - testWindowParenting02ReparentTop2WinImpl(true); + public void test02aReparentTop2WinReparentRecreate() throws InterruptedException { + test02ReparentTop2WinImpl(true); } @Test - public void testWindowParenting02ReparentTop2WinReparentNative() throws InterruptedException { - testWindowParenting02ReparentTop2WinImpl(false); + public void test02bReparentTop2WinReparentNative() throws InterruptedException { + test02ReparentTop2WinImpl(false); } /** * @param reparentRecreate true, if the followup reparent should utilize destroy/create, instead of native reparenting */ - protected void testWindowParenting02ReparentTop2WinImpl(boolean reparentRecreate) throws InterruptedException { + protected void test02ReparentTop2WinImpl(final boolean reparentRecreate) throws InterruptedException { + final int reparentHints = reparentRecreate ? Window.REPARENT_HINT_FORCE_RECREATION : 0; + Assert.assertEquals(0,Display.getActiveDisplayNumber()); Display display1 = null; Screen screen1 = null; GLWindow glWindow1 = GLWindow.create(glCaps); - glWindow1.setTitle("testWindowParenting02ReparentTop2Win"); + glWindow1.setTitle("test02ReparentTop2Win"); glWindow1.setSize(640, 480); GLEventListener demo1 = new RedSquareES2(); setDemoFields(demo1, glWindow1, false); @@ -379,7 +381,7 @@ public class TestParenting01NEWT extends UITestCase { // glWindow2 -- child --> glWindow1: compatible Assert.assertEquals(true, glWindow2.isVisible()); System.err.println("Frames(1) "+glWindow2.getTotalFPSFrames()); - reparentAction = glWindow2.reparentWindow(glWindow1, -1, -1, reparentRecreate); + reparentAction = glWindow2.reparentWindow(glWindow1, -1, -1, reparentHints); System.err.println("Frames(2) "+glWindow2.getTotalFPSFrames()); Assert.assertTrue(Window.ReparentOperation.ACTION_INVALID != reparentAction); Assert.assertEquals(true, glWindow2.isVisible()); @@ -405,7 +407,7 @@ public class TestParenting01NEWT extends UITestCase { // glWindow2 --> top Assert.assertEquals(true, glWindow2.isVisible()); - reparentAction = glWindow2.reparentWindow(null, -1, -1, reparentRecreate); + reparentAction = glWindow2.reparentWindow(null, -1, -1, reparentHints); Assert.assertTrue(Window.ReparentOperation.ACTION_INVALID != reparentAction); Assert.assertEquals(true, glWindow2.isVisible()); Assert.assertEquals(true, glWindow2.isNativeValid()); @@ -484,16 +486,18 @@ public class TestParenting01NEWT extends UITestCase { } @Test - public void testWindowParenting03ReparentWin2TopReparentRecreate() throws InterruptedException { - testWindowParenting03ReparentWin2TopImpl(true); + public void test03aReparentWin2TopReparentRecreate() throws InterruptedException { + test03ReparentWin2TopImpl(true); } @Test - public void testWindowParenting03ReparentWin2TopReparentNative() throws InterruptedException { - testWindowParenting03ReparentWin2TopImpl(false); + public void test03bReparentWin2TopReparentNative() throws InterruptedException { + test03ReparentWin2TopImpl(false); } - protected void testWindowParenting03ReparentWin2TopImpl(boolean reparentRecreate) throws InterruptedException { + protected void test03ReparentWin2TopImpl(final boolean reparentRecreate) throws InterruptedException { + final int reparentHints = reparentRecreate ? Window.REPARENT_HINT_FORCE_RECREATION : 0; + Assert.assertEquals(0,Display.getActiveDisplayNumber()); Display display1 = null; Screen screen1 = null; @@ -503,7 +507,7 @@ public class TestParenting01NEWT extends UITestCase { GLWindow glWindow1 = GLWindow.create(glCaps); screen1 = glWindow1.getScreen(); display1 = screen1.getDisplay(); - glWindow1.setTitle("testWindowParenting03ReparentWin2Top"); + glWindow1.setTitle("test03ReparentWin2Top"); glWindow1.setSize(640, 480); GLEventListener demo1 = new RedSquareES2(); setDemoFields(demo1, glWindow1, false); @@ -567,14 +571,14 @@ public class TestParenting01NEWT extends UITestCase { switch(state) { case 0: Assert.assertEquals(true, glWindow2.isVisible()); - reparentAction = glWindow2.reparentWindow(null, -1, -1, reparentRecreate); + reparentAction = glWindow2.reparentWindow(null, -1, -1, reparentHints); Assert.assertTrue(Window.ReparentOperation.ACTION_INVALID != reparentAction); Assert.assertEquals(true, glWindow2.isVisible()); Assert.assertEquals(true, glWindow2.isNativeValid()); Thread.sleep(20*16); // Wait for a few frames since counter could be reset - 20 frames at 60Hz 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()); @@ -582,14 +586,14 @@ public class TestParenting01NEWT extends UITestCase { break; case 1: Assert.assertEquals(true, glWindow2.isVisible()); - reparentAction = glWindow2.reparentWindow(glWindow1, -1, -1, reparentRecreate); + reparentAction = glWindow2.reparentWindow(glWindow1, -1, -1, reparentHints); Assert.assertTrue(Window.ReparentOperation.ACTION_INVALID != reparentAction); Assert.assertEquals(true, glWindow2.isVisible()); Assert.assertEquals(true, glWindow2.isNativeValid()); Thread.sleep(20*16); // Wait for a few frames since counter could be reset - 20 frames at 60Hz 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()); @@ -657,7 +661,7 @@ public class TestParenting01NEWT extends UITestCase { public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { Assert.assertNotNull(demo); - Assert.assertNotNull(glWindow); + Assert.assertNotNull(glWindow); if(debug) { MiscUtils.setFieldIfExists(demo, "glDebug", true); MiscUtils.setFieldIfExists(demo, "glTrace", true); @@ -689,8 +693,8 @@ public class TestParenting01NEWT extends UITestCase { try { TestParenting01NEWT.initClass(); TestParenting01NEWT m = new TestParenting01NEWT(); - m.testWindowParenting02ReparentTop2WinReparentRecreate(); - m.testWindowParenting01CreateVisibleDestroy(); + m.test02aReparentTop2WinReparentRecreate(); + m.test01CreateVisibleDestroy(); } catch (Throwable t ) { t.printStackTrace(); } 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 6de24d1ea..420a39cb2 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 @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,7 +20,7 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. @@ -68,7 +68,7 @@ public class TestParenting01aAWT extends UITestCase { } @Test - public void testWindowParenting01CreateVisibleDestroy1() throws InterruptedException, InvocationTargetException { + public void test01WindowParenting01CreateVisibleDestroy1() throws InterruptedException, InvocationTargetException { final GLWindow glWindow1 = GLWindow.create(glCaps); Assert.assertNotNull(glWindow1); Assert.assertEquals(false, glWindow1.isVisible()); @@ -112,11 +112,11 @@ public class TestParenting01aAWT extends UITestCase { Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); final Animator animator1 = new Animator(glWindow1); - animator1.setUpdateFPSFrames(1, null); + animator1.setUpdateFPSFrames(1, null); animator1.start(); Assert.assertTrue(AWTRobotUtil.waitForRealized(glWindow1, true)); Assert.assertTrue(AWTRobotUtil.waitForVisible(glWindow1, true)); - + while(animator1.isAnimating() && animator1.getTotalFPSDuration()<durationPerTest) { Thread.sleep(100); } @@ -126,17 +126,17 @@ public class TestParenting01aAWT extends UITestCase { SwingUtilities.invokeAndWait(new Runnable() { public void run() { frame1.setVisible(false); - } } ); + } } ); Assert.assertEquals(true, glWindow1.isNativeValid()); SwingUtilities.invokeAndWait(new Runnable() { public void run() { frame1.setVisible(true); - } } ); + } } ); Assert.assertEquals(true, glWindow1.isNativeValid()); final boolean wasOnscreen = glWindow1.getChosenCapabilities().isOnscreen(); - + SwingUtilities.invokeAndWait(new Runnable() { public void run() { frame1.remove(newtCanvasAWT); @@ -159,7 +159,7 @@ public class TestParenting01aAWT extends UITestCase { } @Test - public void testWindowParenting02CreateVisibleDestroy2Defered() throws InterruptedException, InvocationTargetException { + public void test02WindowParenting02CreateVisibleDestroy2Defered() throws InterruptedException, InvocationTargetException { final GLWindow glWindow1 = GLWindow.create(glCaps); Assert.assertNotNull(glWindow1); Assert.assertEquals(false, glWindow1.isVisible()); @@ -211,7 +211,7 @@ public class TestParenting01aAWT extends UITestCase { } @Test - public void testWindowParenting02CreateVisibleDestroy3Odd() throws InterruptedException, InvocationTargetException { + public void test03WindowParenting02CreateVisibleDestroy3Odd() throws InterruptedException, InvocationTargetException { GLWindow glWindow1 = GLWindow.create(glCaps); GLEventListener demo1 = new RedSquareES2(); setDemoFields(demo1, glWindow1, false); @@ -256,7 +256,7 @@ public class TestParenting01aAWT extends UITestCase { } @Test - public void testWindowParenting03ReparentNewtWin2Top() throws InterruptedException, InvocationTargetException { + public void test04WindowParenting03ReparentNewtWin2Top() throws InterruptedException, InvocationTargetException { GLWindow glWindow1 = GLWindow.create(glCaps); GLEventListener demo1 = new RedSquareES2(); setDemoFields(demo1, glWindow1, false); @@ -283,7 +283,7 @@ public class TestParenting01aAWT extends UITestCase { Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); Animator animator1 = new Animator(glWindow1); - animator1.setUpdateFPSFrames(1, null); + animator1.setUpdateFPSFrames(1, null); animator1.start(); int state = 0; @@ -291,12 +291,12 @@ public class TestParenting01aAWT extends UITestCase { Thread.sleep(durationPerTest); switch(state) { case 0: - glWindow1.reparentWindow(null); + System.err.println("Reparent CHILD -> TOP: "+glWindow1.reparentWindow(null, -1, -1, 0 /* hints */)); Assert.assertEquals(true, glWindow1.isNativeValid()); Assert.assertNull(glWindow1.getParent()); break; case 1: - glWindow1.reparentWindow(newtCanvasAWT.getNativeWindow()); + System.err.println("Reparent TOP -> CHILD: "+glWindow1.reparentWindow(newtCanvasAWT.getNativeWindow(), -1, -1, 0 /* hints */)); Assert.assertEquals(true, glWindow1.isNativeValid()); Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); break; @@ -315,7 +315,7 @@ public class TestParenting01aAWT extends UITestCase { } @Test - public void testWindowParenting04ReparentNewtWin2TopLayouted() throws InterruptedException, InvocationTargetException { + public void test05WindowParenting04ReparentNewtWin2TopLayouted() throws InterruptedException, InvocationTargetException { GLWindow glWindow1 = GLWindow.create(glCaps); GLEventListener demo1 = new RedSquareES2(); setDemoFields(demo1, glWindow1, false); @@ -329,7 +329,7 @@ public class TestParenting01aAWT extends UITestCase { frame.add(new Button("South"), BorderLayout.SOUTH); frame.add(new Button("East"), BorderLayout.EAST); frame.add(new Button("West"), BorderLayout.WEST); - + SwingUtilities.invokeAndWait(new Runnable() { public void run() { frame.setSize(width, height); @@ -344,11 +344,11 @@ public class TestParenting01aAWT extends UITestCase { frame.validate(); } }); - + Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); Animator animator1 = new Animator(glWindow1); - animator1.setUpdateFPSFrames(1, null); + animator1.setUpdateFPSFrames(1, null); animator1.start(); int state = 0; @@ -356,12 +356,12 @@ public class TestParenting01aAWT extends UITestCase { Thread.sleep(durationPerTest); switch(state) { case 0: - glWindow1.reparentWindow(null); + System.err.println("Reparent CHILD -> TOP: "+glWindow1.reparentWindow(null, -1, -1, 0 /* hints */)); Assert.assertEquals(true, glWindow1.isNativeValid()); Assert.assertNull(glWindow1.getParent()); break; case 1: - glWindow1.reparentWindow(newtCanvasAWT.getNativeWindow()); + System.err.println("Reparent TOP -> CHILD: "+glWindow1.reparentWindow(newtCanvasAWT.getNativeWindow(), -1, -1, 0 /* hints */)); Assert.assertEquals(true, glWindow1.isNativeValid()); Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); break; @@ -380,7 +380,7 @@ public class TestParenting01aAWT extends UITestCase { } @Test - public void testWindowParenting05ReparentAWTWinHopFrame2Frame() throws InterruptedException, InvocationTargetException { + public void test06WindowParenting05ReparentAWTWinHopFrame2Frame() throws InterruptedException, InvocationTargetException { GLWindow glWindow1 = GLWindow.create(glCaps); glWindow1.setUndecorated(true); GLEventListener demo1 = new RedSquareES2(); @@ -427,7 +427,7 @@ public class TestParenting01aAWT extends UITestCase { Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); Animator animator1 = new Animator(glWindow1); - animator1.setUpdateFPSFrames(1, null); + animator1.setUpdateFPSFrames(1, null); animator1.start(); int state = 0; @@ -442,7 +442,7 @@ public class TestParenting01aAWT extends UITestCase { frame1.validate(); frame2.validate(); } - }); + }); break; case 1: SwingUtilities.invokeAndWait(new Runnable() { @@ -452,7 +452,7 @@ public class TestParenting01aAWT extends UITestCase { frame2.validate(); frame1.validate(); } - }); + }); break; } state++; @@ -471,7 +471,7 @@ public class TestParenting01aAWT extends UITestCase { public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { Assert.assertNotNull(demo); - Assert.assertNotNull(glWindow); + Assert.assertNotNull(glWindow); if(debug) { MiscUtils.setFieldIfExists(demo, "glDebug", true); MiscUtils.setFieldIfExists(demo, "glTrace", true); @@ -498,17 +498,7 @@ public class TestParenting01aAWT extends UITestCase { } } String tstname = TestParenting01aAWT.class.getName(); - org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { - tstname, - "filtertrace=true", - "haltOnError=false", - "haltOnFailure=false", - "showoutput=true", - "outputtoformatters=true", - "logfailedtests=true", - "logtestlistenerevents=true", - "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", - "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); + org.junit.runner.JUnitCore.main(tstname); } } diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01bAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01bAWT.java index 45612eb1a..598e5f10f 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01bAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01bAWT.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,12 +20,12 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ - + package com.jogamp.opengl.test.junit.newt.parenting; import org.junit.Assert; @@ -68,16 +68,16 @@ public class TestParenting01bAWT extends UITestCase { } @Test - public void testWindowParenting05ReparentAWTWinHopFrame2FrameFPS25Animator() throws InterruptedException, InvocationTargetException { - testWindowParenting05ReparentAWTWinHopFrame2FrameImpl(25); + public void test01AWTWinHopFrame2FrameFPS25Animator() throws InterruptedException, InvocationTargetException { + testAWTWinHopFrame2FrameImpl(25); } @Test - public void testWindowParenting05ReparentAWTWinHopFrame2FrameStdAnimator() throws InterruptedException, InvocationTargetException { - testWindowParenting05ReparentAWTWinHopFrame2FrameImpl(0); + public void test02AWTWinHopFrame2FrameStdAnimator() throws InterruptedException, InvocationTargetException { + testAWTWinHopFrame2FrameImpl(0); } - public void testWindowParenting05ReparentAWTWinHopFrame2FrameImpl(int fps) throws InterruptedException, InvocationTargetException { + public void testAWTWinHopFrame2FrameImpl(int fps) throws InterruptedException, InvocationTargetException { GLWindow glWindow1 = GLWindow.create(glCaps); glWindow1.setUndecorated(true); GLEventListener demo1 = new RedSquareES2(); @@ -85,7 +85,7 @@ public class TestParenting01bAWT extends UITestCase { glWindow1.addGLEventListener(demo1); final NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); - + final Frame frame1 = new Frame("AWT Parent Frame"); frame1.setLayout(new BorderLayout()); frame1.add(new Button("North"), BorderLayout.NORTH); @@ -96,7 +96,7 @@ public class TestParenting01bAWT extends UITestCase { public void run() { frame1.setSize(width, height); frame1.setLocation(0, 0); - frame1.setVisible(true); + frame1.setVisible(true); } }); @@ -110,7 +110,7 @@ public class TestParenting01bAWT extends UITestCase { public void run() { frame2.setSize(width, height); frame2.setLocation(640, 480); - frame2.setVisible(true); + frame2.setVisible(true); } }); @@ -142,7 +142,7 @@ public class TestParenting01bAWT extends UITestCase { frame1.validate(); frame2.validate(); } - }); + }); break; case 1: SwingUtilities.invokeAndWait(new Runnable() { @@ -152,7 +152,7 @@ public class TestParenting01bAWT extends UITestCase { frame2.validate(); frame1.validate(); } - }); + }); break; } } diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cAWT.java index dd5d6eb13..1d7401728 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cAWT.java @@ -66,7 +66,7 @@ public class TestParenting01cAWT extends UITestCase { } @Test - public void testWindowParenting01CreateVisibleDestroy1() throws InterruptedException, InvocationTargetException { + public void test01CreateVisibleDestroy1() throws InterruptedException, InvocationTargetException { int i; GLWindow glWindow1 = GLWindow.create(glCaps); @@ -154,7 +154,7 @@ public class TestParenting01cAWT extends UITestCase { } @Test - public void testWindowParenting05ReparentAWTWinHopFrame2Frame() throws InterruptedException, InvocationTargetException { + public void test02AWTWinHopFrame2Frame() throws InterruptedException, InvocationTargetException { GLWindow glWindow1 = GLWindow.create(glCaps); glWindow1.setUndecorated(true); GLEventListener demo1 = new RedSquareES2(); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java index 375f676f4..4d5c3b25d 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java @@ -121,7 +121,7 @@ public class TestParenting01cSwingAWT extends UITestCase { } @Test - public void testWindowParenting01CreateVisibleDestroy1() throws InterruptedException, InvocationTargetException { + public void test01CreateVisibleDestroy1() throws InterruptedException, InvocationTargetException { /** * JFrame . JPanel . Container . NewtCanvasAWT . GLWindow */ @@ -236,7 +236,7 @@ public class TestParenting01cSwingAWT extends UITestCase { } @Test - public void testWindowParenting05ReparentAWTWinHopFrame2Frame() throws InterruptedException, InvocationTargetException { + public void test02AWTWinHopFrame2Frame() throws InterruptedException, InvocationTargetException { /** * JFrame . JPanel . Container . NewtCanvasAWT . GLWindow */ diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01dAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01dAWT.java new file mode 100644 index 000000000..00b32ac35 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01dAWT.java @@ -0,0 +1,248 @@ +/** + * Copyright 2013 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.newt.parenting; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.FixMethodOrder; +import org.junit.runners.MethodSorters; + +import java.awt.Button; +import java.awt.BorderLayout; +import java.awt.Container; +import java.awt.Frame; + +import javax.media.opengl.*; +import javax.swing.SwingUtilities; + +import com.jogamp.newt.Window; +import com.jogamp.newt.opengl.*; +import com.jogamp.newt.awt.NewtCanvasAWT; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; + +import com.jogamp.opengl.test.junit.util.*; +import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2; + +/** + * Test GL preservation case for reparenting. + * <p> + * Also simulates adding and attaching an already created GLWindow + * to a NewtCanvasAWT in recreation mode, where the GL state shall be preserved. + * </p> + */ +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestParenting01dAWT extends UITestCase { + static int width, height; + static long durationPerTest = 800; + static GLCapabilities glCaps; + + @BeforeClass + public static void initClass() throws InterruptedException { + width = 640; + height = 480; + glCaps = new GLCapabilities(null); + // Thread.sleep(10000); + } + + static class MyGLEventListenerCounter extends GLEventListenerCounter { + @Override + public void init(GLAutoDrawable drawable) { + super.init(drawable); + System.err.println("MyGLEventListenerCounter.init: "+this); + // Thread.dumpStack(); + } + + @Override + public void dispose(GLAutoDrawable drawable) { + super.dispose(drawable); + System.err.println("MyGLEventListenerCounter.dispose: "+this); + // Thread.dumpStack(); + } + } + + @Test + public void test01GLWindowReparentRecreateNoPreserve() throws InterruptedException, InvocationTargetException { + testGLWindowInvisibleReparentRecreateImpl(false /* triggerPreserveGLState */); + } + + @Test + public void test02GLWindowReparentRecreateGLPreserve() throws InterruptedException, InvocationTargetException { + testGLWindowInvisibleReparentRecreateImpl(true /* triggerPreserveGLState */); + } + + private void testGLWindowInvisibleReparentRecreateImpl(boolean triggerPreserveGLState) throws InterruptedException, InvocationTargetException { + final GLWindow glWindow1 = GLWindow.create(glCaps); + Assert.assertNotNull(glWindow1); + Assert.assertEquals(false, glWindow1.isVisible()); + Assert.assertEquals(false, glWindow1.isNativeValid()); + Assert.assertNull(glWindow1.getParent()); + glWindow1.setTitle("testWindowParenting01CreateVisibleDestroy"); + final MyGLEventListenerCounter glelCounter = new MyGLEventListenerCounter(); + glWindow1.addGLEventListener(glelCounter); + GLEventListener demo1 = new RedSquareES2(); + glWindow1.addGLEventListener(demo1); + Assert.assertEquals("Init Counter Invalid "+glelCounter, 0, glelCounter.initCount); + + final NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); + Assert.assertNotNull(newtCanvasAWT); + Assert.assertEquals(false, glWindow1.isVisible()); + Assert.assertEquals(false, glWindow1.isNativeValid()); + Assert.assertNull(glWindow1.getParent()); + Assert.assertEquals("Init Counter Invalid "+glelCounter, 0, glelCounter.initCount); + + final Frame frame1 = new Frame("AWT Parent Frame"); + frame1.setLayout(new BorderLayout()); + frame1.add(new Button("North"), BorderLayout.NORTH); + frame1.add(new Button("South"), BorderLayout.SOUTH); + frame1.add(new Button("East"), BorderLayout.EAST); + frame1.add(new Button("West"), BorderLayout.WEST); + + final Container container1 = new Container(); + container1.setLayout(new BorderLayout()); + container1.add(new Button("north"), BorderLayout.NORTH); + container1.add(new Button("south"), BorderLayout.SOUTH); + container1.add(new Button("east"), BorderLayout.EAST); + container1.add(new Button("west"), BorderLayout.WEST); + container1.add(newtCanvasAWT, BorderLayout.CENTER); + + frame1.add(container1, BorderLayout.CENTER); + + // visible test + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame1.setSize(width, height); + frame1.setVisible(true); + } + }); + Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); + + Assert.assertTrue(AWTRobotUtil.waitForRealized(glWindow1, true)); + Assert.assertTrue(AWTRobotUtil.waitForVisible(glWindow1, true)); + glWindow1.display(); + Assert.assertEquals("Init Counter Invalid "+glelCounter, 1, glelCounter.initCount); + Assert.assertEquals("Dispose Counter Invalid "+glelCounter, 0, glelCounter.disposeCount); + + final int reparentingHints = Window.REPARENT_HINT_FORCE_RECREATION | + ( triggerPreserveGLState ? Window.REPARENT_HINT_BECOMES_VISIBLE : 0 ); + + // + // Even though the hint REPARENT_HINT_BECOMES_VISIBLE is not set (triggerPrerveGLState == false), + // since GLWindow is visible already the GL state shall be preserved! + // + System.err.println(getSimpleTestName(".")+": Start Reparent #1"); + final Window.ReparentOperation rop1 = glWindow1.reparentWindow(null, -1, -1, reparentingHints); + System.err.println(getSimpleTestName(".")+": Result Reparent #1: "+rop1); + Assert.assertEquals(Window.ReparentOperation.ACTION_NATIVE_CREATION, rop1); + glWindow1.display(); + Assert.assertEquals("Init Counter Invalid (Preserve Failed 1) "+glelCounter, 1, glelCounter.initCount); + Assert.assertEquals("Dispose Counter Invalid (Preserve Failed 1) "+glelCounter, 0, glelCounter.disposeCount); + + // + // The following step is equivalent with adding and attaching an already created GLWindow + // to a NewtCanvasAWT in recreation mode if REPARENT_HINT_BECOMES_VISIBLE hint is set (triggerPrerveGLState == true). + // GL state shall be preserved! + // + glWindow1.setVisible(false); + System.err.println(getSimpleTestName(".")+": Start Reparent #2"); + final Window.ReparentOperation rop2 = glWindow1.reparentWindow(newtCanvasAWT.getNativeWindow(), -1, -1, reparentingHints); + System.err.println(getSimpleTestName(".")+": Result Reparent #2: "+rop2); + Assert.assertEquals(Window.ReparentOperation.ACTION_NATIVE_CREATION, rop2); + glWindow1.setVisible(true); + glWindow1.display(); + if( triggerPreserveGLState ) { + Assert.assertEquals("Init Counter Invalid (Preserve Failed 2) "+glelCounter, 1, glelCounter.initCount); + Assert.assertEquals("Dispose Counter Invalid (Preserve Failed 2) "+glelCounter, 0, glelCounter.disposeCount); + } else { + Assert.assertEquals("Init Counter Invalid (Preserve Failed 2) "+glelCounter, 2, glelCounter.initCount); + Assert.assertEquals("Dispose Counter Invalid (Preserve Failed 2) "+glelCounter, 1, glelCounter.disposeCount); + } + + final long t0 = System.currentTimeMillis(); + long t1 = t0; + while( t1 - t0 < durationPerTest ) { + Thread.sleep(100); + t1 = System.currentTimeMillis(); + } + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame1.setVisible(false); + } } ); + Assert.assertEquals(true, glWindow1.isNativeValid()); + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame1.setVisible(true); + } } ); + Assert.assertEquals(true, glWindow1.isNativeValid()); + + final boolean wasOnscreen = glWindow1.getChosenCapabilities().isOnscreen(); + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame1.remove(newtCanvasAWT); + } } ); + // Assert.assertNull(glWindow1.getParent()); + if( wasOnscreen ) { + Assert.assertEquals(true, glWindow1.isNativeValid()); + } // else OK to be destroyed - due to offscreen/onscreen transition + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame1.dispose(); + } } ); + if( wasOnscreen ) { + Assert.assertEquals(true, glWindow1.isNativeValid()); + } // else OK to be destroyed - due to offscreen/onscreen transition + + glWindow1.destroy(); + Assert.assertEquals(false, glWindow1.isNativeValid()); + if( triggerPreserveGLState ) { + Assert.assertEquals("Init Counter Invalid (Preserve Failed 1) "+glelCounter, 1, glelCounter.initCount); + Assert.assertEquals("Dispose Counter Invalid (Preserve Failed 1) "+glelCounter, 1, glelCounter.disposeCount); + } else { + Assert.assertEquals("Init Counter Invalid (Preserve Failed 1) "+glelCounter, 2, glelCounter.initCount); + Assert.assertEquals("Dispose Counter Invalid (Preserve Failed 1) "+glelCounter, 2, glelCounter.disposeCount); + } + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = MiscUtils.atol(args[++i], durationPerTest); + } + } + String tstname = TestParenting01dAWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02AWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02AWT.java index d79bdcaf6..b304a2ce7 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02AWT.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,12 +20,12 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ - + package com.jogamp.opengl.test.junit.newt.parenting; import org.junit.Assert; @@ -65,22 +65,22 @@ public class TestParenting02AWT extends UITestCase { } @Test - public void testWindowParenting01NewtChildOnAWTParentLayouted() throws InterruptedException, InvocationTargetException { + public void test01NewtChildOnAWTParentLayouted() throws InterruptedException, InvocationTargetException { runNewtChildOnAWTParent(true, false); } @Test - public void testWindowParenting02NewtChildOnAWTParentLayoutedDef() throws InterruptedException, InvocationTargetException { + public void test02NewtChildOnAWTParentLayoutedDef() throws InterruptedException, InvocationTargetException { runNewtChildOnAWTParent(true, true); } @Test - public void testWindowParenting03NewtChildOnAWTParentDirect() throws InterruptedException, InvocationTargetException { + public void test03NewtChildOnAWTParentDirect() throws InterruptedException, InvocationTargetException { runNewtChildOnAWTParent(false, false); } @Test - public void testWindowParenting04NewtChildOnAWTParentDirectDef() throws InterruptedException, InvocationTargetException { + public void test04NewtChildOnAWTParentDirectDef() throws InterruptedException, InvocationTargetException { runNewtChildOnAWTParent(false, true); } @@ -152,7 +152,7 @@ public class TestParenting02AWT extends UITestCase { } while(!glWindow.isNativeValid()) ; final boolean wasOnscreen = glWindow.getChosenCapabilities().isOnscreen(); - + Assert.assertEquals(true, glWindow.isNativeValid()); Assert.assertNotNull(glWindow.getParent()); if(verbose) { @@ -203,7 +203,7 @@ public class TestParenting02AWT extends UITestCase { Thread.sleep(step); duration -= step; - while( null != ( event = (NEWTEvent) eventFifo.get() ) ) { + while( null != ( event = eventFifo.get() ) ) { Window source = (Window) event.getSource(); if(event instanceof KeyEvent) { KeyEvent keyEvent = (KeyEvent) event; @@ -215,7 +215,7 @@ public class TestParenting02AWT extends UITestCase { source.setFullscreen(!source.isFullscreen()); break; } - } + } } } if(verbose) { diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02NEWT.java index 6294483f0..9f56ecdbf 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02NEWT.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,12 +20,12 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ - + package com.jogamp.opengl.test.junit.newt.parenting; @@ -92,7 +92,7 @@ public class TestParenting02NEWT extends UITestCase { } @Test - public void testWindowParenting01NewtOnNewtParentChildDraw() throws InterruptedException { + public void test01NewtOnNewtParentChildDraw() throws InterruptedException { GLCapabilities caps = new GLCapabilities(null); Assert.assertNotNull(caps); Display display = NewtFactory.createDisplay(null); // local display @@ -112,7 +112,7 @@ public class TestParenting02NEWT extends UITestCase { glWindow1.setSize(width, height); Assert.assertEquals(width,glWindow1.getWidth()); Assert.assertEquals(height,glWindow1.getHeight()); - glWindow1.setTitle("testWindowParenting01NewtOnNewtParentChildDraw - PARENT"); + glWindow1.setTitle("test01NewtOnNewtParentChildDraw - PARENT"); glWindow1.setPosition(x,y); //glWindow1.addKeyListener(new TraceKeyAdapter(new KeyAction(eventFifo))); //glWindow1.addWindowListener(new TraceWindowAdapter()); @@ -133,7 +133,7 @@ public class TestParenting02NEWT extends UITestCase { glWindow2.setSize(width/2, height/2); //Assert.assertEquals(width/2,glWindow2.getWidth()); //Assert.assertEquals(height/2,glWindow2.getHeight()); - glWindow2.setTitle("testWindowParenting01NewtOnNewtParentChildDraw - CHILD"); + glWindow2.setTitle("test01NewtOnNewtParentChildDraw - CHILD"); glWindow2.setPosition(glWindow1.getWidth()/2, glWindow1.getHeight()/2); //glWindow2.addKeyListener(new TraceKeyAdapter(new KeyAction(eventFifo))); //glWindow2.addWindowListener(new TraceWindowAdapter(new WindowAction(eventFifo))); @@ -166,7 +166,7 @@ public class TestParenting02NEWT extends UITestCase { glWindow2.setPosition(glWindow1.getWidth()/2,glWindow1.getHeight()/2-y); Thread.sleep(step); - while( null != ( event = (NEWTEvent) eventFifo.get() ) ) { + while( null != ( event = eventFifo.get() ) ) { Window source = (Window) event.getSource(); if(WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY == event.getEventType()) { shouldQuit = true; @@ -180,7 +180,7 @@ public class TestParenting02NEWT extends UITestCase { source.setFullscreen(!source.isFullscreen()); break; } - } + } } } destroyWindow(null, null, window2, glWindow2); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03AWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03AWT.java index 30ee0f129..b7497196c 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03AWT.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,12 +20,12 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ - + package com.jogamp.opengl.test.junit.newt.parenting; import java.lang.reflect.*; @@ -69,16 +69,16 @@ public class TestParenting03AWT extends UITestCase { } @Test - public void testWindowParenting1AWTOneNewtChilds01() throws InterruptedException, InvocationTargetException { - testWindowParenting1AWT(false); + public void test01AWTOneNewtChilds01() throws InterruptedException, InvocationTargetException { + testImpl(false); } @Test - public void testWindowParenting1AWTTwoNewtChilds01() throws InterruptedException, InvocationTargetException { - testWindowParenting1AWT(true); + public void test02AWTTwoNewtChilds01() throws InterruptedException, InvocationTargetException { + testImpl(true); } - - public void testWindowParenting1AWT(boolean use2nd) throws InterruptedException, InvocationTargetException { + + public void testImpl(boolean use2nd) throws InterruptedException, InvocationTargetException { final Frame frame1 = new Frame("AWT Parent Frame"); GLWindow glWindow1 = GLWindow.create(glCaps); glWindow1.setUpdateFPSFrames(1, null); @@ -100,7 +100,7 @@ public class TestParenting03AWT extends UITestCase { glWindow2.setUpdateFPSFrames(1, null); newtCanvasAWT2 = new NewtCanvasAWT(glWindow2); newtCanvasAWT2.setPreferredSize(glSize); - + GLEventListener demo2 = new GearsES2(1); setDemoFields(demo2, glWindow2, false); glWindow2.addGLEventListener(demo2); @@ -141,12 +141,12 @@ public class TestParenting03AWT extends UITestCase { System.err.println("******* Frame setVisible"); frame1.setLocation(0, 0); frame1.setSize(fSize); - frame1.validate(); + frame1.validate(); frame1.setVisible(true); }}); Assert.assertEquals(newtCanvasAWT1.getNativeWindow(),glWindow1.getParent()); - + Assert.assertEquals(true, animator1.isAnimating()); Assert.assertEquals(false, animator1.isPaused()); Assert.assertNotNull(animator1.getThread()); @@ -157,7 +157,7 @@ public class TestParenting03AWT extends UITestCase { Assert.assertNotNull(animator2.getThread()); Thread.sleep(waitAdd2nd); - + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { frame1.add(cont2, BorderLayout.WEST); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting04AWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting04AWT.java index 827ac525a..126aaaffa 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting04AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting04AWT.java @@ -70,13 +70,13 @@ public class TestParenting04AWT extends UITestCase { } @Test - public void winHopFrame2FrameDirectHop() throws InterruptedException, InvocationTargetException { + public void test01WinHopFrame2FrameDirectHop() throws InterruptedException, InvocationTargetException { // Will produce some artifacts .. resizing etc winHopFrame2Frame(false); } @Test - public void winHopFrame2FrameDetachFirst() throws InterruptedException, InvocationTargetException { + public void test02WinHopFrame2FrameDetachFirst() throws InterruptedException, InvocationTargetException { // Note: detaching first setNEWTChild(null) is much cleaner visually winHopFrame2Frame(true); } diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting04SWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting04SWT.java index 78b3bc464..586db8a2b 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting04SWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting04SWT.java @@ -136,13 +136,13 @@ public class TestParenting04SWT extends UITestCase { } @Test - public void winHopFrame2FrameDirectHop() throws InterruptedException, InvocationTargetException { + public void test01WinHopFrame2FrameDirectHop() throws InterruptedException, InvocationTargetException { // Will produce some artifacts .. resizing etc winHopFrame2Frame(false); } @Test - public void winHopFrame2FrameDetachFirst() throws InterruptedException, InvocationTargetException { + public void test02WinHopFrame2FrameDetachFirst() throws InterruptedException, InvocationTargetException { // Note: detaching first setNEWTChild(null) is much cleaner visually winHopFrame2Frame(true); } diff --git a/src/test/com/jogamp/opengl/test/junit/util/GLEventListenerCounter.java b/src/test/com/jogamp/opengl/test/junit/util/GLEventListenerCounter.java index b121a4c2a..b0f6e2c7e 100644 --- a/src/test/com/jogamp/opengl/test/junit/util/GLEventListenerCounter.java +++ b/src/test/com/jogamp/opengl/test/junit/util/GLEventListenerCounter.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,7 +20,7 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. @@ -35,14 +35,14 @@ public class GLEventListenerCounter implements GLEventListener { public int displayCount = 0; public int reshapeCount = 0; public int disposeCount = 0; - + public void reset() { initCount = 0; displayCount = 0; reshapeCount = 0; - disposeCount = 0; + disposeCount = 0; } - + @Override public void init(GLAutoDrawable drawable) { initCount++; @@ -50,7 +50,7 @@ public class GLEventListenerCounter implements GLEventListener { @Override public void dispose(GLAutoDrawable drawable) { - disposeCount++; + disposeCount++; } @Override @@ -61,5 +61,9 @@ public class GLEventListenerCounter implements GLEventListener { @Override public void reshape(GLAutoDrawable d, int x, int y, int width, int height) { reshapeCount++; - } + } + + public String toString() { + return "GLEventListenerCounter[init "+initCount+", dispose "+disposeCount+", reshape "+reshapeCount+", display "+displayCount+"]"; + } }
\ No newline at end of file |