// Note: no need to store RTV/DSV formats internal PipelineState(GraphicsDevice graphicsDevice, PipelineStateDescription pipelineStateDescription) : base(graphicsDevice) { // First time, build caches var pipelineStateCache = GetPipelineStateCache(); // Effect this.rootSignature = pipelineStateDescription.RootSignature; this.effectBytecode = pipelineStateDescription.EffectBytecode; CreateShaders(pipelineStateCache); if (rootSignature != null && effectBytecode != null) { ResourceBinder.Compile(graphicsDevice, rootSignature.EffectDescriptorSetReflection, this.effectBytecode); } // TODO: Cache over Effect|RootSignature to create binding operations // States blendState = pipelineStateCache.BlendStateCache.Instantiate(pipelineStateDescription.BlendState); this.sampleMask = pipelineStateDescription.SampleMask; rasterizerState = pipelineStateCache.RasterizerStateCache.Instantiate(pipelineStateDescription.RasterizerState); depthStencilState = pipelineStateCache.DepthStencilStateCache.Instantiate(pipelineStateDescription.DepthStencilState); CreateInputLayout(pipelineStateDescription.InputElements); primitiveTopology = (SharpDX.Direct3D.PrimitiveTopology)pipelineStateDescription.PrimitiveType; }
internal void ApplyState(GraphicsDevice device) { if (_state == null) { // We're now bound to a device... no one should // be changing the state of this object now! GraphicsDevice = device; // Build the description. var desc = new SharpDX.Direct3D11.DepthStencilStateDescription(); desc.IsDepthEnabled = DepthBufferEnable; desc.DepthComparison = GetComparison(DepthBufferFunction); if (DepthBufferWriteEnable) { desc.DepthWriteMask = SharpDX.Direct3D11.DepthWriteMask.All; } else { desc.DepthWriteMask = SharpDX.Direct3D11.DepthWriteMask.Zero; } desc.IsStencilEnabled = StencilEnable; desc.StencilReadMask = (byte)StencilMask; // TODO: Should this instead grab the upper 8bits? desc.StencilWriteMask = (byte)StencilWriteMask; if (TwoSidedStencilMode) { desc.BackFace.Comparison = GetComparison(CounterClockwiseStencilFunction); desc.BackFace.DepthFailOperation = GetStencilOp(CounterClockwiseStencilDepthBufferFail); desc.BackFace.FailOperation = GetStencilOp(CounterClockwiseStencilFail); desc.BackFace.PassOperation = GetStencilOp(CounterClockwiseStencilPass); } else { //use same settings as frontFace desc.BackFace.Comparison = GetComparison(StencilFunction); desc.BackFace.DepthFailOperation = GetStencilOp(StencilDepthBufferFail); desc.BackFace.FailOperation = GetStencilOp(StencilFail); desc.BackFace.PassOperation = GetStencilOp(StencilPass); } desc.FrontFace.Comparison = GetComparison(StencilFunction); desc.FrontFace.DepthFailOperation = GetStencilOp(StencilDepthBufferFail); desc.FrontFace.FailOperation = GetStencilOp(StencilFail); desc.FrontFace.PassOperation = GetStencilOp(StencilPass); // Create the state. _state = new SharpDX.Direct3D11.DepthStencilState(GraphicsDevice._d3dDevice, desc); } Debug.Assert(GraphicsDevice == device, "The state was created for a different device!"); // NOTE: We make the assumption here that the caller has // locked the d3dContext for us to use. // Apply the state! device._d3dContext.OutputMerger.DepthStencilReference = ReferenceStencil; device._d3dContext.OutputMerger.DepthStencilState = _state; }
internal void PlatformApplyState(GraphicsDevice device) { if (_state == null) { // We're now bound to a device... no one should // be changing the state of this object now! GraphicsDevice = device; // Build the description. var desc = new SharpDX.Direct3D11.DepthStencilStateDescription(); desc.IsDepthEnabled = DepthBufferEnable; desc.DepthComparison = GetComparison(DepthBufferFunction); if (DepthBufferWriteEnable) desc.DepthWriteMask = SharpDX.Direct3D11.DepthWriteMask.All; else desc.DepthWriteMask = SharpDX.Direct3D11.DepthWriteMask.Zero; desc.IsStencilEnabled = StencilEnable; desc.StencilReadMask = (byte)StencilMask; // TODO: Should this instead grab the upper 8bits? desc.StencilWriteMask = (byte)StencilWriteMask; if (TwoSidedStencilMode) { desc.BackFace.Comparison = GetComparison(CounterClockwiseStencilFunction); desc.BackFace.DepthFailOperation = GetStencilOp(CounterClockwiseStencilDepthBufferFail); desc.BackFace.FailOperation = GetStencilOp(CounterClockwiseStencilFail); desc.BackFace.PassOperation = GetStencilOp(CounterClockwiseStencilPass); } else { //use same settings as frontFace desc.BackFace.Comparison = GetComparison(StencilFunction); desc.BackFace.DepthFailOperation = GetStencilOp(StencilDepthBufferFail); desc.BackFace.FailOperation = GetStencilOp(StencilFail); desc.BackFace.PassOperation = GetStencilOp(StencilPass); } desc.FrontFace.Comparison = GetComparison(StencilFunction); desc.FrontFace.DepthFailOperation = GetStencilOp(StencilDepthBufferFail); desc.FrontFace.FailOperation = GetStencilOp(StencilFail); desc.FrontFace.PassOperation = GetStencilOp(StencilPass); // Create the state. _state = new SharpDX.Direct3D11.DepthStencilState(GraphicsDevice._d3dDevice, desc); } Debug.Assert(GraphicsDevice == device, "The state was created for a different device!"); // NOTE: We make the assumption here that the caller has // locked the d3dContext for us to use. // Apply the state! device._d3dContext.OutputMerger.SetDepthStencilState(_state, ReferenceStencil); }
private void CreateNativeDeviceChild() { SharpDX.Direct3D11.DepthStencilStateDescription nativeDescription; nativeDescription.IsDepthEnabled = Description.DepthBufferEnable; nativeDescription.DepthComparison = (SharpDX.Direct3D11.Comparison)Description.DepthBufferFunction; nativeDescription.DepthWriteMask = Description.DepthBufferWriteEnable ? SharpDX.Direct3D11.DepthWriteMask.All : SharpDX.Direct3D11.DepthWriteMask.Zero; nativeDescription.IsStencilEnabled = Description.StencilEnable; nativeDescription.StencilReadMask = Description.StencilMask; nativeDescription.StencilWriteMask = Description.StencilWriteMask; nativeDescription.FrontFace.FailOperation = (SharpDX.Direct3D11.StencilOperation)Description.FrontFace.StencilFail; nativeDescription.FrontFace.PassOperation = (SharpDX.Direct3D11.StencilOperation)Description.FrontFace.StencilPass; nativeDescription.FrontFace.DepthFailOperation = (SharpDX.Direct3D11.StencilOperation)Description.FrontFace.StencilDepthBufferFail; nativeDescription.FrontFace.Comparison = (SharpDX.Direct3D11.Comparison)Description.FrontFace.StencilFunction; nativeDescription.BackFace.FailOperation = (SharpDX.Direct3D11.StencilOperation)Description.BackFace.StencilFail; nativeDescription.BackFace.PassOperation = (SharpDX.Direct3D11.StencilOperation)Description.BackFace.StencilPass; nativeDescription.BackFace.DepthFailOperation = (SharpDX.Direct3D11.StencilOperation)Description.BackFace.StencilDepthBufferFail; nativeDescription.BackFace.Comparison = (SharpDX.Direct3D11.Comparison)Description.BackFace.StencilFunction; NativeDeviceChild = new SharpDX.Direct3D11.DepthStencilState(NativeDevice, nativeDescription); }