Sign in to follow this  

Clarifying glEnable(GL_DEPTH_TEST) and glDepthMask()

This topic is 4166 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

This topic is 4166 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this