Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
BlendState.Direct3D.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_DIRECT3D
4 using System;
5 using SiliconStudio.Core.Mathematics;
6 using SharpDX;
7 
8 namespace SiliconStudio.Paradox.Graphics
9 {
10  /// <summary>
11  /// Describes a blend state.
12  /// </summary>
13  public partial class BlendState
14  {
15  /// <summary>
16  /// Initializes a new instance of the <see cref="BlendState"/> class.
17  /// </summary>
18  /// <param name="device">The device.</param>
19  /// <param name="name">The name.</param>
20  /// <param name="blendStateDescription">The blend state description.</param>
21  internal BlendState(GraphicsDevice device, BlendStateDescription blendStateDescription)
22  : base(device)
23  {
24  BlendFactor = SiliconStudio.Core.Mathematics.Color4.White;
25  MultiSampleMask = -1;
26 
27  Description = blendStateDescription;
28 
29  CreateNativeDeviceChild();
30  }
31 
32  /// <inheritdoc/>
33  protected internal override void OnDestroyed()
34  {
35  base.OnDestroyed();
36  DestroyImpl();
37  }
38 
39  /// <inheritdoc/>
40  protected internal override bool OnRecreate()
41  {
42  base.OnRecreate();
43  CreateNativeDeviceChild();
44  return true;
45  }
46 
47  private void CreateNativeDeviceChild()
48  {
49  var nativeDescription = new SharpDX.Direct3D11.BlendStateDescription();
50 
51  nativeDescription.AlphaToCoverageEnable = Description.AlphaToCoverageEnable;
52  nativeDescription.IndependentBlendEnable = Description.IndependentBlendEnable;
53  for (int i = 0; i < Description.RenderTargets.Length; ++i)
54  {
55  nativeDescription.RenderTarget[i].IsBlendEnabled = Description.RenderTargets[i].BlendEnable;
56  nativeDescription.RenderTarget[i].SourceBlend = (SharpDX.Direct3D11.BlendOption)Description.RenderTargets[i].ColorSourceBlend;
57  nativeDescription.RenderTarget[i].DestinationBlend = (SharpDX.Direct3D11.BlendOption)Description.RenderTargets[i].ColorDestinationBlend;
58  nativeDescription.RenderTarget[i].BlendOperation = (SharpDX.Direct3D11.BlendOperation)Description.RenderTargets[i].ColorBlendFunction;
59  nativeDescription.RenderTarget[i].SourceAlphaBlend = (SharpDX.Direct3D11.BlendOption)Description.RenderTargets[i].AlphaSourceBlend;
60  nativeDescription.RenderTarget[i].DestinationAlphaBlend = (SharpDX.Direct3D11.BlendOption)Description.RenderTargets[i].AlphaDestinationBlend;
61  nativeDescription.RenderTarget[i].AlphaBlendOperation = (SharpDX.Direct3D11.BlendOperation)Description.RenderTargets[i].AlphaBlendFunction;
62  nativeDescription.RenderTarget[i].RenderTargetWriteMask = (SharpDX.Direct3D11.ColorWriteMaskFlags)Description.RenderTargets[i].ColorWriteChannels;
63  }
64 
65  NativeDeviceChild = new SharpDX.Direct3D11.BlendState(NativeDevice, nativeDescription);
66  }
67  }
68 }
69 
70 #endif
The data source is the blend factor set with GraphicsDevice.BlendStates. No pre-blend operation...