Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: Binding to a different depth buffer.

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    3

    Binding to a different depth buffer.

    I've gotta keep this short. (the forum code hates me cause I'm new)
    Post denied. New posts are limited by number of URLs it may contain and checked if it doesn't contain forbidden words.
    I've got an offscreen render buffer I use for picking. How do I sometimes attach it to the existing scene depth buffer, and sometimes not.

    I'd show you what I've got so far but I think that's what freaked out the forum code earlier. My compiler acts the same way.

  2. #2
    Administrator Regular Contributor Khronos_webmaster's Avatar
    Join Date
    Apr 2007
    Location
    Montreal
    Posts
    148
    You're welcome to post your code. It is the URLs that are banned for noobs.
    Webmaster Khronos.org and OpenGL.org

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    3
    There were no URLs.

    I got it figured out. At least according to a post on another site that I read, you can't rebind the frame buffer to a different depth buffer but you can blit between the two depth buffers. Like so...

    Code :
        glBindFramebuffer(GL_DRAW_FRAMEBUFFER, my_FBO);
        glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
        glBlitFramebuffer(0, 0, m_CanvasWidth, m_CanvasHeight,
                                0, 0, m_CanvasWidth, m_CanvasHeight,
                                GL_DEPTH_BUFFER_BIT, GL_NEAREST);
        glBindFramebuffer(GL_FRAMEBUFFER, my_FBO);

    It's working for me. I put that in "myCanvas->keepDepth();" and just call it when I need it.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,098
    [quote]you can't rebind the frame buffer to a different depth bufferp/quote] AFAIK this is not true. I certainly bind a depth buffer to different FBO - but I unbind the first FBO before I bind the next.

  5. #5
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    [quote]
    you can't rebind the frame buffer to a different depth bufferp/quote] AFAIK this is not true. I certainly bind a depth buffer to different FBO - but I unbind the first FBO before I bind the next.
    He probably missed putting "default" in front of "frame buffer".

  6. #6
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    3
    Thanks for the reply guys.

    This is how I create my selection buffer. How would I change that to create the buffer bound to the default depth buffer? If I don't want the existing depth information I can clear it just as easily, as making a call to have it preserved. Using the existing depth buffer would be more memory efficient, and I don't know, but it seems that clearing it would be at least as fast as blitting.

    Code :
    void wxBFXCanvas::setSelectionBuffer()
    {
        if(m_SBO != 0) // delete current selection buffer if it exists
        {
            glDeleteFramebuffers(1, &m_SBO);
            glDeleteRenderbuffers(1, &m_SBODepth);
            glDeleteRenderbuffers(1, &m_SBOPixels);
            m_SBO = 0;
        }
        // create depth renderbuffer
        glGenRenderbuffers(1, &m_SBODepth);
        glBindRenderbuffer(GL_RENDERBUFFER, m_SBODepth);
        glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_CanvasWidth, m_CanvasHeight);
        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_SBODepth);
        glBindRenderbuffer(GL_RENDERBUFFER, 0);
        // create pixel renderbuffer
        glGenRenderbuffers(1, &m_SBOPixels);
        glBindRenderbuffer(GL_RENDERBUFFER, m_SBOPixels);
        glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB, m_CanvasWidth, m_CanvasHeight);
        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_SBOPixels);
        glBindRenderbuffer(GL_RENDERBUFFER, 0);
        // create framebuffer object
        glGenFramebuffers(1, &m_SBO);
        glBindFramebuffer(GL_FRAMEBUFFER, m_SBO);
        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_SBOPixels);
        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_SBODepth);
        // Check that things seem to have worked so far
        GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
        if (status != GL_FRAMEBUFFER_COMPLETE)
        {
            wxMessageBox(_T("Selection buffer creation failed"),_T("Oops, Bad Cr*p...."));
            glBindFramebuffer(GL_FRAMEBUFFER, 0);
            m_SBODirty = false;
            m_SBO = 0;
            return;
        }
        glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
        m_SBODirty = false;
        Refresh(false); // force a screen refresh
    }

    Notice the title of the error message box. I think that's the bit that was causing the forum code to choke. My Bad!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •