PDA

View Full Version : glReadPixels GL_DEPTH_COMPONENT downsampled FBO



Schnulla
06-21-2010, 07:20 AM
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:


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

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

Schnulla
06-21-2010, 03:20 PM
I cannot reproduce this issue on:
- NVidia 8800 GTS
- ATI Mobility Radeon HD 3400

It only happens on my
- ATI Radeon HD 5850

Schnulla
06-21-2010, 04:29 PM
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:

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

Ilian Dinev
06-21-2010, 05:17 PM
Driver problems can/should be posted in the Drivers forum here, afaik:
http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=postlist&Board=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 :) .

Schnulla
06-21-2010, 06:59 PM
Thanks I just opened a thread there (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=279315#Post2793 15).

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 ;)