StateBlock in Managed DirectX using C#

I am using the April 2006 DirectX SDK and experimenting with StateBlock's.

I have followed the sample in the SDK documentation however it seems like nothing is ever getting recorded to the StateBlock.

When I call Apply() none of the changes I made to the Device during the BeginStateBlock() EndStateBlock() Capture() get re-applied.

Furtermore, any changes that I make to the Device while creating the StateBlock do not get applied to the Device itself.

For what it is worth I am using a Pure Device.

Can someone please offer some insight

Thanks!

Here is a code snippet....

device.BeginStateBlock();

device.RenderState.Lighting = false;

device.RenderState.FogEnabled = true;

// Strangle enough at this point device.RenderState.Lighting is STILL True and device.RenderState.FogEnabled is STILL False !

StateBlock sb = displayDevice.EndStateBlock();

sb.Capture();

sb.Apply();

// After calling Apply() device.RenderState.Lighting is STILL True and device.RenderState.FogEnabled is STILL False !!!



Answer this question

StateBlock in Managed DirectX using C#

  • Don A

    “Capture” fetches the current value for any state that you have added to your state block. Because of this your state block apply the current values after you have updates your state block. In your case you should only call “Apply” any time you want to set the states you have recorded.

    Additional hint: Don’t forget to recreate your state blocks after a device reset because they are lost during this operation.



  • PhrankBooth

    Seems I was not clear enough.

    The state block you got from the EndStateBlock method already contains your states that you have set after the BeginStateBlock call.

    Any time you call “Capture” on a state block it will override the stored values with the values that are currently set on the pipeline.

    Because of this in your use case you should never call Capture. You will only need “Apply”.



  • Peder Myhre

    Perfect! Thanks so much.

    I must have spent an hour messing around with that - and your answer was so simple that I completely misunderstood it.


  • JohnnyBoyWonder

    I am re-creating the State Block when the Device is reset.

    The problem I am having is that Capture() doesn't seem to record any of the Device changes that I am make within the Begin-End. When calling Apply() none of the changes recorded in the State Block are getting applied to the Device.

    On a side note as I make changes to the Device within the Begin-End they don't seem to be getting applied to the Device itself either. If I step through in DEBUG after this statement ...

    device.RenderState.Lighting = false;

    ...the Device is immediatly reset to the default "True".


  • StateBlock in Managed DirectX using C#