3 Replies Latest reply on Jun 21, 2010 9:31 PM by xtremer

    glReadPixels and multisampled FBO

    xtremer
      Blitting to non-multisampled FBO does not work anymore?

      Hi,

      I installed a new graphic card (Radeon HD 5850) with latest drivers.

      Today I noticed that glReadPixels does not work anymore when I enable multisampling although I downsample the multisampled FBO to a normal buffer using glBlitFramebufferEXT.

      This was working fine on my old NVidia 8800 GTS and on the Radeon in my laptop so I have no clue what is going wrong.

      My System:

      Windows 7 x64 - OpenGL 4.X (but I use the old 1.X/2.X context)

      It works if I disable the multisampling. On the other cards it works in both cases.

       

      Help is really appreciated!



        • glReadPixels and multisampled FBO
          xtremer

          Here is some code.

          The multisampled framebuffer is setup like this:

          // Create multisampled framebuffer

          glGenFramebuffersEXT(1, &Handle_FB_MS);
          glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, Handle_FB_MS);

          // Create and attach multisampled depth-stencil renderbuffer
          glGenRenderbuffersEXT(1, &Handle_RB_depth_stencil);
          glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, Handle_RB_depth_stencil);
          glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples, GL_DEPTH24_STENCIL8_EXT, Width, Height);

          glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, Handle_RB_depth_stencil);
          glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, Handle_RB_depth_stencil);

          // Create and attach multisampled color renderbuffer

          glGenRenderbuffersEXT(1, &Handle_RB_color);
          glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, Handle_RB_color);
          glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples, GL_RGBA8, Width, Height);

          glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, Handle_RB_color);

          CheckStatus();



          The other framebuffer setup:

          Create non-multisampled framebuffer

          glGenFramebuffersEXT(1, &Handle_FB);
          glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, Handle_FB);

          // Create and attach depth-stencil renderbuffer
          glGenRenderbuffersEXT(1, &Handle_RB_depth_stencil);
          glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, Handle_RB_depth_stencil);
          glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT, Width, Height);

          glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, Handle_RB_depth_stencil);
          glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, Handle_RB_depth_stencil);


          glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);

          // Create and attach color renderbuffer (texture)
          TextureColor= InitTexture(...);

          glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, TextureColor->Handle, 0);

          CheckStatus();



          During rendering I blit (downsample) the first multisampled framebuffer to the second non-multisampled:



          glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, From->Handle_FB_MS);
          glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, To->Handle_FB);

          glBlitFramebufferEXT(0, 0, Width, Height, 0, 0, Width, Height, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST);



          Then I read a pixel from the downsampled framebuffer:



          // x and y lie between 0 and the maximum screen width/height
          GLfloat Zf;
          glReadPixels((GLint)x, (GLint)y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &Zf);




          But I always get Zf == 0.0

          As I said this only happens on ATI cards, on NVidia cards it works fine.

          And without multisampling it works on both cards.


          Help is really appreciated cause I'm stuck at this point!

            • glReadPixels and multisampled FBO
              xtremer

              I cannot reproduce this issue on:
              - NVidia 8800 GTS
              - ATI Mobility Radeon HD 3400

              It only happens on my
              - ATI Radeon HD 5850

               

              Any ideas??

                • glReadPixels and multisampled FBO
                  xtremer

                  I was able to solve the issue with the help of some
                  guy from another OpenGL forum.

                  Using glBlitFramebufferEXT without the stencil flag
                  makes the stuff also work on ATI Radeon HD 5850.


                  So this is definitely a driver bug and a workaround is to call...

                  glBlitFramebufferEXT(0, 0, Width, Height, 0, 0, Width, Height, GL_DEPTH_BUFFER_BIT, GL_NEAREST);

                  ...instead of...
                  glBlitFramebufferEXT(0, 0, Width, Height, 0, 0, Width, Height, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST);

                  ...although a packed GL_DEPTH24_STENCIL8_EXT renderbuffer is used.

                  Nasty sh#$% that only happens on ATI Radeon HD 5850.

                  How can I submit this bug report to the driver developers?

                  Here are the driver versions:

                  Driver Packaging Version    8.732-100504a-099996C-ATI   
                  Catalyst™ Version    10.5   
                  Provider    ATI Technologies Inc.   
                  2D Driver Version    8.01.01.1030   
                  2D Driver File Path    /REGISTRY/MACHINE/SYSTEM/ControlSet001/Control/CLASS/{4D36E968-E325-11CE-BFC1-08002BE10318}/0001   
                  Direct3D Version    8.14.10.0753   
                  OpenGL Version    6.14.10.9836   
                  Catalyst™ Control Center Version    2010.0504.2152.37420