Avoiding state changes

I know that it is evil to enable and disable states a lot of times.
However if i, for example, don´t know wether the depth test is enabled, and i enable it a lot of times, although it has never been disabled, is this bad for performance ?

I would think that OpenGL first checks, if a state is already en-/disabled, but if not, i would have to do this.

Maybe you think it´s a stupid question, but i want to be certain about this.


  1. just remember if you set it on or off, then you don’t have to set it x times
  2. i don’t think just setting alphatest on or off will slow down your program a lot. i guess it’s only a variable that is set to true or false

boolean glIsEnabled(GL_DEPTH_TEST)

Unnecessary state changes are always bad.Make your own state checking routine instead.Put the states you use in a hashtable. Slap your own myglEnable and myglDisable calls around it. This is simple and efficient.