I’m rendering my per pixel lights with help of glsl built-in light variables (emulating fixed function). For each object I use the lights closest to it. In my glsl program I have created five shaders (I only allow five lights per object) which emulate 1-5 lights. I turn them on depending on how many of the fixed function lights that are currently in use. The problem is that when I render an object with for example four lights and then I render another object with the same amount of lights the second object is unlit. However, if I execute glUseProgram() with the same program that is already running the problem is solved.
The only cause of the problem that I can come up with is that glsl won’t update the built-in light variables if I don’t execute glUseProgram(). This can cause as much as 10x as many calls to glUseProgram(). I have on the other hand not detected any significant frame drop but it bothers me to execute the same program over and over. I am not very confident that it will run fast on other systems when calling glUseProgram() that many times (around 70-100 times). Is there anyone that can shed some light on this, is it expensive to execute a shader program that already is in use? When does the built-in variables update? Help appreciated.