From 8313200af6da93f83bc70a645e79bfdeb22f05d4 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 8 Sep 2013 15:13:00 +0200 Subject: TileRenderer*: Fix pre-swap and post-swap in regards to endTile(..), i.e. pre-swap only for FBO && MSAA. See TileRendererBase.reqPreSwapBuffers(..) API doc. --- .../com/jogamp/opengl/util/RandomTileRenderer.java | 12 +++-- .../com/jogamp/opengl/util/TileRenderer.java | 12 +++-- .../com/jogamp/opengl/util/TileRendererBase.java | 62 ++++++++++++++++++---- 3 files changed, 66 insertions(+), 20 deletions(-) (limited to 'src/jogl/classes/com/jogamp') diff --git a/src/jogl/classes/com/jogamp/opengl/util/RandomTileRenderer.java b/src/jogl/classes/com/jogamp/opengl/util/RandomTileRenderer.java index 55b31b692..afc57fa30 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/RandomTileRenderer.java +++ b/src/jogl/classes/com/jogamp/opengl/util/RandomTileRenderer.java @@ -126,19 +126,21 @@ public class RandomTileRenderer extends TileRendererBase { // be sure OpenGL rendering is finished gl.glFlush(); - if( DEBUG ) { - System.err.println("TileRenderer.end.0: "+this.toString()); - } - // save current glPixelStore values psm.save(gl); psm.setPackAlignment(gl, 1); final GL2ES3 gl2es3; + final int readBuffer; if( gl.isGL2ES3() ) { gl2es3 = gl.getGL2ES3(); - gl2es3.glReadBuffer(gl2es3.getDefaultReadBuffer()); + readBuffer = gl2es3.getDefaultReadBuffer(); + gl2es3.glReadBuffer(readBuffer); } else { gl2es3 = null; + readBuffer = 0; // undef. probably default: GL_FRONT (single buffering) GL_BACK (double buffering) + } + if( DEBUG ) { + System.err.println("TileRenderer.end.0: readBuffer 0x"+Integer.toHexString(readBuffer)+", "+this.toString()); } final int tmp[] = new int[1]; diff --git a/src/jogl/classes/com/jogamp/opengl/util/TileRenderer.java b/src/jogl/classes/com/jogamp/opengl/util/TileRenderer.java index e24fa9706..bb6cf70f4 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/TileRenderer.java +++ b/src/jogl/classes/com/jogamp/opengl/util/TileRenderer.java @@ -314,20 +314,22 @@ public class TileRenderer extends TileRendererBase { // be sure OpenGL rendering is finished gl.glFlush(); - - if( DEBUG ) { - System.err.println("TileRenderer.end.0: "+this.toString()); - } // save current glPixelStore values psm.save(gl); psm.setPackAlignment(gl, 1); final GL2ES3 gl2es3; + final int readBuffer; if( gl.isGL2ES3() ) { gl2es3 = gl.getGL2ES3(); - gl2es3.glReadBuffer(gl2es3.getDefaultReadBuffer()); + readBuffer = gl2es3.getDefaultReadBuffer(); + gl2es3.glReadBuffer(readBuffer); } else { gl2es3 = null; + readBuffer = 0; // undef. probably default: GL_FRONT (single buffering) GL_BACK (double buffering) + } + if( DEBUG ) { + System.err.println("TileRenderer.end.0: readBuffer 0x"+Integer.toHexString(readBuffer)+", "+this.toString()); } final int tmp[] = new int[1]; diff --git a/src/jogl/classes/com/jogamp/opengl/util/TileRendererBase.java b/src/jogl/classes/com/jogamp/opengl/util/TileRendererBase.java index 70e68b97f..411d33881 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/TileRendererBase.java +++ b/src/jogl/classes/com/jogamp/opengl/util/TileRendererBase.java @@ -41,10 +41,11 @@ import javax.media.nativewindow.util.DimensionImmutable; import javax.media.opengl.GL; import javax.media.opengl.GL2ES3; import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilitiesImmutable; import javax.media.opengl.GLDrawable; import javax.media.opengl.GLEventListener; import javax.media.opengl.GLException; - +import javax.media.opengl.GLFBODrawable; import jogamp.opengl.Debug; /** @@ -138,6 +139,7 @@ public abstract class TileRendererBase { protected int currentTileWidth; protected int currentTileHeight; protected GLAutoDrawable glad; + protected boolean gladRequiresPreSwap; protected boolean gladAutoSwapBufferMode = true; protected GLEventListener[] listeners; protected boolean[] listenersInit; @@ -156,7 +158,7 @@ public abstract class TileRendererBase { sb.append("tile["); tileDetails(sb); sb.append("], image[size "+imageSize+", buffer "+hashStr(imageBuffer)+"], glad["+ - gladListenerCount+" listener, pre "+(null!=glEventListenerPre)+", post "+(null!=glEventListenerPost)+"]"); + gladListenerCount+" listener, pre "+(null!=glEventListenerPre)+", post "+(null!=glEventListenerPost)+", preSwap "+gladRequiresPreSwap+"]"); return sb; } public String toString() { @@ -271,9 +273,9 @@ public abstract class TileRendererBase { * Must be called after rendering the scene, * see {@link #beginTile(GL)}. *

- * Is is highly recommended to perform {@link GLDrawable#swapBuffers() swapBuffers()} before calling this method.
- * This is especially true in regards to multisampling offscreen FBO drawables, - * where {@link GLDrawable#swapBuffers() swapBuffers()} triggers the downsampling to the readable sampling sink. + * Please consider {@link #reqPreSwapBuffers(GLCapabilitiesImmutable)} to determine + * whether you need to perform {@link GLDrawable#swapBuffers() swap-buffers} before or after + * calling this method! *

*

* User has to comply with the GL profile requirement. @@ -285,6 +287,29 @@ public abstract class TileRendererBase { */ public abstract void endTile( GL gl ) throws IllegalStateException, GLException; + /** + * Determines whether the chosen {@link GLCapabilitiesImmutable} + * requires a pre-{@link GLDrawable#swapBuffers() swap-buffers} + * before accessing the results, i.e. before {@link #endTile(GL)}. + *

+ * 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.
+ * Here {@link GLDrawable#swapBuffers() swap-buffers} shall happen after calling {@link #endTile(GL)}, the default. + *

+ *

+ * However, multisampling offscreen {@link GLFBODrawable}s + * utilize {@link GLDrawable#swapBuffers() swap-buffers} to downsample + * the multisamples into the readable sampling sink. + * In this case, we require a {@link GLDrawable#swapBuffers() swap-buffers} before calling {@link #endTile(GL)}. + *

+ * @param chosenCaps the chosen {@link GLCapabilitiesImmutable} + * @return chosenCaps.isFBO() && chosenCaps.getSampleBuffers() + */ + public final boolean reqPreSwapBuffers(GLCapabilitiesImmutable chosenCaps) { + return chosenCaps.isFBO() && chosenCaps.getSampleBuffers(); + } + /** * Attaches this renderer to the {@link GLAutoDrawable}. *

@@ -295,7 +320,8 @@ public abstract class TileRendererBase { *

*

* The {@link GLAutoDrawable}'s {@link GLAutoDrawable#getAutoSwapBufferMode() auto-swap mode} is cached - * and set to false, since {@link GLAutoDrawable#swapBuffers() swapBuffers()} must be issued before {@link #endTile(GL)}. + * and set to false, since {@link GLAutoDrawable#swapBuffers() swapBuffers()} maybe issued before {@link #endTile(GL)}, + * see {@link #reqPreSwapBuffers(GLCapabilitiesImmutable)}. *

*

* This tile renderer's {@link GLEventListener} is then added to handle the tile rendering, @@ -309,8 +335,9 @@ public abstract class TileRendererBase { *

  • {@link GLEventListener#reshape(GLAutoDrawable, int, int, int, int) reshape(0, 0, tile-width, tile-height)}
  • *
  • {@link GLEventListener#display(GLAutoDrawable) display(autoDrawable)}
  • * - *
  • {@link GLAutoDrawable#swapBuffers() swapBuffers()}
  • + *
  • if ( {@link #reqPreSwapBuffers(GLCapabilitiesImmutable) pre-swap} ) { {@link GLAutoDrawable#swapBuffers() swapBuffers()} }
  • *
  • {@link #endTile(GL)}
  • + *
  • if ( !{@link #reqPreSwapBuffers(GLCapabilitiesImmutable) pre-swap} ) { {@link GLAutoDrawable#swapBuffers() swapBuffers()} }
  • *
  • Optional {@link #setGLEventListener(GLEventListener, GLEventListener) post-glel}.{@link GLEventListener#display(GLAutoDrawable) display(..)}
  • * *

    @@ -357,7 +384,12 @@ public abstract class TileRendererBase { } glad.addGLEventListener(tiledGLEL); gladAutoSwapBufferMode = glad.getAutoSwapBufferMode(); + gladRequiresPreSwap = this.reqPreSwapBuffers(glad.getChosenGLCapabilities()); glad.setAutoSwapBufferMode(false); + if( DEBUG ) { + System.err.println("TileRenderer: attached: "+glad); + System.err.println("TileRenderer: preSwap "+gladRequiresPreSwap+", "+glad.getChosenGLCapabilities()+", cached "+listeners.length+" listener"); + } } /** @@ -384,6 +416,10 @@ public abstract class TileRendererBase { glad.setGLEventListenerInitState(l, listenersInit[i]); } glad.setAutoSwapBufferMode(gladAutoSwapBufferMode); + if( DEBUG ) { + System.err.println("TileRenderer: detached: "+glad); + System.err.println("TileRenderer: "+glad.getChosenGLCapabilities()); + } listeners = null; listenersInit = null; @@ -459,9 +495,15 @@ public abstract class TileRendererBase { listeners[i].reshape(drawable, 0, 0, currentTileWidth, currentTileHeight); listeners[i].display(drawable); } - glad.swapBuffers(); - - endTile(gl); + + if( gladRequiresPreSwap ) { + glad.swapBuffers(); + endTile(gl); + } else { + endTile(gl); + glad.swapBuffers(); + } + if( null != glEventListenerPost ) { glEventListenerPost.display(drawable); } -- cgit v1.2.3