Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: glReadPixels GL_DEPTH_COMPONENT downsampled FBO

  1. #1
    Junior Member Regular Contributor
    Join Date
    May 2008
    Posts
    120

    glReadPixels GL_DEPTH_COMPONENT downsampled FBO

    Hi!

    The following issue only occurs on ATI cards.

    I render the scene into a multisampled framebuffer.
    Then I blit (downsample) the multisampled framebuffer
    to a non-multisampled one and try to read the depth
    value at a certain pixel using glReadPixels.
    But I always get 0.0 as depth value.

    On NVidia cards everything works fine.
    If I disable the multisampling it also works on ATI cards.


    ============= Full description =============

    The multisampled framebuffer is setup like this:

    Code :
    // 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:

    Code :
    // 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:

    Code :
    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:

    Code :
    // 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 everything works fine.
    And without multisampling it works on both cards.

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

  2. #2
    Junior Member Regular Contributor
    Join Date
    May 2008
    Posts
    120

    Re: glReadPixels GL_DEPTH_COMPONENT downsampled FBO

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

    It only happens on my
    - ATI Radeon HD 5850

  3. #3
    Junior Member Regular Contributor
    Join Date
    May 2008
    Posts
    120

    Re: glReadPixels GL_DEPTH_COMPONENT downsampled FBO

    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...
    Code :
    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:
    Code :
    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

  4. #4
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,261

    Re: glReadPixels GL_DEPTH_COMPONENT downsampled FBO

    Driver problems can/should be posted in the Drivers forum here, afaik:
    http://www.opengl.org/discussion_boa...=13&page=1

    Btw, imho there's no need to cross-post between this board and gamedev.net : most (if not all) members here visit both places, afaik .

  5. #5
    Junior Member Regular Contributor
    Join Date
    May 2008
    Posts
    120

    Re: glReadPixels GL_DEPTH_COMPONENT downsampled FBO

    Thanks I just opened a thread there.

    I cross-posted this on gamedev because no one was
    replying on the ATI board or in the OpenGL.org forum ^^

    Anyway now I can go to sleep

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •