glClearNamedFramebufferfv
Clears one attachment of a framebuffer to a value of your choice, without glClearColor.
Signature
void glClearNamedFramebufferfv(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLfloat *value);
How it works
glClear clears every colour attachment to the same glClearColor. With several targets that is often wrong: weighted blended OIT needs its accumulation buffer cleared to 0 and its revealage buffer to 1. This function clears a single one, chosen by its index in the draw-buffer list, to the value given.
Parameters
The framebuffer, 0 for the window.
What to clear.
Common values
- GL_COLOR
- One colour attachment; value points to 4 floats.
- GL_DEPTH
- The depth buffer; value points to 1 float, drawbuffer must be 0.
For GL_COLOR, the index in the glNamedFramebufferDrawBuffers list (not the attachment enum).
The clear value.
Tips & pitfalls
Direct State Access (GL 4.5): the object is passed as a parameter, so nothing needs to be bound and no global state is disturbed.
Pick the suffix by the attachment's format: fv for float and normalized formats, uiv for unsigned integer (GL_R32UI), iv for signed integer.
Example
1const float zero[4] = { 0, 0, 0, 0 };
2const float one[4] = { 1, 1, 1, 1 };
3glClearNamedFramebufferfv(oitFbo, GL_COLOR, 0, zero); // accumulation
4glClearNamedFramebufferfv(oitFbo, GL_COLOR, 1, one); // revealage