Kamujin's picture

Framebuffer Objects

As I've googled tutorials on OpenGL FBO's, the C based example often follow the follow form to add a depth buffer.

GLuint depthbuffer;
glGenRenderbuffersEXT(1, &depthbuffer);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthbuffer);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthbuffer);

In your example, you skip the use of the renderbuffer entirely and use a texture object as your depth buffer.

Can you help me understand why this is?

I suspect the answer will also explain why the GL_DEPTH_COMPONENT define doesn't have a place with the RenderbufferStorage enumeration.

The following port will not compile due to the missing enum.
GL.Ext.GenRenderbuffers(1, out handleRenderBuffer);
GL.Ext.BindRenderbuffer(RenderbufferTarget.RenderbufferExt, handleRenderBuffer);
GL.Ext.RenderbufferStorage(RenderbufferTarget.RenderbufferExt, RenderbufferStorage.DepthComponent, width, height);
GL.Ext.FramebufferRenderbuffer(FramebufferTarget.FramebufferExt, FramebufferAttachment.DepthAttachmentExt, RenderbufferTarget.RenderbufferExt, handleRenderBuffer);


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Inertia's picture

The example uses texture objects rather than renderbuffer objects, because no matter how the renderbuffer was configured it would return a FramebufferUnsupported error (Geforce FX5600). For Shadowmapping you have to set the depth buffer's filtering to linear in order to get PCF, and I honestly have no idea how to set this for a renderbuffer object. The only difference I see between texture and renderbuffer is that the later can only be 2D, while a texture can be 1D/3D aswell. Not sure if there are any performance differences as the renderbuffer object wouldn't work.

Although a temporary solution, you can get it to compile by casting:
GL.Ext.RenderbufferStorage(RenderbufferTarget.RenderbufferExt, (RenderbufferStorage) All.DepthComponent, width, height);

Kamujin's picture

I had tried casting All.DepthComponent myself and got the same FramebufferUnsupported error that you mentioned. I also cast every reasonable hex value that I found defined in gl.h with the similar results (The stencil values return a different error).

My hardware is an nVidia 8600M GT. (correction from 6800GT)

Using your sample, I get FramebufferComplete, so I think I'll just stick with the texture based depth buffer for now.

Thanks for the quick response.

Inertia's picture

Np, the depth buffer attachment also seemed to fail every time the DepthComponent wasn't the same as the main window's depth. Maybe that helps in case someone feels the urge to use renderbuffer objects rather than textures, but since no GL Error is reported and only the FBO reported that the desired configuration wasn't supported I'm quite sure that the problem is related to the driver/card and not to the OpenGL bindings.

Edit: GL_EXT_framebuffer_multisample sheds some light on the purpose of renderbuffers.