Question about state changes

State changes are generally considered to be expensive in OpenGL.

I have a few questions about that. I can imagine that calls like glBindTexture() are pretty expensive but is this also true for calls like glBlendFunc(), glEnable(…), glShadeModel(), … and so on? Is it worth the effort to implement some sort of caching system. i.e. something like:

void myShadeModel(int par)
{
    if (par == old_par) return;
    glShadeModel (par);
    old_par = par;
}

Or is that a waste of time?

Greetings,


Jorrit Tyberghein, Project Manager of Crystal Space Open Source 3D Engine http://crystal.linuxgames.com

Jorrit,
Your question was discussed here some time ago. The short answer is yes, it is a good idea, do it.
http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/001787.html

Originally posted by Michail Bespalov:
Jorrit,
Your question was discussed here some time ago. The short answer is yes, it is a good idea, do it.

Thanks for your answer and sorry for starting this thread again. There is however one thing that I can’t seem to find in that thread. What about things that are usually on the client side like glEnableClientSide()? Does it make sense to cache them too are is that not needed in this case?

Greetings,

Yes, it does make sense, because in typical situations there is really no difference between “client” and “server” state. It’s all OpenGL state, and the driver has to deal with all of it.

  • Matt