Jump to content
  • Advertisement
Sign in to follow this  
hmcen

Bind FBO with a depth renderbuffer or a depth texture?

This topic is 4170 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, i'm using frame buffer object to save depth information of the scene for later use. First i use a renderbuffer for depth:
// Create the renderbuffer for depth	
glGenRenderbuffersEXT(1, &depth);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height);
// Attach the depth renderbuffer to the FBO
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth);


when rendering is done, i try to visualize the depth info, but i can see nothing but all black.(the scene is placed between my zNear and zFar clipping plane) Then i bind the FBO with a depth texture instead of a depth renderbuffer:
// Create texture for depth
glGenTextures(1, &depth);
glBindTexture(GL_TEXTURE_2D, depth);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// Attach the depth texture to the FBO
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, depth, 0);


this time i can see correct depth info, but my frame rates drops a little. my question is: 1. Bind FBO with a depth renderbuffer or with a depth texture, is there anything difference? (performance, actual value) 2. what exactly are recorded into FBO's depth component during rendering? my understanding is: for a vertex in object space, convert it into projection space, divide it by its w component, and scale the xyz into [0,1], finally its z component is recorded into depth buffer. Anyone can help figuring out where i am doing wrong, and give me some hints? thanks a lot! (sorry for my poor english :( )

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by hmcen
1. Bind FBO with a depth renderbuffer or with a depth texture, is there anything difference? (performance, actual value)

Performance depends on your hardware. The actual values stored internally also depend on the hardware. When accessing a depth texture from a fragment shader, you can choose between two modes:

1) 8bit luminance values. This is only useful for debugging purposes. It's invoked if at least one filter mode is set to GL_LINEAR. You don't want this.

2) Normalized floating point values. This is what you want. You have to set the filters to GL_NEAREST for this mode to be enabled (because linear filtering doesn't make sense on depth values anyway).

Quote:

2. what exactly are recorded into FBO's depth component during rendering?
my understanding is: for a vertex in object space, convert it into projection space, divide it by its w component, and scale the xyz into [0,1], finally its z component is recorded into depth buffer.

Correct.

Share this post


Link to post
Share on other sites
thanks Yann L:) quite clear now.

i'm not quite sure whether the renderbuffer can be directly used in texture mapping as ordinary texture do, and i've changed the filter mode to GL_NEAREST , but the frame rates of my program still drop a level when i bind FBO with a depth texture compare to a depth renderbuffer, is that the hardware problem? or something else? thanks guys

Share this post


Link to post
Share on other sites
Quote:
Original post by hmcen
i'm not quite sure whether the renderbuffer can be directly used in texture mapping as ordinary texture do,

Nope. That's why it is a renderbuffer, and not a texture [wink] You could obviously copy its contents to a texture, but this is much slower than rendering directly to the latter (unless you want to use multisampling, where the copy is mandatory).

Quote:
Original post by hmcen
and i've changed the filter mode to GL_NEAREST , but the frame rates of my program still drop a level when i bind FBO with a depth texture compare to a depth renderbuffer, is that the hardware problem?

Well, what is your hardware ?

Share this post


Link to post
Share on other sites
Hummmm....Does that mean i can't just pass the depth renderbuffer into a fragment shader as sampler2D and use something like tex2D() to index and fetch the depth value? If so, i think i should render depth to texture rather than renderbuffer.
my hardware: NV Geforce 6800. Now i guess the performance drop might be that i mistakenly use renderbuffer as textures in my program.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!