Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

glDrawBuffers - state change or command?

1,326 views
Skip to first unread message

VelociChicken

unread,
Nov 18, 2012, 10:52:43 AM11/18/12
to
Hello again. I'm getting a little confused over the glDrawBuffers function.

Is glDrawBuffers a state change or...
Is glDrawBuffers a command that draws everything sent so far?

I'm asking becauseit seems to swap between the two.

I have a small fragment shader that creates a texture and a normal map
using fractals.
Using the with the following highly cut down code:-

GLenum drawBuff[] = {GL_COLOR_ATTACHMENT0_EXT,
GL_COLOR_ATTACHMENT1_EXT};
glDrawBuffers(2, drawBuff);
DrawTextureShader(&manager->shaders->progBark); // --- render the 2D
quad that makes the texture and normal map.

The third line draws into the buffers, now I thought it would be
DrawBuffers last as this appears to work in my main game loop.
Can anyone confirm how DrawBuffers influences rendering?

Thanks,
Confused, Dave.



VelociChicken

unread,
Nov 18, 2012, 3:41:42 PM11/18/12
to
OK it does look like it's a state change, basically switches how the
next rendering is performed.
But it has to be set AFTER glBindFramebufferEXT is called, because
glDrawBuffers appears to be associated with each frame buffer rather
than a universal setting for all. Which makes sense I guess, can anyone
confirm this for me?

Dave.

Nobody

unread,
Nov 18, 2012, 6:38:01 PM11/18/12
to
On Sun, 18 Nov 2012 15:52:43 +0000, VelociChicken wrote:

> Hello again. I'm getting a little confused over the glDrawBuffers
> function.
>
> Is glDrawBuffers a state change or... Is glDrawBuffers a command that
> draws everything sent so far?

It's a state change. It sets the association between the elements
of gl_FragData[] and specific colour buffers.

> I'm asking becauseit seems to swap between the two.

Any command may perform an implicit glFlush().

> But it has to be set AFTER glBindFramebufferEXT is called, because
> glDrawBuffers appears to be associated with each frame buffer rather
> than a universal setting for all.

Correct. The draw-buffer and read-buffer bindings are per-framebuffer
state.

In fact, it could not be otherwise.

If a context is bound to the default framebuffer, the draw and read
buffers must be one of GL_FRONT, GL_BACK, GL_FRONT_LEFT, etc, while if it
is bound to a FBO, they must be one of the GL_COLOR_ATTACHMENTn names.
Similarly, only colour buffers which exist in the currently-bound
framebuffer can be used (e.g. you can't use e.g. GL_COLOR_ATTACHMENT3
with a FBO which only has one colour buffer).

If the bindings were global, any setting which was valid for the default
framebuffer would become invalid when a FBO was bound, and vice versa.

But any such error is generated when you call glDrawBuffers() or similar,
not when calling glBindFramebuffer().

VelociChicken

unread,
Nov 19, 2012, 10:34:22 AM11/19/12
to
Thank-you for the detailed explanation, far better than anywhere else as
usual. I now have my deferred renderer with forward rendering afterwards
plus FX all with logical ordering of 'drawBuffer' locations.
Cheers!
It's such a shame that not many people use this Newsgroup. Where does
everybody go nowadays?








Nobody

unread,
Nov 19, 2012, 1:38:00 PM11/19/12
to
On Mon, 19 Nov 2012 15:34:22 +0000, VelociChicken wrote:

> Thank-you for the detailed explanation, far better than anywhere else as
> usual. I now have my deferred renderer with forward rendering afterwards
> plus FX all with logical ordering of 'drawBuffer' locations. Cheers!
> It's such a shame that not many people use this Newsgroup. Where does
> everybody go nowadays?

The ones which occur most frequently in my google search results are
opengl.org, gamedev.net, stackoverflow.com.

VelociChicken

unread,
Nov 19, 2012, 3:05:46 PM11/19/12
to
Thanks, I'm sure I've been to all of those at some point, perhaps I'm
not searching them properly once I get there.

Lars Pensjö

unread,
Nov 21, 2012, 4:35:35 AM11/21/12
to
What is the relation between glDrawBuffer() and glDrawBuffers()? Obviously, the last one can be used to select a list of buffers, while the first one can't select GL_COLOR_ATTACHMENTn. The documentation isn't very helpful why you would use one or the other.

It looks to me like glDrawBuffers() is a newer and more general purpose version (supporting multiple render targets), replacing the older glDrawBuffer(). Or is there something that can be done with glDrawBuffer() that can't be done with glDrawBuffers()?

The example at http://developer.amd.com.php53-23.ord1-1.websitetestlink.com/wordpress/media/2012/10/FramebufferObjects.pdf actually uses glDrawBuffers() consecutively for GL_COLOR_ATTACHMENT0_EXT and GL_COLOR_ATTACHMENT1.

Nobody

unread,
Nov 21, 2012, 6:53:33 AM11/21/12
to
On Wed, 21 Nov 2012 01:35:35 -0800, Lars Pensjö wrote:

> What is the relation between glDrawBuffer() and glDrawBuffers()?
> Obviously, the last one can be used to select a list of buffers, while the
> first one can't select GL_COLOR_ATTACHMENTn. The documentation isn't very
> helpful why you would use one or the other.
>
> It looks to me like glDrawBuffers() is a newer and more general purpose
> version (supporting multiple render targets), replacing the older
> glDrawBuffer(). Or is there something that can be done with glDrawBuffer()
> that can't be done with glDrawBuffers()?

The default framebuffer can have up to four buffers: front-left,
front-right, back-left and back-right.

glDrawBuffers() can use GL_FRONT_LEFT, GL_FRONT_RIGHT, GL_BACK_LEFT
or GL_BACK_RIGHT to attach one buffer to each output location (output
variable or gl_FragData[] element).

glDrawBuffer() can also use GL_FRONT, GL_BACK, GL_LEFT, GL_RIGHT to attach
a pair of buffers to a single location, or GL_FRONT_AND_BACK to attach all
four.

0 new messages