summaryrefslogtreecommitdiffstats
path: root/src/test/com/jogamp
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/com/jogamp')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLReadBuffer01GLCanvasAWT.java252
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLReadBuffer01GLJPanelAWT.java1
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLReadBuffer01GLWindowNEWT.java1
3 files changed, 254 insertions, 0 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLReadBuffer01GLCanvasAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLReadBuffer01GLCanvasAWT.java
new file mode 100644
index 000000000..0f77affe1
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLReadBuffer01GLCanvasAWT.java
@@ -0,0 +1,252 @@
+/**
+ * Copyright 2014 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.jogl.acore;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+import javax.media.opengl.GL;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLCapabilitiesImmutable;
+import javax.media.opengl.GLDrawable;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.awt.GLCanvas;
+import javax.swing.SwingUtilities;
+
+import org.junit.Assume;
+import org.junit.BeforeClass;
+import org.junit.FixMethodOrder;
+import org.junit.runners.MethodSorters;
+
+import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
+import com.jogamp.opengl.test.junit.util.MiscUtils;
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.util.GLDrawableUtil;
+import com.jogamp.opengl.util.awt.AWTGLReadBufferUtil;
+import com.jogamp.opengl.util.texture.TextureIO;
+
+/**
+ * Multiple GLJPanels in a JFrame
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestGLReadBuffer01GLCanvasAWT extends GLReadBuffer00Base {
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton();
+ }
+
+ @Override
+ public void test(final GLCapabilitiesImmutable caps, final boolean useSwingDoubleBuffer, final boolean skipGLOrientationVerticalFlip) {
+ if( skipGLOrientationVerticalFlip || useSwingDoubleBuffer ) {
+ return; // NOP
+ }
+ final AWTGLReadBufferUtil awtGLReadBufferUtil = new AWTGLReadBufferUtil(caps.getGLProfile(), false);
+ final Frame frame = new Frame();
+ final Dimension d = new Dimension(320, 240);
+ final GLCanvas glad = createGLCanvas(caps, d);
+ final TextRendererGLEL textRendererGLEL = new TextRendererGLEL();
+ final SnapshotGLELAWT snapshotGLEL = doSnapshot ? new SnapshotGLELAWT(textRendererGLEL, awtGLReadBufferUtil) : null;
+ try {
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.setLocation(64, 64);
+ frame.setLayout(new BorderLayout());
+ // final JPanel panel = new JPanel();
+ // panel.setLayout(new BorderLayout());
+ // panel.setDoubleBuffered(useSwingDoubleBuffer);
+ // frame.getContentPane().add(panel);
+
+ final GearsES2 gears = new GearsES2(1);
+ gears.setVerbose(false);
+ glad.addGLEventListener(gears);
+ glad.addGLEventListener(textRendererGLEL);
+ if( doSnapshot ) {
+ glad.addGLEventListener(snapshotGLEL);
+ }
+ // panel.add(glad);
+ frame.add(glad, BorderLayout.CENTER);
+ frame.pack();
+ frame.setVisible(true);
+ } } );
+ } catch( Throwable throwable ) {
+ throwable.printStackTrace();
+ Assume.assumeNoException( throwable );
+ }
+ glad.display(); // trigger initialization to get chosen-caps!
+ final Dimension size0 = frame.getSize();
+ final Dimension size1 = new Dimension(size0.width+100, size0.height+100);
+ final Dimension size2 = new Dimension(size0.width-100, size0.height-100);
+ try {
+ for(int i=0; i<3; i++) {
+ final String str = "Frame# "+textRendererGLEL.frameNo+", user #"+(i+1);
+ System.err.println(str);
+ if( keyFrame ) {
+ waitForKey(str);
+ }
+ textRendererGLEL.userCounter = i + 1;
+ glad.display();
+ }
+ try { Thread.sleep(duration); } catch (InterruptedException e) { }
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.setSize(size1);
+ frame.validate();
+ } } );
+ try { Thread.sleep(duration); } catch (InterruptedException e) { }
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.setSize(size2);
+ frame.validate();
+ } } );
+ try { Thread.sleep(duration); } catch (InterruptedException e) { }
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.setSize(size0);
+ frame.validate();
+ } } );
+ try { Thread.sleep(duration); } catch (InterruptedException e) { }
+
+ if( doSnapshot ) {
+ glad.disposeGLEventListener(snapshotGLEL, true /* remove */);
+ }
+ final Animator anim = new Animator(glad);
+ anim.start();
+ try { Thread.sleep(2*duration); } catch (InterruptedException e) { }
+ anim.stop();
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ }
+ try {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.dispose();
+ } } );
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ }
+ }
+
+ private GLCanvas createGLCanvas(final GLCapabilitiesImmutable caps, final Dimension size) {
+ final GLCanvas canvas = new GLCanvas(caps);
+ canvas.setSize(size);
+ canvas.setPreferredSize(size);
+ canvas.setMinimumSize(size);
+ return canvas;
+ }
+
+ private class SnapshotGLELAWT implements GLEventListener {
+ final TextRendererGLEL textRendererGLEL;
+ final AWTGLReadBufferUtil glReadBufferUtil;
+ boolean defAutoSwapMode;
+ boolean swapBuffersBeforeRead;
+ int i;
+
+ SnapshotGLELAWT(final TextRendererGLEL textRendererGLEL, final AWTGLReadBufferUtil glReadBufferUtil) {
+ this.textRendererGLEL = textRendererGLEL;
+ this.glReadBufferUtil = glReadBufferUtil;
+ this.defAutoSwapMode = true;
+ this.swapBuffersBeforeRead = false;
+ i = 0;
+ }
+
+ @Override
+ public void init(GLAutoDrawable drawable) {
+ defAutoSwapMode = drawable.getAutoSwapBufferMode();
+ swapBuffersBeforeRead = GLDrawableUtil.swapBuffersBeforeRead(drawable.getChosenGLCapabilities());
+ drawable.setAutoSwapBufferMode( !swapBuffersBeforeRead );
+ }
+ @Override
+ public void dispose(GLAutoDrawable drawable) {
+ drawable.setAutoSwapBufferMode( defAutoSwapMode );
+ }
+ @Override
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { }
+ @Override
+ public void display(GLAutoDrawable drawable) {
+ snapshot(i++, drawable.getGL(), TextureIO.PNG, null);
+ }
+ public void snapshot(int sn, GL gl, String fileSuffix, String destPath) {
+ final GLDrawable drawable = gl.getContext().getGLReadDrawable();
+ final String postSNDetail = String.format("awt-usr%03d", textRendererGLEL.userCounter);
+ final String filenameAWT = getSnapshotFilename(sn, postSNDetail,
+ drawable.getChosenGLCapabilities(), drawable.getWidth(), drawable.getHeight(),
+ glReadBufferUtil.hasAlpha(), fileSuffix, destPath);
+ if( swapBuffersBeforeRead ) {
+ drawable.swapBuffers();
+ // Just to test whether we use the right buffer,
+ // i.e. back-buffer shall no more be required ..
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT);
+ } else {
+ gl.glFinish(); // just make sure rendering finished ..
+ }
+
+ final boolean awtOrientation = drawable.isGLOriented();
+ System.err.println(Thread.currentThread().getName()+": ** screenshot: awtOrient/v-flip "+awtOrientation+", swapBuffersBeforeRead "+swapBuffersBeforeRead+", "+filenameAWT);
+
+ final BufferedImage image = glReadBufferUtil.readPixelsToBufferedImage(gl, awtOrientation);
+ final File fout = new File(filenameAWT);
+ try {
+ ImageIO.write(image, "png", fout);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ /**
+ final String filenameJGL = getSnapshotFilename(sn, "jgl",
+ drawable.getChosenGLCapabilities(), drawable.getWidth(), drawable.getHeight(),
+ glReadBufferUtil.hasAlpha(), fileSuffix, destPath);
+ glReadBufferUtil.write(new File(filenameJGL));
+ */
+ }
+ };
+
+ static GLCapabilitiesImmutable caps = null;
+ static boolean doSnapshot = true;
+ static boolean keyFrame = false;
+
+ public static void main(String[] args) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ duration = MiscUtils.atol(args[i], duration);
+ } else if(args[i].equals("-keyFrame")) {
+ keyFrame = true;
+ } else if(args[i].equals("-noSnapshot")) {
+ doSnapshot = false;
+ }
+ }
+ org.junit.runner.JUnitCore.main(TestGLReadBuffer01GLCanvasAWT.class.getName());
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLReadBuffer01GLJPanelAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLReadBuffer01GLJPanelAWT.java
index f3b5e42de..e93356d50 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLReadBuffer01GLJPanelAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLReadBuffer01GLJPanelAWT.java
@@ -68,6 +68,7 @@ public class TestGLReadBuffer01GLJPanelAWT extends GLReadBuffer00Base {
GLProfile.initSingleton();
}
+ @Override
public void test(final GLCapabilitiesImmutable caps, final boolean useSwingDoubleBuffer, final boolean skipGLOrientationVerticalFlip) {
final AWTGLReadBufferUtil awtGLReadBufferUtil = new AWTGLReadBufferUtil(caps.getGLProfile(), false);
final JFrame frame = new JFrame();
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLReadBuffer01GLWindowNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLReadBuffer01GLWindowNEWT.java
index 9bc47f9e0..a170d9b14 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLReadBuffer01GLWindowNEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLReadBuffer01GLWindowNEWT.java
@@ -61,6 +61,7 @@ public class TestGLReadBuffer01GLWindowNEWT extends GLReadBuffer00Base {
GLProfile.initSingleton();
}
+ @Override
public void test(final GLCapabilitiesImmutable caps, final boolean useSwingDoubleBuffer, final boolean skipGLOrientationVerticalFlip) {
if( skipGLOrientationVerticalFlip || useSwingDoubleBuffer ) {
return; // NOP