Archived

This topic is now archived and is closed to further replies.

RhoneRanger

Changing texture stages mid loop

Recommended Posts

RhoneRanger    100
How fast is it to change texture stages 0 and 1 in midpoint game? I was always under the impression that you should set your stages at the beginning of the app, and leave them the way they are throughout the life of the app. Just curious what you all do!

Share this post


Link to post
Share on other sites
S1CA    1418
Changing rendering state is usually unavoidable. The key is to not change it when you don''t need to. Try to keep all state changes together so that all of the state changes required to render something are set near to each other.

Underneath the surface, the graphics chip has a bunch of states and registers which are DIFFERENT to the "ideal" model D3D (or OpenGL) presents. For example changing a single renderstate in D3D might change 4 internal states. And vice versa - the affect of 4 D3D render states might all just be flags in a single hardware state.

This means that the device driver has to translate from D3D states into internal hardware states. Changing one texture stage state may require ALL internal hardware states to be re-computed on some devices. This is why you shouldn''t change when you don''t need to.

A more expensive change is for the texture itself - sometimes that might mean D3D uploading a new texture from system memory to video memory.

Even more expensive to change is vertex or pixel shader.


Conclusion:
-----------

- It''s OK to change states, textures and shaders during a frame.

- But don''t do it excessively (e.g. keep texture changes below say 100, keep shader changes below say 50)

- Sort your rendering first by shader, then by texture, finally by render states

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites