Esempio n. 1
0
        /// <summary>
        /// Binds the implementation. This is called the first time an unbound state is set to the device or manually by the user in order to
        /// create the underlying state ahead of time (best practice). Once called the state properties are read-only.
        /// </summary>
        public override void BindDepthStencilState()
        {
            if (!base.IsBound)
            {
                D3D.DepthStencilStateDescription desc = new D3D.DepthStencilStateDescription();

                desc.DepthWriteMask   = (base.DepthWriteEnable) ? D3D.DepthWriteMask.All : D3D.DepthWriteMask.Zero;
                desc.DepthComparison  = D3D10Helper.ToD3DComparison(base.DepthFunction);
                desc.IsDepthEnabled   = base.DepthEnable;
                desc.IsStencilEnabled = base.StencilEnable;
                desc.StencilWriteMask = (byte)base.StencilWriteMask;
                desc.StencilReadMask  = (byte)base.StencilReadMask;

                //Set front facing stencil op
                D3D.DepthStencilOperationDescription opDesc = new D3D.DepthStencilOperationDescription();
                opDesc.Comparison         = D3D10Helper.ToD3DComparison(base.StencilFunction);
                opDesc.DepthFailOperation = D3D10Helper.ToD3DStencilOperation(base.StencilDepthFail);
                opDesc.FailOperation      = D3D10Helper.ToD3DStencilOperation(base.StencilFail);
                opDesc.PassOperation      = D3D10Helper.ToD3DStencilOperation(base.StencilPass);
                desc.FrontFace            = opDesc;

                D3D.DepthStencilOperationDescription ccwopDesc = new D3D.DepthStencilOperationDescription();
                //Set back facing stencil op if enabled, otherwise enforced defaults
                if (base.TwoSidedStencilEnable)
                {
                    ccwopDesc.Comparison         = D3D10Helper.ToD3DComparison(base.CounterClockwiseStencilFunction);
                    ccwopDesc.DepthFailOperation = D3D10Helper.ToD3DStencilOperation(base.CounterClockwiseStencilDepthFail);
                    ccwopDesc.FailOperation      = D3D10Helper.ToD3DStencilOperation(base.CounterClockwiseStencilFail);
                    ccwopDesc.PassOperation      = D3D10Helper.ToD3DStencilOperation(base.CounterClockwiseStencilPass);
                }
                else
                {
                    ccwopDesc.Comparison         = D3D.Comparison.Always;
                    ccwopDesc.DepthFailOperation = D3D.StencilOperation.Keep;
                    ccwopDesc.FailOperation      = D3D.StencilOperation.Keep;
                    ccwopDesc.PassOperation      = D3D.StencilOperation.Keep;
                }
                desc.BackFace = ccwopDesc;

                _ds          = D3D.DepthStencilState.FromDescription(_graphicsDevice, desc);
                base.IsBound = true;

                _renderer.Resources.AddTrackedObject(_ds.ComPointer, this);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Releases unmanaged and - optionally - managed resources
 /// </summary>
 /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
 protected override void Dispose(bool disposing)
 {
     if (!IsDisposed)
     {
         //Dispose of managed resources
         if (disposing)
         {
             if (_ds != null)
             {
                 if (_renderer != null)
                 {
                     _renderer.Resources.RemoveTrackedObject(_ds.ComPointer);
                 }
                 _ds.Dispose();
                 _ds = null;
             }
         }
         base.Dispose(disposing);
     }
 }