diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index a818820f8..a633b5154 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -3117,6 +3117,14 @@ public class PGL { // Reading Pixels public void readPixels(int x, int y, int width, int height, int format, int type, Buffer buffer) { + // The beginPixelsOp/endPixelsOp calls are needed to properly setup the + // framebuffers to read from. + PGraphicsOpenGL.pgCurrent.beginPixelsOp(PGraphicsOpenGL.OP_READ); + readPixelsImpl(x, y, width, height, format, type, buffer); + PGraphicsOpenGL.pgCurrent.endPixelsOp(); + } + + protected void readPixelsImpl(int x, int y, int width, int height, int format, int type, Buffer buffer) { gl.glReadPixels(x, y, width, height, format, type, buffer); } diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 233fbf8e3..314e1d4cf 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -5056,13 +5056,13 @@ public class PGraphicsOpenGL extends PGraphics { protected void readPixels() { beginPixelsOp(OP_READ); try { - // The readPixels() call in inside a try/catch block because it appears + // The readPixelsImpl() call in inside a try/catch block because it appears // that (only sometimes) JOGL will run beginDraw/endDraw on the EDT // thread instead of the Animation thread right after a resize. Because // of this the width and height might have a different size than the // one of the pixels arrays. - pgl.readPixels(0, 0, width, height, PGL.RGBA, PGL.UNSIGNED_BYTE, - pixelBuffer); + pgl.readPixelsImpl(0, 0, width, height, PGL.RGBA, PGL.UNSIGNED_BYTE, + pixelBuffer); } catch (IndexOutOfBoundsException e) { // Silently catch the exception. } @@ -5217,9 +5217,9 @@ public class PGraphicsOpenGL extends PGraphics { beginPixelsOp(OP_READ); try { - // Se comments in readPixels() for the reason for this try/catch. - pgl.readPixels(0, 0, width, height, PGL.RGBA, PGL.UNSIGNED_BYTE, - nativePixelBuffer); + // See comments in readPixels() for the reason for this try/catch. + pgl.readPixelsImpl(0, 0, width, height, PGL.RGBA, PGL.UNSIGNED_BYTE, + nativePixelBuffer); } catch (IndexOutOfBoundsException e) { } endPixelsOp();