PDA

View Full Version : How does glDrawBuffer interact with glDrawBuffers



theold
11-10-2017, 08:21 PM
From what I understand:

- glDrawBuffer selects a single draw color buffer attachment in an FBO, or up to four color buffers in the default framebuffer (using aliases); in the latter case the fragment shader will write the same fragment to each color buffer
- glDrawBuffers creates a table of color buffers whose indexes correspond to fragment shader output locations

Is this state stored independently?

What happens with fragment shader with more than one output location in the case where glDrawBuffer was called? Does only the 0 location get written into the specified color buffers?

Edit: Also I have similar confusion for the result of glClear(GL_COLOR_BUFFER_BIT)-- this will clear *all* the color buffers? only those specified by glDrawBuffer and/or glDrawBuffers?

GClements
11-10-2017, 08:57 PM
Is this state stored independently?

No. GL_DRAW_BUFFER is effectively an alias for GL_DRAW_BUFFER0. The manifest constants have different numeric values, but they refer to the same state (i.e. glGetIntegerv() will always return the same value for both).



What happens with fragment shader with more than one output location in the case where glDrawBuffer was called? Does only the 0 location get written into the specified color buffers?

Yes. The specification says (17.4.1) "DrawBuffer will set the draw buffer for fragment colors other than zero to NONE."


Edit: Also I have similar confusion for the result of glClear(GL_COLOR_BUFFER_BIT)-- this will clear *all* the color buffers? only those specified by glDrawBuffer and/or glDrawBuffers?
The latter; the specification says (17.4.3) "the buffers currently enabled for color writing". You can use glClearBuffer() or glClearNamedFramebuffer() to clear individual buffers.