Z-Buffer

Is there a way to directly access the OpenGL Z-Buffer or how can i blit a precalculated
Z-field into the Z-Buffer?

You can use glReadBuffer and glDrawBuffer to set the target read/write buffers, then access them using glReadPixels/glDrawPixels/glCopyPixels.

The process might not be as fast as you would like, though.

– Jeff

You can use WGL_ARB_buffer_region to store a “depth image” in video RAM and blit it to the Z buffer. It’s very fast (as in: at least a hundred times faster than using glDrawPixels()).

  • Tom

It’s certainly not 100 times faster, not if you’re doing things right.

  • Matt
  • Thanks for your reply!
    it helped a lot!

  • Christoph

Precalculated means like stored in a file, or rendered by the same program while running?
Tom, there is no way to get the data into a buffer region other than to use Save- and RestoreBufferRegion.
Furthermore, you don’t have access to the internal data representation used for those regions.

Originally posted by mcraighead:
It’s certainly not 100 times faster, not if you’re doing things right.

So it seems! I just tried modifying my WGL_ARB_buffer_region demo to use glDrawPixels() instead, and I got a very respectable 30 fps for a 512x512 depth image (PII-350 with a GeForce2). To my defense, though, I don’t think I’ve used glReadPixels()/glDrawPixels() since I was still running on a Riva128. That may have biased my estimate a bit

That said, I get 210 fps using buffer regions, so I was only off by about a factor 14

Relic: what I did is load the depth image from file, then draw it to the framebuffer with glDrawPixels(), then save it using SaveBufferRegion(). Not very elegant, but hey, you only have to do it once.

  • Tom

[This message has been edited by Tom Nuydens (edited 05-18-2001).]