glNamedFramebufferDrawBuffers
Lists which colour attachments the fragment shader's outputs go to (multiple render targets).
Signature
void glNamedFramebufferDrawBuffers(GLuint framebuffer, GLsizei n, const GLenum *bufs);
How it works
A fragment shader can write several outputs: layout(location = 0) out vec4 accum; layout(location = 1) out float reveal;. This list connects output location i to bufs[i]. By default only GL_COLOR_ATTACHMENT0 is enabled, so a second output is silently dropped until you list both.
It is a setting of the framebuffer, so set it once after attaching, not every frame.
Parameters
The framebuffer (0 = the window, which takes GL_BACK_LEFT and similar).
Number of entries, up to GL_MAX_DRAW_BUFFERS (at least 8).
GL_COLOR_ATTACHMENTi or GL_NONE for each output location.
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.
Errors
When the call is invalid it does nothing and sets an error, which glGetError returns:
- GL_INVALID_VALUE
- n is larger than GL_MAX_DRAW_BUFFERS.
- GL_INVALID_OPERATION
- The same attachment appears twice.
Example
1GLenum bufs[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
2glNamedFramebufferDrawBuffers(oitFbo, 2, bufs);