Clarifying glEnable(GL_DEPTH_TEST) and glDepthMask()

Started by
3 comments, last by HellRaiZer 17 years, 9 months ago
So I think that these assumptions are correct: When we have glDisable(GL_DEPTH_TEST), no depth testing occurs (according to the function defined by the glDepthFunc()) and everything is written to the color buffer.What happens to the Z-buffer? When there's glDepthMask(GL_TRUE) and glEnable(GL_DEPTH_TEST), we have no writing to the Z-buffer but there's actually depth testing so the color buffer is populated according the results of the test. Am I right? Just seeking to clarify things about these commands a little more.
Advertisement
When You disable depth test, the z-buffer is left untouched.

The second assumption is right except disabling depth writing is done with glDepthMask(GL_FALSE).
if (time() == $) { $ = 0; }
Depth test is another test in the pipeline just as the stencil test, alpha test, etc.
Whenever you disable depth testing via glDisable(GL_DEPTH_TEST), this means that all the fragments will pass this stage in the pipeline, whatever depth they have. If you don't have any other tests enabled, then all the buffers whose masks are true will be overwritten. If you have glDepthMask(GL_TRUE) then the z-buffer will be updated with the new values, whatever value it previously had. If depth mask is set to false, then the depth-buffer won't be updated.

Another example. If you have depth testing enabled, and depth mask equal to false, then whenever a fragment passes the depth test, all the other buffers (except z-buffer) will be updated with the new value.

Hope that clears things up.

HellRaiZer
HellRaiZer
Quote:Original post by HellRaiZer
...Whenever you disable depth testing via glDisable(GL_DEPTH_TEST) ... If you have glDepthMask(GL_TRUE) then the z-buffer will be updated with the new values...
That part's wrong. If depth testing is disabled the depth buffer is not updated at all, regardless of the depth mask. Just like the stencil buffer is not updated if the stencil test is disabled. If the stencil test is enabled and the depth test is disabled, then for the stencil operation it is as if the fragment passed the depth test.
Quote:Original post by Kalidor
Quote:Original post by HellRaiZer
...Whenever you disable depth testing via glDisable(GL_DEPTH_TEST) ... If you have glDepthMask(GL_TRUE) then the z-buffer will be updated with the new values...
That part's wrong. If depth testing is disabled the depth buffer is not updated at all, regardless of the depth mask. Just like the stencil buffer is not updated if the stencil test is disabled.


Oops... sorry for that :) Apparently Kalidor is right. I just forgot about the specs completely. This reminds me that I got to search first even if i think i know the answer :)

HellRaiZer

HellRaiZer

This topic is closed to new replies.

Advertisement