Depth, blending & cullingGL 1.0

glDepthMask

Turns writing to the depth buffer on or off (testing still happens).

Signature

void glDepthMask(GLboolean flag);

How it works

Depth testing and depth writing are separate. With glDepthMask(GL_FALSE) fragments are still tested against existing depth, but they do not update it.

The standard use is transparent objects: they must be hidden behind opaque walls (test), but must not hide what is behind them (no write).

Parameters

flagGLboolean

GL_TRUE to write depth (default), GL_FALSE to keep it read-only.

Tips & pitfalls

  • glClear respects the mask: with depth writes off, GL_DEPTH_BUFFER_BIT does nothing. Always restore GL_TRUE at the end of the frame.

Example

example.cpp
1drawOpaque();
2glDepthMask(GL_FALSE);
3drawTransparentSortedBackToFront();
4glDepthMask(GL_TRUE);
Official Khronos documentation