PDA

View Full Version : MRT : write to a single output



Aurelien
05-16-2013, 01:48 PM
Hi,

I use a FBO and MRT as following :

- Texture "0" is attached to my FBO's COLOR_BUFFER_0
- Texture "1" is attached to my FBO's COLOR_BUFFER_1

Then I draw a set of objects :

- objects of type "A" need to write to Texture "0"
- objects of type "B" need to write to Texture "1"
- objects of type "C" need to write to Texture "0" and Texture "1"
- additive blending is always enabled for both Texture "0" and Texture "1"

Currently I do the output selection in "A", "B" and "C" shaders :

- "A" shader only write to "gl_FragData[0]"
- "B" shader only write to "gl_FragData[1]"
- "C" shader write to "gl_FragData[0]" and "gl_FragData[1]"

Everything work as expected on my NVidia card, but :

- do the OpenGL specification allow to do this ?
- is there any drawback ? (perfomances...)


Thanks.

malexander
05-16-2013, 02:07 PM
You're leaving an element of gl_FragData[] uninitialized in the A and B cases, which isn't a good idea. Since you have additive blending enabled, just initialize the unused gl_FragData[] element with zero.

I recall Apple's GL2 driver not liking it much if you don't write to a buffer that is enabled for writing.

tonyo_au
05-17-2013, 06:03 AM
I recall Apple's GL2 driver not liking it much if you don't write to a buffer that is enabled for writing.
I had this problem on either nVidia or AMD at some point. Now I am just careful to only enable the buffers I intend to write to. I don't know what the spec say.

Aurelien
05-17-2013, 07:50 AM
You're leaving an element of gl_FragData[] uninitialized in the A and B cases, which isn't a good idea. Since you have additive blending enabled, just initialize the unused gl_FragData[] element with zero.

Thanks for pointing this and possible issues.

I've modified my shaders to always write to the 2 output buffers, still working, and probably better !

tksuoran
05-31-2013, 09:24 AM
Use glDrawBuffers () to tell which buffers to write to and not.