Clearing a portion of the depth buffer

Is there a way to clear only a rectangle region of the depth buffer?

Not sure about this, but try to setup a viewport (glViewport()), which covers the area you want to clear. Then use the standard glClear-function.

I don’t think this will work. On windows, I set the viewport to be a small portion of the screen and used the glClear on the color buffer bit and the entire area of the window was cleared. I think this extends to the depth buffer bit as well.

does it? Hmm. okay…

what about trying defining a scissor region?

hope this helps

cheers,
John

Coyp-and-pasted directly from MSVC 6 documentation on glClear()…

The pixel-ownership test, the scissor test, dithering, and the buffer writemasks affect the operation of glClear. The scissor box bounds the cleared region. The alpha function, blend function, logical operation, stenciling, texture mapping, and z-buffering are ignored by glClear.

So it seems like a scissor box should do the job.

I’ll try the scissor region. Thanks.

About glClear clearing the entire window DC regardless of what the viewport is set too, I’m recalling this from a while back, so I’m going to verify that what I said previously is true. I just want to clear up any confusion I might have caused.

Yup, I confirmed it. I did this…

  • Set my viewport to be the entire viewing area

  • Drew test scene 1 to the back buffer, but didn’t swap buffers

  • Set my viewport to be a portion of the viewing area using glViewport

  • Called glClear(GL_COLOR_BUFFER_BIT)

  • Drew test scene 2

  • Swap the buffers

  • The only scene that is visible is the test scene 2.

By contrast, if you skip the glClear call after setting the viewport, both test scenes are on the screen.