Skip to content

Commit 71e67c7

Browse files
committed
ported readPixels() fix
1 parent 8fe99b5 commit 71e67c7

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,42 +1672,51 @@ protected void endReadPixels() {
16721672

16731673
protected void beginPixelsOp(int op) {
16741674
FrameBuffer pixfb = null;
1675+
FrameBuffer currfb = getCurrentFB();
16751676
if (primaryGraphics) {
1676-
if (op == OP_READ) {
1677-
if (pgl.isFBOBacked() && pgl.isMultisampled()) {
1678-
// Making sure the back texture is up-to-date...
1679-
pgl.syncBackTexture();
1680-
// ...because the read framebuffer uses it as the color buffer (the
1681-
// draw framebuffer is MSAA so it cannot be read from it).
1682-
pixfb = readFramebuffer;
1683-
} else {
1684-
pixfb = drawFramebuffer;
1677+
FrameBuffer rfb = readFramebuffer;
1678+
FrameBuffer dfb = drawFramebuffer;
1679+
if ((currfb == rfb) || (currfb == dfb)) {
1680+
// Not user-provided FB, need to check if the correct FB is current.
1681+
if (op == OP_READ) {
1682+
if (pgl.isFBOBacked() && pgl.isMultisampled()) {
1683+
// Making sure the back texture is up-to-date...
1684+
pgl.syncBackTexture();
1685+
// ...because the read framebuffer uses it as the color buffer (the
1686+
// draw framebuffer is MSAA so it cannot be read from it).
1687+
pixfb = rfb;
1688+
} else {
1689+
pixfb = dfb;
1690+
}
1691+
} else if (op == OP_WRITE) {
1692+
// We can write to the draw framebuffer irrespective of whether is
1693+
// FBO-baked or multisampled.
1694+
pixfb = dfb;
16851695
}
1686-
} else if (op == OP_WRITE) {
1687-
// We can write to the draw framebuffer irrespective of whether is
1688-
// FBO-baked or multisampled.
1689-
pixfb = drawFramebuffer;
16901696
}
16911697
} else {
16921698
FrameBuffer ofb = offscreenFramebuffer;
16931699
FrameBuffer mfb = multisampleFramebuffer;
1694-
if (op == OP_READ) {
1695-
if (offscreenMultisample) {
1696-
// Making sure the offscreen FBO is up-to-date
1697-
int mask = PGL.COLOR_BUFFER_BIT;
1698-
if (hints[ENABLE_BUFFER_READING]) {
1699-
mask |= PGL.DEPTH_BUFFER_BIT | PGL.STENCIL_BUFFER_BIT;
1700-
}
1701-
if (ofb != null && mfb != null) {
1702-
mfb.copy(ofb, mask);
1700+
if ((currfb == ofb) || (currfb == mfb)) {
1701+
// Not user-provided FB, need to check if the correct FB is current.
1702+
if (op == OP_READ) {
1703+
if (offscreenMultisample) {
1704+
// Making sure the offscreen FBO is up-to-date
1705+
int mask = PGL.COLOR_BUFFER_BIT;
1706+
if (hints[ENABLE_BUFFER_READING]) {
1707+
mask |= PGL.DEPTH_BUFFER_BIT | PGL.STENCIL_BUFFER_BIT;
1708+
}
1709+
if (ofb != null && mfb != null) {
1710+
mfb.copy(ofb, mask);
1711+
}
17031712
}
1713+
// We always read the screen pixels from the color FBO.
1714+
pixfb = ofb;
1715+
} else if (op == OP_WRITE) {
1716+
// We can write directly to the color FBO, or to the multisample FBO
1717+
// if multisampling is enabled.
1718+
pixfb = offscreenMultisample ? mfb : ofb;
17041719
}
1705-
// We always read the screen pixels from the color FBO.
1706-
pixfb = ofb;
1707-
} else if (op == OP_WRITE) {
1708-
// We can write directly to the color FBO, or to the multisample FBO
1709-
// if multisampling is enabled.
1710-
pixfb = offscreenMultisample ? mfb : ofb;
17111720
}
17121721
}
17131722

0 commit comments

Comments
 (0)