openglgraphicsdepth-bufferzbuffer

OpenGL GL_DEPTH_TEST vs glDepthFunc and glDepthMask?


I've been using glDisable(GL_DEPTH_TEST) to disable depth testing, thinking that it only disables depth "testing". The reason I've been confused I guess is because I've created two functions, one to disable the depth "test", and another to disable depth "writes" with glDepthMask(GL_FALSE);

If disabling GL_DEPTH_TEST disables both "testing" and "writing" then would it be the equivalent of doing:

glDepthFunc(GL_ALWAYS​); // DISABLE TESTS (OR ACTUALLY ALWAYS LET THE TEST SUCCEED)
glDepthMask(GL_FALSE); // DISABLE WRITES

I'm thinking that there's little use for disabling GL_DEPTH_TEST unless I want to disable both tests and writes, and I'm wondering which one is better. The wording seems confusing, but maybe it's just me. I suppose doing disabling depth tests with glDepthFun(GL_ALWAYS) will still do a comparison, I suppose there's no way to disable the depth test entirely while still allowing writes?


Solution

  • glDisable(GL_DEPTH_TEST)
    

    turns off the Depth Test from pipeline. If you use:

    glDepthFunc(GL_ALWAYS​);
    glDepthMask(GL_FALSE);
    

    instead it just hide it after condition (but still present in the pipeline) which could mean performance difference on some platforms ...

    Also using your equivalent would need you to set/remember original DepthFunc in case you want to turn it on again (as there are many rendering techniques that need to switch the DeptTest on/off several times.

    And lastly two GL function calls are bigger overhead than just one. So from performance point of view using glDisable(GL_DEPTH_TEST) is better for this. The glDepthFunc,glDepthMask are intended for different purpose like multi pass rendering, order independent transparency,holes, etc ...