Making current OpenGL context active

I notice that the current OpenGL context is made active every time a frame is drawn. Is there a particular reason for this? It seems like you could just make the context active once at the beginning of the program. Or am I wrong? I’m just wondering because I’ve heard that there is some overhead for making a context active.

Strangely though, when I do try to just call it once at the beginning of the program, it doesn’t seem to work, though I can’t figure out why.

Anyone know what’s going on here?

User-code in the callback or paint method could do anything - it may activate a different context for some reason. What’s wrong with calling it each time? If the context is already active, there’ll be almost no overhead in making the call…

Ok. I just wasn’t sure what the overhead was. But if it’s very small, it’s fine.

I haven’t measured it, but would be very surprised if any drivers didn’t check for it already being active!

I agree, but really, you never know. :slight_smile:

“Checking” things is an expensive OpenGL operation. It involves sync’ing the GL command queue and the CPU. If your app has knowledge about what state is active (any state, but especially the active context) it should void re-setting it.

Having said that, changing context is very expensive, more than just checking.

Bruce