diff --git a/android/core/src/processing/opengl/PGraphicsOpenGL.java b/android/core/src/processing/opengl/PGraphicsOpenGL.java index 6b3ef5b3b..df2ec961d 100644 --- a/android/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/android/core/src/processing/opengl/PGraphicsOpenGL.java @@ -1434,7 +1434,9 @@ public class PGraphicsOpenGL extends PGraphics { if (primarySurface) { pgl.updatePrimary(); - pgl.glDrawBuffer(PGL.GL_BACK); + if (pgl.primaryIsDoubleBuffered()) { + pgl.glDrawBuffer(PGL.GL_BACK); + } } else { if (!pgl.initialized) { initOffscreen(); @@ -1630,22 +1632,7 @@ public class PGraphicsOpenGL extends PGraphics { offscreenFramebufferMultisample.copy(offscreenFramebuffer); } - if (!pgl.initialized || !pgPrimary.pgl.initialized || parent.frameCount == 0) { - // If the primary surface is re-initialized, this offscreen - // surface needs to save its contents into the pixels array - // so they can be restored after the FBOs are recreated. - // Note that a consequence of how this is code works, is that - // if the user changes th smooth level of the primary surface - // in the middle of draw, but after drawing the offscreen surfaces - // then these won't be restored in the next frame since their - // endDraw() calls didn't pick up any change in the initialization - // state of the primary surface. - saveSurfaceToPixels(); - restoreSurface = true; - } - - popFramebuffer(); - + /* // Make the offscreen color buffer opaque so it doesn't show // the background when drawn on the main surface. if (offscreenMultisample) { @@ -1658,13 +1645,30 @@ public class PGraphicsOpenGL extends PGraphics { pgl.glColorMask(true, true, true, true); if (offscreenMultisample) { popFramebuffer(); + } + */ + + if (!pgl.initialized || !pgPrimary.pgl.initialized || parent.frameCount == 0) { + // If the primary surface is re-initialized, this offscreen + // surface needs to save its contents into the pixels array + // so they can be restored after the FBOs are recreated. + // Note that a consequence of how this is code works, is that + // if the user changes the smooth level of the primary surface + // in the middle of draw, but after drawing the offscreen surfaces + // then these won't be restored in the next frame since their + // endDraw() calls didn't pick up any change in the initialization + // state of the primary surface. + saveSurfaceToPixels(); + restoreSurface = true; } - pgl.endOffscreenDraw(pgPrimary.clearColorBuffer0); + popFramebuffer(); + pgl.endOffscreenDraw(pgPrimary.clearColorBuffer0); + pgPrimary.restoreGL(); } - + // Done! drawing = false; if (pgCurrent == pgPrimary) { @@ -1727,7 +1731,9 @@ public class PGraphicsOpenGL extends PGraphics { pgl.glDepthMask(true); } - pgl.glDrawBuffer(PGL.GL_BACK); + if (pgl.primaryIsDoubleBuffered()) { + pgl.glDrawBuffer(PGL.GL_BACK); + } } @@ -2387,6 +2393,7 @@ public class PGraphicsOpenGL extends PGraphics { if (flushMode == FLUSH_WHEN_FULL && !hints[DISABLE_TRANSFORM_CACHE]) { modelview = modelview0; modelviewInv = modelviewInv0; + calcProjmodelview(); } } @@ -3549,7 +3556,7 @@ public class PGraphicsOpenGL extends PGraphics { cameraInv.reset(); } - + public void applyMatrix(PMatrix2D source) { applyMatrixImpl(source.m00, source.m01, 0, source.m02, source.m10, source.m11, 0, source.m12, @@ -4696,7 +4703,7 @@ public class PGraphicsOpenGL extends PGraphics { protected void backgroundImpl() { flush(); - + pgl.glDepthMask(true); pgl.glClearDepth(1); pgl.glClear(PGL.GL_DEPTH_BUFFER_BIT); @@ -4705,12 +4712,12 @@ public class PGraphicsOpenGL extends PGraphics { } else { pgl.glDepthMask(true); } - + pgl.glClearColor(backgroundR, backgroundG, backgroundB, backgroundA); pgl.glClear(PGL.GL_COLOR_BUFFER_BIT); if (0 < parent.frameCount) { clearColorBuffer = true; - } + } } diff --git a/java/libraries/opengl/src/processing/opengl/PGL.java b/java/libraries/opengl/src/processing/opengl/PGL.java index 6893112df..4107f8cd0 100644 --- a/java/libraries/opengl/src/processing/opengl/PGL.java +++ b/java/libraries/opengl/src/processing/opengl/PGL.java @@ -654,6 +654,10 @@ public class PGL { // to update the screenFramebuffer object so when the framebuffer // is popped back to the screen, the correct id is set. PGraphicsOpenGL.screenFramebuffer.glFboID = colorFBO[0]; + } else { + // To make sure that the default screen buffer is used, specially after + // doing screen rendering on an FBO (the OSX 10.7+ above). + PGraphicsOpenGL.screenFramebuffer.glFboID = 0; } } diff --git a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java index 368a516f8..df2ec961d 100644 --- a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java +++ b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java @@ -1434,7 +1434,9 @@ public class PGraphicsOpenGL extends PGraphics { if (primarySurface) { pgl.updatePrimary(); - pgl.glDrawBuffer(PGL.GL_BACK); + if (pgl.primaryIsDoubleBuffered()) { + pgl.glDrawBuffer(PGL.GL_BACK); + } } else { if (!pgl.initialized) { initOffscreen(); @@ -1630,6 +1632,7 @@ public class PGraphicsOpenGL extends PGraphics { offscreenFramebufferMultisample.copy(offscreenFramebuffer); } + /* // Make the offscreen color buffer opaque so it doesn't show // the background when drawn on the main surface. if (offscreenMultisample) { @@ -1643,7 +1646,8 @@ public class PGraphicsOpenGL extends PGraphics { if (offscreenMultisample) { popFramebuffer(); } - + */ + if (!pgl.initialized || !pgPrimary.pgl.initialized || parent.frameCount == 0) { // If the primary surface is re-initialized, this offscreen // surface needs to save its contents into the pixels array @@ -1661,10 +1665,10 @@ public class PGraphicsOpenGL extends PGraphics { popFramebuffer(); pgl.endOffscreenDraw(pgPrimary.clearColorBuffer0); - + pgPrimary.restoreGL(); } - + // Done! drawing = false; if (pgCurrent == pgPrimary) { @@ -1727,7 +1731,9 @@ public class PGraphicsOpenGL extends PGraphics { pgl.glDepthMask(true); } - pgl.glDrawBuffer(PGL.GL_BACK); + if (pgl.primaryIsDoubleBuffered()) { + pgl.glDrawBuffer(PGL.GL_BACK); + } }