diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index 51cc65a78..731164e69 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -75,13 +75,6 @@ public abstract class PGL { protected static boolean USE_DIRECT_BUFFERS = true; protected static int MIN_DIRECT_BUFFER_SIZE = 1; - /** This flag enables/disables a hack to make sure that anything drawn - * in setup will be maintained even a renderer restart (e.g.: smooth change). - * See the code and comments involving this constant in - * PGraphicsOpenGL.endDraw(). - */ - protected static boolean SAVE_SURFACE_TO_PIXELS_HACK = false; - /** Enables/disables mipmap use. */ protected static boolean MIPMAPS_ENABLED = true; @@ -138,6 +131,7 @@ public abstract class PGL { // FBO layer protected boolean requestedFBOLayer = false; + protected boolean requestedFBOLayerReset = false; protected boolean fboLayerCreated = false; protected boolean fboLayerInUse = false; protected boolean firstFrame = true; @@ -446,6 +440,11 @@ public abstract class PGL { } + public void dispose() { + destroyFBOLayer(); + } + + public void setPrimary(boolean primary) { primaryPGL = primary; } @@ -479,27 +478,6 @@ public abstract class PGL { // protected abstract void registerListeners(); - protected void deleteSurface() { - if (threadIsCurrent() && fboLayerCreated) { - deleteFramebuffers(1, glColorFbo); - deleteTextures(2, glColorTex); - deleteRenderbuffers(1, glDepthStencil); - deleteRenderbuffers(1, glDepth); - deleteRenderbuffers(1, glStencil); - - deleteFramebuffers(1, glMultiFbo); - deleteRenderbuffers(1, glMultiColor); - deleteRenderbuffers(1, glMultiDepthStencil); - deleteRenderbuffers(1, glMultiDepth); - deleteRenderbuffers(1, glMultiStencil); - } - - fboLayerCreated = false; - fboLayerInUse = false; - firstFrame = false; - } - - protected int getReadFramebuffer() { return fboLayerInUse ? glColorFbo.get(0) : 0; } @@ -532,6 +510,11 @@ public abstract class PGL { } + public void requestFBOLayerReset() { + requestedFBOLayerReset = true; + } + + protected boolean isMultisampled() { return 1 < numSamples; } @@ -671,6 +654,10 @@ public abstract class PGL { protected void beginDraw(boolean pclear) { if (requestedFBOLayer) { + if (requestedFBOLayerReset) { + destroyFBOLayer(); + requestedFBOLayerReset = false; + } if (!fboLayerCreated) createFBOLayer(); bindFramebufferImpl(FRAMEBUFFER, glColorFbo.get(0)); @@ -711,9 +698,7 @@ public abstract class PGL { fboLayerInUse = false; } - if (firstFrame) { - firstFrame = false; - } + firstFrame = false; } @@ -919,6 +904,27 @@ public abstract class PGL { fboLayerCreated = true; } + + protected void destroyFBOLayer() { + if (threadIsCurrent() && fboLayerCreated) { + deleteFramebuffers(1, glColorFbo); + deleteTextures(2, glColorTex); + deleteRenderbuffers(1, glDepthStencil); + deleteRenderbuffers(1, glDepth); + deleteRenderbuffers(1, glStencil); + + deleteFramebuffers(1, glMultiFbo); + deleteRenderbuffers(1, glMultiColor); + deleteRenderbuffers(1, glMultiDepthStencil); + deleteRenderbuffers(1, glMultiDepth); + deleteRenderbuffers(1, glMultiStencil); + } + + fboLayerCreated = false; + fboLayerInUse = false; +// firstFrame = false; + } + private void createDepthAndStencilBuffer(boolean multisample, int depthBits, int stencilBits, boolean packed) { // Creating depth and stencil buffers diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 2d8c47fd7..22d143abc 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -418,9 +418,6 @@ public class PGraphicsOpenGL extends PGraphics { /** True if we are inside a beginDraw()/endDraw() block. */ protected boolean drawing = false; - /** Used to indicate an OpenGL surface recreation */ - protected boolean restoreSurface = false; - /** Used to detect continuous use of the smooth/noSmooth functions */ protected boolean smoothDisabled = false; protected int smoothCallCount = 0; @@ -652,10 +649,8 @@ public class PGraphicsOpenGL extends PGraphics { } } -// deleteFinalizedGLResources(pgl); - if (primaryGraphics) { - pgl.deleteSurface(); + pgl.dispose(); } } @@ -2196,17 +2191,6 @@ public class PGraphicsOpenGL extends PGraphics { // Flushing any remaining geometry. flush(); - if (PGL.SAVE_SURFACE_TO_PIXELS_HACK && - (!getPrimaryPG().initialized || parent.frameCount == 0)) { - // Smooth was disabled/enabled at some point during drawing. We save - // the current contents of the back buffer (because the buffers haven't - // been swapped yet) to the pixels array. The frameCount == 0 condition - // is to handle the situation when no smooth is called in setup in the - // PDE, but the OpenGL appears to be recreated due to the size() nastiness. - saveSurfaceToPixels(); - restoreSurface = true; - } - if (primaryGraphics) { endOnscreenDraw(); } else { @@ -6091,17 +6075,6 @@ public class PGraphicsOpenGL extends PGraphics { } - protected void saveSurfaceToPixels() { - allocatePixels(); - readPixels(); - } - - - protected void restoreSurfaceFromPixels() { - drawPixels(0, 0, width, height); - } - - protected void readPixels() { updatePixelSize(); beginPixelsOp(OP_READ); @@ -7247,11 +7220,6 @@ public class PGraphicsOpenGL extends PGraphics { defaultSettings(); } - if (restoreSurface) { - restoreSurfaceFromPixels(); - restoreSurface = false; - } - if (hints[DISABLE_DEPTH_MASK]) { pgl.depthMask(false); } else { diff --git a/core/src/processing/opengl/PSurfaceJOGL.java b/core/src/processing/opengl/PSurfaceJOGL.java index 7eab2372e..aab346585 100644 --- a/core/src/processing/opengl/PSurfaceJOGL.java +++ b/core/src/processing/opengl/PSurfaceJOGL.java @@ -3,15 +3,11 @@ package processing.opengl; import java.awt.Component; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; -//import java.awt.Dimension; import java.awt.Point; -//import java.awt.Frame; import java.awt.Rectangle; import java.awt.image.BufferedImage; -import java.awt.image.DataBufferByte; import java.awt.image.DataBufferInt; import java.nio.ByteBuffer; -import java.nio.IntBuffer; import java.util.ArrayList; import java.util.List; @@ -19,7 +15,6 @@ import com.jogamp.common.util.IOUtil.ClassResources; import com.jogamp.nativewindow.NativeSurface; import com.jogamp.nativewindow.ScalableSurface; import com.jogamp.nativewindow.util.Dimension; -import com.jogamp.nativewindow.util.DimensionImmutable; import com.jogamp.nativewindow.util.PixelFormat; import com.jogamp.nativewindow.util.PixelRectangle; import com.jogamp.opengl.GLAnimatorControl; @@ -36,8 +31,6 @@ import com.jogamp.newt.NewtFactory; import com.jogamp.newt.Screen; import com.jogamp.newt.awt.NewtCanvasAWT; import com.jogamp.newt.event.InputEvent; -//import com.jogamp.newt.event.WindowAdapter; -//import com.jogamp.newt.event.WindowEvent; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.util.FPSAnimator; @@ -737,7 +730,13 @@ public class PSurfaceJOGL implements PSurface { } public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) { - +// int c = graphics.backgroundColor; +// pgl.clearColor(((c >> 16) & 0xff) / 255f, +// ((c >> 8) & 0xff) / 255f, +// ((c >> 0) & 0xff) / 255f, +// ((c >> 24) & 0xff) / 255f); +// pgl.clear(PGL.COLOR_BUFFER_BIT); + pgl.requestFBOLayerReset(); // final float[] valReqSurfacePixelScale = window.getRequestedSurfaceScale(new float[2]); window.getCurrentSurfaceScale(currentPixelScale); // final float[] nativeSurfacePixelScale = window.getMaximumSurfaceScale(new float[2]);