PDA

View Full Version : [OpenGL 3.2] glUseProgram: inside the mainloop ?



pixpaf
11-09-2012, 09:19 AM
Hello

I wonder if i should put «glUseProgram» inside my render loop, or just calling it once after the GLSL program has been compiled and linked.

I'm asking this, because i tried and put it outside the render loop, and it worked.
But i read several tutorials which put it inside the render loop.


Thank you

Alfonse Reinheart
11-09-2012, 09:41 AM
Do you only ever intend to render with one program? In general, in any serious application, you will be using multiple programs. So yes, it "goes in the render loop."

Kopelrativ
11-09-2012, 11:05 PM
I wonder if i should put «glUseProgram» inside my render loop, or just calling it once after the GLSL program has been compiled and linked.

I'm asking this, because i tried and put it outside the render loop, and it worked.
But i read several tutorials which put it inside the render loop.

The OpenGL program is a global state, and only one program can be active. So if you have more than one program, then you need to enable each of them every time you use them.

There is some overhead for switching programs. If you have two programs and switch MANY times between those for every frame, then it can be a good idea to sort the drawing. For example, draw all geometry with the first program, and then switch to the second program and draw the other things.