@@ -1672,42 +1672,51 @@ protected void endReadPixels() {
1672
1672
1673
1673
protected void beginPixelsOp (int op ) {
1674
1674
FrameBuffer pixfb = null ;
1675
+ FrameBuffer currfb = getCurrentFB ();
1675
1676
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 ;
1685
1695
}
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 ;
1690
1696
}
1691
1697
} else {
1692
1698
FrameBuffer ofb = offscreenFramebuffer ;
1693
1699
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
+ }
1703
1712
}
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 ;
1704
1719
}
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 ;
1711
1720
}
1712
1721
}
1713
1722
0 commit comments