diff options
Diffstat (limited to 'src/test/com')
9 files changed, 143 insertions, 36 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 81be58aa5..22c1f62dd 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 @@ -84,7 +84,7 @@ public class TestBug461FBOSupersamplingSwingAWT extends UITestCase implements GL /* @Override */ public void init(GLAutoDrawable drawable) { - awtGLReadBufferUtil = new AWTGLReadBufferUtil(false); + awtGLReadBufferUtil = new AWTGLReadBufferUtil(drawable.getGLProfile(), false); } /* @Override */ 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 3f593e908..dc1d528f8 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((ByteBuffer)rbu.getPixelBuffer(), glad.getWidth(), glad.getHeight(), 3); + testFlipped((ByteBuffer)rbu.getPixelBuffer().buffer, glad.getWidth(), glad.getHeight(), 3); glad.destroy(); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelsAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelsAWT.java index e4c0f47a4..0b0030d99 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelsAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelsAWT.java @@ -30,7 +30,10 @@ package com.jogamp.opengl.test.junit.jogl.demos.es2.awt; import java.awt.AWTException; import java.awt.BorderLayout; -import java.awt.Dimension; +import java.awt.Component; +import java.awt.Container; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; import java.lang.reflect.InvocationTargetException; import java.nio.FloatBuffer; @@ -39,8 +42,10 @@ import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLCapabilitiesImmutable; import javax.media.opengl.GLProfile; import javax.media.opengl.awt.GLJPanel; +import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JPanel; +import javax.swing.JTextField; import javax.swing.SwingUtilities; import org.junit.AfterClass; @@ -54,11 +59,15 @@ import com.jogamp.opengl.test.junit.util.MiscUtils; import com.jogamp.opengl.test.junit.util.QuitAdapter; import com.jogamp.opengl.test.junit.util.UITestCase; import com.jogamp.opengl.util.FPSAnimator; +import com.jogamp.opengl.util.awt.AWTGLPixelBuffer.AWTGLPixelBufferProvider; +import com.jogamp.opengl.util.awt.AWTGLPixelBuffer.SingleAWTGLPixelBufferProvider; public class TestGearsES2GLJPanelsAWT extends UITestCase { static int demoCount = 4; - static boolean opaque = false; // always faster and flicker-less w/o opaque, i.e. w/ alpha channel due to JComponent _paintImmediately(..) - static float alpha = 0.3f; + static boolean jOpaque = false; // flicker-less w/o opaque, opaque leads to overdraw w/ mixed clipRects -> flicker - due to JComponent _paintImmediately(..) (?) + static boolean glOpaque = true; // can be either .. + static float glAlpha = 0.3f; + static boolean jZOrder = false; static GLProfile glp; static boolean shallUsePBuffer = false; static boolean shallUseBitmap = false; @@ -66,7 +75,15 @@ public class TestGearsES2GLJPanelsAWT extends UITestCase { static int swapInterval = 0; static boolean useAnimator = true; static boolean manualTest = false; + static boolean useSingleBuffer = true; // default + /** + * Even though GLJPanel uses a SingleAWTGLPixelBufferProvider per default, + * we like to initialize it's size to a common maximum to ensure + * only one {@link AWTGLPixelBuffer} gets allocated. + */ + static SingleAWTGLPixelBufferProvider singleAWTGLPixelBufferProvider; + @BeforeClass public static void initClass() { if(GLProfile.isAvailable(GLProfile.GL2)) { @@ -75,21 +92,33 @@ public class TestGearsES2GLJPanelsAWT extends UITestCase { } else { setTestSupported(false); } + + if( useSingleBuffer ) { + singleAWTGLPixelBufferProvider = new SingleAWTGLPixelBufferProvider( glp.isGL2GL3() /* allowRowStride */); + singleAWTGLPixelBufferProvider.initSingleton(600, 600, 1, true); + } else { + singleAWTGLPixelBufferProvider = null; + } } @AfterClass public static void releaseClass() { } - private void addPanel(GLCapabilitiesImmutable caps, GLAnimatorControl anim, final JFrame frame, boolean opaque, int x, int y, int w, int h, FloatBuffer color, float[] clearColor) + final static boolean useInterPanel = true; + + /** Adds new JPanel to frame's content pane at index 0 */ + private JComponent addPanel(GLCapabilitiesImmutable caps, GLAnimatorControl anim, final JFrame frame, boolean opaque, int x, int y, int w, int h, FloatBuffer color, float[] clearColor) throws InterruptedException, InvocationTargetException { final GLJPanel canvas = new GLJPanel(caps); + if( useSingleBuffer ) { + canvas.setPixelBufferProvider( singleAWTGLPixelBufferProvider ); + } canvas.setOpaque(opaque); - final Dimension glc_sz = new Dimension(w, h); - canvas.setMinimumSize(glc_sz); - canvas.setPreferredSize(glc_sz); - canvas.setSize(glc_sz); + if ( !useInterPanel ) { + canvas.setBounds(x, y, w, h); + } GearsES2 demo = new GearsES2(swapInterval); demo.setIgnoreFocus(true); demo.setGearsColors(color, color, color); @@ -99,31 +128,62 @@ public class TestGearsES2GLJPanelsAWT extends UITestCase { anim.add(canvas); } - final JPanel panel = new JPanel(new BorderLayout()); - panel.setBounds(x, y, w, h); - panel.setOpaque(opaque); + final JPanel panel; + final JTextField text; + if ( useInterPanel ) { + panel = new JPanel(new BorderLayout()); + panel.setBounds(x, y, w, h); + panel.setOpaque(opaque); + text = new JTextField(x+"/"+y+" "+w+"x"+h); + text.setOpaque(true); + } else { + panel = null; + text = null; + } SwingUtilities.invokeAndWait(new Runnable() { public void run() { - panel.add(canvas, BorderLayout.CENTER); - frame.getContentPane().add(panel); + if ( useInterPanel ) { + panel.add(text, BorderLayout.NORTH); + panel.add(canvas, BorderLayout.CENTER); + frame.getContentPane().add(panel, 0); + } else { + frame.getContentPane().add(canvas, 0); + } } } ) ; + return useInterPanel ? panel : canvas; } public static final FloatBuffer red = Buffers.newDirectFloatBuffer( new float[] { 1.0f, 0.0f, 0.0f, 1.0f } ); public static final FloatBuffer green = Buffers.newDirectFloatBuffer( new float[] { 0.0f, 1.0f, 0.0f, 1.0f } ); public static final FloatBuffer blue = Buffers.newDirectFloatBuffer( new float[] { 0.0f, 0.0f, 1.0f, 1.0f } ); public static final FloatBuffer yellow = Buffers.newDirectFloatBuffer( new float[] { 1.0f, 1.0f, 0.0f, 1.0f } ); + public static final FloatBuffer grey = Buffers.newDirectFloatBuffer( new float[] { 0.5f, 0.5f, 0.5f, 1.0f } ); public static final float grayf = 0.3f; - public static final float[] redish = new float[] { grayf, 0.0f, 0.0f, alpha }; - public static final float[] greenish = new float[] { 0.0f, grayf, 0.0f, alpha }; - public static final float[] blueish = new float[] { 0.0f, 0.0f, grayf, alpha }; - public static final float[] yellowish = new float[] { grayf, grayf, 0.0f, alpha }; + public static final float[] redish = new float[] { grayf, 0.0f, 0.0f, glAlpha }; + public static final float[] greenish = new float[] { 0.0f, grayf, 0.0f, glAlpha }; + public static final float[] blueish = new float[] { 0.0f, 0.0f, grayf, glAlpha }; + public static final float[] yellowish = new float[] { grayf, grayf, 0.0f, glAlpha }; + public static final float[] greyish = new float[] { grayf, grayf, grayf, glAlpha }; + + protected void relayout(Container cont, float oW, float oH) { + final int count = cont.getComponentCount(); + final int nW = cont.getWidth(); + final int nH = cont.getHeight(); + for(int i = 0 ; i < count; i++ ) { + final Component comp = cont.getComponent(i); + float fx = comp.getX() / oW; + float fy = comp.getY() / oH; + float fw = comp.getWidth() / oW; + float fh = comp.getHeight() / oH; + comp.setBounds( (int)(fx * nW), (int)(fy * nH), (int)(fw * nW), (int)(fh * nH) ); + } + } protected void runTestGL(GLCapabilities caps) throws AWTException, InterruptedException, InvocationTargetException { - if( !opaque ) { + if( !glOpaque ) { caps.setAlphaBits(caps.getRedBits()); } @@ -137,22 +197,46 @@ public class TestGearsES2GLJPanelsAWT extends UITestCase { frame.getContentPane().setLayout(null); } } ); + final float[] oldSize = new float[] { 600f, 600f }; + + frame.addComponentListener(new ComponentAdapter() { + @Override + public void componentResized(ComponentEvent e) { + final int count = frame.getComponentCount(); + for(int i = 0 ; i < count; i++ ) { + relayout(frame.getContentPane(), oldSize[0], oldSize[1]); + } + frame.getContentPane().invalidate(); + frame.getContentPane().validate(); + // frame.pack(); + oldSize[0] = frame.getContentPane().getWidth(); + oldSize[1] = frame.getContentPane().getHeight(); + } + } ) ; + if( demoCount > 0 ) { - addPanel(caps, animator, frame, opaque, 50, 50, 300, 300, red, redish); // A + addPanel(caps, animator, frame, jOpaque, 50, 50, 300, 300, red, redish); // A } if( demoCount > 1 ) { - addPanel(caps, animator, frame, opaque, 200, 0, 150, 150, green, greenish); // B + addPanel(caps, animator, frame, jOpaque, 0, 250, 300, 300, blue, blueish); // C } if( demoCount > 2 ) { - addPanel(caps, animator, frame, opaque, 0, 250, 300, 300, blue, blueish); // C + addPanel(caps, animator, frame, jOpaque, 300, 0, 150, 150, green, greenish); // B } if( demoCount > 3 ) { - addPanel(caps, animator, frame, opaque, 300, 300, 100, 100, yellow, yellowish); // D + addPanel(caps, animator, frame, jOpaque, 300, 300, 100, 100, yellow, yellowish); // D + } + if( jZOrder ) { + final Container cont = frame.getContentPane(); + final int count = cont.getComponentCount(); + for(int i = 0 ; i < count; i++ ) { + cont.setComponentZOrder(cont.getComponent(i), count - 1 - i); + } } SwingUtilities.invokeAndWait(new Runnable() { public void run() { - frame.setSize(600, 600); + frame.setSize((int)oldSize[0], (int)oldSize[1]); frame.getContentPane().validate(); // frame.pack(); frame.setVisible(true); @@ -284,11 +368,20 @@ public class TestGearsES2GLJPanelsAWT extends UITestCase { swapInterval = MiscUtils.atoi(args[i], swapInterval); } else if(args[i].equals("-msaa")) { useMSAA = true; - } else if(args[i].equals("-opaque")) { - opaque = true; + } else if(args[i].equals("-jOpaque")) { + i++; + jOpaque = MiscUtils.atob(args[i], jOpaque); + } else if(args[i].equals("-glOpaque")) { + i++; + glOpaque = MiscUtils.atob(args[i], glOpaque); } else if(args[i].equals("-alpha")) { i++; - alpha = MiscUtils.atof(args[i], alpha); + glAlpha = MiscUtils.atof(args[i], glAlpha); + } else if(args[i].equals("-singleBuffer")) { + i++; + useSingleBuffer = MiscUtils.atob(args[i], useSingleBuffer); + } else if(args[i].equals("-jZOrder")) { + jZOrder = true; } else if(args[i].equals("-noanim")) { useAnimator = false; } else if(args[i].equals("-pbuffer")) { @@ -303,14 +396,16 @@ public class TestGearsES2GLJPanelsAWT extends UITestCase { } } System.err.println("swapInterval "+swapInterval); - System.err.println("opaque "+opaque); - System.err.println("alpha "+alpha); + System.err.println("opaque gl "+glOpaque+", java/gljpanel "+jOpaque); + System.err.println("alpha "+glAlpha); + System.err.println("jZOrder "+jZOrder); System.err.println("demos "+demoCount); 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); + System.err.println("useSingleBuffer "+useSingleBuffer); org.junit.runner.JUnitCore.main(TestGearsES2GLJPanelsAWT.class.getName()); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestJPEGImage01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestJPEGImage01NEWT.java index 71a63a701..bf8323e88 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestJPEGImage01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestJPEGImage01NEWT.java @@ -21,6 +21,7 @@ import com.jogamp.opengl.test.junit.util.MiscUtils; import com.jogamp.opengl.test.junit.util.QuitAdapter; import com.jogamp.opengl.test.junit.util.UITestCase; import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.util.GLPixelBuffer.GLPixelAttributes; import com.jogamp.opengl.util.GLReadBufferUtil; import com.jogamp.opengl.util.texture.TextureData; import com.jogamp.opengl.util.texture.TextureIO; @@ -49,7 +50,7 @@ public class TestJPEGImage01NEWT extends UITestCase { image.getWidth(), image.getHeight(), 0, - new TextureData.PixelAttributes(image.getGLFormat(), image.getGLType()), + new GLPixelAttributes(image.getGLFormat(), image.getGLType()), false /* mipmap */, false /* compressed */, false /* must flip-vert */, diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestJPEGJoglAWTBenchmarkNewtAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestJPEGJoglAWTBenchmarkNewtAWT.java index 681667362..1e27f5dae 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestJPEGJoglAWTBenchmarkNewtAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestJPEGJoglAWTBenchmarkNewtAWT.java @@ -36,6 +36,7 @@ import javax.imageio.ImageIO; import javax.media.opengl.GL; import javax.media.opengl.GLProfile; +import com.jogamp.opengl.util.GLPixelBuffer.GLPixelAttributes; import com.jogamp.opengl.util.texture.TextureData; import com.jogamp.opengl.util.texture.awt.AWTTextureData; import com.jogamp.opengl.util.texture.spi.JPEGImage; @@ -68,7 +69,7 @@ public class TestJPEGJoglAWTBenchmarkNewtAWT extends UITestCase { image.getWidth(), image.getHeight(), 0, - new TextureData.PixelAttributes(image.getGLFormat(), image.getGLType()), + new GLPixelAttributes(image.getGLFormat(), image.getGLType()), false /* mipmap */, false /* compressed */, false /* must flip-vert */, @@ -96,7 +97,7 @@ public class TestJPEGJoglAWTBenchmarkNewtAWT extends UITestCase { image.getWidth(), image.getHeight(), 0, - new TextureData.PixelAttributes(image.getGLFormat(), image.getGLType()), + new GLPixelAttributes(image.getGLFormat(), image.getGLType()), false /* mipmap */, false /* compressed */, false /* must flip-vert */, diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestJPEGJoglAWTCompareNewtAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestJPEGJoglAWTCompareNewtAWT.java index 5d2969815..0df275652 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestJPEGJoglAWTCompareNewtAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestJPEGJoglAWTCompareNewtAWT.java @@ -49,6 +49,7 @@ import com.jogamp.opengl.util.texture.TextureIO; import com.jogamp.opengl.util.texture.awt.AWTTextureData; import com.jogamp.opengl.util.texture.spi.JPEGImage; import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.util.GLPixelBuffer.GLPixelAttributes; import com.jogamp.opengl.util.GLReadBufferUtil; import java.awt.image.BufferedImage; @@ -112,7 +113,7 @@ public class TestJPEGJoglAWTCompareNewtAWT extends UITestCase { image.getWidth(), image.getHeight(), 0, - new TextureData.PixelAttributes(image.getGLFormat(), image.getGLType()), + new GLPixelAttributes(image.getGLFormat(), image.getGLType()), false /* mipmap */, false /* compressed */, false /* must flip-vert */, 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 5b2876744..c33384611 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 @@ -122,7 +122,7 @@ public class TestTexture01AWT extends UITestCase { @Test public void test1() throws InterruptedException { - final AWTGLReadBufferUtil awtGLReadBufferUtil = new AWTGLReadBufferUtil(false); + final AWTGLReadBufferUtil awtGLReadBufferUtil = new AWTGLReadBufferUtil(caps.getGLProfile(), false); final Frame frame0 = new Frame("GL -> AWT"); final Canvas canvas = new Canvas(); frame0.add(canvas); 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 index bdc8934fc..5948f5971 100644 --- 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 @@ -77,7 +77,7 @@ public class TestTexture02AWT extends UITestCase { @Test public void test1() throws InterruptedException { - final AWTGLReadBufferUtil awtGLReadBufferUtil = new AWTGLReadBufferUtil(false); + final AWTGLReadBufferUtil awtGLReadBufferUtil = new AWTGLReadBufferUtil(caps.getGLProfile(), false); final Frame frame0 = new Frame("GL -> AWT"); final ImageIcon imageIcon = new ImageIcon(); final JLabel imageLabel = new JLabel(imageIcon); diff --git a/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java b/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java index d17914939..d6e9743e0 100644 --- a/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java +++ b/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java @@ -33,6 +33,15 @@ import java.lang.reflect.*; import java.nio.FloatBuffer; public class MiscUtils { + public static boolean atob(String str, boolean def) { + try { + return Boolean.parseBoolean(str); + } catch (Exception ex) { + ex.printStackTrace(); + } + return def; + } + public static int atoi(String str, int def) { try { return Integer.parseInt(str); |