I'm working on a full-scale solar-system renderer and as part of that I need to draw the scene in multiple depth “slices”. For each slice, I scale the scene objects relative to the camera to bring them closer (within depth buffer precision), and make the frustum near/far fit the objects for the slice. I draw the slices from back to front, and between slices I need to clear to depth buffer so that close-up objects are not occluded by far-away objects (whose depths are in the same range).
However, when I try to just insert a glClear( GL_DEPTH_BUFFER_BIT ) between depth slices, it doesn't seem to be working. Far-away objects are occluding the close-up objects. Is it valid to clear the depth buffer (of the same framebuffer) more than once per frame (and I have a bug somewhere)? Or do I have to use a separate framebuffer for each depth pass and then composite them together? (yuck) Any tips for how to effectively “reset” the depth buffer multiple times per frame?
Edit: I think I found the bug in my code. I was using a queue of render commands, which were all being submitted at the end of the frame (after both calls to glClear()). I'm still interested if there are better ways to clear the depth often.