[Solved] Problem with RTT depth buffers

My goal is to implement glow using RTT (FBO w/ depth buffer).

To render glow I am doing the following:

  • Allocate two FBOs
  • Create a depth texture and attach it to the FBOs as their depth buffer
  • When opaque geometry has been rendered, copy the back buffer’s depth buffer to the depth texture
  • render stuff that should have glow to FBO #1
  • render FBO #1 to FBO #2 doing vertical Gaussian blur
  • render FBO #2 to FBO #1 doing horizontal Gaussian blur
  • render blurred FBO #1 to back buffer

I know this may not be optimal, but for the time being I want to follow this path.

Now the problem is that the depth buffer I have been attaching to the FBOs doesn’t seem to get properly updated when copying the back buffer’s depth buffer to it (subsequently rendering to the FBO shows artifacts in the image rendered to the FBO), and I don’t understand why. I am using the depth texture in another scenario successfully (depth blending), so generally copying the depth buffer to a texture and using that texture to access the current depth information works. When I clear the FBOs’ depth texture before rendering to the FBOs there are no artifacts.

  • Can’t the two FBOs share the same depth texture as depth buffer?
  • Can’t I copy the back buffer’s depth buffer to the depth texture while it’s attached to the FBOs as depth buffer?

I could solve the problem myself. My previous use of the depth texture set the GL_TEXTURE_COMPARE_MODE to none (didn’t need it there):

glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);

This must not be done for an RTT FBO’s depth texture. Actually I had that distinction in my call already - I just didn’t call my depth texture creation function with the proper parameter.