3
\$\begingroup\$

I'm doing a shadowmap pass (only storing depth values) so I set glDrawBuffer(GL_NONE) to disable color writing for the moment.

Yet, I see some tutorials also do glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE). Is this really necessary, given glDrawBuffer(GL_NONE)? Don't they accomplish the same thing?

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

The behavior of both of those functions, in general, is different:

glDrawBuffer controls writes to an entire color buffer. You can use it to enable or disable all writes to the front left, front right, back left, or back right buffers (or to some combination thereof).

glColorMask, however, controls writes of entire color channels to all color buffers (the related function, glColorMaski can be used to control entire color channels for a specific buffer).

In the case where you using the functions as specified, the effective result is the same for both calls: glDrawBuffer(GL_NONE) specifies that no buffers are to be drawn to, whereas glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE) specifies that no colors are to be written to all buffers.

In general, of course, the behavior is different. You'd use glColorMask if you wanted to only disable writes of the red color channel; glDrawBuffer does not give you that kind of granularity. However, glColorMask only makes sense in RGBA mode, but it has a nice parity with other masking functions like glDepthMask. Et cetera.

In the case where the effective result would be the same, you can choose whichever function you like best... and it doesn't make sense to do both, as you are implying some tutorials suggest.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .