/// <summary>
        ///    Converts our StencilOperation enum to the D3D StencilOperation equivalent.
        /// </summary>
        /// <param name="op"></param>
        /// <returns></returns>
        public static D3D.StencilOperation ConvertEnum(Axiom.Graphics.StencilOperation op, bool invert)
        {
            switch (op)
            {
            case Axiom.Graphics.StencilOperation.Keep:
                return(D3D.StencilOperation.Keep);

            case Axiom.Graphics.StencilOperation.Zero:
                return(D3D.StencilOperation.Zero);

            case Axiom.Graphics.StencilOperation.Replace:
                return(D3D.StencilOperation.Replace);

            case Axiom.Graphics.StencilOperation.Increment:
                return(invert ?
                       D3D.StencilOperation.DecrementSaturation : D3D.StencilOperation.IncrementSaturation);

            case Axiom.Graphics.StencilOperation.Decrement:
                return(invert ?
                       D3D.StencilOperation.IncrementSaturation : D3D.StencilOperation.DecrementSaturation);

            case Axiom.Graphics.StencilOperation.IncrementWrap:
                return(invert ?
                       D3D.StencilOperation.Decrement : D3D.StencilOperation.Increment);

            case Axiom.Graphics.StencilOperation.DecrementWrap:
                return(invert ?
                       D3D.StencilOperation.Increment : D3D.StencilOperation.Decrement);

            case Axiom.Graphics.StencilOperation.Invert:
                return(D3D.StencilOperation.Invert);
            }

            return(0);
        }
        public override void SetStencilBufferParams( CompareFunction function = CompareFunction.AlwaysPass, 
            int refValue = 0, int mask = -1, 
            StencilOperation stencilFailOp = StencilOperation.Keep, StencilOperation depthFailOp = StencilOperation.Keep, 
            StencilOperation passOp = StencilOperation.Keep, bool twoSidedOperation = false )
        {
            bool flip;

            // 2 sided operation?
            if ( twoSidedOperation )
            {
                if (!currentCapabilities.HasCapability(Graphics.Capabilities.TwoSidedStencil))
                {
                    throw new AxiomException( "2-sided stencils are not supported on this hardware!" );
                }

                SetRenderState( RenderState.TwoSidedStencilMode, true );

                // NB: We should always treat CCW as front face for consistent with default
                // culling mode. Therefore, we must take care with two-sided stencil settings.
                flip = (invertVertexWinding && activeRenderTarget.RequiresTextureFlipping) ||
                    (!invertVertexWinding && !activeRenderTarget.RequiresTextureFlipping);

                SetRenderState( RenderState.CcwStencilFail, (int)D3DHelper.ConvertEnum( stencilFailOp, !flip ) );
                SetRenderState( RenderState.CcwStencilZFail, (int)D3DHelper.ConvertEnum( depthFailOp, !flip ) );
                SetRenderState( RenderState.CcwStencilPass, (int)D3DHelper.ConvertEnum( passOp, !flip ) );
            }
            else
            {
                SetRenderState( RenderState.TwoSidedStencilMode, false );
                flip = false;
            }

            // configure standard version of the stencil operations
            SetRenderState( RenderState.StencilFunc, (int)D3DHelper.ConvertEnum( function ) );
            SetRenderState( RenderState.StencilRef, refValue );
            SetRenderState( RenderState.StencilMask, mask );
            SetRenderState( RenderState.StencilFail, (int)D3DHelper.ConvertEnum( stencilFailOp, flip ) );
            SetRenderState( RenderState.StencilZFail, (int)D3DHelper.ConvertEnum( depthFailOp, flip ) );
            SetRenderState( RenderState.StencilPass, (int)D3DHelper.ConvertEnum( passOp, flip ) );
        }
        public override void SetStencilBufferParams(CompareFunction function, int refValue, int mask, StencilOperation stencilFailOp, StencilOperation depthFailOp, StencilOperation passOp, bool twoSidedOperation)
        {
            // 2 sided operation?
            if(twoSidedOperation) {
                if(!caps.CheckCap(Capabilities.TwoSidedStencil)) {
                    throw new AxiomException("2-sided stencils are not supported on this hardware!");
                }

                device.RenderState.TwoSidedStencilMode = true;

                // use CCW version of the operations
                device.RenderState.CounterClockwiseStencilFail = D3DHelper.ConvertEnum(stencilFailOp, true);
                device.RenderState.CounterClockwiseStencilZBufferFail = D3DHelper.ConvertEnum(depthFailOp, true);
                device.RenderState.CounterClockwiseStencilPass = D3DHelper.ConvertEnum(passOp, true);
            }
            else {
                device.RenderState.TwoSidedStencilMode = false;
            }

            // configure standard version of the stencil operations
            device.RenderState.StencilFunction = D3DHelper.ConvertEnum(function);
            device.RenderState.ReferenceStencil = refValue;
            device.RenderState.StencilMask = mask;
            device.RenderState.StencilFail = D3DHelper.ConvertEnum(stencilFailOp);
            device.RenderState.StencilZBufferFail = D3DHelper.ConvertEnum(depthFailOp);
            device.RenderState.StencilPass = D3DHelper.ConvertEnum(passOp);
        }
 public static D3D.StencilOperation ConvertEnum(Axiom.Graphics.StencilOperation op)
 {
     return(ConvertEnum(op, false));
 }