Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: MRT : write to a single output

  1. #1
    Junior Member Newbie
    Join Date
    May 2013
    Posts
    24

    MRT : write to a single output

    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.

  2. #2
    Member Regular Contributor malexander's Avatar
    Join Date
    Aug 2009
    Location
    Ontario
    Posts
    317
    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.

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    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.

  4. #4
    Junior Member Newbie
    Join Date
    May 2013
    Posts
    24
    Quote Originally Posted by malexander View Post
    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 !

  5. #5
    Junior Member Regular Contributor tksuoran's Avatar
    Join Date
    Mar 2008
    Location
    Cambridge, UK
    Posts
    224
    Use glDrawBuffers () to tell which buffers to write to and not.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •