Reputation: 4022
I have a total of 5 render targets. I use the same shader to write to the first 4, then in a seperate pass write to the last one.
Before calling rendering to the first 4 targets I call:
GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3};
glDrawBuffers(4, drawBuffers);
However, when I call it for second pass and only want to write to the last one, the 5th target, why does the following give strange results?
GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT4 };
glDrawBuffers(1, drawBuffers);
Why do I have to instead use:
GLenum drawBuffers[] = { GL_NONE, GL_NONE, GL_NONE, GL_NONE, GL_COLOR_ATTACHMENT4 };
glDrawBuffers(5, drawBuffers);
Is this simply how glDrawBuffers() works, or is being caused by something else?
EDIT: fixed code with regards Jarrods comment
Upvotes: 1
Views: 2508
Reputation: 347
I find that there's something wrong in glDrawBuffers(). for exmple tmp = {attement_color0, attachement_color2} glDrawBuffers(tmp). in shader: gl_fragdata[0]=... gl_fragdata[2]=...
or u can use layout location to define the attments output. But sometimes, at least in my PC, it does not work. I mean the attachment_color2 does NOT have the exact output.
Upvotes: 0
Reputation: 473174
Yes, this is simply how glDrawBuffers
works. But there's a reason for that.
Fragment shaders write color outputs that map to certain "color numbers". These have no relation to GL_COLOR_ATTACHMENT''i'' numbers. The entire point of glDrawBuffers
is to map those fragment color numbers to actual buffers in the framebuffer.
Upvotes: 3
Reputation: 4944
http://www.opengl.org/sdk/docs/man/xhtml/glDrawBuffers.xml
The 2nd parameter must be of the type const GLenum*
i.e. a pointer "to an array of symbolic constants specifying the buffers into which fragment colors or data values will be written".
So just passing GL_COLOR_ATTACHMENT4
as the 2nd param is the wrong type. You need to pass a pointer to an array of GLEnum
.
Upvotes: 1