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?
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).