From the few examples I have seen around the net, gl_FragData[0] is assumed to be a color buffer. I tried to find the meaning of each index into gl_FragData and came across this passage from OpenGL Shading language book (orange book)
gl_FragData is an array that can be assigned values that are written
into one or more offscreen buffers. The size of this array is
implementation dependent and can be queried with glGet with the
symbolic constant GL_MAX_DRAW_BUFFERS. The offscreen buffers that are
modified as a result of writing values into gl_FragData within a
fragment shader are specified with glDrawBuffers. The value written
into gl_FragData[0] updates the first buffer in the list specified in
the call to glDrawBuffers, the value written into gl_FragData[1]
updates the second buffer in the list, and so on.
It’s not specified that 0th value of gl_FragData is always color buffer. If there is such specification, where can I find it? If not, what is a normal practice when writing to gl_FragData?
It doesn’t have to be a color buffer per-se. But if it’s not a color buffer, then it’s nothing.
The
gl_FragDataoutput array refers to the values set byglDrawBuffers. And when using an FBO, the values you pass to this function can only beGL_COLOR_ATTACHMENTnorGL_NONE. Which, as the names state, are color buffers.So it’s either a color buffer or it’s
GL_NONE.For GL ES implementations that don’t offer
glDrawBuffers(ie, that don’t implement NV_draw_buffers), it is defined as though index zero was set toGL_COLOR_ATTACHMENT0.It is silly of ES 2.0 to allow for the possibility of multiple attachments without actually providing a way to render to more than one of them…