@@ -1665,42 +1665,51 @@ protected void endReadPixels() {
1665
1665
1666
1666
protected void beginPixelsOp (int op ) {
1667
1667
FrameBuffer pixfb = null ;
1668
+ FrameBuffer currfb = getCurrentFB ();
1668
1669
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 ;
1678
1688
}
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 ;
1683
1689
}
1684
1690
} else {
1685
1691
FrameBuffer ofb = offscreenFramebuffer ;
1686
1692
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
+ }
1696
1705
}
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 ;
1697
1712
}
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 ;
1704
1713
}
1705
1714
}
1706
1715
0 commit comments