diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index 0c562940f..6365c756b 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -733,6 +733,7 @@ public class PGL { protected Texture wrapBackTexture() { if (USE_JOGL_FBOLAYER) { + System.out.println("back texture: " + backTexAttach.getName()); Texture tex = new Texture(); tex.init(pg.width, pg.height, backTexAttach.getName(), TEXTURE_2D, RGBA, @@ -759,6 +760,7 @@ public class PGL { protected Texture wrapFrontTexture() { if (USE_JOGL_FBOLAYER) { + System.out.println("front texture: " + frontTexAttach.getName()); Texture tex = new Texture(); tex.init(pg.width, pg.height, backTexAttach.getName(), TEXTURE_2D, RGBA, @@ -2565,27 +2567,33 @@ public class PGL { // When using multisampled FBO, the back buffer is the MSAA // surface so it cannot be read from. The sink buffer contains // the readable 2D texture. - // In this case, we create an auxiliar "front" buffer that it is + // In this case, we create an auxiliary "front" buffer that it is // swapped with the sink buffer at the beginning of each frame. // In this way, we always have a readable copy of the previous // frame in the front texture, while the back is synchronized // with the contents of the MSAA back buffer when requested. - if (frontFBO == null) { - // init - frontFBO = new FBObject(); - frontFBO.reset(gl, pg.width, pg.height); - frontFBO.attachTexture2D(gl, 0, true); - sinkFBO = backFBO.getSamplingSinkFBO(); + if (1 < pg.parent.frameCount) { + if (frontFBO == null) { + // init + System.out.println("init"); + frontFBO = new FBObject(); + frontFBO.reset(gl, pg.width, pg.height); + frontFBO.attachTexture2D(gl, 0, true); + sinkFBO = backFBO.getSamplingSinkFBO(); + } else { + // swap + System.out.println("swap"); + FBObject temp = sinkFBO; + sinkFBO = frontFBO; + frontFBO = temp; + backFBO.setSamplingSink(sinkFBO); + } } else { - // swap - FBObject temp = sinkFBO; - sinkFBO = frontFBO; - frontFBO = temp; - backFBO.setSamplingSink(sinkFBO); + frontFBO = sinkFBO = backFBO.getSamplingSinkFBO(); } - backTexAttach = (FBObject.TextureAttachment) sinkFBO. + backTexAttach = (FBObject.TextureAttachment)sinkFBO. getColorbuffer(0); frontTexAttach = (FBObject.TextureAttachment)frontFBO. getColorbuffer(0); diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 43f564d19..e7aadb050 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -5790,7 +5790,7 @@ public class PGraphicsOpenGL extends PGraphics { } - protected void bindBackTexture() { + protected void bindFrontTexture() { if (primarySurface) { pgl.bindFrontTexture(); } else { @@ -5800,7 +5800,7 @@ public class PGraphicsOpenGL extends PGraphics { } - protected void unbindBackTexture() { + protected void unbindFrontTexture() { if (primarySurface) { pgl.unbindFrontTexture(); } else { @@ -6171,9 +6171,9 @@ public class PGraphicsOpenGL extends PGraphics { if (restoreSurface) { restoreSurfaceFromPixels(); - if (1 < parent.frameCount) { + //if (1 < parent.frameCount) { restoreSurface = false; - } + //} } if (hints[DISABLE_DEPTH_MASK]) { @@ -6612,7 +6612,7 @@ public class PGraphicsOpenGL extends PGraphics { if (-1 < bufferLoc) { pgl.requestFBOLayer(); pgl.activeTexture(PGL.TEXTURE0 + bufferUnit); - pgCurrent.unbindBackTexture(); + pgCurrent.unbindFrontTexture(); pgl.activeTexture(PGL.TEXTURE0); } @@ -6649,7 +6649,7 @@ public class PGraphicsOpenGL extends PGraphics { bufferUnit = getLastTexUnit() + 1; setUniformValue(bufferLoc, bufferUnit); pgl.activeTexture(PGL.TEXTURE0 + bufferUnit); - pgCurrent.bindBackTexture(); + pgCurrent.bindFrontTexture(); } else { bufferUnit = -1; }