Skip to content

Commit 2a033e5

Browse files
committed
ported readPixels() fix
1 parent 2db52c2 commit 2a033e5

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
@@ -1665,42 +1665,51 @@ protected void endReadPixels() {
16651665

16661666
protected void beginPixelsOp(int op) {
16671667
FrameBuffer pixfb = null;
1668+
FrameBuffer currfb = getCurrentFB();
16681669
if (primaryGraphics) {
1669-
if (op == OP_READ) {
1670-
if (pgl.isFBOBacked() && pgl.isMultisampled()) {
1671-
// Making sure the back texture is up-to-date...
1672-
pgl.syncBackTexture();
1673-
// ...because the read framebuffer uses it as the color buffer (the
1674-
// draw framebuffer is MSAA so it cannot be read from it).
1675-
pixfb = readFramebuffer;
1676-
} else {
1677-
pixfb = drawFramebuffer;
1670+
FrameBuffer rfb = readFramebuffer;
1671+
FrameBuffer dfb = drawFramebuffer;
1672+
if ((currfb == rfb) || (currfb == dfb)) {
1673+
// Not user-provided FB, need to check if the correct FB is current.
1674+
if (op == OP_READ) {
1675+
if (pgl.isFBOBacked() && pgl.isMultisampled()) {
1676+
// Making sure the back texture is up-to-date...
1677+
pgl.syncBackTexture();
1678+
// ...because the read framebuffer uses it as the color buffer (the
1679+
// draw framebuffer is MSAA so it cannot be read from it).
1680+
pixfb = rfb;
1681+
} else {
1682+
pixfb = dfb;
1683+
}
1684+
} else if (op == OP_WRITE) {
1685+
// We can write to the draw framebuffer irrespective of whether is
1686+
// FBO-baked or multisampled.
1687+
pixfb = dfb;
16781688
}
1679-
} else if (op == OP_WRITE) {
1680-
// We can write to the draw framebuffer irrespective of whether is
1681-
// FBO-baked or multisampled.
1682-
pixfb = drawFramebuffer;
16831689
}
16841690
} else {
16851691
FrameBuffer ofb = offscreenFramebuffer;
16861692
FrameBuffer mfb = multisampleFramebuffer;
1687-
if (op == OP_READ) {
1688-
if (offscreenMultisample) {
1689-
// Making sure the offscreen FBO is up-to-date
1690-
int mask = PGL.COLOR_BUFFER_BIT;
1691-
if (hints[ENABLE_BUFFER_READING]) {
1692-
mask |= PGL.DEPTH_BUFFER_BIT | PGL.STENCIL_BUFFER_BIT;
1693-
}
1694-
if (ofb != null && mfb != null) {
1695-
mfb.copy(ofb, mask);
1693+
if ((currfb == ofb) || (currfb == mfb)) {
1694+
// Not user-provided FB, need to check if the correct FB is current.
1695+
if (op == OP_READ) {
1696+
if (offscreenMultisample) {
1697+
// Making sure the offscreen FBO is up-to-date
1698+
int mask = PGL.COLOR_BUFFER_BIT;
1699+
if (hints[ENABLE_BUFFER_READING]) {
1700+
mask |= PGL.DEPTH_BUFFER_BIT | PGL.STENCIL_BUFFER_BIT;
1701+
}
1702+
if (ofb != null && mfb != null) {
1703+
mfb.copy(ofb, mask);
1704+
}
16961705
}
1706+
// We always read the screen pixels from the color FBO.
1707+
pixfb = ofb;
1708+
} else if (op == OP_WRITE) {
1709+
// We can write directly to the color FBO, or to the multisample FBO
1710+
// if multisampling is enabled.
1711+
pixfb = offscreenMultisample ? mfb : ofb;
16971712
}
1698-
// We always read the screen pixels from the color FBO.
1699-
pixfb = ofb;
1700-
} else if (op == OP_WRITE) {
1701-
// We can write directly to the color FBO, or to the multisample FBO
1702-
// if multisampling is enabled.
1703-
pixfb = offscreenMultisample ? mfb : ofb;
17041713
}
17051714
}
17061715

0 commit comments

Comments
 (0)