I’m implementing the dynamic LOD algorithm Occluder Shadows, which consists of reading back from the depth buffer (on my Geforce II). I’m currently using glReadPixels(), but it’s very slow. Is there a faster way of reading back from the depth buffer, or would I be better to use Software Rasteraztion instead.
As far as I know, glReadPixels is the only way to access the depth buffer…
Sorry !
I do not know what the algorithm you are using involves but what do you exactly do when reading the buffer ?
Do you read the whole buffer at once and then work on it ?
Do you read parts of the buffer several time ?
If you are doing 2), perhaps you should try to read the whole buffer only once as described in 1)… It should be faster than multiple “mini”-glReadPixels (on this one, nVidia guys will answer better than me !).
If you need to read it at different stages of your rendering process, then I guess you have to stick to multiple “mini”-reads…
Now, if you are already reading the whole buffer at once and it is too slow, I have no idea…
I don’t think switching to software mode would help: you do not have direct access to the depth buffer either if you use Microsoft GDI Generic implementation (although I am sure there is a dirty hack to find in this case !).
How slow is very slow? That should actually run at a reasonable speed (tens of megapixels per second). Make sure you’re reading back into a fixed-point format, though. Floats will introduce extra conversions.
In the game I am working on we used glReadPixels to check depth buffer values for determining visibility of certain things in screen-space coordinates. Certain hardware handles this nicely (read: very little speed hit), nvidia hardware for example. Other hardware takes a massive speed hit for reading from the back buffer (3Dfx comes to mind). This is definiately a feature of your app that is definately going to vary greatly across hardware.
You could also use the accumulation buffer to grab the depth buffer which might be faster but I don’t know whether this would help with what you are doing or not