From 701e1e8da5e7d31ffdf166ead77250e4d007f86f Mon Sep 17 00:00:00 2001
From: Sven Gothel
+ * Analyzes behavior of reported bugs
+ *
+ *
+ *
+ * See {@link GLReadBuffer00Base} for related bugs and further details. + *
+ */ +public abstract class GLReadBuffer00BaseAWT extends GLReadBuffer00Base { + + protected class SnapshotGLELAWT implements GLEventListener { + final TextRendererGLEL textRendererGLEL; + final AWTGLReadBufferUtil glReadBufferUtil; + final boolean skipGLOrientationVerticalFlip; + boolean defAutoSwapMode; + boolean swapBuffersBeforeRead; + int i; + + SnapshotGLELAWT(final TextRendererGLEL textRendererGLEL, final AWTGLReadBufferUtil glReadBufferUtil, final boolean skipGLOrientationVerticalFlip) { + this.textRendererGLEL = textRendererGLEL; + this.glReadBufferUtil = glReadBufferUtil; + this.skipGLOrientationVerticalFlip = skipGLOrientationVerticalFlip; + this.defAutoSwapMode = true; + this.swapBuffersBeforeRead = false; + i = 0; + } + + @Override + public void init(final GLAutoDrawable drawable) { + defAutoSwapMode = drawable.getAutoSwapBufferMode(); + swapBuffersBeforeRead = GLDrawableUtil.swapBuffersBeforeRead(drawable.getChosenGLCapabilities()); + drawable.setAutoSwapBufferMode( !swapBuffersBeforeRead ); + } + @Override + public void dispose(final GLAutoDrawable drawable) { + drawable.setAutoSwapBufferMode( defAutoSwapMode ); + } + @Override + public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { } + @Override + public void display(final GLAutoDrawable drawable) { + snapshot(i++, drawable.getGL(), TextureIO.PNG, null); + } + public void snapshot(final int sn, final GL gl, final String fileSuffix, final 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.getSurfaceWidth(), drawable.getSurfaceHeight(), + 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() && skipGLOrientationVerticalFlip ); + 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 (final 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)); + */ + } + }; + +} 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 index 2b6c84bf3..b2291e5f5 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLReadBuffer01GLCanvasAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLReadBuffer01GLCanvasAWT.java @@ -30,16 +30,8 @@ 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; @@ -50,17 +42,20 @@ 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.jogl.demos.es2.MultisampleDemoES2; 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 + * Test synchronous GLAutoDrawable display, swap-buffer and read-pixels with AWT GLCanvas + * including non-MSAA and MSAA framebuffer. + *+ * See {@link GLReadBuffer00Base} for related bugs and further details. + *
*/ @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestGLReadBuffer01GLCanvasAWT extends GLReadBuffer00Base { +public class TestGLReadBuffer01GLCanvasAWT extends GLReadBuffer00BaseAWT { @BeforeClass public static void initClass() { @@ -77,7 +72,7 @@ public class TestGLReadBuffer01GLCanvasAWT extends GLReadBuffer00Base { 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; + final SnapshotGLELAWT snapshotGLEL = doSnapshot ? new SnapshotGLELAWT(textRendererGLEL, awtGLReadBufferUtil, false) : null; try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { @@ -88,9 +83,17 @@ public class TestGLReadBuffer01GLCanvasAWT extends GLReadBuffer00Base { // panel.setDoubleBuffered(useSwingDoubleBuffer); // frame.getContentPane().add(panel); - final GearsES2 gears = new GearsES2(1); - gears.setVerbose(false); - glad.addGLEventListener(gears); + { + final GearsES2 gears = new GearsES2(1); + gears.setVerbose(false); + glad.addGLEventListener(gears); + } + { + final MultisampleDemoES2 demo = new MultisampleDemoES2(caps.getSampleBuffers()); + demo.setClearBuffers(false);; + glad.addGLEventListener(demo); + } + glad.addGLEventListener(textRendererGLEL); if( doSnapshot ) { glad.addGLEventListener(snapshotGLEL); @@ -166,71 +169,6 @@ public class TestGLReadBuffer01GLCanvasAWT extends GLReadBuffer00Base { 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(final GLAutoDrawable drawable) { - defAutoSwapMode = drawable.getAutoSwapBufferMode(); - swapBuffersBeforeRead = GLDrawableUtil.swapBuffersBeforeRead(drawable.getChosenGLCapabilities()); - drawable.setAutoSwapBufferMode( !swapBuffersBeforeRead ); - } - @Override - public void dispose(final GLAutoDrawable drawable) { - drawable.setAutoSwapBufferMode( defAutoSwapMode ); - } - @Override - public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { } - @Override - public void display(final GLAutoDrawable drawable) { - snapshot(i++, drawable.getGL(), TextureIO.PNG, null); - } - public void snapshot(final int sn, final GL gl, final String fileSuffix, final 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.getSurfaceWidth(), drawable.getSurfaceHeight(), - 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 (final 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; 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 7f5755fc7..e862e46e2 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 @@ -29,16 +29,8 @@ package com.jogamp.opengl.test.junit.jogl.acore; import java.awt.BorderLayout; import java.awt.Dimension; -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.GLJPanel; import javax.swing.JFrame; @@ -51,17 +43,20 @@ 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.jogl.demos.es2.MultisampleDemoES2; 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 + * Test synchronous GLAutoDrawable display, swap-buffer and read-pixels with AWT GLJPanel + * including non-MSAA and MSAA framebuffer. + *+ * See {@link GLReadBuffer00Base} for related bugs and further details. + *
*/ @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestGLReadBuffer01GLJPanelAWT extends GLReadBuffer00Base { +public class TestGLReadBuffer01GLJPanelAWT extends GLReadBuffer00BaseAWT { @BeforeClass public static void initClass() { @@ -85,10 +80,17 @@ public class TestGLReadBuffer01GLJPanelAWT extends GLReadBuffer00Base { panel.setDoubleBuffered(useSwingDoubleBuffer); frame.getContentPane().add(panel); - final GearsES2 gears = new GearsES2(1); - gears.setFlipVerticalInGLOrientation(skipGLOrientationVerticalFlip); - gears.setVerbose(false); - glad.addGLEventListener(gears); + { + final GearsES2 gears = new GearsES2(1); + gears.setFlipVerticalInGLOrientation(skipGLOrientationVerticalFlip); + gears.setVerbose(false); + glad.addGLEventListener(gears); + } + { + final MultisampleDemoES2 demo = new MultisampleDemoES2(caps.getSampleBuffers()); + demo.setClearBuffers(false);; + glad.addGLEventListener(demo); + } textRendererGLEL.setFlipVerticalInGLOrientation(skipGLOrientationVerticalFlip); glad.addGLEventListener(textRendererGLEL); if( doSnapshot ) { @@ -166,73 +168,6 @@ public class TestGLReadBuffer01GLJPanelAWT extends GLReadBuffer00Base { return canvas; } - private class SnapshotGLELAWT implements GLEventListener { - final TextRendererGLEL textRendererGLEL; - final AWTGLReadBufferUtil glReadBufferUtil; - final boolean skipGLOrientationVerticalFlip; - boolean defAutoSwapMode; - boolean swapBuffersBeforeRead; - int i; - - SnapshotGLELAWT(final TextRendererGLEL textRendererGLEL, final AWTGLReadBufferUtil glReadBufferUtil, final boolean skipGLOrientationVerticalFlip) { - this.textRendererGLEL = textRendererGLEL; - this.glReadBufferUtil = glReadBufferUtil; - this.skipGLOrientationVerticalFlip = skipGLOrientationVerticalFlip; - this.defAutoSwapMode = true; - this.swapBuffersBeforeRead = false; - i = 0; - } - - @Override - public void init(final GLAutoDrawable drawable) { - defAutoSwapMode = drawable.getAutoSwapBufferMode(); - swapBuffersBeforeRead = GLDrawableUtil.swapBuffersBeforeRead(drawable.getChosenGLCapabilities()); - drawable.setAutoSwapBufferMode( !swapBuffersBeforeRead ); - } - @Override - public void dispose(final GLAutoDrawable drawable) { - drawable.setAutoSwapBufferMode( defAutoSwapMode ); - } - @Override - public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { } - @Override - public void display(final GLAutoDrawable drawable) { - snapshot(i++, drawable.getGL(), TextureIO.PNG, null); - } - public void snapshot(final int sn, final GL gl, final String fileSuffix, final 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.getSurfaceWidth(), drawable.getSurfaceHeight(), - 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() && skipGLOrientationVerticalFlip ); - 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 (final 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; 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 8e0e6bfb9..57a571ba9 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 @@ -44,6 +44,7 @@ import org.junit.runners.MethodSorters; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; +import com.jogamp.opengl.test.junit.jogl.demos.es2.MultisampleDemoES2; import com.jogamp.opengl.test.junit.util.MiscUtils; import com.jogamp.opengl.util.Animator; import com.jogamp.opengl.util.GLDrawableUtil; @@ -51,7 +52,11 @@ import com.jogamp.opengl.util.GLReadBufferUtil; import com.jogamp.opengl.util.texture.TextureIO; /** - * Multiple GLJPanels in a JFrame + * Test synchronous GLAutoDrawable display, swap-buffer and read-pixels with NEWT + * including non-MSAA and MSAA framebuffer. + *+ * See {@link GLReadBuffer00Base} for related bugs and further details. + *
*/ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestGLReadBuffer01GLWindowNEWT extends GLReadBuffer00Base { @@ -73,9 +78,16 @@ public class TestGLReadBuffer01GLWindowNEWT extends GLReadBuffer00Base { try { glad.setPosition(64, 64); glad.setSize(320, 240); - final GearsES2 gears = new GearsES2(1); - gears.setVerbose(false); - glad.addGLEventListener(gears); + { + final GearsES2 gears = new GearsES2(1); + gears.setVerbose(false); + glad.addGLEventListener(gears); + } + { + final MultisampleDemoES2 demo = new MultisampleDemoES2(caps.getSampleBuffers()); + demo.setClearBuffers(false);; + glad.addGLEventListener(demo); + } textRendererGLEL.setFlipVerticalInGLOrientation(skipGLOrientationVerticalFlip); glad.addGLEventListener(textRendererGLEL); if( doSnapshot ) { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/MultisampleDemoES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/MultisampleDemoES2.java index 7c4c5106b..8e4dbfefe 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/MultisampleDemoES2.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/MultisampleDemoES2.java @@ -55,7 +55,7 @@ import com.jogamp.opengl.util.glsl.ShaderState; public class MultisampleDemoES2 implements GLEventListener { - private boolean multisample; + private boolean multisample, clearBuffers; private final ShaderState st; private final PMVMatrix pmvMatrix; private ShaderProgram sp0; @@ -64,11 +64,14 @@ public class MultisampleDemoES2 implements GLEventListener { public MultisampleDemoES2(final boolean multisample) { this.multisample = multisample; + this.clearBuffers = true; st = new ShaderState(); st.setVerbose(true); pmvMatrix = new PMVMatrix(); } + public void setClearBuffers(final boolean v) { clearBuffers = v; } + public void init(final GLAutoDrawable glad) { final GL2ES2 gl = glad.getGL().getGL2ES2(); @@ -135,10 +138,12 @@ public class MultisampleDemoES2 implements GLEventListener { if (multisample) { gl.glEnable(GL.GL_MULTISAMPLE); } - gl.glClearColor(0, 0, 0, 0); - // gl.glEnable(GL.GL_DEPTH_TEST); - // gl.glDepthFunc(GL.GL_LESS); - gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + if( clearBuffers ) { + gl.glClearColor(0, 0, 0, 0); + // gl.glEnable(GL.GL_DEPTH_TEST); + // gl.glDepthFunc(GL.GL_LESS); + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + } st.useProgram(gl, true); -- cgit v1.2.3