//each of these 4 methods is more efficient than the previous... //this method is the manual method where each state is setup peice by peice private void DrawManual(DrawState state) { //manual render state //First, take a copy of current render state.. DeviceRenderState currentState = state.RenderState; //The DeviceRenderState structure stores common render state, it's bit-packed so it's small. //The majority of render state is stored, with most commonly used xbox-supported state included. //The entire structure is 16 bytes (the size of a Vector4) // //The DeviceRenderState structure stores four smaller structures: // // StencilTestState StencilTest; (8 bytes) // AlphaBlendState AlphaBlend; (4 bytes) // AlphaTestState AlphaTest; (2 bytes) // DepthColourCullState DepthColourCull; (2 bytes) // //DepthColourCullState combines the three smaller states, Depth testing, Colour masking and FrustumCull mode // //When geometry is rendered, state.RenderState is compared to the current known device state //This comparison is very fast. Any changes detected will be applied at render time. // //Because of this, changing state.RenderState is very fast and efficient, as actual render state //on the GraphicsDevice doesn't change until the geometry is drawn. No logic is run when changing //the value. // //In terms of efficiency, think of setting the DeviceRenderState as equivalent assigning integers. //Here the alpha blend state is changed manually... //reset the state to default (no blending) state.RenderState.AlphaBlend = new AlphaBlendState(); //4 bytes assigned to zero, no heap allocations //set blending... state.RenderState.AlphaBlend.Enabled = true; //one bit is changed state.RenderState.AlphaBlend.SourceBlend = Blend.SourceAlpha; //4 bits are changed state.RenderState.AlphaBlend.DestinationBlend = Blend.InverseSourceAlpha; //4 bits are changed //draw the sphere DrawGeometry(state); //set the previous state back state.SetRenderState(ref currentState); //Note: //you cannot write: //state.RenderState = currentState; //you have to call 'SetRenderState()' instead. }