View Full Version : Clearing a portion of the depth buffer

08-09-2000, 06:26 AM
Is there a way to clear only a rectangle region of the depth buffer?

08-09-2000, 08:27 AM
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.

08-09-2000, 03:47 PM
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.

08-09-2000, 04:25 PM
does it? Hmm. okay...

what about trying defining a scissor region?

hope this helps


08-10-2000, 01:02 AM
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.

08-10-2000, 03:40 AM
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.

08-10-2000, 04:27 AM
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.