PDA

View Full Version : Binding to a different depth buffer.



BentFX
01-11-2013, 04:44 AM
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.

Khronos_webmaster
01-11-2013, 06:34 AM
You're welcome to post your code. It is the URLs that are banned for noobs.

BentFX
01-11-2013, 09:06 AM
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...



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.

tonyo_au
01-11-2013, 06:05 PM
[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.

Alfonse Reinheart
01-11-2013, 06:35 PM
[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".

BentFX
01-11-2013, 08:15 PM
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.


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!

tonyo_au
01-12-2013, 07:32 PM
I am attaching texture buffers rather that render buffers to the frame buffer when I swap depth buffers