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 3 of 3

Thread: Multiple shaders and execution sequence...

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2011
    Posts
    18

    Multiple shaders and execution sequence...

    Hi,

    I am learning shader programming and wanted to know if I have more than 1 vertex shaders(say for example shader A and shader B) for an object, then I want know what is the sequence of execution of shaders.

    If it is the addshader which controls the sequence, then is it possible to change the sequence in the runtime if required?

    thanks in advance.

    thanks,
    drmz.
    Last edited by drmz0counting; 11-18-2012 at 09:40 AM.

  2. #2
    Member Regular Contributor malexander's Avatar
    Join Date
    Aug 2009
    Location
    Ontario
    Posts
    305
    Linking multiple vertex shader sources creates a single vertex shader, much the way that linking multiple C files creates a single program. One vertex shader must have main() defined, and the others should only define support functions. It's more common to pass multiple shader sources as separate strings to the compiler, rather than compile them as separate shaders for the same stage and link them together.

    If you need multiple "main" functions, you can define the main bodies as helper functions, and call one conditionally based on a uniform value in the actual main() function. There is also a subroutine uniform for GL4 which allows you to streamline this process a bit. Alternatively, you can create a separate shader for each. Each approach has its advantages, and really depends on how you're planning on using the shader(s).

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2011
    Posts
    18
    Hi malexander,

    Thanks for the reply and I guess its the same for the other type of shaders also... fragment, geometry and tesselation.

    thanks,
    drmz.

Posting Permissions

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