View Full Version : glDrawBuffers(N, {GL_NONE, GL_COLOR_ATTACHMENT...}

07-07-2012, 04:36 PM

I have a draw buffers related question. Lets say I want to draw to one (or more) frame buffer attachments with user defined output names in the fragment shader. I attach my buffers to my FBO and define frag data locations for my user defined fragment shader outputs to start from 1 (not from 0!). To 'bend' this frag data locations to my attachments, I set glDrawBuffers( 8, {GL_NONE, GL_COLOR_ATTACHMENT0, GL_NONE, ...} ) (in case of one attachment).
As far as I understand the specs, this should work as I connected the output of the shader to "1", while the entry "1" in the array I gave glDrawBuffers points to GL_COLOR_ATTACHMENT0 and the first texture I attached to my FBO is the one I want to draw to.

So let's not debate why I start not with 0 in this case.

The problem I have is, that this setup works fine on Windows and Linux (NVidia and ATI) but fails to draw anything to the texture on MacOS X (glClear works in this setup and my queries tell me the correct number of fragments being created, but nothing from rendering happens to go into the texture unless I change the glDrawBuffers call). So I'm wondering wether I missed something in the spec (maybe a core vs. compatibility nuance?) or if this might be just another MacOS bug.

Any input is welcome.

07-08-2012, 02:26 AM
As I read it, glDrawBuffers() associates COLOR_ATTACHMENT_i at position n in the array with color number n as long as n is smaller than GL_MAX_DRAW_BUFFERS. Your constants are definitely legal and I don't assume you try to exceed the above limit.

I don't see anything illegal and having it work for NVidia and AMD seems to me like it's a rotten Apple. By the way, the core spec seems wrong in this section:

If a fragment shader writes to gl_FragColor, DrawBuffers specifies a set of draw buffers into which the single fragment color defined by gl_FragColor is written. If a fragment shader writes to gl_FragData, or a user-defined output variable, DrawBuffers specifies a set of draw buffers into which each of the multiple output colors defined by these variables are separately written. If a fragment shader writes to none of gl_FragColor, gl_FragData, nor any user-defined output variables, the values of the fragment colors following shader execution areundefined, and may differ for each fragment color.

Yeah, gl_FragColor and gl_FragData ... Ironically the API reference doesn't include this section whereas the legacy reference does.

07-08-2012, 08:22 AM
This now has a Bug ID#11826727.

07-09-2012, 04:37 PM
Are you sure you linked the program after calling glBindFragDataLocation?

07-10-2012, 01:09 AM
Thanks for the hint arekkusu, I actually forgot to link the program in my example I build for Apple (need to fix that). However, in my original app and the fixed example the bug exists even if I correctly link the program after changing the frag data location.