• Advertisement
Sign in to follow this  

state changes are expensive

This topic is 4250 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello, i hear quite often that state changes are expensive. now which states are that exactly? or is it all of them? for example: is gl.glEn(Dis)able(GL.GL_TEXTURE_2D) expensive?

Share this post


Link to post
Share on other sites
Advertisement
It's all relative.

State changes aren't really *THAT* expensive. Some are more expensive than others (texture changes especially?).

The only reason they're considered to be "expensive", is that you can lose performance if you do *way* too many of them. Like many thousands and thousands per frame of unnecessary ones, then you may start to notice it **

Clearly many state changes are absolutely unavoidable. But if you're only doing something a few times per frame, I really wouldn't worry about it.

Mark

** Not tested, your mileage may vary.

Share this post


Link to post
Share on other sites
I thought I should add Superpig's "bloody obvious" observation:

If you spend more time avoiding state changes than you save by not doing them, then don't bother!

Things like sorting a scene with many objects to avoid a small number of state changes, MAY be pointless. It will certainly complicate your code, and the benefit may be small or negative.

Mark

Share this post


Link to post
Share on other sites
State changing cost can vary. The expensive part is the validation of state changes.

See http://www.opengl.org/resources/code/samples/s2001/perfogl.pdf for details.

Sorting by state is never a bad idea.

Guenther

Share this post


Link to post
Share on other sites
its not actually the glEnable(GL_TEXTURE_XD) that is expensive, but the glBind operation. The glBind is the one that causes memory fetches to the pipeline and hence should be minimised.

Ofcourse, this is totally scene dependant; With state sorting, you cant depth sort, and when you can't depth sort, you are overdrawing on pixels and you can't occlusion cull properly.

So again, its all relative and your mileage may vary. But if your making a Quake type of game, state changes help...alot.

Regards,
DarkProphet

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement