View Full Version : Copying the depth and color buffer?

09-25-2006, 03:09 AM

I render a scene which may consist of up to 50 million triangles, so the rendering may take a while. Upon that rendered scene, I want to do some interactive "drawing", f. ex. the user moves his mouse over the scene and additional things like a polyline will be rendered additionally onto the basic scene.

Since I want to avoid to re-render the large scene each time the user moves his mouse, I thought of rendering the basic scene first, storing the depth and color buffer, and on each mouse motion, copy these buffers back and then do the additional drawing commands.

The software must work on several cards, so I cannot use hardware-dependant code.
Do you think that using glReadPixels/glDrawPixels is the best way or are there better alternatives?


09-25-2006, 03:36 AM
The best is WGL_ARB_buffer_region but this is just an extension so not all cards support it.
glReadPixels/glDrawPixels is the next option.

You might want to simply your scene since 50 million triangles are not likely to be visible on screen.

Try to use formats the hw prefers

10-05-2006, 07:33 AM
Unfortunately I can't use hw specific code.

glReadPixels/glDrawPixels works fine for the color-buffer, but when I try to restore the depth buffer, I have problems; glDrawPixels seems to draw into the color buffer even when GL_DEPTH_COMPONENT is used.

Any hints how I can save and restore the depthbuffer?

10-05-2006, 08:22 AM
For the depth buffer, from what you said I guess the best solution would simply be not to clear it at all.

Another solution: you can try to use FBOs. Render your scene first in a FBO then copy the image into the front buffer each time you need it.

10-05-2006, 11:36 AM
DrawPixels always draws fragment groups (color/depth/stencil). It is up to you to mask off the parts you don't want, with Disable for depth/stencil and ColorMask for color.

10-06-2006, 04:44 AM
thanks, now it works!

not clearing the buffer means that I must not modify it if I want to use it several times; this has some unwanted effects...

Thanks all for you help!