1 Replies - 7913 Views - Last Post: 10 December 2010 - 08:06 AM

#1 pryogene  Icon User is offline

  • The Leafiest of the Leif's
  • member icon

Reputation: 45
  • View blog
  • Posts: 691
  • Joined: 30-June 09

Changing RenderStates in XNA 4.0

Posted 09 December 2010 - 04:24 PM

Hi all!
I'm working on a graphics engine, and unlike XNA 3.1, 4.0 isn't giving me access to a few variables I need.
Specifically, in 3.1 I could do:
GraphicsDevice.RenderState.CullMode = <CullMode> and GraphicsDevice.RenderState.DepthBufferEnable = bool
But in 4.0 these don't exist, however:
GraphicsDevice.RasterizerState.CullMode = <CullMode> and GraphicsDevice.DepthStencilState.DepthBufferEnable = bool do.
Oddly though, the debugger says this about them:
"InvalidOperationException was unhandled. Cannot change read-only RasterizerState. State objects become read-only the first time they are bound to a GraphicsDevice. To change property values, create a new RasterizerState instance."
Okay, I though, let's try it:
            RasterizerState state = new RasterizerState();
            state = parent.GraphicsDevice.RasterizerState;
            float camToCenter = Vector3.Distance(camera.Position, pos);
            if (camToCenter < radius)
                //parent.GraphicsDevice.RasterizerState.CullMode = CullMode.CullClockwiseFace;
                state.CullMode = CullMode.CullClockwiseFace;
                //parent.GraphicsDevice.RasterizerState.CullMode = CullMode.CullCounterClockwiseFace;
                state.CullMode = CullMode.CullCounterClockwiseFace;
            parent.GraphicsDevice.RasterizerState = state;

It gave exactly the same error as above. Somewhere, I could swear I'm going to be missing something.
Could anyone help with this? This is the biggest, and the only, niggle (I smoothed everything else out before testing this class along side the rest of them) left but it stops EVERYTHING else from functioning. If anyone can help it'd be appreciated. It's sleepytime for me now, but as soon as I get off work tomorrow I'll be back trying to find a fix, if anyone suggests anything before then I'll give those a shot too.

Thanks in advance guys!! (happy coding)

Is This A Good Question/Topic? 0
  • +

Replies To: Changing RenderStates in XNA 4.0

#2 lesPaul456  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 174
  • View blog
  • Posts: 729
  • Joined: 16-April 09

Re: Changing RenderStates in XNA 4.0

Posted 10 December 2010 - 08:06 AM

Get rid of this line:

state = parent.GraphicsDevice.RasterizerState;

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1