PGL.readPixels() calls beginPixelsOp/endPixelsOp to properly set the

framebuffers for reading.
This commit is contained in:
codeanticode
2013-05-27 23:31:42 -04:00
parent bfec690a28
commit c589c2d459
2 changed files with 14 additions and 6 deletions
+8
View File
@@ -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();