Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
BlendState.cs
Go to the documentation of this file.
1using System;
5
7
9{
11
13
15
17
19
21
23
25
27
29
31
33
34 public static readonly BlendState Opaque = new BlendState(Blend.One, Blend.Zero, "BlendState.Opaque");
35
36 public static readonly BlendState AlphaBlend = new BlendState(Blend.One, Blend.InverseSourceAlpha, "BlendState.AlphaBlend");
37
38 public static readonly BlendState Additive = new BlendState(Blend.SourceAlpha, Blend.One, "BlendState.Additive");
39
40 public static readonly BlendState NonPremultiplied = new BlendState(Blend.SourceAlpha, Blend.InverseSourceAlpha, "BlendState.NonPremultiplied");
41
42 internal bool isBound;
43
44 internal bool blendEnable;
45
46 internal bool separateAlphaBlend;
47
48 internal _D3DBLEND d3dColorSourceBlend;
49
50 internal _D3DBLEND d3dColorDestinationBlend;
51
52 internal _D3DBLENDOP d3dColorBlendFunction;
53
54 internal _D3DBLEND d3dAlphaSourceBlend;
55
56 internal _D3DBLEND d3dAlphaDestinationBlend;
57
58 internal _D3DBLENDOP d3dAlphaBlendFunction;
59
60 internal uint d3dBlendFactor;
61
62 internal uint stateTrackerFlags;
63
64 public int MultiSampleMask
65 {
66 get
67 {
69 }
70 set
71 {
74 }
75 }
76
78 {
79 get
80 {
81 return cachedBlendFactor;
82 }
83 set
84 {
87 }
88 }
89
91 {
92 get
93 {
95 }
96 set
97 {
100 }
101 }
102
104 {
105 get
106 {
108 }
109 set
110 {
111 ThrowIfBound();
113 }
114 }
115
117 {
118 get
119 {
121 }
122 set
123 {
124 ThrowIfBound();
126 }
127 }
128
130 {
131 get
132 {
134 }
135 set
136 {
137 ThrowIfBound();
139 }
140 }
141
143 {
144 get
145 {
147 }
148 set
149 {
150 ThrowIfBound();
152 }
153 }
154
156 {
157 get
158 {
160 }
161 set
162 {
163 ThrowIfBound();
165 }
166 }
167
169 {
170 get
171 {
173 }
174 set
175 {
176 ThrowIfBound();
178 }
179 }
180
182 {
183 get
184 {
186 }
187 set
188 {
189 ThrowIfBound();
191 }
192 }
193
195 {
196 get
197 {
199 }
200 set
201 {
202 ThrowIfBound();
204 }
205 }
206
208 {
209 get
210 {
212 }
213 set
214 {
215 ThrowIfBound();
217 }
218 }
219
248
249 public BlendState()
250 {
251 try
252 {
253 SetDefaults();
254 isBound = false;
255 return;
256 }
257 catch
258 {
259 //try-fault
260 base.Dispose(true);
261 throw;
262 }
263 }
264
265 private BlendState(Blend sourceBlend, Blend destinationBlend, string name)
266 {
267 try
268 {
269 SetDefaults();
270 ThrowIfBound();
271 cachedColorSourceBlend = sourceBlend;
272 ThrowIfBound();
273 cachedColorDestinationBlend = destinationBlend;
274 ThrowIfBound();
275 cachedAlphaSourceBlend = sourceBlend;
276 ThrowIfBound();
277 cachedAlphaDestinationBlend = destinationBlend;
278 base.Name = name;
279 isBound = true;
280 return;
281 }
282 catch
283 {
284 //try-fault
285 base.Dispose(true);
286 throw;
287 }
288 }
289
290 private void _007EBlendState()
291 {
292 }
293
294 internal unsafe void Apply(GraphicsDevice device)
295 {
296 if (isDisposed)
297 {
298 throw new ObjectDisposedException(typeof(BlendState).Name);
299 }
300 if (_parent != device)
301 {
302 ProfileCapabilities profileCapabilities = device._profileCapabilities;
303 if (!profileCapabilities.SeparateAlphaBlend)
304 {
305 Blend alphaBlend = cachedAlphaSourceBlend;
306 Blend colorBlend = cachedColorSourceBlend;
307 if (GraphicsHelpers.IsSeparateBlend(colorBlend, alphaBlend))
308 {
309 profileCapabilities.ThrowNotSupportedException(FrameworkResources.ProfileNoSeparateAlphaBlend, "ColorSourceBlend", "AlphaSourceBlend");
310 }
313 if (GraphicsHelpers.IsSeparateBlend(colorBlend2, alphaBlend2))
314 {
315 profileCapabilities.ThrowNotSupportedException(FrameworkResources.ProfileNoSeparateAlphaBlend, "ColorDestinationBlend", "AlphaDestinationBlend");
316 }
318 {
319 profileCapabilities.ThrowNotSupportedException(FrameworkResources.ProfileNoSeparateAlphaBlend, "ColorBlendFunction", "AlphaBlendFunction");
320 }
321 }
322 if (!profileCapabilities.DestBlendSrcAlphaSat)
323 {
324 if (cachedColorDestinationBlend == Blend.SourceAlphaSaturation)
325 {
326 profileCapabilities.ThrowNotSupportedException(FrameworkResources.ProfileFeatureNotSupported, "ColorDestinationBlend = Blend.SourceAlphaSaturation");
327 }
328 if (cachedAlphaDestinationBlend == Blend.SourceAlphaSaturation)
329 {
330 profileCapabilities.ThrowNotSupportedException(FrameworkResources.ProfileFeatureNotSupported, "AlphaDestinationBlend = Blend.SourceAlphaSaturation");
331 }
332 }
333 if (!profileCapabilities.MinMaxSrcDestBlend)
334 {
336 if ((blendFunction == BlendFunction.Min || blendFunction == BlendFunction.Max) && (cachedColorSourceBlend != 0 || cachedColorDestinationBlend != 0))
337 {
339 }
341 if ((blendFunction2 == BlendFunction.Min || blendFunction2 == BlendFunction.Max) && (cachedAlphaSourceBlend != 0 || cachedAlphaDestinationBlend != 0))
342 {
344 }
345 }
346 _parent = device;
347 isBound = true;
349 int num = ((blend != 0 || cachedColorDestinationBlend != Blend.Zero || cachedColorBlendFunction != 0 || cachedAlphaSourceBlend != 0 || cachedAlphaDestinationBlend != Blend.Zero || cachedAlphaBlendFunction != 0) ? 1 : 0);
350 blendEnable = (byte)num != 0;
352 separateAlphaBlend = (byte)num2 != 0;
353 d3dColorSourceBlend = _003CModule_003E.ConvertXnaBlendToDx(cachedColorSourceBlend);
354 d3dColorDestinationBlend = _003CModule_003E.ConvertXnaBlendToDx(cachedColorDestinationBlend);
355 d3dColorBlendFunction = _003CModule_003E.ConvertXnaBlendOpToDx(cachedColorBlendFunction);
356 d3dAlphaSourceBlend = _003CModule_003E.ConvertXnaBlendToDx(GraphicsHelpers.AdjustAlphaBlend(cachedAlphaSourceBlend));
358 d3dAlphaBlendFunction = _003CModule_003E.ConvertXnaBlendOpToDx(cachedAlphaBlendFunction);
359 uint num3 = (uint)(cachedBlendFactor.A << 8);
360 uint num4 = (cachedBlendFactor.R | num3) << 8;
361 uint num5 = (cachedBlendFactor.G | num4) << 8;
362 d3dBlendFactor = cachedBlendFactor.B | num5;
364 if (blendEnable)
365 {
367 }
369 {
370 stateTrackerFlags |= 2u;
371 }
373 {
374 stateTrackerFlags |= 4u;
375 }
377 {
378 stateTrackerFlags |= 8u;
379 }
381 {
382 stateTrackerFlags |= 16u;
383 }
384 }
385 IntPtr pComPtr = (IntPtr)device.pComPtr;
386 Helpers.CheckDisposed(device, pComPtr);
387 IDirect3DDevice9* pComPtr2 = device.pComPtr;
388 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DRENDERSTATETYPE, uint, int>)(int)(*(uint*)(*(int*)pComPtr2 + 228)))((nint)pComPtr2, (_D3DRENDERSTATETYPE)27, blendEnable ? 1u : 0u);
389 if (blendEnable)
390 {
391 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DRENDERSTATETYPE, uint, int>)(int)(*(uint*)(*(int*)pComPtr2 + 228)))((nint)pComPtr2, (_D3DRENDERSTATETYPE)19, (uint)d3dColorSourceBlend);
392 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DRENDERSTATETYPE, uint, int>)(int)(*(uint*)(*(int*)pComPtr2 + 228)))((nint)pComPtr2, (_D3DRENDERSTATETYPE)20, (uint)d3dColorDestinationBlend);
393 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DRENDERSTATETYPE, uint, int>)(int)(*(uint*)(*(int*)pComPtr2 + 228)))((nint)pComPtr2, (_D3DRENDERSTATETYPE)171, (uint)d3dColorBlendFunction);
394 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DRENDERSTATETYPE, uint, int>)(int)(*(uint*)(*(int*)pComPtr2 + 228)))((nint)pComPtr2, (_D3DRENDERSTATETYPE)206, separateAlphaBlend ? 1u : 0u);
396 {
397 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DRENDERSTATETYPE, uint, int>)(int)(*(uint*)(*(int*)pComPtr2 + 228)))((nint)pComPtr2, (_D3DRENDERSTATETYPE)207, (uint)d3dAlphaSourceBlend);
398 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DRENDERSTATETYPE, uint, int>)(int)(*(uint*)(*(int*)pComPtr2 + 228)))((nint)pComPtr2, (_D3DRENDERSTATETYPE)208, (uint)d3dAlphaDestinationBlend);
399 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DRENDERSTATETYPE, uint, int>)(int)(*(uint*)(*(int*)pComPtr2 + 228)))((nint)pComPtr2, (_D3DRENDERSTATETYPE)209, (uint)d3dAlphaBlendFunction);
400 }
401 }
402 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DRENDERSTATETYPE, uint, int>)(int)(*(uint*)(*(int*)pComPtr2 + 228)))((nint)pComPtr2, (_D3DRENDERSTATETYPE)168, (uint)cachedColorWriteChannels);
403 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DRENDERSTATETYPE, uint, int>)(int)(*(uint*)(*(int*)pComPtr2 + 228)))((nint)pComPtr2, (_D3DRENDERSTATETYPE)190, (uint)cachedColorWriteChannels1);
404 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DRENDERSTATETYPE, uint, int>)(int)(*(uint*)(*(int*)pComPtr2 + 228)))((nint)pComPtr2, (_D3DRENDERSTATETYPE)191, (uint)cachedColorWriteChannels2);
405 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DRENDERSTATETYPE, uint, int>)(int)(*(uint*)(*(int*)pComPtr2 + 228)))((nint)pComPtr2, (_D3DRENDERSTATETYPE)192, (uint)cachedColorWriteChannels3);
406 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DRENDERSTATETYPE, uint, int>)(int)(*(uint*)(*(int*)pComPtr2 + 228)))((nint)pComPtr2, (_D3DRENDERSTATETYPE)193, d3dBlendFactor);
407 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DRENDERSTATETYPE, uint, int>)(int)(*(uint*)(*(int*)pComPtr2 + 228)))((nint)pComPtr2, (_D3DRENDERSTATETYPE)162, (uint)cachedMultiSampleMask);
408 *(uint*)((byte*)device.pStateTracker + 112) = stateTrackerFlags;
409 }
410
411 internal void ThrowIfBound()
412 {
413 if (isBound)
414 {
415 throw new InvalidOperationException(string.Format(args: new object[1] { typeof(BlendState).Name }, provider: CultureInfo.CurrentCulture, format: FrameworkResources.BoundStateObject));
416 }
417 }
418
419 [HandleProcessCorruptedStateExceptions]
420 protected override void Dispose([MarshalAs(UnmanagedType.U1)] bool P_0)
421 {
422 if (P_0)
423 {
424 try
425 {
426 return;
427 }
428 finally
429 {
430 base.Dispose(true);
431 }
432 }
433 base.Dispose(false);
434 }
435}
static readonly BlendState Opaque
Definition BlendState.cs:34
unsafe void Apply(GraphicsDevice device)
static readonly BlendState AlphaBlend
Definition BlendState.cs:36
static readonly BlendState NonPremultiplied
Definition BlendState.cs:40
override void Dispose([MarshalAs(UnmanagedType.U1)] bool P_0)
static readonly BlendState Additive
Definition BlendState.cs:38
BlendState(Blend sourceBlend, Blend destinationBlend, string name)
static bool IsSeparateBlend(Blend colorBlend, Blend alphaBlend)
static void CheckDisposed(object obj, IntPtr pComPtr)
Definition Helpers.cs:188
static CultureInfo CurrentCulture