/// <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 BindBlendState() { if (!base.IsBound) { D3D.BlendStateDescription desc = new D3D.BlendStateDescription(); desc.AlphaBlendOperation = D3D10Helper.ToD3DBlendOperation(base.AlphaBlendFunction); desc.SourceAlphaBlend = D3D10Helper.ToD3DBlendOption(base.AlphaSourceBlend); desc.DestinationAlphaBlend = D3D10Helper.ToD3DBlendOption(base.AlphaDestinationBlend); desc.BlendOperation = D3D10Helper.ToD3DBlendOperation(base.ColorBlendFunction); desc.SourceBlend = D3D10Helper.ToD3DBlendOption(base.ColorSourceBlend); desc.DestinationBlend = D3D10Helper.ToD3DBlendOption(base.ColorDestinationBlend); for (int i = 0; i < 8; i++) { desc.SetBlendEnable((uint)i, this.GetBlendEnable(i)); desc.SetWriteMask((uint)i, (D3D.ColorWriteMaskFlags) this.GetWriteChannels(i)); } _bs = D3D.BlendState.FromDescription(_graphicsDevice, desc); base.IsBound = true; //Add the SlimDX object to the tracker _renderer.Resources.AddTrackedObject(_bs.ComPointer, this); } }
public void SetBlendState(bool enableAlphaBlending) { AlphaBlendState = new D3D.BlendStateDescription() { BlendOperation = D3D.BlendOperation.Add, SourceBlend = D3D.BlendOption.SourceAlpha, DestinationBlend = D3D.BlendOption.InverseSourceAlpha, IsAlphaToCoverageEnabled = false, AlphaBlendOperation = D3D.BlendOperation.Add, SourceAlphaBlend = D3D.BlendOption.Zero, DestinationAlphaBlend = D3D.BlendOption.Zero, }; AlphaBlendState.SetBlendEnable(0, enableAlphaBlending); AlphaBlendState.SetWriteMask(0, D3D.ColorWriteMaskFlags.All); Device.OutputMerger.BlendState = D3D.BlendState.FromDescription(Device, AlphaBlendState); }