// 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.BlendStateDescription(); var targetDesc = new SharpDX.Direct3D11.RenderTargetBlendDescription(); // We're blending if we're not in the opaque state. targetDesc.IsBlendEnabled = !(ColorSourceBlend == Opaque.ColorSourceBlend && ColorDestinationBlend == Opaque.ColorDestinationBlend && AlphaSourceBlend == Opaque.AlphaSourceBlend && AlphaDestinationBlend == Opaque.AlphaDestinationBlend); targetDesc.BlendOperation = GetBlendOperation(ColorBlendFunction); targetDesc.SourceBlend = GetBlendOption(ColorSourceBlend); targetDesc.DestinationBlend = GetBlendOption(ColorDestinationBlend); targetDesc.AlphaBlendOperation = GetBlendOperation(AlphaBlendFunction); targetDesc.SourceAlphaBlend = GetBlendOption(AlphaSourceBlend); targetDesc.DestinationAlphaBlend = GetBlendOption(AlphaDestinationBlend); // Set the first 4 targets to the same settings. desc.RenderTarget[0] = targetDesc; desc.RenderTarget[1] = targetDesc; desc.RenderTarget[2] = targetDesc; desc.RenderTarget[3] = targetDesc; // Set the color write controls per-target. desc.RenderTarget[0].RenderTargetWriteMask = GetColorWriteMask(ColorWriteChannels); desc.RenderTarget[1].RenderTargetWriteMask = GetColorWriteMask(ColorWriteChannels1); desc.RenderTarget[2].RenderTargetWriteMask = GetColorWriteMask(ColorWriteChannels2); desc.RenderTarget[3].RenderTargetWriteMask = GetColorWriteMask(ColorWriteChannels3); // These are new DX11 features we should consider exposing // as part of the extended MonoGame API. desc.AlphaToCoverageEnable = false; desc.IndependentBlendEnable = false; // Create the state. _state = new SharpDX.Direct3D11.BlendState(graphicsDevice._d3dDevice, ref 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! var d3dContext = device._d3dContext; d3dContext.OutputMerger.BlendFactor = new SharpDX.Color4(BlendFactor.R / 255.0f, BlendFactor.G / 255.0f, BlendFactor.B / 255.0f, BlendFactor.A / 255.0f); d3dContext.OutputMerger.BlendSampleMask = -1; d3dContext.OutputMerger.BlendState = _state; }
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.BlendStateDescription(); _targetBlendState[0].GetState(ref desc.RenderTarget[0]); _targetBlendState[1].GetState(ref desc.RenderTarget[1]); _targetBlendState[2].GetState(ref desc.RenderTarget[2]); _targetBlendState[3].GetState(ref desc.RenderTarget[3]); desc.IndependentBlendEnable = _independentBlendEnable; // This is a new DX11 feature we should consider // exposing as part of the extended MonoGame API. desc.AlphaToCoverageEnable = false; // Create the state. _state = new SharpDX.Direct3D11.BlendState(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! var blendFactor = new SharpDX.Color4(_blendFactor.R / 255.0f, _blendFactor.G / 255.0f, _blendFactor.B / 255.0f, _blendFactor.A / 255.0f); device._d3dContext.OutputMerger.SetBlendState(_state, blendFactor); }
internal SharpDX.Direct3D11.BlendState GetDxState(GraphicsDevice device) { if (_state == null) { // Build the description. var desc = new SharpDX.Direct3D11.BlendStateDescription(); _targetBlendState[0].GetState(ref desc.RenderTarget[0]); _targetBlendState[1].GetState(ref desc.RenderTarget[1]); _targetBlendState[2].GetState(ref desc.RenderTarget[2]); _targetBlendState[3].GetState(ref desc.RenderTarget[3]); desc.IndependentBlendEnable = _independentBlendEnable; // This is a new DX11 feature we should consider // exposing as part of the extended MonoGame API. desc.AlphaToCoverageEnable = false; // Create the state. _state = new SharpDX.Direct3D11.BlendState(GraphicsDevice._d3dDevice, desc); } Debug.Assert(GraphicsDevice == device, "The state was created for a different device!"); // Apply the state! return(_state); }
public BlendState(GraphicsDevice graphicsDevice, BlendStateInfo info) : base(graphicsDevice, new StackTrace(1)) { this.Info = info; SharpDX.Direct3D11.BlendStateDescription desc = new SharpDX.Direct3D11.BlendStateDescription(); desc.AlphaToCoverageEnable = info.AlphaToCoverageEnable; desc.IndependentBlendEnable = info.IndependentBlendEnable; for (int i = 0; i < info.RenderTargets.Length; i++) { RTBlendInfo rtInfo = info.RenderTargets[i]; desc.RenderTarget[i] = new SharpDX.Direct3D11.RenderTargetBlendDescription() { IsBlendEnabled = rtInfo.IsBlendEnabled, SourceBlend = EnumConverter.Convert(rtInfo.SrcBlend), DestinationBlend = EnumConverter.Convert(rtInfo.DestBlend), BlendOperation = EnumConverter.Convert(rtInfo.BlendOp), SourceAlphaBlend = EnumConverter.Convert(rtInfo.SrcBlendAlpha), DestinationAlphaBlend = EnumConverter.Convert(rtInfo.DestBlendAlpha), AlphaBlendOperation = EnumConverter.Convert(rtInfo.BlendOpAlpha), RenderTargetWriteMask = EnumConverter.Convert(rtInfo.RenderTargetWriteMask) }; } Handle = new SharpDX.Direct3D11.BlendState(graphicsDevice.Device, desc); }
internal void PlatformApplyState(GraphicsDevice device) { if (_state == null) { // Build the description. var desc = new SharpDX.Direct3D11.BlendStateDescription(); _targetBlendState[0].GetState(ref desc.RenderTarget[0]); _targetBlendState[1].GetState(ref desc.RenderTarget[1]); _targetBlendState[2].GetState(ref desc.RenderTarget[2]); _targetBlendState[3].GetState(ref desc.RenderTarget[3]); desc.IndependentBlendEnable = _independentBlendEnable; // This is a new DX11 feature we should consider // exposing as part of the extended MonoGame API. desc.AlphaToCoverageEnable = false; // Create the state. _state = new SharpDX.Direct3D11.BlendState(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! var blendFactor = new SharpDX.Color4(_blendFactor.R / 255.0f, _blendFactor.G / 255.0f, _blendFactor.B / 255.0f, _blendFactor.A / 255.0f); device._d3dContext.OutputMerger.SetBlendState(_state, blendFactor); }
private void CreateNativeDeviceChild() { var nativeDescription = new SharpDX.Direct3D11.BlendStateDescription(); nativeDescription.AlphaToCoverageEnable = Description.AlphaToCoverageEnable; nativeDescription.IndependentBlendEnable = Description.IndependentBlendEnable; for (int i = 0; i < Description.RenderTargets.Length; ++i) { nativeDescription.RenderTarget[i].IsBlendEnabled = Description.RenderTargets[i].BlendEnable; nativeDescription.RenderTarget[i].SourceBlend = (SharpDX.Direct3D11.BlendOption)Description.RenderTargets[i].ColorSourceBlend; nativeDescription.RenderTarget[i].DestinationBlend = (SharpDX.Direct3D11.BlendOption)Description.RenderTargets[i].ColorDestinationBlend; nativeDescription.RenderTarget[i].BlendOperation = (SharpDX.Direct3D11.BlendOperation)Description.RenderTargets[i].ColorBlendFunction; nativeDescription.RenderTarget[i].SourceAlphaBlend = (SharpDX.Direct3D11.BlendOption)Description.RenderTargets[i].AlphaSourceBlend; nativeDescription.RenderTarget[i].DestinationAlphaBlend = (SharpDX.Direct3D11.BlendOption)Description.RenderTargets[i].AlphaDestinationBlend; nativeDescription.RenderTarget[i].AlphaBlendOperation = (SharpDX.Direct3D11.BlendOperation)Description.RenderTargets[i].AlphaBlendFunction; nativeDescription.RenderTarget[i].RenderTargetWriteMask = (SharpDX.Direct3D11.ColorWriteMaskFlags)Description.RenderTargets[i].ColorWriteChannels; } NativeDeviceChild = new SharpDX.Direct3D11.BlendState(NativeDevice, nativeDescription); }
internal void PlatformApplyState(GraphicsDevice device) { if (_state == null) { // Build the description. var desc = new SharpDX.Direct3D11.BlendStateDescription(); _targetBlendState[0].GetState(ref desc.RenderTarget[0]); _targetBlendState[1].GetState(ref desc.RenderTarget[1]); _targetBlendState[2].GetState(ref desc.RenderTarget[2]); _targetBlendState[3].GetState(ref desc.RenderTarget[3]); desc.IndependentBlendEnable = _independentBlendEnable; // This is a new DX11 feature we should consider // exposing as part of the extended MonoGame API. desc.AlphaToCoverageEnable = false; // Create the state. _state = new SharpDX.Direct3D11.BlendState(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! #if WINDOWS_UAP device._d3dContext.OutputMerger.SetBlendState(_state, new SharpDX.Mathematics.Interop.RawColor4( _blendFactor.R / 255.0f, _blendFactor.G / 255.0f, _blendFactor.B / 255.0f, _blendFactor.A / 255.0f)); #else device._d3dContext.OutputMerger.SetBlendState(_state, _blendFactor.ToColor4()); #endif }
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.BlendStateDescription(); var targetDesc = new SharpDX.Direct3D11.RenderTargetBlendDescription(); // We're blending if we're not in the opaque state. targetDesc.IsBlendEnabled = !( ColorSourceBlend == Opaque.ColorSourceBlend && ColorDestinationBlend == Opaque.ColorDestinationBlend && AlphaSourceBlend == Opaque.AlphaSourceBlend && AlphaDestinationBlend == Opaque.AlphaDestinationBlend); targetDesc.BlendOperation = GetBlendOperation(ColorBlendFunction); targetDesc.SourceBlend = GetBlendOption(ColorSourceBlend); targetDesc.DestinationBlend = GetBlendOption(ColorDestinationBlend); targetDesc.AlphaBlendOperation = GetBlendOperation(AlphaBlendFunction); targetDesc.SourceAlphaBlend = GetBlendOption(AlphaSourceBlend); targetDesc.DestinationAlphaBlend = GetBlendOption(AlphaDestinationBlend); // Set the first 4 targets to the same settings. desc.RenderTarget[0] = targetDesc; desc.RenderTarget[1] = targetDesc; desc.RenderTarget[2] = targetDesc; desc.RenderTarget[3] = targetDesc; // Set the color write controls per-target. desc.RenderTarget[0].RenderTargetWriteMask = GetColorWriteMask(ColorWriteChannels); desc.RenderTarget[1].RenderTargetWriteMask = GetColorWriteMask(ColorWriteChannels1); desc.RenderTarget[2].RenderTargetWriteMask = GetColorWriteMask(ColorWriteChannels2); desc.RenderTarget[3].RenderTargetWriteMask = GetColorWriteMask(ColorWriteChannels3); // These are new DX11 features we should consider exposing // as part of the extended MonoGame API. desc.AlphaToCoverageEnable = false; desc.IndependentBlendEnable = false; // Create the state. _state = new SharpDX.Direct3D11.BlendState(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! var d3dContext = device._d3dContext; d3dContext.OutputMerger.BlendFactor = new SharpDX.Color4(BlendFactor.R / 255.0f, BlendFactor.G / 255.0f, BlendFactor.B / 255.0f, BlendFactor.A / 255.0f); d3dContext.OutputMerger.BlendSampleMask = -1; d3dContext.OutputMerger.BlendState = _state; }
private void _Direct3Dを初期化する() { // D3DDevice, DXGISwapChain を生成する。 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, }); // ブレンドステートを作成する。 var blendStateNorm = new SharpDX.Direct3D11.BlendStateDescription() { AlphaToCoverageEnable = false, // アルファマスクで透過する(するならZバッファ必須) IndependentBlendEnable = false, // 個別設定。false なら BendStateDescription.RenderTarget[0] だけが有効で、[1~7] は無視される。 }; blendStateNorm.RenderTarget[0].IsBlendEnabled = true; // true ならブレンディングが有効。 blendStateNorm.RenderTarget[0].RenderTargetWriteMask = SharpDX.Direct3D11.ColorWriteMaskFlags.All; blendStateNorm.RenderTarget[0].SourceBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha; // 色値のブレンディング blendStateNorm.RenderTarget[0].DestinationBlend = SharpDX.Direct3D11.BlendOption.InverseSourceAlpha; blendStateNorm.RenderTarget[0].BlendOperation = SharpDX.Direct3D11.BlendOperation.Add; blendStateNorm.RenderTarget[0].SourceAlphaBlend = SharpDX.Direct3D11.BlendOption.One; // アルファ値のブレンディング blendStateNorm.RenderTarget[0].DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.Zero; blendStateNorm.RenderTarget[0].AlphaBlendOperation = SharpDX.Direct3D11.BlendOperation.Add; this._BlendState通常合成 = new SharpDX.Direct3D11.BlendState(this._D3D11Device, blendStateNorm); }
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, }); }