Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is gl_FragData[0] always a color buffer?

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?

like image 488
Jayesh Avatar asked Mar 27 '12 05:03

Jayesh


1 Answers

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_FragData output array refers to the values set by glDrawBuffers. And when using an FBO, the values you pass to this function can only be GL_COLOR_ATTACHMENTn or GL_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 to GL_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...

like image 106
Nicol Bolas Avatar answered Sep 30 '22 21:09

Nicol Bolas