Quick way to copy a depth buffer

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

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 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-bufferdrawScene();shader->Disable(DS_GBUFFER_FILL);	shader->Enable(DS_DEPTH_RENDER);	//Phase 2 fill depth bufferdrawScene();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 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 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 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 on other sites
no idea ( i believe there might be someit u can do though )

perhaps check out WGL_ARB_buffer_region (for windows)

• 16
• 11
• 10
• 9
• 49
• Forum Statistics

• Total Topics
631392
• Total Posts
2999743
×