State management nightmare

I'm in C++ and I have many different shape to draw

Each of them come with different state :

Render States

Texture Stage States

Sampler States

Some are transparent, some use light, others use alpha test

They can be call from function that I can place in any order in my code

My problem is that I need to go back to the default state or undo

what the previous state setting changed...before setting only the state I need

I'm at a point where I will have to use 2 functions :

SetAlphaON() and SetAlphaOFF()

So I can immediatly remove any state change before I draw something else

Is there a better way to undo any state change

ID3DXEffectStateManager seems to do this for Fx files...

One thing I have realized is that state change in a loop is very costly on speed...

So I need to minimize change in state...

I wish the function ResetToDefaultState would exist...



Answer this question

State management nightmare

  • laiseng

    Thank you very much for your answer

    I will check if I set for PURE device or not, and now I know the redundant values are not much of a problem...

    I should change all at once and not call drawing function and set state in a loop...

    I found some advise on not using state block...and use effect instead...

    http://www.gamedev.net/community/forums/topic.asp topic_id=392052

    Try not to use StateBlocks to save & restore device state; you may be setting too much state that way. One way of getting around this problem is to use effects and create some known good states for your rendering techniques, and then switch between those.

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=61263&SiteID=1


    On a non-PURE device, they are filtered by D3D. Redundant calls (i.e. changes to the same value) get filtered. Non-redundant values are added to the command-buffer.

    On almost all drivers, when they get a state change command, they simply remember it. When they get a DIP-style command, then they think about setting states and so on.

  • All states are set at the same time in the driver. For this reason, most IHVs say that changing a single state is expensive, but changing lots of states at the same time is not much more expensive.

  • Using state blocks at worst saves you multiple SRS and STSS calls. At the best, it goes really fast and stuff.

  • Izzy545

    Usually engines add a state-filtering layer that only allows changed states to make it through to the API. This saves the API calling overhead. Note that D3D might be doing states filtering for you as well if you're not using a pure device...

    An excellent wrap up:
    http://tomsdxfaq.blogspot.com/2002_07_01_tomsdxfaq_archive.html#78505386


  • State management nightmare