Binding multiple shader objects to program object.

I heard that I can bind several V/G/F shader objects to one program object. But what happens when I call glLinkProgram ?
Which shaders for each stage will be choosed ? Or do I have to set, in some way, actual shader to link in every stage?

Thank very much for solving this out :).

EDIT:
I have also additional question about binding params to shader program:

  • When I can bind (attrib locations/uniforms like matrices, textures) and when I should bind them to minimize recompilation of glsl program or need to relinking it?

The compilation/linking of GLSL is similar to that of C. Each shader is compiled into some intermdiate form, just as each .c file is compiled into a .o file. Then the linker takes all of these intermediaries and assembles them into a final product. For each of the V/G/F shaders, it finds the main function, which can be in only one of the attached shaders. The linker will get an error if there is more than one main function. This way, if there is code common to all of your programs, you only need to create and compile one shader object for it and attach it to all the programs.

The attribute/uniform locations don’t exist before a program has been linked, so you need to bind/get those after linking occurs. From this, it follows that you do not need to recompile/relink the shaders/program when you change those. Just change them and you’ll be all set.

Thanks a lot , you really cleared my mind :).