PDA

View Full Version : multiple FBO and one depth buffer



addmx
06-02-2009, 07:14 AM
hi

I have the wollowing question:

I have frame_buffer_object and few textures attached to it


glGenFramebuffersEXT(1, &fbo)
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tid0, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, tid1, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_TEXTURE_2D, tid2, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, depth_texture, 0);

now i render some things to those 3 textures (and write depth to depth texture)


glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

now all my 3 textures are just fine, depth_texture olso contains expected values

the trick i want to do now is to bind another fbo


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

bind another texture (witch have the dimensions and format identical as tid0, tid1 and tid2)


glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tid3, 0);

bind THAT SAME depth buffer as previous


glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, depth_texture, 0);

and continue rendering using values stored in depth buffer AND in the fragment shader
reading values from depth_texture

the depth_texture reads in shader have proper values - but it seems that depth buffer contains
some trash inside not the depth values from previous fbo :p

(the trash is random, sometimes the upper half of depth buffer is fine, sometimes whole depth buffer is fine,
it's per frame basic - as if the driver sometimes trash some parts of depth buffer)

is there any neat trick for this ?
i need the values in second pass to be exact that same as in first pass couse i use


glEnable( GL_DEPTH_TEST);
glDepthMask( GL_FALSE);
glDepthFunc(GL_EQUAL);

setup for geometry in the second pass.

There are no any glErrors generated.
what specification says about such a setup ?

I use Nvidia GF 280 GTX and latest non-beta drivers (on vista x64 sp2)

I cannot just copy content from depth_texture to depth buffer using shader couse
the values outputed are not exacly that same and i see zfighting with this solution (sure i could offset them - its stil faster than rendering again tons of geometry)
(olso copying 1920 x 1080 image takes significant amount of time, and i must be in 30Hz)

thanks for any info

Ilian Dinev
06-02-2009, 03:42 PM
I met that problem (or bug in my code) some time ago, on gf7600. Haven't checked if it's still broken. In my case it looked like the depth-texture contained values from the previous frame.

addmx
06-03-2009, 01:11 AM
I'v just installed new beta drivers from nvidia and the problem is gone (or it was just coincidence ?) -- now it works like a charm.

The question is - will this 'fix' made to whql drivers that most ppl istall ? I hope so :)