Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Disable write buffer "from the shader" ?

  1. #1
    Junior Member Newbie
    Join Date
    May 2013

    Disable write buffer "from the shader" ?


    I have several shaders which writes to multiple outputs, for example :

    Code :
    layout(location = 0)​ vec4 SceneColor
    layout(location = 1)​ vec4 SceneInfos

    In some situations, I want to only write to the first output. As I use a FBO, I simply disable some write buffers.

    But for GLSL part what is the best way ?

    - write 2 shaders, a version with 2 outputs, a version with a single output and switch between the 2 ? (sure that's works, but not really developper-friendly)
    - a single shader, declare the 2 outputs, and use a bool uniform to know if I should write to both outputs ?
    - a single shader, and simply disable some write buffers of the FBO ?

    The third solution seems the best, but I know don't if there is any issue or performance hit when a shader write to an output which is disabled.


  2. #2
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Runtime switching of functionality is usually implemented the way you suggest: either switch based on a uniform value or select appropriate functionality with subroutines (essentially function pointers).

    In your case, however, I'd try to simply enable/disable buffers you want to write to using either DrawBuffer[s]() or ColorMaski().

    If you're curious, and actually in this case the effort should be almost negligible, implement both approaches and profile the results. My guess is that you won't see much of a difference but I can't be sure.

Posting Permissions

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