Newbie question about relation of draw buffer and frame buffer object

When reading OpenGL specification , I found FBO is well documented , and there are some mentions of draw buffer

  1. DRAW_BUFFERi, which seems some kind of index
  2. MAX_DRAW_BUFFERS, on my machine , it’s value is 8

So , what is a draw buffer , is it a sub structure of FBO? Many thanks!

A draw buffer is a single rendering target.

The default (physical) framebuffer can have 4 draw buffers (front left, front right, back left, back right), although stereoscopic contexts (with both left and right buffers) are rare, and it’s uncommon to access the front buffer directly.

A framebuffer object (FBO) can have multiple draw buffers identified by the targets GL_COLOR_ATTACHMENTi where i is between zero and GL_MAX_COLOR_ATTACHMENTS minus one.

glDrawBuffers controls which fragment shader output goes to which draw buffer. glDrawBuffer does the same for the fragment shader output with index zero, or the output from fixed-function rendering.

So for FBO , GL_COLOR_ATTACHMENTi and GL_DRAW_BUFFERi are the same thing? (I have verified that GL_MAX_COLOR_ATTACHMENTS has the same value as GL_MAX_DRAW_BUFFERS on my machine)


glDrawBuffers establishes a mapping between fragment shader outputs and draw buffers.

GL_COLOR_ATTACHMENTi identifies a specific render target (colour attachment or physical draw buffer). glGetIntegerv(GL_DRAW_BUFFERi) queries which render target is associated with fragment shader output i.

For the default framebuffer, output zero is initially associated with GL_BACK if a back buffer exists (double-buffered context) or GL_FRONT otherwise (single-buffered context). For a FBO, output zero is initially associated with GL_COLOR_ATTACHMENT0. In either case, outputs other than zero are initially associated with GL_NONE, i.e. you need to use glDrawBuffers to direct outputs other than zero to a specific colour attachment or physical buffer.

This isn’t required to be the case, although I suspect that it’s typical.

1 Like

this function will return something like GL_COLOR_ATTACHMENTj , so how GL_DRAW_BUFFERi is associated with GL_COLOR_ATTACHMENTj?

  1. In case of glDrawBuffer, it seems the implicit draw buffer will be GL_DRAW_BUFFER0, i.e. GL_DRAW_BUFFER0 is associated with whatever the parameter of the glDrawBuffer.
  2. In case of glDrawBuffers , can I conclude that for every GL_COLOR_ATTACHMENTi there will a corresponding GL_DRAW_BUFFERi implicitly associated?

many thanks!

A draw buffer needn’t be associated with any attachment, i.e. it can be GL_NONE. Most FBOs don’t use all of the available attachments. I suspect that most FBOs only use GL_COLOR_ATTACHMENT0. And even if all attachments are used (i.e. have texture levels or renderbuffers bound to them), some of the draw buffers may be GL_NONE.

The initial state is for GL_DRAW_BUFFER0 to be mapped to GL_COLOR_ATTACHMENT0 and all others to be mapped to GL_NONE. If you want to use multiple attachments, you have to bind texture levels or renderbuffers to them and associate the corresponding draw buffer.

If you call glDrawBuffer, or glDrawBuffers with a count less than the value of GL_MAX_DRAW_BUFFERS, the other draw buffers are set to GL_NONE (i.e. each such call assigns all of the draw buffers, it doesn’t leave the other draw buffers at their previous setting).

I found it. for the following array


glDrawBuffers will associate the element of att sequentially with from GL_DRAW_BUFFER0 to GL_DRAW_BUFFER2, i.e.


glDrawBuffer is just the case that att is an one element array.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.