-
-
Notifications
You must be signed in to change notification settings - Fork 911
/
BlendStateDescription.cs
152 lines (135 loc) · 6.08 KB
/
BlendStateDescription.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Copyright (c) Stride contributors (https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System;
using System.Runtime.InteropServices;
using Stride.Core;
using Stride.Core.Extensions;
using Stride.Core.Mathematics;
namespace Stride.Graphics
{
/// <summary>
/// Describes a blend state.
/// </summary>
[DataContract]
[StructLayout(LayoutKind.Sequential)]
public struct BlendStateDescription : IEquatable<BlendStateDescription>
{
/// <summary>
/// Initializes a new instance of the <see cref="BlendStateDescription"/> class.
/// </summary>
/// <param name="sourceBlend">The source blend.</param>
/// <param name="destinationBlend">The destination blend.</param>
public BlendStateDescription(Blend sourceBlend, Blend destinationBlend) : this()
{
SetDefaults();
RenderTarget0.BlendEnable = true;
RenderTarget0.ColorSourceBlend = sourceBlend;
RenderTarget0.ColorDestinationBlend = destinationBlend;
RenderTarget0.AlphaSourceBlend = sourceBlend;
RenderTarget0.AlphaDestinationBlend = destinationBlend;
}
/// <summary>
/// Setup this blend description with defaults value.
/// </summary>
public unsafe void SetDefaults()
{
AlphaToCoverageEnable = false;
IndependentBlendEnable = false;
fixed (BlendStateRenderTargetDescription* renderTargets = &RenderTarget0)
{
for (int i = 0; i < 8; i++)
{
ref var renderTarget = ref renderTargets[i];
renderTarget.BlendEnable = false;
renderTarget.ColorSourceBlend = Blend.One;
renderTarget.ColorDestinationBlend = Blend.Zero;
renderTarget.ColorBlendFunction = BlendFunction.Add;
renderTarget.AlphaSourceBlend = Blend.One;
renderTarget.AlphaDestinationBlend = Blend.Zero;
renderTarget.AlphaBlendFunction = BlendFunction.Add;
renderTarget.ColorWriteChannels = ColorWriteChannels.All;
}
}
}
/// <summary>
/// Gets default values for this instance.
/// </summary>
public static BlendStateDescription Default
{
get
{
var desc = new BlendStateDescription();
desc.SetDefaults();
return desc;
}
}
/// <summary>
/// Determines whether or not to use alpha-to-coverage as a multisampling technique when setting a pixel to a rendertarget.
/// </summary>
public bool AlphaToCoverageEnable;
/// <summary>
/// Set to true to enable independent blending in simultaneous render targets. If set to false, only the RenderTarget[0] members are used. RenderTarget[1..7] are ignored.
/// </summary>
public bool IndependentBlendEnable;
/// <summary>
/// An array of render-target-blend descriptions (see <see cref="BlendStateRenderTargetDescription"/>); these correspond to the eight rendertargets that can be set to the output-merger stage at one time.
/// </summary>
public BlendStateRenderTargetDescription RenderTarget0;
public BlendStateRenderTargetDescription RenderTarget1;
public BlendStateRenderTargetDescription RenderTarget2;
public BlendStateRenderTargetDescription RenderTarget3;
public BlendStateRenderTargetDescription RenderTarget4;
public BlendStateRenderTargetDescription RenderTarget5;
public BlendStateRenderTargetDescription RenderTarget6;
public BlendStateRenderTargetDescription RenderTarget7;
/// <inheritdoc/>
public bool Equals(BlendStateDescription other)
{
if (AlphaToCoverageEnable != other.AlphaToCoverageEnable
|| IndependentBlendEnable != other.IndependentBlendEnable)
return false;
if (RenderTarget0 != other.RenderTarget0
|| RenderTarget1 != other.RenderTarget1
|| RenderTarget2 != other.RenderTarget2
|| RenderTarget3 != other.RenderTarget3
|| RenderTarget4 != other.RenderTarget4
|| RenderTarget5 != other.RenderTarget5
|| RenderTarget6 != other.RenderTarget6
|| RenderTarget7 != other.RenderTarget7)
return false;
return true;
}
/// <inheritdoc/>
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
return obj is BlendStateDescription && Equals((BlendStateDescription)obj);
}
public static bool operator ==(BlendStateDescription left, BlendStateDescription right)
{
return left.Equals(right);
}
public static bool operator !=(BlendStateDescription left, BlendStateDescription right)
{
return !left.Equals(right);
}
/// <inheritdoc/>
public override int GetHashCode()
{
unchecked
{
int hashCode = AlphaToCoverageEnable.GetHashCode();
hashCode = (hashCode * 397) ^ IndependentBlendEnable.GetHashCode();
hashCode = (hashCode * 397) ^ RenderTarget0.GetHashCode();
hashCode = (hashCode * 397) ^ RenderTarget1.GetHashCode();
hashCode = (hashCode * 397) ^ RenderTarget2.GetHashCode();
hashCode = (hashCode * 397) ^ RenderTarget3.GetHashCode();
hashCode = (hashCode * 397) ^ RenderTarget4.GetHashCode();
hashCode = (hashCode * 397) ^ RenderTarget5.GetHashCode();
hashCode = (hashCode * 397) ^ RenderTarget6.GetHashCode();
hashCode = (hashCode * 397) ^ RenderTarget7.GetHashCode();
return hashCode;
}
}
}
}