// 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 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.RasterizerStateDescription(); switch ( CullMode ) { case Graphics.CullMode.CullClockwiseFace: desc.CullMode = SharpDX.Direct3D11.CullMode.Front; break; case Graphics.CullMode.CullCounterClockwiseFace: desc.CullMode = SharpDX.Direct3D11.CullMode.Back; break; case Graphics.CullMode.None: desc.CullMode = SharpDX.Direct3D11.CullMode.None; break; } desc.IsScissorEnabled = ScissorTestEnable; desc.IsMultisampleEnabled = MultiSampleAntiAlias; desc.DepthBias = (int)DepthBias; desc.SlopeScaledDepthBias = SlopeScaleDepthBias; if (FillMode == Graphics.FillMode.WireFrame) desc.FillMode = SharpDX.Direct3D11.FillMode.Wireframe; else desc.FillMode = SharpDX.Direct3D11.FillMode.Solid; // These are new DX11 features we should consider exposing // as part of the extended MonoGame API. desc.IsFrontCounterClockwise = false; desc.IsAntialiasedLineEnabled = false; // To support feature level 9.1 these must // be set to these exact values. desc.DepthBiasClamp = 0.0f; desc.IsDepthClipEnabled = true; // Create the state. _state = new SharpDX.Direct3D11.RasterizerState(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.Rasterizer.State = _state; }
internal void PlatformApplyState(GraphicsDevice device) { if (_state == null) { // Build the description. var desc = new SharpDX.Direct3D11.RasterizerStateDescription(); switch (CullMode) { case Graphics.CullMode.CullClockwiseFace: desc.CullMode = SharpDX.Direct3D11.CullMode.Front; break; case Graphics.CullMode.CullCounterClockwiseFace: desc.CullMode = SharpDX.Direct3D11.CullMode.Back; break; case Graphics.CullMode.None: desc.CullMode = SharpDX.Direct3D11.CullMode.None; break; } desc.IsScissorEnabled = ScissorTestEnable; desc.IsMultisampleEnabled = MultiSampleAntiAlias; desc.DepthBias = (int)DepthBias; desc.SlopeScaledDepthBias = SlopeScaleDepthBias; if (FillMode == Graphics.FillMode.WireFrame) { desc.FillMode = SharpDX.Direct3D11.FillMode.Wireframe; } else { desc.FillMode = SharpDX.Direct3D11.FillMode.Solid; } // These are new DX11 features we should consider exposing // as part of the extended MonoGame API. desc.IsFrontCounterClockwise = false; desc.IsAntialiasedLineEnabled = false; // To support feature level 9.1 these must // be set to these exact values. desc.DepthBiasClamp = 0.0f; desc.IsDepthClipEnabled = true; // Create the state. _state = new SharpDX.Direct3D11.RasterizerState(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.Rasterizer.State = _state; }
private void CreateNativeDeviceChild() { SharpDX.Direct3D11.RasterizerStateDescription nativeDescription; nativeDescription.CullMode = (SharpDX.Direct3D11.CullMode)Description.CullMode; nativeDescription.FillMode = (SharpDX.Direct3D11.FillMode)Description.FillMode; nativeDescription.IsFrontCounterClockwise = Description.FrontFaceCounterClockwise; nativeDescription.DepthBias = Description.DepthBias; nativeDescription.SlopeScaledDepthBias = Description.SlopeScaleDepthBias; nativeDescription.DepthBiasClamp = Description.DepthBiasClamp; nativeDescription.IsDepthClipEnabled = Description.DepthClipEnable; nativeDescription.IsScissorEnabled = Description.ScissorTestEnable; nativeDescription.IsMultisampleEnabled = Description.MultiSampleAntiAlias; nativeDescription.IsAntialiasedLineEnabled = Description.MultiSampleAntiAliasLine; NativeDeviceChild = new SharpDX.Direct3D11.RasterizerState(NativeDevice, nativeDescription); }
private void CreateNativeDeviceChild() { SharpDX.Direct3D11.RasterizerStateDescription nativeDescription; nativeDescription.CullMode = (SharpDX.Direct3D11.CullMode)Description.CullMode; nativeDescription.FillMode = (SharpDX.Direct3D11.FillMode)Description.FillMode; nativeDescription.IsFrontCounterClockwise = Description.FrontFaceCounterClockwise; nativeDescription.DepthBias = Description.DepthBias; nativeDescription.SlopeScaledDepthBias = Description.SlopeScaleDepthBias; nativeDescription.DepthBiasClamp = Description.DepthBiasClamp; nativeDescription.IsDepthClipEnabled = Description.DepthClipEnable; nativeDescription.IsScissorEnabled = Description.ScissorTestEnable; nativeDescription.IsMultisampleEnabled = Description.MultiSampleAntiAlias; nativeDescription.IsAntialiasedLineEnabled = Description.MultiSampleAntiAliasLine; NativeDeviceChild = new SharpDX.Direct3D11.RasterizerState(NativeDevice, nativeDescription); }
internal void PlatformApplyState(GraphicsDevice device) { if (_state == null) { // Build the description. var desc = new SharpDX.Direct3D11.RasterizerStateDescription(); switch (CullMode) { case CullMode.CullClockwiseFace: desc.CullMode = SharpDX.Direct3D11.CullMode.Front; break; case CullMode.CullCounterClockwiseFace: desc.CullMode = SharpDX.Direct3D11.CullMode.Back; break; case CullMode.None: desc.CullMode = SharpDX.Direct3D11.CullMode.None; break; } desc.IsScissorEnabled = ScissorTestEnable; desc.IsMultisampleEnabled = MultiSampleAntiAlias; // discussion and explanation in https://github.com/MonoGame/MonoGame/issues/4826 int depthMul; switch (device.ActiveDepthFormat) { case DepthFormat.None: depthMul = 0; break; case DepthFormat.Depth16: depthMul = 1 << 16 - 1; break; case DepthFormat.Depth24: case DepthFormat.Depth24Stencil8: depthMul = 1 << 24 - 1; break; default: throw new ArgumentOutOfRangeException(); } desc.DepthBias = (int)(DepthBias * depthMul); desc.SlopeScaledDepthBias = SlopeScaleDepthBias; if (FillMode == FillMode.WireFrame) { desc.FillMode = SharpDX.Direct3D11.FillMode.Wireframe; } else { desc.FillMode = SharpDX.Direct3D11.FillMode.Solid; } desc.IsDepthClipEnabled = DepthClipEnable; // These are new DX11 features we should consider exposing // as part of the extended MonoGame API. desc.IsFrontCounterClockwise = false; desc.IsAntialiasedLineEnabled = false; // To support feature level 9.1 these must // be set to these exact values. desc.DepthBiasClamp = 0.0f; // Create the state. _state = new SharpDX.Direct3D11.RasterizerState(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.Rasterizer.State = _state; }
private void _Direct3Dを初期化する() { // D3D11デバイスと SwapChain を生成します。 SharpDX.Direct3D11.Device.CreateWithSwapChain( SharpDX.Direct3D.DriverType.Hardware, SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport, new SharpDX.Direct3D.FeatureLevel[] { SharpDX.Direct3D.FeatureLevel.Level_11_1 }, // 機能レベル 11.1 new SharpDX.DXGI.SwapChainDescription { BufferCount = 1, Flags = SharpDX.DXGI.SwapChainFlags.AllowModeSwitch, IsWindowed = true, ModeDescription = new SharpDX.DXGI.ModeDescription { Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm, Width = this.ClientSize.Width, Height = this.ClientSize.Height, Scaling = SharpDX.DXGI.DisplayModeScaling.Stretched, }, OutputHandle = this.Handle, SampleDescription = new SharpDX.DXGI.SampleDescription(4, 0), // MSAA x4 SwapEffect = SharpDX.DXGI.SwapEffect.Discard, Usage = SharpDX.DXGI.Usage.RenderTargetOutput, }, out this._D3D11Device, out this._DXGISwapChain); // 既定のRenderTarget と 既定のDepthStencil ならびにそのビューを作成します。 this._既定のD3D11RenderTarget = this._DXGISwapChain.GetBackBuffer <SharpDX.Direct3D11.Texture2D>(0); this._既定のD3D11DepthStencil = new SharpDX.Direct3D11.Texture2D( this._D3D11Device, new SharpDX.Direct3D11.Texture2DDescription { Width = this._既定のD3D11RenderTarget.Description.Width, Height = this._既定のD3D11RenderTarget.Description.Height, MipLevels = 1, ArraySize = 1, Format = SharpDX.DXGI.Format.D24_UNorm_S8_UInt, SampleDescription = this._既定のD3D11RenderTarget.Description.SampleDescription, Usage = SharpDX.Direct3D11.ResourceUsage.Default, BindFlags = SharpDX.Direct3D11.BindFlags.DepthStencil, CpuAccessFlags = SharpDX.Direct3D11.CpuAccessFlags.None, OptionFlags = SharpDX.Direct3D11.ResourceOptionFlags.None, }); this._既定のD3D11RenderTargetView = new SharpDX.Direct3D11.RenderTargetView(this._D3D11Device, this._既定のD3D11RenderTarget); this._既定のD3D11DepthStencilView = new SharpDX.Direct3D11.DepthStencilView(this._D3D11Device, this._既定のD3D11DepthStencil); // 加算合成用のブレンドステートを作成します。 var BlendStateAdd = new SharpDX.Direct3D11.BlendStateDescription() { AlphaToCoverageEnable = false, // アルファマスクで透過する(するならZバッファ必須) IndependentBlendEnable = false, // 個別設定。false なら BendStateDescription.RenderTarget[0] だけが有効で、[1~7] は無視される。 }; BlendStateAdd.RenderTarget[0].IsBlendEnabled = true; // true ならブレンディングが有効。 BlendStateAdd.RenderTarget[0].RenderTargetWriteMask = SharpDX.Direct3D11.ColorWriteMaskFlags.All; // RGBA の書き込みマスク。 // アルファ値のブレンディング設定 ... 特になし BlendStateAdd.RenderTarget[0].SourceAlphaBlend = SharpDX.Direct3D11.BlendOption.One; BlendStateAdd.RenderTarget[0].DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.Zero; BlendStateAdd.RenderTarget[0].AlphaBlendOperation = SharpDX.Direct3D11.BlendOperation.Add; // 色値のブレンディング設定 ... 加算合成 BlendStateAdd.RenderTarget[0].SourceBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha; BlendStateAdd.RenderTarget[0].DestinationBlend = SharpDX.Direct3D11.BlendOption.One; BlendStateAdd.RenderTarget[0].BlendOperation = SharpDX.Direct3D11.BlendOperation.Add; // ブレンドステートを作成する。 this._BlendState加算合成 = new SharpDX.Direct3D11.BlendState(this._D3D11Device, BlendStateAdd); // ブレンドステートと深度ステンシルステートを OM に設定します。 this._D3D11Device.ImmediateContext.OutputMerger.BlendState = this._BlendState加算合成; this._D3D11Device.ImmediateContext.OutputMerger.DepthStencilState = null; // ラスタライザステートを作成します。 this._RasterizerState = new SharpDX.Direct3D11.RasterizerState( this._D3D11Device, new SharpDX.Direct3D11.RasterizerStateDescription { CullMode = SharpDX.Direct3D11.CullMode.Back, FillMode = SharpDX.Direct3D11.FillMode.Solid, }); }