Share Pastebin
Guest
Public paste!

CentauriBoy

By: a guest | Feb 6th, 2010 | Syntax: C# | Size: 28.92 KB | Hits: 98 | Expires: Never
Copy text to clipboard
  1. //////////////////////////////////////////////////////////////////////////
  2. /// <summary>
  3. /// A helper class for setting render states of the graphics device.
  4. /// </summary>
  5. //////////////////////////////////////////////////////////////////////////
  6. public static class RSHelper
  7. {
  8.     /*********************************************************************/
  9.     // Members.
  10.     /*********************************************************************/
  11.  
  12.     #region Enumerations
  13.  
  14.     [Flags]
  15.     public enum RSVar : ulong
  16.     {
  17.         AlphaBlendEnable = 1,
  18.         AlphaBlendOperation = AlphaBlendEnable << 1,
  19.         AlphaDestinationBlend = AlphaBlendOperation << 1,
  20.         AlphaFunction = AlphaDestinationBlend << 1,
  21.         AlphaSourceBlend = AlphaFunction << 1,
  22.         AlphaTestEnable = AlphaSourceBlend << 1,
  23.         BlendFactor = AlphaTestEnable << 1,
  24.         BlendFunction = BlendFactor << 1,
  25.         ColorWriteChannels = BlendFunction << 1,
  26.         ColorWriteChannels1 = ColorWriteChannels << 1,
  27.         ColorWriteChannels2 = ColorWriteChannels1 << 1,
  28.         ColorWriteChannels3 = ColorWriteChannels2 << 1,
  29.         CounterClockwiseStencilDepthBufferFail = ColorWriteChannels3 << 1,
  30.         CounterClockwiseStencilFail = CounterClockwiseStencilDepthBufferFail << 1,
  31.         CounterClockwiseStencilFunction = CounterClockwiseStencilFail << 1,
  32.         CounterClockwiseStencilPass = CounterClockwiseStencilFunction << 1,
  33.         CullMode = CounterClockwiseStencilPass << 1,
  34.         DepthBias = CullMode << 1,
  35.         DepthBufferEnable = DepthBias << 1,
  36.         DepthBufferFunction = DepthBufferEnable << 1,
  37.         DepthBufferWriteEnable = DepthBufferFunction << 1,
  38.         DestinationBlend = DepthBufferWriteEnable << 1,
  39.         FillMode = DestinationBlend << 1,
  40.         FogColor = FillMode << 1,
  41.         FogDensity = FogColor << 1,
  42.         FogEnable = FogDensity << 1,
  43.         FogEnd = FogEnable << 1,
  44.         FogStart = FogEnd << 1,
  45.         FogTableMode = FogStart << 1,
  46.         FogVertexMode = FogTableMode << 1,
  47.         MultiSampleAntiAlias = FogVertexMode << 1,
  48.         MultiSampleMask = MultiSampleAntiAlias << 1,
  49.         PointSize = MultiSampleMask << 1,
  50.         PointSizeMax = PointSize << 1,
  51.         PointSizeMin = PointSizeMax << 1,
  52.         PointSpriteEnable = PointSizeMin << 1,
  53.         RangeFogEnable = PointSpriteEnable << 1,
  54.         ReferenceAlpha = RangeFogEnable << 1,
  55.         ReferenceStencil = ReferenceAlpha << 1,
  56.         ScissorTestEnable = ReferenceStencil << 1,
  57.         SeparateAlphaBlendEnabled = ScissorTestEnable << 1,
  58.         SlopeScaleDepthBias = SeparateAlphaBlendEnabled << 1,
  59.         SourceBlend = SlopeScaleDepthBias << 1,
  60.         StencilDepthBufferFail = SourceBlend << 1,
  61.         StencilEnable = StencilDepthBufferFail << 1,
  62.         StencilFail = StencilEnable << 1,
  63.         StencilFunction = StencilFail << 1,
  64.         StencilMask = StencilFunction << 1,
  65.         StencilPass = StencilMask << 1,
  66.         StencilWriteMask = StencilPass << 1,
  67.         TwoSidedStencilMode = StencilWriteMask << 1,
  68.     }
  69.  
  70.     #endregion // Enumerations
  71.  
  72.     #region Internal Data Structures
  73.  
  74.     //////////////////////////////////////////////////////////////////////////
  75.     /// <summary>
  76.     /// Render state data structure.
  77.     /// </summary>
  78.     //////////////////////////////////////////////////////////////////////////
  79.     private struct RSData
  80.     {
  81.         /*********************************************************************/
  82.         // Members.
  83.         /*********************************************************************/
  84.  
  85.         #region Fields
  86.  
  87.         /// <summary>Index reference.</summary>
  88.         public int Index;
  89.  
  90.         /// <summary>Shift data.</summary>
  91.         public ulong ShiftData;
  92.  
  93.         /// <summary>Object type.</summary>
  94.         public object ObjectType;
  95.  
  96.         #endregion // Fields
  97.  
  98.         /*********************************************************************/
  99.         // Functions.
  100.         /*********************************************************************/
  101.  
  102.         #region Intialization
  103.  
  104.         //////////////////////////////////////////////////////////////////////////
  105.         /// <summary>
  106.         /// Alternate constructor.
  107.         /// </summary>
  108.         /// <param name="_nIndex">Index reference.</param>
  109.         /// <param name="_ulShiftDatta">Shift data.</param>
  110.         /// <param name="_objType">Object type.</param>
  111.         //////////////////////////////////////////////////////////////////////////
  112.         public RSData(int _nIndex, ulong _ulShiftDatta, object _objType)
  113.         {
  114.             Index = _nIndex;
  115.             ShiftData = _ulShiftDatta;
  116.             ObjectType = _objType;
  117.         }
  118.  
  119.         #endregion // Initialization
  120.     }
  121.  
  122.     #endregion // Internal Data Structures
  123.  
  124.     #region Fields
  125.  
  126.     /// <summary>Stored previous state.</summary>
  127.     private static ulong m_prevState = 0x00;
  128.  
  129.     /// <summary>List of render state data.</summary>
  130.     private static List<RSData> m_RSList = new List<RSData>();
  131.  
  132.     #endregion // Fields
  133.  
  134.     /*********************************************************************/
  135.     // Functions.
  136.     /*********************************************************************/
  137.  
  138.     #region Private Methods
  139.  
  140.     //////////////////////////////////////////////////////////////////////////
  141.     /// <summary>
  142.     /// Determine if the bit is on.
  143.     /// </summary>
  144.     /// <param name="_nBitField">The bitfield to manipulate.</param>
  145.     /// <param name="_nBitPos">The bit position to toggle on/off.</param>
  146.     //////////////////////////////////////////////////////////////////////////
  147.     private static bool IsBitOn(ulong _nBitField, ulong _nShiftBitPos)
  148.     {
  149.         return ((_nShiftBitPos & _nBitField) == _nShiftBitPos) ? true : false;
  150.     }
  151.  
  152.     //////////////////////////////////////////////////////////////////////////
  153.     /// <summary>
  154.     /// Set the current renderstate based on parameters passed in.
  155.     /// </summary>
  156.     /// <param name="_RenderState">The current renderstate to use.</param>
  157.     /// <param name="_ulRSVariable">Variables to set.</param>
  158.     /// <param name="_nIndex">Current index of the _Values.</param>
  159.     /// <param name="_Values">Values used to set the variables. (Must be in sequence with _Variables).</param>
  160.     //////////////////////////////////////////////////////////////////////////
  161.     private static void SetRenderState(RenderState _RenderState, ulong _ulRSVariable, int _nIndex, params object[] _Values)
  162.     {
  163.         switch ((RSVar)_ulRSVariable)
  164.         {
  165.             case RSVar.AlphaBlendEnable: _RenderState.AlphaBlendEnable = (bool)_Values[_nIndex]; break;
  166.             case RSVar.AlphaBlendOperation: _RenderState.AlphaBlendOperation = (BlendFunction)_Values[_nIndex]; break;
  167.             case RSVar.AlphaDestinationBlend: _RenderState.AlphaDestinationBlend = (Blend)_Values[_nIndex]; break;
  168.             case RSVar.AlphaFunction: _RenderState.AlphaFunction = (CompareFunction)_Values[_nIndex]; break;
  169.             case RSVar.AlphaSourceBlend: _RenderState.AlphaSourceBlend = (Blend)_Values[_nIndex]; break;
  170.             case RSVar.AlphaTestEnable: _RenderState.AlphaTestEnable = (bool)_Values[_nIndex]; break;
  171.             case RSVar.BlendFactor: _RenderState.BlendFactor = (Color)_Values[_nIndex]; break;
  172.             case RSVar.BlendFunction: _RenderState.BlendFunction = (BlendFunction)_Values[_nIndex]; break;
  173.             case RSVar.ColorWriteChannels: _RenderState.ColorWriteChannels = (ColorWriteChannels)_Values[_nIndex]; break;
  174.             case RSVar.ColorWriteChannels1: _RenderState.ColorWriteChannels1 = (ColorWriteChannels)_Values[_nIndex]; break;
  175.             case RSVar.ColorWriteChannels2: _RenderState.ColorWriteChannels2 = (ColorWriteChannels)_Values[_nIndex]; break;
  176.             case RSVar.ColorWriteChannels3: _RenderState.ColorWriteChannels3 = (ColorWriteChannels)_Values[_nIndex]; break;
  177.             case RSVar.CounterClockwiseStencilDepthBufferFail: _RenderState.CounterClockwiseStencilDepthBufferFail = (StencilOperation)_Values[_nIndex]; break;
  178.             case RSVar.CounterClockwiseStencilFail: _RenderState.CounterClockwiseStencilFail = (StencilOperation)_Values[_nIndex]; break;
  179.             case RSVar.CounterClockwiseStencilFunction: _RenderState.CounterClockwiseStencilFunction = (CompareFunction)_Values[_nIndex]; break;
  180.             case RSVar.CounterClockwiseStencilPass: _RenderState.CounterClockwiseStencilPass = (StencilOperation)_Values[_nIndex]; break;
  181.             case RSVar.CullMode: _RenderState.CullMode = (CullMode)_Values[_nIndex]; break;
  182.             case RSVar.DepthBias: _RenderState.DepthBias = (float)_Values[_nIndex]; break;
  183.             case RSVar.DepthBufferEnable: _RenderState.AlphaBlendEnable = (bool)_Values[_nIndex]; break;
  184.             case RSVar.DepthBufferFunction: _RenderState.DepthBufferFunction = (CompareFunction)_Values[_nIndex]; break;
  185.             case RSVar.DepthBufferWriteEnable: _RenderState.DepthBufferWriteEnable = (bool)_Values[_nIndex]; break;
  186.             case RSVar.DestinationBlend: _RenderState.DestinationBlend = (Blend)_Values[_nIndex]; break;
  187.             case RSVar.FillMode: _RenderState.FillMode = (FillMode)_Values[_nIndex]; break;
  188.             case RSVar.FogColor: _RenderState.FogColor = (Color)_Values[_nIndex]; break;
  189.             case RSVar.FogDensity: _RenderState.FogDensity = (float)_Values[_nIndex]; break;
  190.             case RSVar.FogEnable: _RenderState.FogEnable = (bool)_Values[_nIndex]; break;
  191.             case RSVar.FogEnd: _RenderState.FogEnd = (float)_Values[_nIndex]; break;
  192.             case RSVar.FogStart: _RenderState.FogStart = (float)_Values[_nIndex]; break;
  193.             case RSVar.FogTableMode: _RenderState.FogTableMode = (FogMode)_Values[_nIndex]; break;
  194.             case RSVar.FogVertexMode: _RenderState.FogVertexMode = (FogMode)_Values[_nIndex]; break;
  195.             case RSVar.MultiSampleAntiAlias: _RenderState.MultiSampleAntiAlias = (bool)_Values[_nIndex]; break;
  196.             case RSVar.MultiSampleMask: _RenderState.MultiSampleMask = (int)_Values[_nIndex]; break;
  197.             case RSVar.PointSize: _RenderState.PointSize = (float)_Values[_nIndex]; break;
  198.             case RSVar.PointSizeMax: _RenderState.PointSizeMax = (float)_Values[_nIndex]; break;
  199.             case RSVar.PointSizeMin: _RenderState.PointSizeMin = (float)_Values[_nIndex]; break;
  200.             case RSVar.PointSpriteEnable: _RenderState.PointSpriteEnable = (bool)_Values[_nIndex]; break;
  201.             case RSVar.RangeFogEnable: _RenderState.RangeFogEnable = (bool)_Values[_nIndex]; break;
  202.             case RSVar.ReferenceAlpha: _RenderState.ReferenceAlpha = (int)_Values[_nIndex]; break;
  203.             case RSVar.ReferenceStencil: _RenderState.ReferenceStencil = (int)_Values[_nIndex]; break;
  204.             case RSVar.ScissorTestEnable: _RenderState.ScissorTestEnable = (bool)_Values[_nIndex]; break;
  205.             case RSVar.SeparateAlphaBlendEnabled: _RenderState.SeparateAlphaBlendEnabled = (bool)_Values[_nIndex]; break;
  206.             case RSVar.SlopeScaleDepthBias: _RenderState.SlopeScaleDepthBias = (float)_Values[_nIndex]; break;
  207.             case RSVar.SourceBlend: _RenderState.SourceBlend = (Blend)_Values[_nIndex]; break;
  208.             case RSVar.StencilDepthBufferFail: _RenderState.StencilDepthBufferFail = (StencilOperation)_Values[_nIndex]; break;
  209.             case RSVar.StencilEnable: _RenderState.StencilEnable = (bool)_Values[_nIndex]; break;
  210.             case RSVar.StencilFail: _RenderState.StencilFail = (StencilOperation)_Values[_nIndex]; break;
  211.             case RSVar.StencilFunction: _RenderState.StencilFunction = (CompareFunction)_Values[_nIndex]; break;
  212.             case RSVar.StencilMask: _RenderState.StencilMask = (int)_Values[_nIndex]; break;
  213.             case RSVar.StencilPass: _RenderState.StencilPass = (StencilOperation)_Values[_nIndex]; break;
  214.             case RSVar.StencilWriteMask: _RenderState.StencilWriteMask = (int)_Values[_nIndex]; break;
  215.             case RSVar.TwoSidedStencilMode: _RenderState.TwoSidedStencilMode = (bool)_Values[_nIndex]; break;
  216.  
  217.             default:
  218.                 break;
  219.         }
  220.     }
  221.  
  222.     #endregion // Private Methods
  223.  
  224.     #region Public Methods
  225.  
  226.     //////////////////////////////////////////////////////////////////////////
  227.     /// <summary>
  228.     /// Set the render state based on parameters passed in.
  229.     /// <para>NOTE: This function runs through _Variables from least to most</para>
  230.     /// <para>significant bit. In other words, _Variables must be in alphabetical</para>
  231.     /// <para>order for the function to work correctly.</para>
  232.     /// </summary>
  233.     /// <param name="_RenderState">The current render state to use.</param>
  234.     /// <param name="_Variables">Render state variables to set. (Must be in alphabetical order (Enumeration order)).</param>
  235.     /// <param name="_Values">Values used to set the variables. (Must be in the same sequence as the _Variables).</param>
  236.     //////////////////////////////////////////////////////////////////////////
  237.     public static void Set(RenderState _RenderState,
  238.                            RSVar _Variables,
  239.                            params object[] _Values)
  240.     {
  241.         //////////////////////////////////////////////////////////////////////////
  242.         // Local variables.
  243.         int nBitPos = 0;
  244.         int nIndex = 0;
  245.         bool bBreak = false;
  246.         bool bNoChange = true;
  247.         List<ulong> UpdateList = new List<ulong>();
  248.         List<RSData> NewList = new List<RSData>();
  249.         //
  250.         //////////////////////////////////////////////////////////////////////////
  251.  
  252.         //////////////////////////////////////////////////////////////////////////
  253.         // Run through the list of renderstates to check if values have changed.
  254.         while (m_RSList.Count > 0 && UpdateList.Count < _Values.Length && NewList.Count < _Values.Length &&
  255.                nBitPos < (sizeof(ulong) * 8))
  256.         {
  257.             //////////////////////////////////////////////////////////////////////////
  258.             // Shift to the next bit position and check if the bit is on.
  259.             ulong nShiftBitPos = (ulong)((ulong)1 << nBitPos);
  260.             if (IsBitOn((ulong)_Variables, nShiftBitPos))
  261.             {
  262.                 //////////////////////////////////////////////////////////////////////////
  263.                 // Run through the list of variables.
  264.                 foreach (RSData data in m_RSList)
  265.                 {
  266.                     //////////////////////////////////////////////////////////////////////////
  267.                     // Run through the list of values.
  268.                     foreach (object value in _Values)
  269.                     {
  270.                         //////////////////////////////////////////////////////////////////////////
  271.                         // Check if the render state has already been activated.
  272.                         if (data.ShiftData == nShiftBitPos)
  273.                         {
  274.                             //////////////////////////////////////////////////////////////////////////
  275.                             // Check the data type and value if they have changed.
  276.                             if (data.ObjectType.GetType() == value.GetType() &&
  277.                                 data.ObjectType.ToString() != value.ToString())
  278.                                 UpdateList.Add(nShiftBitPos);
  279.  
  280.                             // Break out of the loop.
  281.                             bBreak = true;
  282.                             bNoChange = false;
  283.                             break;
  284.                         }
  285.                            
  286.                         //
  287.                         //////////////////////////////////////////////////////////////////////////
  288.                     }
  289.                     //
  290.                     //////////////////////////////////////////////////////////////////////////
  291.  
  292.                     //////////////////////////////////////////////////////////////////////////
  293.                     // Break out of the loop.
  294.                     if (bBreak)
  295.                         break;
  296.                     //
  297.                     //////////////////////////////////////////////////////////////////////////
  298.                 }
  299.                 //
  300.                 //////////////////////////////////////////////////////////////////////////
  301.  
  302.                 //////////////////////////////////////////////////////////////////////////
  303.                 // There is a new render state.
  304.                 if (!bBreak)
  305.                     NewList.Add(new RSData(nIndex, nShiftBitPos, _Values[nIndex]));
  306.                 //
  307.                 //////////////////////////////////////////////////////////////////////////
  308.  
  309.                 //////////////////////////////////////////////////////////////////////////
  310.                 // Reset break flag and increment the next index.
  311.                 bBreak = false;
  312.                 ++nIndex;
  313.                 //
  314.                 //////////////////////////////////////////////////////////////////////////
  315.             }
  316.             //
  317.             //////////////////////////////////////////////////////////////////////////
  318.  
  319.             // Increment to next bit position.
  320.             ++nBitPos;
  321.         }
  322.         //
  323.         //////////////////////////////////////////////////////////////////////////
  324.  
  325.         //////////////////////////////////////////////////////////////////////////
  326.         // Determine if there are new renderstates.
  327.         if (NewList.Count > 0)
  328.         {
  329.             nIndex = 0;
  330.             for (int i = NewList.Count - 1; i >= 0; --i)
  331.             {
  332.                 SetRenderState(_RenderState, NewList[i].ShiftData, NewList[i].Index, _Values);
  333.                 m_RSList.Add(new RSData(NewList[i].Index, NewList[i].ShiftData, _Values[nIndex++]));
  334.             }
  335.         }
  336.         //
  337.         //////////////////////////////////////////////////////////////////////////
  338.         //////////////////////////////////////////////////////////////////////////
  339.         // Determine if there has been a change to an already activated renderstate.
  340.         else if (UpdateList.Count > 0)
  341.         {
  342.             nIndex = 0;
  343.             foreach (ulong ulValue in UpdateList)
  344.             {
  345.                 SetRenderState(_RenderState, ulValue, nIndex, _Values);
  346.                 m_RSList.Add(new RSData(nIndex, ulValue, _Values[nIndex]));
  347.  
  348.                 //////////////////////////////////////////////////////////////////////////
  349.                 // Run through the list, in reverse, to determine if this render state has
  350.                 // been added and modified.
  351.                 for (int i = m_RSList.Count - 2; i >= 0; --i)
  352.                 {
  353.                     // This means we found the same render state but it has been modified.
  354.                     // So we will need to copy it and remove the last added one.
  355.                     if (m_RSList[i].ShiftData == ulValue)
  356.                     {
  357.                         // Remove at current location, insert new data and remove the last added data.
  358.                         m_RSList.RemoveAt(i);
  359.                         m_RSList.Insert(i, new RSData(nIndex, ulValue, _Values[nIndex]));
  360.                         m_RSList.RemoveAt(m_RSList.Count - 1);
  361.                     }
  362.                 }
  363.                 //
  364.                 //////////////////////////////////////////////////////////////////////////
  365.  
  366.                 // Increment next index.
  367.                 ++nIndex;
  368.             }
  369.         }
  370.         //////////////////////////////////////////////////////////////////////////
  371.         // Check if there have been changes.
  372.         else if (bNoChange)
  373.         {
  374.             //////////////////////////////////////////////////////////////////////////
  375.             // See what states have changed.
  376.             ulong ulChanges = (ulong)_Variables ^ m_prevState;
  377.             //
  378.             //////////////////////////////////////////////////////////////////////////
  379.  
  380.             //////////////////////////////////////////////////////////////////////////
  381.             // Reset local variables.
  382.             nIndex = 0;
  383.             nBitPos = 0;
  384.             //
  385.             //////////////////////////////////////////////////////////////////////////
  386.  
  387.             //////////////////////////////////////////////////////////////////////////
  388.             // Run through and search which bit has been activated.
  389.             while ((ulChanges != 0) && nBitPos < (sizeof(ulong) * 8))
  390.             {
  391.                 //////////////////////////////////////////////////////////////////////////
  392.                 // Determine if the bit is on.
  393.                 ulong nShiftBitPos = (ulong)(1 << nBitPos);
  394.                 if (IsBitOn((ulong)_Variables, nShiftBitPos))
  395.                 {
  396.                     SetRenderState(_RenderState, nShiftBitPos, nIndex, _Values);
  397.                     m_RSList.Add(new RSData(nIndex, nShiftBitPos, _Values[nIndex++]));
  398.                 }
  399.                 //
  400.                 //////////////////////////////////////////////////////////////////////////
  401.  
  402.                 //////////////////////////////////////////////////////////////////////////
  403.                 // Increment to the next bit position.
  404.                 ++nBitPos;
  405.                 //
  406.                 //////////////////////////////////////////////////////////////////////////
  407.  
  408.                 //////////////////////////////////////////////////////////////////////////
  409.                 // Clear this bit to shorten the loop.
  410.                 ulChanges ^= (nShiftBitPos & (ulong)ulChanges);
  411.                 //
  412.                 //////////////////////////////////////////////////////////////////////////
  413.             }
  414.             //
  415.             //////////////////////////////////////////////////////////////////////////
  416.  
  417.             // Store the pervious state.
  418.             m_prevState = (ulong)_Variables;
  419.         }
  420.         //
  421.         //////////////////////////////////////////////////////////////////////////
  422.     }
  423.  
  424.     //////////////////////////////////////////////////////////////////////////
  425.     /// <summary>
  426.     /// Reset the current renderstate based on changes made.
  427.     /// </summary>
  428.     /// <param name="_currentRenderState">The current render state.</param>
  429.     //////////////////////////////////////////////////////////////////////////
  430.     public static void Reset(RenderState _currentRenderState)
  431.     {
  432.         //////////////////////////////////////////////////////////////////////////
  433.         // Check if there were any changes.
  434.         if (m_RSList.Count > 0)
  435.         {
  436.             //////////////////////////////////////////////////////////////////////////
  437.             // Run through the list of changes.
  438.             foreach (RSData data in m_RSList)
  439.             {
  440.                 //////////////////////////////////////////////////////////////////////////
  441.                 // Determine the index reference.
  442.                 switch ((RSVar)data.Index)
  443.                 {
  444.                     case RSVar.AlphaBlendEnable: _currentRenderState.AlphaBlendEnable = false; break;
  445.                     case RSVar.AlphaBlendOperation: _currentRenderState.AlphaBlendOperation = BlendFunction.Add; break;
  446.                     case RSVar.AlphaDestinationBlend: _currentRenderState.AlphaDestinationBlend = Blend.One; break;
  447.                     case RSVar.AlphaFunction: _currentRenderState.AlphaFunction = CompareFunction.Always; break;
  448.                     case RSVar.AlphaSourceBlend: _currentRenderState.AlphaSourceBlend = Blend.One; break;
  449.                     case RSVar.AlphaTestEnable: _currentRenderState.AlphaTestEnable = false; break;
  450.                     case RSVar.BlendFactor: _currentRenderState.BlendFactor = Color.White; break;
  451.                     case RSVar.BlendFunction: _currentRenderState.BlendFunction = BlendFunction.Add; break;
  452.                     case RSVar.ColorWriteChannels: _currentRenderState.ColorWriteChannels = ColorWriteChannels.None; break;
  453.                     case RSVar.ColorWriteChannels1: _currentRenderState.ColorWriteChannels1 = ColorWriteChannels.None; break;
  454.                     case RSVar.ColorWriteChannels2: _currentRenderState.ColorWriteChannels2 = ColorWriteChannels.None; break;
  455.                     case RSVar.ColorWriteChannels3: _currentRenderState.ColorWriteChannels3 = ColorWriteChannels.None; break;
  456.                     case RSVar.CounterClockwiseStencilDepthBufferFail: _currentRenderState.CounterClockwiseStencilDepthBufferFail = StencilOperation.Keep; break;
  457.                     case RSVar.CounterClockwiseStencilFail: _currentRenderState.CounterClockwiseStencilFail = StencilOperation.Keep; break;
  458.                     case RSVar.CounterClockwiseStencilFunction: _currentRenderState.CounterClockwiseStencilFunction = CompareFunction.Always; break;
  459.                     case RSVar.CounterClockwiseStencilPass: _currentRenderState.CounterClockwiseStencilPass = StencilOperation.Keep; break;
  460.                     case RSVar.CullMode: _currentRenderState.CullMode = CullMode.CullCounterClockwiseFace; break;
  461.                     case RSVar.DepthBias: _currentRenderState.DepthBias = 0f; break;
  462.                     case RSVar.DepthBufferEnable: _currentRenderState.DepthBufferEnable = false; break;
  463.                     case RSVar.DepthBufferFunction: _currentRenderState.DepthBufferFunction = CompareFunction.LessEqual; break;
  464.                     case RSVar.DepthBufferWriteEnable: _currentRenderState.DepthBufferWriteEnable = true; break;
  465.                     case RSVar.DestinationBlend: _currentRenderState.DestinationBlend = Blend.Zero; break;
  466.                     case RSVar.FillMode: _currentRenderState.FillMode = FillMode.Solid; break;
  467.                     case RSVar.FogColor: _currentRenderState.FogColor = Color.TransparentBlack; break;
  468.                     case RSVar.FogDensity: _currentRenderState.FogDensity = 1f; break;
  469.                     case RSVar.FogEnable: _currentRenderState.FogEnable = false; break;
  470.                     case RSVar.FogEnd: _currentRenderState.FogEnd = 1f; break;
  471.                     case RSVar.FogStart: _currentRenderState.FogStart = 0f; break;
  472.                     case RSVar.FogTableMode: _currentRenderState.FogTableMode = FogMode.None; break;
  473.                     case RSVar.FogVertexMode: _currentRenderState.FogVertexMode = FogMode.None; break;
  474.                     case RSVar.MultiSampleAntiAlias: _currentRenderState.MultiSampleAntiAlias = true; break;
  475.                     case RSVar.MultiSampleMask: unchecked { _currentRenderState.MultiSampleMask = (int)0xffffffff; } break;
  476.                     case RSVar.PointSize: _currentRenderState.PointSize = 64f; break;
  477.                     case RSVar.PointSizeMax: _currentRenderState.PointSizeMax = 64f; break;
  478.                     case RSVar.PointSizeMin: _currentRenderState.PointSizeMin = 1f; break;
  479.                     case RSVar.PointSpriteEnable: _currentRenderState.PointSpriteEnable = false; break;
  480.                     case RSVar.RangeFogEnable: _currentRenderState.RangeFogEnable = false; break;
  481.                     case RSVar.ReferenceAlpha: _currentRenderState.ReferenceAlpha = 0; break;
  482.                     case RSVar.ReferenceStencil: _currentRenderState.ReferenceStencil = 0; break;
  483.                     case RSVar.ScissorTestEnable: _currentRenderState.ScissorTestEnable = false; break;
  484.                     case RSVar.SeparateAlphaBlendEnabled: _currentRenderState.SeparateAlphaBlendEnabled = false; break;
  485.                     case RSVar.SlopeScaleDepthBias: _currentRenderState.SlopeScaleDepthBias = 0; break;
  486.                     case RSVar.SourceBlend: _currentRenderState.SourceBlend = Blend.One; break;
  487.                     case RSVar.StencilDepthBufferFail: _currentRenderState.StencilDepthBufferFail = StencilOperation.Keep; break;
  488.                     case RSVar.StencilEnable: _currentRenderState.StencilEnable = false; break;
  489.                     case RSVar.StencilFail: _currentRenderState.StencilFail = StencilOperation.Keep; break;
  490.                     case RSVar.StencilFunction: _currentRenderState.StencilFunction = CompareFunction.Always; break;
  491.                     case RSVar.StencilMask: _currentRenderState.StencilMask = Int32.MaxValue; break;
  492.                     case RSVar.StencilPass: _currentRenderState.StencilPass = StencilOperation.Keep; break;
  493.                     case RSVar.StencilWriteMask: _currentRenderState.StencilWriteMask = Int32.MaxValue; break;
  494.                     case RSVar.TwoSidedStencilMode: _currentRenderState.TwoSidedStencilMode = false; break;
  495.  
  496.                     default:
  497.                         break;
  498.                 }
  499.                 //
  500.                 //////////////////////////////////////////////////////////////////////////
  501.             }
  502.             //
  503.             //////////////////////////////////////////////////////////////////////////
  504.  
  505.             //////////////////////////////////////////////////////////////////////////
  506.             // Clear the list and trim excess.
  507.             m_RSList.Clear();
  508.             m_RSList.TrimExcess();
  509.             m_prevState = 0;
  510.             //
  511.             //////////////////////////////////////////////////////////////////////////
  512.         }
  513.         //
  514.         //////////////////////////////////////////////////////////////////////////
  515.     }
  516.  
  517.     #endregion // Public Methods
  518. }