summaryrefslogtreecommitdiffstats
path: root/src/test/com
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-04-27 08:47:24 +0200
committerSven Gothel <[email protected]>2013-04-27 08:47:24 +0200
commit4d35eaa766071fd8dedab8b6e2ee53710831c567 (patch)
treecbf22cde01ea2ead789684f3098be44fb1b08c79 /src/test/com
parent587ec1437ed762ed8cdfcbf27f940ab83813f4a5 (diff)
GLReadBufferUtil: Utilizing PixelBufferProvider; Adding AWTGLReadBufferUtil adding BufferedImage support; Demonstrating w/ unit tests.
Diffstat (limited to 'src/test/com')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug461FBOSupersamplingSwingAWT.java31
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/caps/TestBug605FlippedImageNEWT.java2
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTexture01AWT.java85
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTexture02AWT.java165
4 files changed, 263 insertions, 20 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug461FBOSupersamplingSwingAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug461FBOSupersamplingSwingAWT.java
index 089520658..81be58aa5 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug461FBOSupersamplingSwingAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug461FBOSupersamplingSwingAWT.java
@@ -28,6 +28,7 @@
package com.jogamp.opengl.test.junit.jogl.awt;
+import java.awt.Container;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
@@ -49,7 +50,9 @@ import javax.swing.JLabel;
import org.junit.Assert;
import org.junit.Test;
+import com.jogamp.opengl.test.junit.util.MiscUtils;
import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.util.awt.AWTGLReadBufferUtil;
/**
* Tests for bug 461, a failure of GLDrawableFactory.createGLPbuffer() on Windows
@@ -58,8 +61,10 @@ import com.jogamp.opengl.test.junit.util.UITestCase;
* @author Wade Walker (from code sample provided by Owen Dimond)
*/
public class TestBug461FBOSupersamplingSwingAWT extends UITestCase implements GLEventListener {
+ static long durationPerTest = 500;
JFrame jframe;
GLOffscreenAutoDrawable offScreenBuffer;
+ AWTGLReadBufferUtil awtGLReadBufferUtil;
private void render(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
@@ -78,7 +83,8 @@ public class TestBug461FBOSupersamplingSwingAWT extends UITestCase implements GL
}
/* @Override */
- public void init(GLAutoDrawable drawable) {
+ public void init(GLAutoDrawable drawable) {
+ awtGLReadBufferUtil = new AWTGLReadBufferUtil(false);
}
/* @Override */
@@ -88,14 +94,18 @@ public class TestBug461FBOSupersamplingSwingAWT extends UITestCase implements GL
/* @Override */
public void display(GLAutoDrawable drawable) {
render(offScreenBuffer);
- BufferedImage outputImage = com.jogamp.opengl.util.awt.Screenshot.readToBufferedImage(200, 200, false);
+ // BufferedImage outputImage = com.jogamp.opengl.util.awt.Screenshot.readToBufferedImage(200, 200, false);
+ BufferedImage outputImage = awtGLReadBufferUtil.readPixelsToBufferedImage(drawable.getGL(), 0, 0, 200, 200, true /* awtOrientation */);
Assert.assertNotNull(outputImage);
ImageIcon imageIcon = new ImageIcon(outputImage);
final JLabel imageLabel = new JLabel(imageIcon);
try {
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
- jframe.getContentPane().add(imageLabel);
+ Container cont = jframe.getContentPane();
+ cont.removeAll();
+ cont.add(imageLabel);
+ cont.validate();
}});
} catch (Exception e) {
e.printStackTrace();
@@ -105,6 +115,7 @@ public class TestBug461FBOSupersamplingSwingAWT extends UITestCase implements GL
/* @Override */
public void dispose(GLAutoDrawable drawable) {
try {
+ awtGLReadBufferUtil.dispose(drawable.getGL());
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
jframe.setVisible(false);
@@ -141,7 +152,8 @@ public class TestBug461FBOSupersamplingSwingAWT extends UITestCase implements GL
glCap.setSampleBuffers(true);
// Without line below, there is an error on Windows.
- glCap.setDoubleBuffered(false);
+ // glCap.setDoubleBuffered(false); // implicit double buffer -> MSAA + FBO
+
// Needed for drop shadows
glCap.setStencilBits(1);
@@ -149,16 +161,25 @@ public class TestBug461FBOSupersamplingSwingAWT extends UITestCase implements GL
offScreenBuffer = fac.createOffscreenAutoDrawable(GLProfile.getDefaultDevice(), glCap, null, 200, 200, null);
Assert.assertNotNull(offScreenBuffer);
offScreenBuffer.addGLEventListener(this);
- offScreenBuffer.display();
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
jframe.setSize( 300, 300);
jframe.setVisible(true);
}});
+ offScreenBuffer.display(); // read from front buffer due to FBO+MSAA -> double-buffer
+ offScreenBuffer.display(); // now we have prev. image in front buffer to be read out
+
+ Thread.sleep(durationPerTest);
+
offScreenBuffer.destroy();
}
public static void main(String args[]) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = MiscUtils.atol(args[++i], durationPerTest);
+ }
+ }
org.junit.runner.JUnitCore.main(TestBug461FBOSupersamplingSwingAWT.class.getName());
}
}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestBug605FlippedImageNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestBug605FlippedImageNEWT.java
index 837d94cb3..3f593e908 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestBug605FlippedImageNEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestBug605FlippedImageNEWT.java
@@ -128,7 +128,7 @@ public class TestBug605FlippedImageNEWT extends UITestCase {
glad.display();
System.err.println("XXX "+glad.getChosenGLCapabilities());
System.err.println("XXX "+glad.getContext().getGLVersion());
- testFlipped(rbu.getPixelBuffer(), glad.getWidth(), glad.getHeight(), 3);
+ testFlipped((ByteBuffer)rbu.getPixelBuffer(), glad.getWidth(), glad.getHeight(), 3);
glad.destroy();
}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTexture01AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTexture01AWT.java
index 8baba68ec..5b2876744 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTexture01AWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTexture01AWT.java
@@ -29,17 +29,25 @@
package com.jogamp.opengl.test.junit.jogl.util.texture;
+import com.jogamp.common.util.awt.AWTEDTExecutor;
import com.jogamp.opengl.test.junit.jogl.demos.gl2.TextureDraw01GL2Listener;
+import com.jogamp.opengl.test.junit.util.MiscUtils;
import com.jogamp.opengl.test.junit.util.UITestCase;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.awt.GLCanvas;
+import javax.swing.ImageIcon;
+import javax.swing.JLabel;
+
+import com.jogamp.opengl.util.awt.AWTGLReadBufferUtil;
import com.jogamp.opengl.util.texture.TextureData;
import com.jogamp.opengl.util.texture.awt.AWTTextureIO;
-import com.jogamp.opengl.util.Animator;
import java.awt.AlphaComposite;
+import java.awt.Canvas;
import java.awt.Color;
import java.awt.Frame;
import java.awt.GradientPaint;
@@ -54,7 +62,14 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+/**
+ * Demonstrates TextureData w/ AWT usage in both directions,
+ * i.e. generating a texture based on an AWT BufferedImage data
+ * as well as reading out GL framebuffer and displaying it
+ * as an BufferedImage.
+ */
public class TestTexture01AWT extends UITestCase {
+ static long durationPerTest = 500;
static GLProfile glp;
static GLCapabilities caps;
BufferedImage textureImage;
@@ -107,37 +122,74 @@ public class TestTexture01AWT extends UITestCase {
@Test
public void test1() throws InterruptedException {
+ final AWTGLReadBufferUtil awtGLReadBufferUtil = new AWTGLReadBufferUtil(false);
+ final Frame frame0 = new Frame("GL -> AWT");
+ final Canvas canvas = new Canvas();
+ frame0.add(canvas);
+
final GLCanvas glCanvas = new GLCanvas(caps);
- final Frame frame = new Frame("Texture Test");
- Assert.assertNotNull(frame);
- frame.add(glCanvas);
+ final Frame frame1 = new Frame("AWT -> Texture");
+ Assert.assertNotNull(frame1);
+ frame1.add(glCanvas);
// create texture
TextureData textureData = AWTTextureIO.newTextureData(caps.getGLProfile(), textureImage, false);
glCanvas.addGLEventListener(new TextureDraw01GL2Listener(textureData));
+ glCanvas.addGLEventListener(new GLEventListener() {
+
+ @Override
+ public void init(GLAutoDrawable drawable) { }
+ @Override
+ public void dispose(GLAutoDrawable drawable) { }
+ @Override
+ public void display(GLAutoDrawable drawable) {
+ BufferedImage outputImage = awtGLReadBufferUtil.readPixelsToBufferedImage(drawable.getGL(), true /* awtOrientation */);
+ ImageIcon imageIcon = new ImageIcon(outputImage);
+ final JLabel imageLabel = new JLabel(imageIcon);
+ try {
+ AWTEDTExecutor.singleton.invoke(true, new Runnable() {
+ public void run() {
+ frame0.removeAll();
+ frame0.add(imageLabel);
+ frame0.validate();
+ }});
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ frame0.setSize(frame1.getWidth(), frame1.getHeight());
+ frame0.setLocation(frame1.getX()+frame1.getWidth()+32, frame0.getY());
+ frame0.validate();
+ }
+ });
- Animator animator = new Animator(glCanvas);
try {
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
- frame.setSize(512, 512);
- frame.setVisible(true);
+ frame1.setSize(256, 256);
+ frame1.setLocation(0, 0);
+ frame1.setVisible(true);
+ frame0.setSize(frame1.getWidth(), frame1.getHeight());
+ frame0.setLocation(frame1.getX()+frame1.getWidth()+32, frame0.getY());
+ frame0.setVisible(true);
}});
} catch( Throwable throwable ) {
throwable.printStackTrace();
Assume.assumeNoException( throwable );
}
- animator.start();
+
+ Thread.sleep(durationPerTest);
- Thread.sleep(500); // 500 ms
-
- animator.stop();
try {
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
- frame.setVisible(false);
- frame.remove(glCanvas);
- frame.dispose();
+ frame0.setVisible(false);
+ frame0.dispose();
+ frame1.setVisible(false);
+ frame1.dispose();
}});
} catch( Throwable throwable ) {
throwable.printStackTrace();
@@ -146,6 +198,11 @@ public class TestTexture01AWT extends UITestCase {
}
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 = TestTexture01AWT.class.getName();
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
tstname,
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTexture02AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTexture02AWT.java
new file mode 100644
index 000000000..bdc8934fc
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTexture02AWT.java
@@ -0,0 +1,165 @@
+/**
+ * Copyright 2010 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.util.texture;
+
+
+import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
+import com.jogamp.opengl.test.junit.util.MiscUtils;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.awt.GLCanvas;
+import javax.swing.ImageIcon;
+import javax.swing.JLabel;
+
+import com.jogamp.opengl.util.FPSAnimator;
+import com.jogamp.opengl.util.awt.AWTGLReadBufferUtil;
+
+import java.awt.Frame;
+import java.awt.image.BufferedImage;
+
+import java.io.IOException;
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Demonstrates TextureData w/ AWT usage,
+ * i.e. reading out an animated GL framebuffer and displaying it
+ * as an BufferedImage.
+ */
+public class TestTexture02AWT extends UITestCase {
+ static long durationPerTest = 500;
+ static GLProfile glp;
+ static GLCapabilities caps;
+
+ @BeforeClass
+ public static void initClass() {
+ if(!GLProfile.isAvailable(GLProfile.GL2ES2)) {
+ UITestCase.setTestSupported(false);
+ return;
+ }
+ glp = GLProfile.getGL2ES2();
+ Assert.assertNotNull(glp);
+ caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ }
+
+ @Test
+ public void test1() throws InterruptedException {
+ final AWTGLReadBufferUtil awtGLReadBufferUtil = new AWTGLReadBufferUtil(false);
+ final Frame frame0 = new Frame("GL -> AWT");
+ final ImageIcon imageIcon = new ImageIcon();
+ final JLabel imageLabel = new JLabel(imageIcon);
+ frame0.add(imageLabel);
+
+ final GLCanvas glCanvas = new GLCanvas(caps);
+ final Frame frame1 = new Frame("GearsES2");
+ Assert.assertNotNull(frame1);
+ frame1.add(glCanvas);
+
+ glCanvas.addGLEventListener(new GearsES2(1));
+ glCanvas.addGLEventListener(new GLEventListener() {
+ @Override
+ public void init(GLAutoDrawable drawable) { }
+ @Override
+ public void dispose(GLAutoDrawable drawable) { }
+ @Override
+ public void display(GLAutoDrawable drawable) {
+ BufferedImage outputImage = awtGLReadBufferUtil.readPixelsToBufferedImage(drawable.getGL(), true /* awtOrientation */);
+ imageIcon.setImage(outputImage);
+ imageLabel.repaint();
+ }
+
+ @Override
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ frame0.setSize(frame1.getWidth(), frame1.getHeight());
+ frame0.setLocation(frame1.getX()+frame1.getWidth()+32, frame0.getY());
+ frame0.validate();
+ }
+ });
+
+ try {
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame1.setSize(256, 256);
+ frame1.setLocation(0, 0);
+ frame1.setVisible(true);
+ frame0.setSize(frame1.getWidth(), frame1.getHeight());
+ frame0.setLocation(frame1.getX()+frame1.getWidth()+32, frame0.getY());
+ frame0.setVisible(true);
+ }});
+ } catch( Throwable throwable ) {
+ throwable.printStackTrace();
+ Assume.assumeNoException( throwable );
+ }
+ FPSAnimator animator = new FPSAnimator(glCanvas, 15); // 15fps
+ animator.start();
+
+ Thread.sleep(durationPerTest);
+
+ animator.stop();
+ try {
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame0.setVisible(false);
+ frame0.dispose();
+ frame1.setVisible(false);
+ frame1.dispose();
+ }});
+ } catch( Throwable throwable ) {
+ throwable.printStackTrace();
+ Assume.assumeNoException( throwable );
+ }
+ }
+
+ 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 = TestTexture02AWT.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" } );
+ }
+}