PDA

View Full Version : How to specify fragment shaders output?



padawan
08-14-2011, 08:38 AM
From the GLSL specification 3.30, par. 7.:


Both gl_FragColor and gl_FragData are deprecated; the preferred usage is to explicitly declare these outputs in the fragment shader using the out storage qualifier.
I'm not sure what this means. Shall I declare my own gl_FragColor and gl_FragData, which wouldn't make much sense, or use glBindFragDataLocation/glBindFragDataLocationIndexed, or something else?
It seems that a common way is just to declare an out variable in the fragment shader, but I'm not sure it's the best way.

Alfonse Reinheart
08-14-2011, 12:15 PM
If you're using core GLSL 3.1 or above (ie: removed functionality is removed), then you just declare an output variable. That's all gl_FragColor was anyway.

kyle_
08-14-2011, 01:33 PM
That's all gl_FragColor was anyway.

Actually, thats not entirely true.

gl_FragColor is (was) special. Writing to gl_FragColor writes to all enabled draw buffers. You cant get exact same behavior with user out variables

Now this is pretty useless, but thats how it worked.

padawan
08-14-2011, 05:21 PM
Thanks for the answers guys. I actually noticed that I missed something in the superbible, which more or less confirms my guess.
So, if I understand correctly, when using one buffer it's okay to specify one variable. That goes automatically to buffer 0. When using multiple buffers the way to do that is to use glBindFragDataLocation or glBindFragDataLocationIndexed.
Not that I want to do fancy things with more buffers now, but it's nice to have a clear idea.