3

Using Frame Buffer objects, I have created render buffers for color and depth and attached them to the FBO.

//set up color buffer for rendering
glGenRenderbuffers(1, &my_fbo_params.color_rb[i]);
glBindRenderbuffer(GL_RENDERBUFFER, my_fbo_params.color_rb[i]);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB565, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,           my_fbo_params.color_rb[i]);

//set up depth buffer
glGenRenderbuffers(1, &my_fbo_params.depth_rb[i]);
glBindRenderbuffer(GL_RENDERBUFFER, my_fbo_params.depth_rb[i]);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, my_fbo_params.depth_rb[i]); 

This is all fine and working good. When I proceed to the next scene, I want to keep the color buffer but detach and unbind the depth buffer. I learnt that the following code will do the detach:

glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0); 

But how can I unbind the depth buffer while keeping the color buffer intact?

Alex Shesterov
  • 26,085
  • 12
  • 82
  • 103
Suri
  • 41
  • 4
  • The above code will undbind the cdepth buffer and leave the color buffer intact, so what is the problem you are experiencing. Another thing: why do you actually need to do that? – derhass Oct 07 '13 at 19:34
  • Trying to implement a benchmark framework where I need to do offscreen rendering and whether depth/color/stencil buffers needed or not may depend on the test specification. So, you are saying that thw following will do tha unbinding? glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0); – Suri Oct 07 '13 at 20:54
  • fro the following thread, I thought the above call will do detach but not unbinding. http://stackoverflow.com/questions/6144845/frame-buffer-object-fbo-and-render-depth-buffers-relation – Suri Oct 07 '13 at 20:55
  • the actual "unbinding" is a totally unneccesary operation. The depth buffer will be detached. It does not matter wich render buffer you have bound to the `GL_RENDERBUFFER` target anyways, except when calling `glRenderbufferStorage` and friends. I think you have some misunderstand of what binding a renderbuffer actually means. – derhass Oct 07 '13 at 21:08
  • I will have some test cases where depth is enabled and some where depth is disabled. For the tests, where depth is disabled, i want to unbind the depth render buffer (and do not want to free/delete the depth render buffer allocated memory as I may need to rebind the depth buffer for an upcoming test). Almost all the material on the net talks about the binding code. Could not really find a reliable source of information on how to unbind a particular render buffer. My question is how to unbind the depth render buffer, without freeing/deleting its allocated memory? – Suri Oct 07 '13 at 21:20
  • What you really want to do is just detaching (and later reattaching) the depth buffer from/to the FBO. And you already do that. "Unbinding" has nothing to do with that, and is completely irrelevant here. Note that disabling the depth test will also disable writes to the depth buffer, so there isn't really a need to detach it at all. – derhass Oct 07 '13 at 21:24
  • That explains. Thanks for the clarification. – Suri Oct 07 '13 at 23:21

0 Answers0