Yes, absolutely. E.g. (coded as I type):
glEnable(GL_DEPTH_TEST); // to enable writing to the depth buffer
glDepthFunc(GL_ALWAYS); // to ensure everything you draw passes
glDepthMask(GL_TRUE); // to allow writes to the depth buffer
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
// so that whatever we draw isn't actually visible
glClear(GL_DEPTH_BUFFER_BIT); // for a fresh start
/* here: draw geometry to clip to the inside of, e.g. at z = -2 */
glDepthFunc(GL_GREATER); // so that the z test will actually be applied
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
// so that pixels are painted again...
glDepthMask(GL_FALSE); // ... but don't change the clip area
/* here: draw the geometry to clip inside the old shape at a z further than -2 */
So, key features are:
- the depth test can be set always to pass
- colour plotting can be disabled even while other buffer values are set