/// <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); } }
/// <summary> /// Releases unmanaged and - optionally - managed resources /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected override void Dispose(bool disposing) { if (!IsDisposed) { //Dispose of managed resources if (disposing) { if (_bs != null) { //Remove from resource tracker if (_renderer != null) { _renderer.Resources.RemoveTrackedObject(_bs.ComPointer); } _bs.Dispose(); _bs = null; } } base.Dispose(disposing); } }