Depth pre-pass: does OpenGL still execute fragment shader if color mask is GL_FALSE?

Supposing I set up as:

glFramebufferDrawBufferEXT(id, GL_NONE); // id is currently bound framebuffer object

[li]If the bound fragment shader does not explicitly write to gl_FragDepth, will it still be executed, given that the color mask is false and the draw buffer is nil? Or can I assume the driver will be smarter than that? [/li][li]Is it better to simply not have an active fragment shader, or will that cause the fixed function fragment processing to be substituted? [/li][li]Overall, what’s the best approach here? Should I have a separate version of each shader for the depth pre-pass, or rely on the driver being smart enough to cull unnecessary computations (including vertex shader outputs which end up not being used in subsequent stages, like normals, for example)? [/li][/ol]

  1. All drivers will be smart enough to disable fragment-shader invocation, unless you use any of: gl_FragDepth, discard/coverage/samplemask, atomics. Because this is a very common thing, when drawing a shadowmap.
  2. A fixed-func shader will be generated

A simple and decent solution is to just use your normal fragment+vertex shaders and disable color-write. The best solution is to use a special frag+vert pair, that has no varyings or extra fluff. This will accelerate vertex processing and triangle setup. Also, because the shader is so simple, you will probably only have 2-3 such GLSL programs total. One for solids, one for alphatested/discarded stuff, one for things that write to gl_FragDepth. Versus the hundreds/thousands of programs of your material-library. So, switching between these programs will be rare and very fast.