Using shader programs

Three questions about shader programs (not the vertex or fragment, but the entire program after compilation):

  1. What is the difference between glLinkProgram() and glUseProgram()? it sounded to me in the spec that glLinkProgram() would also cause the shader program to be in use for the pipeline, and if so, then what’s the use for glUseProgram()?

  2. What is the overhead to switch from program to program within a frame of rendering? Would it be reasonable that I could do at least 3-4 times without seeing a major performance hit from the switching?

  3. How does the fixed-function pipeline compare in speed to a basic shader program (ie one that’s not doing too much where it’s obvious that it’d run slower).

Linking combines the individually compiled shader sources, like a C/C++ linker does. So you need to do this once if your program doesn’t change and you can execute it and switch them (glUseProgram) it as often you want . IMO it’s a good practice to create a new program instead of updating an exiting and in future openGL versions, you’ll even have to since programs will be immutable objects.

glUseProgram is cheap, but lots of uniform updates per frame can be expensive (as other OpenGL changes)…

Usually simple shader programs are much faster :slight_smile: