View Full Version : Copying Depth Buffer

04-08-2003, 09:00 AM
What is the best way to do the following?

-store the depth buffer
-draw some stuff
-put the depth buffer back to how it was stored in the first step

I am hoping I can do this without having to read the depth buffer into RAM. I took a look at 'GL_SGIX_depth_texture', but there doesn't seem to be a way to put that back into the depth buffer.

04-08-2003, 09:12 AM
Have you checked out the Buffer Region extension?

04-08-2003, 10:39 AM
Do you need to depth buffer the new stuff you draw? If you can get away with it the best option would be to try to avoid depth writes when drawing the new stuff. You could also do something creative like render to texture for that stuff and draw the texture on a billboard in place with no depth writes if the individual items need to be depth buffered.

04-08-2003, 10:42 AM
could you render to an offscreen buffer for your second step (-draw some stuff), this way you dont damage what is in your framebuffer?

04-09-2003, 12:09 AM
when you are considering using depthtextures, take into account that this will work only with gf3 and better HW.
a solution which works with most HW(even TNT or RagePRO) is:

Draw your depthbuffer.
create a buffer region and save the depthbuffer in it.(KTX_buffer_region or ARB_buffer_region, i suggest to use both, because not all cards support the ARB-version now)

then you can restore your depthbuffer every frame instead of clearing the depthbuffer, and draw your new stuff on top of that.

i am using this method in a game with prerendered screens and 3d characters.
it works fine and is very fast.