mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
PGL.readPixels() calls beginPixelsOp/endPixelsOp to properly set the
framebuffers for reading.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user