diff options
author | Sven Gothel <[email protected]> | 2014-02-18 21:47:06 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-02-18 21:47:06 +0100 |
commit | 41190c3830157abdf9649cbf7767e57108f55075 (patch) | |
tree | 667356d534208cf9bae6dd17e9947b1d56d916bd /src/test | |
parent | d46d9ad8f998a7128d9f023294d5f489673d6d8a (diff) |
Bug 975 - GLJPanel's OffscreenDrawable shall not double swap - Fix auto-swap mechanism ; Refined API doc getDefaultReadBuffer() ; Add GLDrawableUtil.swapBuffersBeforeRead(..)
Commit 82f679b064784213591b460fc5eaa1f5f196fbd1 which introduces the default swap-buffers
mechanism is erroneous:
The OffscreenBack backend requires the following operation order:
Order-1:
[1] - GL display
[2] - GL swapBuffers (always due to single-buffer non-MSAA or MSAA offscreen drawable)
[3] - readPixels
+++
Commit 82f679b064784213591b460fc5eaa1f5f196fbd1 however introduced:
Order-2:
[a] - GL display
[b] - readPixels
[c] - GL swapBuffers (always due to single-buffer non-MSAA or MSAA offscreen drawable)
since [a] and [b] happened in Updater's display method, and [c] followed the same
triggered by GLAutoDrawableHelper.
+++
The proof, commit d46d9ad8f998a7128d9f023294d5f489673d6d8a, is faulty,
since it always included the 'snapshot' GL event listener
which turned-off auto-swap and swapped before read-pixels.
TL;DR it enforced proper Order-1.
+++
This fix allows the Backend to intercept disable GLDrawableHelper's setAutoSwapBufferMode(..)
and perform the auto-swap mode itself in the proper Order-1.
The unit test has been refined to optionally disable the snapshot
to validate auto-swap mode.
+++
Refined GLBase and GLContext's API doc for 'getDefaultReadBuffer()'
+++
Add GLDrawableUtil.swapBuffersBeforeRead(..)
and reuse it for TileRendererBase (original impl.).
Diffstat (limited to 'src/test')
3 files changed, 24 insertions, 31 deletions
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 58ca24453..5853087f5 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 @@ -54,6 +54,7 @@ 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 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; @@ -74,7 +75,7 @@ public class TestGLReadBuffer01GLJPanelAWT extends GLReadBuffer00Base { final Dimension d = new Dimension(320, 240); final GLJPanel glad = createGLJPanel(skipGLOrientationVerticalFlip, useSwingDoubleBuffer, caps, d); final TextRendererGLEL textRendererGLEL = new TextRendererGLEL(); - final SnapshotGLELAWT snapshotGLEL = new SnapshotGLELAWT(textRendererGLEL, awtGLReadBufferUtil, skipGLOrientationVerticalFlip); + final SnapshotGLELAWT snapshotGLEL = doSnapshot ? new SnapshotGLELAWT(textRendererGLEL, awtGLReadBufferUtil, skipGLOrientationVerticalFlip) : null; try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { @@ -90,7 +91,9 @@ public class TestGLReadBuffer01GLJPanelAWT extends GLReadBuffer00Base { glad.addGLEventListener(gears); textRendererGLEL.setFlipVerticalInGLOrientation(skipGLOrientationVerticalFlip); glad.addGLEventListener(textRendererGLEL); - glad.addGLEventListener(snapshotGLEL); + if( doSnapshot ) { + glad.addGLEventListener(snapshotGLEL); + } panel.add(glad); frame.pack(); frame.setVisible(true); @@ -133,7 +136,9 @@ public class TestGLReadBuffer01GLJPanelAWT extends GLReadBuffer00Base { } } ); try { Thread.sleep(duration); } catch (InterruptedException e) { } - glad.disposeGLEventListener(snapshotGLEL, true /* remove */); + if( doSnapshot ) { + glad.disposeGLEventListener(snapshotGLEL, true /* remove */); + } final Animator anim = new Animator(glad); anim.start(); try { Thread.sleep(2*duration); } catch (InterruptedException e) { } @@ -181,7 +186,7 @@ public class TestGLReadBuffer01GLJPanelAWT extends GLReadBuffer00Base { @Override public void init(GLAutoDrawable drawable) { defAutoSwapMode = drawable.getAutoSwapBufferMode(); - swapBuffersBeforeRead = UITestCase.swapBuffersBeforeRead(drawable.getChosenGLCapabilities()); + swapBuffersBeforeRead = GLDrawableUtil.swapBuffersBeforeRead(drawable.getChosenGLCapabilities()); drawable.setAutoSwapBufferMode( !swapBuffersBeforeRead ); } @Override @@ -229,6 +234,7 @@ public class TestGLReadBuffer01GLJPanelAWT extends GLReadBuffer00Base { }; static GLCapabilitiesImmutable caps = null; + static boolean doSnapshot = true; static boolean keyFrame = false; public static void main(String[] args) { @@ -238,6 +244,8 @@ public class TestGLReadBuffer01GLJPanelAWT extends GLReadBuffer00Base { 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(TestGLReadBuffer01GLJPanelAWT.class.getName()); 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 af5ff2a1a..8cfb18f79 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 @@ -47,6 +47,7 @@ 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 com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.util.GLDrawableUtil; import com.jogamp.opengl.util.GLReadBufferUtil; import com.jogamp.opengl.util.texture.TextureIO; @@ -68,7 +69,7 @@ public class TestGLReadBuffer01GLWindowNEWT extends GLReadBuffer00Base { final GLReadBufferUtil glReadBufferUtil = new GLReadBufferUtil(false, false); final GLWindow glad= GLWindow.create(caps); final TextRendererGLEL textRendererGLEL = new TextRendererGLEL(); - final SnapshotGLEL snapshotGLEL = new SnapshotGLEL(textRendererGLEL, glReadBufferUtil); + final SnapshotGLEL snapshotGLEL = doSnapshot ? new SnapshotGLEL(textRendererGLEL, glReadBufferUtil) : null; try { glad.setPosition(64, 64); glad.setSize(320, 240); @@ -77,7 +78,9 @@ public class TestGLReadBuffer01GLWindowNEWT extends GLReadBuffer00Base { glad.addGLEventListener(gears); textRendererGLEL.setFlipVerticalInGLOrientation(skipGLOrientationVerticalFlip); glad.addGLEventListener(textRendererGLEL); - glad.addGLEventListener(snapshotGLEL); + if( doSnapshot ) { + glad.addGLEventListener(snapshotGLEL); + } glad.setVisible(true); } catch( Throwable throwable ) { throwable.printStackTrace(); @@ -104,7 +107,9 @@ public class TestGLReadBuffer01GLWindowNEWT extends GLReadBuffer00Base { glad.setSize(size0.getWidth(), size0.getHeight()); try { Thread.sleep(duration); } catch (InterruptedException e) { } - glad.disposeGLEventListener(snapshotGLEL, true /* remove */); + if( doSnapshot ) { + glad.disposeGLEventListener(snapshotGLEL, true /* remove */); + } final Animator anim = new Animator(glad); anim.start(); try { Thread.sleep(2*duration); } catch (InterruptedException e) { } @@ -133,7 +138,7 @@ public class TestGLReadBuffer01GLWindowNEWT extends GLReadBuffer00Base { @Override public void init(GLAutoDrawable drawable) { defAutoSwapMode = drawable.getAutoSwapBufferMode(); - swapBuffersBeforeRead = UITestCase.swapBuffersBeforeRead(drawable.getChosenGLCapabilities()); + swapBuffersBeforeRead = GLDrawableUtil.swapBuffersBeforeRead(drawable.getChosenGLCapabilities()); drawable.setAutoSwapBufferMode( !swapBuffersBeforeRead ); } @Override @@ -170,6 +175,7 @@ public class TestGLReadBuffer01GLWindowNEWT extends GLReadBuffer00Base { }; static GLCapabilitiesImmutable caps = null; + static boolean doSnapshot = true; static boolean keyFrame = false; public static void main(String[] args) { @@ -179,6 +185,8 @@ public class TestGLReadBuffer01GLWindowNEWT extends GLReadBuffer00Base { 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(TestGLReadBuffer01GLWindowNEWT.class.getName()); diff --git a/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java b/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java index 79c76e49f..a08e9f842 100644 --- a/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java +++ b/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java @@ -277,29 +277,6 @@ public abstract class UITestCase { static final String unsupportedTestMsg = "Test not supported on this platform."; - /** - * Determines whether the chosen {@link GLCapabilitiesImmutable} - * requires a {@link GLDrawable#swapBuffers() swap-buffers} - * before reading pixels. - * <p> - * Usually one uses the {@link GL#getDefaultReadBuffer() default-read-buffer}, i.e. - * {@link GL#GL_FRONT} for single-buffer and {@link GL#GL_BACK} for double-buffer {@link GLDrawable}s - * and {@link GL#GL_COLOR_ATTACHMENT0} for offscreen framebuffer objects.<br> - * Here {@link GLDrawable#swapBuffers() swap-buffers} shall happen <b>after</b> calling reading pixels, the default. - * </p> - * <p> - * However, <i>multisampling</i> offscreen {@link javax.media.opengl.GLFBODrawable}s - * utilize {@link GLDrawable#swapBuffers() swap-buffers} to <i>downsample</i> - * the multisamples into the readable sampling sink. - * In this case, we require a {@link GLDrawable#swapBuffers() swap-buffers} <b>before</b> reading pixels. - * </p> - * @param chosenCaps the chosen {@link GLCapabilitiesImmutable} - * @return chosenCaps.isFBO() && chosenCaps.getSampleBuffers() - */ - public static final boolean swapBuffersBeforeRead(GLCapabilitiesImmutable chosenCaps) { - return chosenCaps.isFBO() && chosenCaps.getSampleBuffers(); - } - public String getSnapshotFilename(int sn, String postSNDetail, GLCapabilitiesImmutable caps, int width, int height, boolean sinkHasAlpha, String fileSuffix, String destPath) { if(null == fileSuffix) { fileSuffix = TextureIO.PNG; |