Results 1 to 7 of 7

Thread: Depth test for custom framebuffer not working

  1. #1
    Junior Member Newbie
    Join Date
    May 2014
    Posts
    12

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

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

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

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

  2. #2
    Senior Member Regular Contributor
    Join Date
    Apr 2012
    Posts
    318
    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.

  3. #3
    Junior Member Newbie
    Join Date
    May 2014
    Posts
    12
    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?

  4. #4
    Senior Member Regular Contributor
    Join Date
    Apr 2012
    Posts
    318
    Quote Originally Posted by Blizzard_jedi View Post
    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?
    1,2. if it works for default, that means it is enabled.
    3. you should create a depth attachment (renderbuffer).

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,135
    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.

    3. 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.

  6. #6
    Junior Member Newbie
    Join Date
    May 2014
    Posts
    12
    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.

  7. #7
    Junior Member Newbie
    Join Date
    May 2014
    Posts
    12
    Yeah, thanks a lot, guys! I've attached a renderbuffer object to the depth attachment point - now everything works fine! )

Similar Threads

  1. Road to Single Render Pass : custom depth test ?
    By bubuche in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 09-29-2018, 07:13 PM
  2. FBO: depth is not stored, while the depth test is working
    By Goossen in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 12-29-2016, 08:55 AM
  3. Depth test not working
    By esapir in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-28-2014, 12:52 PM
  4. Framebuffer depth test with depth and stencil buffer
    By moldyviolinist in forum OpenGL: Basic Coding
    Replies: 10
    Last Post: 07-29-2013, 08:21 PM
  5. Custom Depth Test Problem?
    By ViolentHamster in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 06-04-2013, 09:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean