meta: Use gl_FragColor to output color values to all the draw buffers
authorAnuj Phogat <anuj.phogat@gmail.com>
Mon, 19 May 2014 18:55:01 +0000 (11:55 -0700)
committerAnuj Phogat <anuj.phogat@gmail.com>
Wed, 21 May 2014 15:43:14 +0000 (08:43 -0700)
commit46737cebd337200f8b88ba9081796fa0f94e9143
treeae964f0c9b3f3f8cb4332be2f2f6c6bfa11d5c51
parentbee2915210e53585bca27c9c5f7d7407f61bcc0f
meta: Use gl_FragColor to output color values to all the draw buffers

_mesa_meta_setup_blit_shader() currently generates a fragment shader
which, irrespective of the number of draw buffers, writes the color
to only one 'out' variable. Current shader rely on an undefined
behavior and possibly works by chance.

From OpenGL 4.0  spec, page 256:
  "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 varying out 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 varying out
   variables, the values of the fragment colors following shader execution
   are undefined, and may differ for each fragment color."

OpenGL 4.4 spec, page 463, added an additional line in this section:
  "If some, but not all user-defined output variables are written, the
   values of fragment colors corresponding to unwritten variables are
   similarly undefined."

V2: Write color output to gl_FragColor instead of writing to multiple
    'out' variables. This'll avoid recompiling the shader every time
    draw buffers count is updated.

Cc: <mesa-stable@lists.freedesktop.org>
Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/drivers/common/meta.c