diff --git a/java/libraries/opengl/src/processing/opengl/PFramebuffer.java b/java/libraries/opengl/src/processing/opengl/PFramebuffer.java index 32fae2c85..cff5aefe6 100644 --- a/java/libraries/opengl/src/processing/opengl/PFramebuffer.java +++ b/java/libraries/opengl/src/processing/opengl/PFramebuffer.java @@ -402,6 +402,25 @@ public class PFramebuffer implements PConstants { } + protected boolean contextIsOutdated() { + boolean outdated = !pgl.contextIsCurrent(context); + if (outdated) { + glFboID = 0; + glDepthBufferID = 0; + glStencilBufferID = 0; + glDepthStencilBufferID = 0; + glColorBufferMultisampleID = 0; + + for (int i = 0; i < numColorBuffers; i++) { + colorBufferTex[i] = null; + } + + backupTexture = null; + } + return outdated; + } + + protected void createColorBufferMultisample() { if (screenFb) return; diff --git a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java index d03585056..db6ecdea4 100644 --- a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java +++ b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java @@ -1376,7 +1376,14 @@ public class PGraphicsOpenGL extends PGraphics { } else { if (!pgl.initialized) { initOffscreen(); - } + } else { + boolean outdated = offscreenFramebuffer != null && offscreenFramebuffer.contextIsOutdated(); + boolean outdatedMulti = offscreenFramebufferMultisample != null && offscreenFramebufferMultisample.contextIsOutdated(); + if (outdated || outdatedMulti) { + pgl.initialized = false; + initOffscreen(); + } + } pushFramebuffer(); if (offscreenMultisample) { @@ -4851,7 +4858,7 @@ public class PGraphicsOpenGL extends PGraphics { protected void loadTextureImpl(int sampling) { if (width == 0 || height == 0) return; - if (texture == null) { + if (texture == null || texture.contextIsOutdated()) { PTexture.Parameters params = PTexture.newParameters(ARGB, sampling); texture = new PTexture(parent, width, height, params); texture.setFlippedY(true);