Depth test for custom framebuffer not working

Hello everybody!

I have a small framework, written in C++, which renders a simple scene. Everything is fine. And now I’m trying to add reflection mapping. So I’ve created a cubemap and 6 cameras in order to render the whole scene to 6 2D-textures inside the cubemap. Let’s name this rendering process as local.

The local rendering works with a custom framebuffer object. I create it once before all the rendering takes place:


    glGenFramebuffers (1, &oReflectionMap->_fbo);

Then every frame I perform the local rendering, where I do the following for each of the 6 2D-textures, mentioned above:


    glBindFramebuffer (GL_FRAMEBUFFER, _fbo);
    glFramebufferTexture2D (GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, iTextureIndex, _texture->GetTexId (), 0);

    glReadBuffer (GL_NONE);

Then I render the scene. And finally, I disable the fbo:


    glBindFramebuffer (GL_FRAMEBUFFER, 0);

The problem is that the depth testing for the local rendering doesn’t work. The result of the rendering operation depends on the order of the objects in the rendering queue. Have I missed something? Btw, glIsEnabled (GL_DEPTH_TEST) says, that depth testing is enabled.

checklist:

  1. You have cleared depth buffer and have set the function.
  2. While creating context, you have enabled depth buffer bit.
  3. your depth attachment.

1),2) Depth test works correctly for the main rendering routine. I supposed, that all the opengl settings (like glEnable (GL_DEPTH_TEST)) are set for opengl environment in general - not for the current framebuffer only. Am I wrong?
3) So, I have to create depth attachment manually? Isn’t there a default depth attachment created for the new framebuffer, like it is done for the default framebuffer?

[QUOTE=Blizzard_jedi;1260014]
3) So, I have to create depth attachment manually? Isn’t there a default depth attachment created for the new framebuffer, like it is done for the default framebuffer?[/QUOTE]
1,2. if it works for default, that means it is enabled.
3. you should create a depth attachment (renderbuffer).

So, I have to create depth attachment manually? Isn’t there a default depth attachment created for the new framebuffer, like it is done for the default framebuffer?

Nope, there’s actually a separate attachment point for depth-renderable targets, i.e. DEPTH_ATTACHMENT (or DEPTH_STENCIL_ATTACHMENT depending on what you need).

Why would a FBO rely on the default framebuffer’s depth buffer? Does that really make sense to you? Also, it is valid to not have a depth attachment and depth testing disabled altogether - image processing on a full-screen quad comes to mind etc. etc.

Also, there is no such thing a “custom framebuffer” - it’s called a framebuffer and any non-default framebuffer can be realized with a framebuffer object.

  1. you should create a depth attachment (renderbuffer).

A depth attachment need not a be a renderbuffer - if you need to re-use the resulting image with a texture object or other means of input to a shader, renderbuffers are out of the question anyway or you need to incur additional costs for copying data to a texture. I’m not aware of any significant advantage of a renderbuffer over a texture.

Well, when I wrote “custom framebuffer”, I actually meant “a framebuffer, different from the default one”. Sorry for some mess in terminology.

Anyway, I’ll try to add some kind of depth attachment to my new framebuffer. Thank you for help.

Yeah, thanks a lot, guys! I’ve attached a renderbuffer object to the depth attachment point - now everything works fine! )