Skip to main content
GameDev.net gamedev.net
🔒 Locked

state changes are expensive

Started by ehmdjii Jul 4, 2006 at 3:31 AM 4 replies 1.1k views
Original Post
ehmdjii
ehmdjii
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?
markr
markr
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.
markr
markr
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
GuentherKrass
GuentherKrass
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
darkprophet
darkprophet
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
3rd generation time waster
ade-the-heat
ade-the-heat
this forum's faq's have the answers.

regards

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.