Sign in to follow this  

Quick way to copy a depth buffer

This topic is 4267 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

Hey, I'm trying to optimise my deferred shader (see my other post), and I was wondering what is the fastest way to copy a depth buffer from a framebuffer object into the main framebuffer? I tried glReadPixels and glDrawPixels but it was slow, at the moment im redrawing the scene with the draw buffer disabled in the main framebuffer after rendering to the FBO. Is there a quicker way to copy the buffer? Luke.

Share this post


Link to post
Share on other sites
Does anybody have any ideas?

I just need to somehow get the depth buffer from the FBO to the main framebuffer quickly. At the moment the whole redraw makes my code alot longer, i'd like my engine calls to go something like:

shader->Enable();
drawScene();
shader->Disable();

but at the moment I have:

shader->Enable(DS_GBUFFER_FILL); //Phase 1 fill G-buffer
drawScene();
shader->Disable(DS_GBUFFER_FILL);

shader->Enable(DS_DEPTH_RENDER); //Phase 2 fill depth buffer
drawScene();
shader->Disable(DS_DEPTH_RENDER);


so i'd like to merge the 2 so that when the shader is disabled the depth buffer is copied, either that or is there anyway for a FBO to use the main depth buffer instead of an attachment?

Thanks

Luke.

Share this post


Link to post
Share on other sites
Just a few ideas ;
- Use glReadPixels and glDrawPixels with PBO to get asynchronous transfer (easy and perhaps satisfying but requires lots of VRAM).
- Render a quad on your main framebuffer wih color write disable and a fragment shader that will read the depth from your GBuffer (a depth texture) and write it to your main buffer (a bit more complex, avoids the allocation of a PBO and therefore saves memory usage).

This is just my 2 cents. I'm really not sure that these idea are good (I did not try them).

Vincent

Share this post


Link to post
Share on other sites
If your assigning your FBO a render buffer to use as the depth component(using GL_DEPTH_ATTACHMENT_EXT), couldnt you just attach the same render buffer to your main framebuffer as the depth component?

Share this post


Link to post
Share on other sites
No.

At least according to the spec ;
"By default, the GL uses the window-system-provided framebuffer. The storage, dimensions, allocation, and format of the images attached to this framebuffer are managed entirely by the window-system. Consequently, the state of the window-system-provided framebuffer, including its images, can not be changed by the GL, nor can the window-system-provided framebuffer itself, or its images, be deleted by the GL."

Therefore, I don't think there is a way to share the data of the main frame buffer with application frame buffer. Thus the idea I proposed ; through PBO you have 2 transfers ; one made when you call glReadPixel and one when you call glDRawPixel. With the fragment shader solution, you have only one transfer but with the expense of the fragment shader.

Share this post


Link to post
Share on other sites

This topic is 4267 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this