static public void InitializeOutputMerger() { backbuffer = Texture2D.FromSwapChain <Texture2D>(swapchain, 0); renderview = new RenderTargetView(device, backbuffer); //MainWindow.ClientSize = new Size(1200, 900); device.Rasterizer.SetViewports(new Viewport(0, 0, MainWindow.ClientSize.Width, MainWindow.ClientSize.Height, 0.0f, 1.0f)); DX10.Texture2DDescription dtd = new Texture2DDescription(); dtd.Width = MainWindow.ClientSize.Width; dtd.Height = MainWindow.ClientSize.Height; dtd.MipLevels = 1; dtd.ArraySize = 1; dtd.BindFlags = BindFlags.DepthStencil; dtd.CpuAccessFlags = CpuAccessFlags.None; dtd.Format = Format.D32_Float; dtd.SampleDescription = new SampleDescription(1, 0); dtd.Usage = ResourceUsage.Default; dtd.OptionFlags = ResourceOptionFlags.None; depthbuffer = new Texture2D(device, dtd); depthview = new DepthStencilView(device, depthbuffer); DX10.DepthStencilStateDescription stencilStateDesc = new SlimDX.Direct3D10.DepthStencilStateDescription(); stencilStateDesc.IsDepthEnabled = true; stencilStateDesc.IsStencilEnabled = false; stencilStateDesc.DepthWriteMask = DX10.DepthWriteMask.All; stencilStateDesc.DepthComparison = DX10.Comparison.Less; device.OutputMerger.SetTargets(depthview, renderview); depthstate = DepthStencilState.FromDescription(device, stencilStateDesc); }
/// <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); } }