Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
GraphicsDevice.cs
Go to the documentation of this file.
1using System;
6using _003CCppImplementationDetails_003E;
7using Microsoft.Xna.Framework.GamerServices;
8using std;
9
11
13{
15
17
19
21
23
25
27
29
31
33
34 private EventHandler<EventArgs> _003Cbacking_store_003EDeviceResetting;
35
36 private EventHandler<EventArgs> _003Cbacking_store_003EDeviceReset;
37
38 private EventHandler<EventArgs> _003Cbacking_store_003EDeviceLost;
39
40 private EventHandler<ResourceCreatedEventArgs> _003Cbacking_store_003EResourceCreated;
41
42 private EventHandler<ResourceDestroyedEventArgs> _003Cbacking_store_003EResourceDestroyed;
43
45
47
49
51
53
55
56 private bool blendStateDirty;
57
59
60 private int lazyClearFlags;
61
63
65
67
69
70 internal int instanceStreamMask;
71
73
75
77
79
80 internal bool _insideScene;
81
82 internal unsafe IDirect3DSurface9* pImplicitDepthSurface;
83
84 internal uint _creationFlags;
85
86 internal readonly EmbeddedNativeType_003C_D3DCAPS9_003E d3dCaps;
87
88 internal _D3DDEVTYPE _deviceType;
89
91
93
95
97
99
101
103
104 private bool willItBlend;
105
107
108 internal bool isDisposed;
109
110 private EventHandler<EventArgs> _003Cbacking_store_003EDisposing;
111
112 internal unsafe IDirect3DDevice9* pComPtr;
113
114 internal ulong _internalHandle;
115
116 internal ushort spriteBeginCount;
117
119
120 internal EventHandler<EventArgs> _DrawGuideHandler;
121
122 public bool IsDisposed
123 {
124 [return: MarshalAs(UnmanagedType.U1)]
125 get
126 {
127 return isDisposed;
128 }
129 }
130
132 {
133 get
134 {
135 ClearOptions result = ClearOptions.Target;
137 if (depthFormat != 0)
138 {
139 result = ClearOptions.Target | ClearOptions.DepthBuffer;
140 if (depthFormat == DepthFormat.Depth24Stencil8)
141 {
142 result = ClearOptions.Target | ClearOptions.DepthBuffer | ClearOptions.Stencil;
143 }
144 }
145 return result;
146 }
147 }
148
149 internal unsafe bool IsDeviceLost
150 {
151 [return: MarshalAs(UnmanagedType.U1)]
152 get
153 {
154 IDirect3DDevice9* ptr = pComPtr;
155 if (ptr == null)
156 {
157 return true;
158 }
159 int num = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, int>)(int)(*(uint*)(*(int*)ptr + 12)))((nint)ptr);
160 int num2 = ((num == -2005530520 || num == -2005530519) ? 1 : 0);
161 return (byte)num2 != 0;
162 }
163 }
164
166 {
167 get
168 {
169 IntPtr intPtr = (IntPtr)pComPtr;
170 Helpers.CheckDisposed(this, intPtr);
171 IDirect3DDevice9* ptr = pComPtr;
172 System.Runtime.CompilerServices.Unsafe.SkipInit(out tagRECT result);
173 int num = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, tagRECT*, int>)(int)(*(uint*)(*(int*)ptr + 304)))((nint)ptr, &result);
174 if (num < 0)
175 {
177 }
178 System.Runtime.CompilerServices.Unsafe.As<tagRECT, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref result, 8)) -= *(int*)(&result);
179 System.Runtime.CompilerServices.Unsafe.As<tagRECT, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref result, 12)) -= System.Runtime.CompilerServices.Unsafe.As<tagRECT, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref result, 4));
180 return (Rectangle)result;
181 }
182 set
183 {
184 IntPtr intPtr = (IntPtr)pComPtr;
185 Helpers.CheckDisposed(this, intPtr);
186 if (*(int*)(&value) >= 0 && System.Runtime.CompilerServices.Unsafe.As<Rectangle, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref value, 8)) >= 0 && System.Runtime.CompilerServices.Unsafe.As<Rectangle, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref value, 4)) >= 0 && System.Runtime.CompilerServices.Unsafe.As<Rectangle, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref value, 12)) >= 0)
187 {
190 int num;
191 int num2;
193 {
194 RenderTargetHelper renderTargetHelper = currentRenderTargets[0];
195 num = renderTargetHelper.width;
196 num2 = renderTargetHelper.height;
197 }
198 else
199 {
202 }
203 if (*(int*)(&value) <= num && System.Runtime.CompilerServices.Unsafe.As<Rectangle, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref value, 8)) <= num && System.Runtime.CompilerServices.Unsafe.As<Rectangle, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref value, 4)) <= num2 && System.Runtime.CompilerServices.Unsafe.As<Rectangle, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref value, 12)) <= num2)
204 {
205 if (System.Runtime.CompilerServices.Unsafe.As<Rectangle, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref value, 8)) - *(int*)(&value) <= num && System.Runtime.CompilerServices.Unsafe.As<Rectangle, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref value, 12)) - System.Runtime.CompilerServices.Unsafe.As<Rectangle, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref value, 4)) <= num2)
206 {
207 IDirect3DDevice9* ptr = pComPtr;
208 int num3 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, tagRECT*, int>)(int)(*(uint*)(*(int*)ptr + 300)))((nint)ptr, (tagRECT*)(&value));
209 if (num3 < 0)
210 {
211 throw GraphicsHelpers.GetExceptionFromResult((uint)num3);
212 }
213 return;
214 }
216 }
218 }
220 }
221 }
222
223 public unsafe IndexBuffer Indices
224 {
225 get
226 {
227 return _currentIB;
228 }
229 set
230 {
231 IntPtr intPtr = (IntPtr)pComPtr;
232 Helpers.CheckDisposed(this, intPtr);
233 if (value != null)
234 {
235 IntPtr intPtr2 = (IntPtr)value.pComPtr;
236 Helpers.CheckDisposed(value, intPtr2);
237 }
238 if (value == _currentIB)
239 {
240 return;
241 }
242 IDirect3DIndexBuffer9* ptr = ((value == null) ? null : value.pComPtr);
243 IDirect3DDevice9* ptr2 = pComPtr;
244 int num = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, IDirect3DIndexBuffer9*, int>)(int)(*(uint*)(*(int*)ptr2 + 416)))((nint)ptr2, ptr);
245 if (num < 0)
246 {
247 if (value != null && value.GraphicsDevice != this)
248 {
250 }
252 }
254 }
255 }
256
257 public unsafe Viewport Viewport
258 {
259 get
260 {
261 IntPtr intPtr = (IntPtr)pComPtr;
262 Helpers.CheckDisposed(this, intPtr);
263 return currentViewport;
264 }
265 set
266 {
267 IntPtr intPtr = (IntPtr)pComPtr;
268 Helpers.CheckDisposed(this, intPtr);
269 if (value.X >= 0 && value.Y >= 0 && value.Width > 0 && value.Height > 0)
270 {
271 int num;
272 int num2;
274 {
275 RenderTargetHelper renderTargetHelper = currentRenderTargets[0];
276 num = renderTargetHelper.width;
277 num2 = renderTargetHelper.height;
278 }
279 else
280 {
283 }
284 if (value.X + value.Width <= num && value.Y + value.Height <= num2)
285 {
286 if (!(value.MinDepth < 0f) && !(value.MinDepth > 1f))
287 {
288 if (!(value.MaxDepth < 0f) && !(value.MaxDepth > 1f))
289 {
290 double num3 = value.MaxDepth;
291 if (num3 < (double)value.MinDepth)
292 {
294 }
295 IDirect3DDevice9* ptr = pComPtr;
296 int num4 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DVIEWPORT9*, int>)(int)(*(uint*)(*(int*)ptr + 188)))((nint)ptr, (_D3DVIEWPORT9*)(int)(ref value));
297 if (num4 < 0)
298 {
299 throw GraphicsHelpers.GetExceptionFromResult((uint)num4);
300 }
302 return;
303 }
305 }
307 }
309 }
311 }
312 }
313
315 {
316 get
317 {
318 IntPtr intPtr = (IntPtr)pComPtr;
319 Helpers.CheckDisposed(this, intPtr);
320 IDirect3DDevice9* ptr = pComPtr;
321 System.Runtime.CompilerServices.Unsafe.SkipInit(out _D3DDISPLAYMODE d3DDISPLAYMODE);
322 int num = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, _D3DDISPLAYMODE*, int>)(int)(*(uint*)(*(int*)ptr + 32)))((nint)ptr, 0u, &d3DDISPLAYMODE);
323 if (num < 0)
324 {
326 }
327 DisplayMode displayMode = _displayMode;
328 if (displayMode == null)
329 {
330 _displayMode = new DisplayMode(*(int*)(&d3DDISPLAYMODE), System.Runtime.CompilerServices.Unsafe.As<_D3DDISPLAYMODE, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DDISPLAYMODE, 4)), _003CModule_003E.ConvertWindowsFormatToXna(System.Runtime.CompilerServices.Unsafe.As<_D3DDISPLAYMODE, _D3DFORMAT>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DDISPLAYMODE, 12))));
331 }
332 else
333 {
334 displayMode._width = *(int*)(&d3DDISPLAYMODE);
335 _displayMode._height = System.Runtime.CompilerServices.Unsafe.As<_D3DDISPLAYMODE, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DDISPLAYMODE, 4));
336 _displayMode._format = _003CModule_003E.ConvertWindowsFormatToXna(System.Runtime.CompilerServices.Unsafe.As<_D3DDISPLAYMODE, _D3DFORMAT>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DDISPLAYMODE, 12)));
337 }
338 return _displayMode;
339 }
340 }
341
343 {
344 get
345 {
346 IntPtr intPtr = (IntPtr)pComPtr;
347 Helpers.CheckDisposed(this, intPtr);
348 IDirect3DDevice9* intPtr2 = pComPtr;
349 int num = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, int>)(int)(*(uint*)(*(int*)intPtr2 + 12)))((nint)intPtr2);
350 if (num < 0)
351 {
352 return num switch
353 {
354 -2005530519 => GraphicsDeviceStatus.NotReset,
355 -2005530520 => GraphicsDeviceStatus.Lost,
356 _ => throw GraphicsHelpers.GetExceptionFromResult((uint)num),
357 };
358 }
359 return GraphicsDeviceStatus.Normal;
360 }
361 }
362
364
366
368
370 {
371 get
372 {
374 }
375 set
376 {
377 if (value == null)
378 {
380 }
382 {
383 EffectPass effectPass = activePass;
384 if (effectPass != null && (effectPass._stateFlags & EffectStateFlags.Rasterizer) != 0)
385 {
386 effectPass.EndPass();
387 activePass = null;
388 }
389 value.Apply(this);
391 }
392 }
393 }
394
395 public unsafe int ReferenceStencil
396 {
397 get
398 {
400 }
401 set
402 {
403 IntPtr intPtr = (IntPtr)pComPtr;
404 Helpers.CheckDisposed(this, intPtr);
405 EffectPass effectPass = activePass;
406 if (effectPass != null && (effectPass._stateFlags & EffectStateFlags.DepthStencil) != 0)
407 {
408 effectPass.EndPass();
409 activePass = null;
410 }
411 IDirect3DDevice9* ptr = pComPtr;
412 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DRENDERSTATETYPE, uint, int>)(int)(*(uint*)(*(int*)ptr + 228)))((nint)ptr, (_D3DRENDERSTATETYPE)57, (uint)value);
415 }
416 }
417
419 {
420 get
421 {
423 }
424 set
425 {
426 if (value == null)
427 {
429 }
431 {
432 EffectPass effectPass = activePass;
433 if (effectPass != null && (effectPass._stateFlags & EffectStateFlags.DepthStencil) != 0)
434 {
435 effectPass.EndPass();
436 activePass = null;
437 }
438 value.Apply(this);
440 cachedReferenceStencil = value.cachedReferenceStencil;
442 }
443 }
444 }
445
446 public unsafe int MultiSampleMask
447 {
448 get
449 {
451 }
452 set
453 {
454 IntPtr intPtr = (IntPtr)pComPtr;
455 Helpers.CheckDisposed(this, intPtr);
456 EffectPass effectPass = activePass;
457 if (effectPass != null && (effectPass._stateFlags & EffectStateFlags.Blend) != 0)
458 {
459 effectPass.EndPass();
460 activePass = null;
461 }
462 IDirect3DDevice9* ptr = pComPtr;
463 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DRENDERSTATETYPE, uint, int>)(int)(*(uint*)(*(int*)ptr + 228)))((nint)ptr, (_D3DRENDERSTATETYPE)162, (uint)value);
465 blendStateDirty = true;
466 }
467 }
468
469 public unsafe Color BlendFactor
470 {
471 get
472 {
473 return cachedBlendFactor;
474 }
475 set
476 {
477 IntPtr intPtr = (IntPtr)pComPtr;
478 Helpers.CheckDisposed(this, intPtr);
479 EffectPass effectPass = activePass;
480 if (effectPass != null && (effectPass._stateFlags & EffectStateFlags.Blend) != 0)
481 {
482 effectPass.EndPass();
483 activePass = null;
484 }
485 int num = *(int*)pComPtr + 228;
486 uint num2 = (uint)(value.A << 8);
487 uint num3 = (value.R | num2) << 8;
488 uint num4 = (value.G | num3) << 8;
489 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DRENDERSTATETYPE, uint, int>)(int)(*(uint*)num))((nint)pComPtr, (_D3DRENDERSTATETYPE)193, value.B | num4);
491 blendStateDirty = true;
492 }
493 }
494
496 {
497 get
498 {
499 return cachedBlendState;
500 }
501 set
502 {
503 if (value == null)
504 {
506 }
508 {
509 EffectPass effectPass = activePass;
510 if (effectPass != null && (effectPass._stateFlags & EffectStateFlags.Blend) != 0)
511 {
512 effectPass.EndPass();
513 activePass = null;
514 }
515 value.Apply(this);
517 ref Color reference = ref cachedBlendFactor;
518 reference = value.cachedBlendFactor;
519 cachedMultiSampleMask = value.cachedMultiSampleMask;
520 blendStateDirty = false;
521 }
522 }
523 }
524
526
528
530
532
534
535 [SpecialName]
536 internal event EventHandler<EventArgs> DrawGuide
537 {
538 add
539 {
540 _DrawGuideHandler = (EventHandler<EventArgs>)Delegate.Combine(_DrawGuideHandler, value);
541 }
542 remove
543 {
544 _DrawGuideHandler = (EventHandler<EventArgs>)Delegate.Remove(_DrawGuideHandler, value);
545 }
546 }
547
548 [SpecialName]
549 public event EventHandler<EventArgs> Disposing
550 {
551 [MethodImpl(MethodImplOptions.Synchronized)]
552 add
553 {
555 }
556 [MethodImpl(MethodImplOptions.Synchronized)]
557 remove
558 {
560 }
561 }
562
563 [SpecialName]
564 public event EventHandler<ResourceDestroyedEventArgs> ResourceDestroyed
565 {
566 [MethodImpl(MethodImplOptions.Synchronized)]
567 add
568 {
570 }
571 [MethodImpl(MethodImplOptions.Synchronized)]
572 remove
573 {
575 }
576 }
577
578 [SpecialName]
579 public event EventHandler<ResourceCreatedEventArgs> ResourceCreated
580 {
581 [MethodImpl(MethodImplOptions.Synchronized)]
582 add
583 {
585 }
586 [MethodImpl(MethodImplOptions.Synchronized)]
587 remove
588 {
590 }
591 }
592
593 [SpecialName]
594 public event EventHandler<EventArgs> DeviceLost
595 {
596 [MethodImpl(MethodImplOptions.Synchronized)]
597 add
598 {
600 }
601 [MethodImpl(MethodImplOptions.Synchronized)]
602 remove
603 {
605 }
606 }
607
608 [SpecialName]
609 public event EventHandler<EventArgs> DeviceReset
610 {
611 [MethodImpl(MethodImplOptions.Synchronized)]
612 add
613 {
615 }
616 [MethodImpl(MethodImplOptions.Synchronized)]
617 remove
618 {
620 }
621 }
622
623 [SpecialName]
624 public event EventHandler<EventArgs> DeviceResetting
625 {
626 [MethodImpl(MethodImplOptions.Synchronized)]
627 add
628 {
630 }
631 [MethodImpl(MethodImplOptions.Synchronized)]
632 remove
633 {
635 }
636 }
637
638 private unsafe void CreateDevice(GraphicsAdapter adapter, PresentationParameters presentationParameters)
639 {
640 _creationFlags = 38u;
641 _D3DCAPS9* t = d3dCaps.t;
642 int num = *(int*)GraphicsAdapter.pComPtr + 56;
643 int num2 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, _D3DDEVTYPE, _D3DCAPS9*, int>)(int)(*(uint*)num))((nint)GraphicsAdapter.pComPtr, adapter.adapter, _deviceType, t);
644 if (num2 < 0)
645 {
646 throw GraphicsHelpers.GetExceptionFromResult((uint)num2);
647 }
648 if (_deviceType == (_D3DDEVTYPE)1 && ((uint)(*(int*)((byte*)d3dCaps.t + 28)) & 0x10000u) != 0)
649 {
650 _creationFlags = (_creationFlags & 0xFFFFFFDFu) | 0x40u;
651 }
652 System.Runtime.CompilerServices.Unsafe.SkipInit(out _D3DPRESENT_PARAMETERS_ d3DPRESENT_PARAMETERS_);
653 *(int*)(&d3DPRESENT_PARAMETERS_) = 0;
654 // IL initblk instruction
655 System.Runtime.CompilerServices.Unsafe.InitBlock(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DPRESENT_PARAMETERS_, 4), 0, 52);
656 ConvertPresentationParametersToNative(adapter, presentationParameters, &d3DPRESENT_PARAMETERS_);
657 fixed (IDirect3DDevice9** ptr = &pComPtr)
658 {
659 try
660 {
661 int num3 = *(int*)GraphicsAdapter.pComPtr + 64;
662 int num4 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, _D3DDEVTYPE, HWND__*, uint, _D3DPRESENT_PARAMETERS_*, IDirect3DDevice9**, int>)(int)(*(uint*)num3))((nint)GraphicsAdapter.pComPtr, adapter.adapter, _deviceType, (HWND__*)(int)System.Runtime.CompilerServices.Unsafe.As<_D3DPRESENT_PARAMETERS_, uint>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DPRESENT_PARAMETERS_, 28)), _creationFlags, &d3DPRESENT_PARAMETERS_, ptr);
663 if (num4 < 0)
664 {
665 throw GraphicsHelpers.GetExceptionFromResult((uint)num4);
666 }
667 }
668 catch
669 {
670 //try-fault
671 ptr = null;
672 throw;
673 }
674 }
675 StateTrackerDevice* ptr2 = (StateTrackerDevice*)_003CModule_003E.@new(144u, (nothrow_t*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref _003CModule_003E.std_002Enothrow));
676 StateTrackerDevice* ptr3;
677 try
678 {
679 if (ptr2 != null)
680 {
681 ProfileCapabilities profileCapabilities = _profileCapabilities;
682 ptr3 = _003CModule_003E.Microsoft_002EXna_002EFramework_002EGraphics_002EStateTrackerDevice_002E_007Bctor_007D(ptr2, pComPtr, profileCapabilities.VertexShaderVersion, profileCapabilities.PixelShaderVersion);
683 }
684 else
685 {
686 ptr3 = null;
687 }
688 }
689 catch
690 {
691 //try-fault
692 _003CModule_003E.delete(ptr2, (nothrow_t*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref _003CModule_003E.std_002Enothrow));
693 throw;
694 }
695 pStateTracker = ptr3;
696 if (ptr3 == null)
697 {
698 throw new OutOfMemoryException();
699 }
700 ConvertPresentationParametersToManaged(&d3DPRESENT_PARAMETERS_, presentationParameters);
702 {
703 IDirect3DQuery9* ptr4 = null;
704 IDirect3DDevice9* ptr5 = pComPtr;
705 int num5 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DQUERYTYPE, IDirect3DQuery9**, int>)(int)(*(uint*)(*(int*)ptr5 + 472)))((nint)ptr5, (_D3DQUERYTYPE)9, &ptr4);
706 if (ptr4 != null)
707 {
708 IDirect3DQuery9* intPtr = ptr4;
709 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)intPtr + 8)))((nint)intPtr);
710 ptr4 = null;
711 }
712 if (num5 < 0)
713 {
715 if (ptr6 != null)
716 {
717 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)ptr6 + 8)))((nint)ptr6);
718 pStateTracker = null;
719 }
720 IDirect3DDevice9* ptr7 = pComPtr;
721 if (ptr7 != null)
722 {
723 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)ptr7 + 8)))((nint)ptr7);
724 pComPtr = null;
725 }
727 }
728 }
729 try
730 {
731 return;
732 }
733 catch
734 {
735 //try-fault
736 throw;
737 }
738 }
739
740 private unsafe void CreateHelperClasses()
741 {
750 ProfileCapabilities profileCapabilities = _profileCapabilities;
753 willItBlend = true;
754 fixed (IDirect3DSurface9** ptr = &pImplicitDepthSurface)
755 {
756 int num = *(int*)pComPtr + 160;
757 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, IDirect3DSurface9**, int>)(int)(*(uint*)num))((nint)pComPtr, ptr);
758 }
759 }
760
761 public unsafe void Present(Rectangle? sourceRectangle, Rectangle? destinationRectangle, IntPtr overrideWindowHandle)
762 {
763 tagRECT* ptr = null;
764 tagRECT* ptr2 = null;
765 Rectangle rectangle = default(Rectangle);
766 Rectangle rectangle2 = default(Rectangle);
767 if (sourceRectangle.HasValue)
768 {
769 rectangle = sourceRectangle.Value;
770 ptr = (tagRECT*)(int)(ref rectangle);
771 if (ptr != null)
772 {
773 *(int*)((byte*)ptr + 8) += *(int*)ptr;
774 *(int*)((byte*)ptr + 12) += *(int*)((byte*)ptr + 4);
775 }
776 }
777 if (destinationRectangle.HasValue)
778 {
779 rectangle2 = destinationRectangle.Value;
780 ptr2 = (tagRECT*)(int)(ref rectangle2);
781 if (ptr2 != null)
782 {
783 *(int*)((byte*)ptr2 + 8) += *(int*)ptr2;
784 *(int*)((byte*)ptr2 + 12) += *(int*)((byte*)ptr2 + 4);
785 }
786 }
787 Present(ptr, ptr2, (HWND__*)overrideWindowHandle.ToPointer());
788 }
789
790 public unsafe void Present()
791 {
792 Present(null, null, null);
793 }
794
795 [CLSCompliant(false)]
796 private unsafe void Present(tagRECT* pSource, tagRECT* pDest, HWND__* hOverride)
797 {
798 IntPtr intPtr = (IntPtr)pComPtr;
799 Helpers.CheckDisposed(this, intPtr);
801 {
803 }
804 EffectPass effectPass = activePass;
805 if (effectPass != null)
806 {
807 effectPass.EndPass();
808 activePass = null;
809 }
810 if (lazyClearFlags != 0)
811 {
813 }
814 if (pSource == null && pDest == null && hOverride == null)
815 {
817 }
818 if (_insideScene)
819 {
820 IDirect3DDevice9* intPtr2 = pComPtr;
821 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, int>)(int)(*(uint*)(*(int*)intPtr2 + 168)))((nint)intPtr2);
822 _insideScene = false;
823 }
824 try
825 {
826 IDirect3DDevice9* ptr = pComPtr;
827 int num = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, tagRECT*, tagRECT*, HWND__*, _RGNDATA*, int>)(int)(*(uint*)(*(int*)ptr + 68)))((nint)ptr, pSource, pDest, hOverride, null);
829 if (num < 0)
830 {
831 if (num == -2005530520)
832 {
834 }
836 }
837 }
839 {
840 }
841 }
842
843 internal void FireCreatedEvent(object resource)
844 {
845 ResourceCreatedEventArgs resourceCreatedEventArgs = pCreatedEventArgs;
846 if (resourceCreatedEventArgs == null)
847 {
849 }
850 else
851 {
852 resourceCreatedEventArgs._resource = resource;
853 }
854 EventHandler<ResourceCreatedEventArgs> eventHandler = _003Cbacking_store_003EResourceCreated;
855 if (eventHandler != null)
856 {
857 eventHandler(this, pCreatedEventArgs);
858 }
859 pCreatedEventArgs._resource = null;
860 }
861
862 internal void FireDestroyedEvent(string name, object tag)
863 {
864 ResourceDestroyedEventArgs resourceDestroyedEventArgs = pDestroyedEventArgs;
865 if (resourceDestroyedEventArgs == null)
866 {
868 }
869 else
870 {
871 resourceDestroyedEventArgs._name = name;
872 pDestroyedEventArgs._tag = tag;
873 }
874 EventHandler<ResourceDestroyedEventArgs> eventHandler = _003Cbacking_store_003EResourceDestroyed;
875 if (eventHandler != null)
876 {
877 eventHandler(this, pDestroyedEventArgs);
878 }
879 }
880
881 internal unsafe void VerifyCanDraw([MarshalAs(UnmanagedType.U1)] bool bUserPrimitives, [MarshalAs(UnmanagedType.U1)] bool bIndexedPrimitives)
882 {
883 if (lazyClearFlags != 0)
884 {
886 }
887 int num = 0;
889 {
890 do
891 {
892 currentRenderTargets[num].pTexture.SetContentLost(isContentLost: false);
893 num++;
894 }
895 while (num < currentRenderTargetCount);
896 }
898 uint num2 = *(uint*)((byte*)ptr + 20);
899 uint num3 = *(uint*)((byte*)ptr + 24);
900 Texture texture;
901 if (num2 != 0 && num3 != 0)
902 {
903 bool num4 = num2 < 768;
904 int num5 = ((num3 < 768) ? 1 : 0);
905 if ((num4 ? 1 : 0) != num5)
906 {
908 }
909 if (!_003CModule_003E.Microsoft_002EXna_002EFramework_002EGraphics_002EVertexShaderInputSemantics_002EIsCompatibleWithDecl((VertexShaderInputSemantics*)((byte*)ptr + 28), (VertexShaderInputSemantics*)((byte*)ptr + 60)))
910 {
912 ptr = pStateTracker;
913 System.Runtime.CompilerServices.Unsafe.SkipInit(out _D3DDECLUSAGE usage);
914 System.Runtime.CompilerServices.Unsafe.SkipInit(out int num6);
915 if (_003CModule_003E.Microsoft_002EXna_002EFramework_002EGraphics_002EVertexShaderInputSemantics_002EGetMissingSemantic((VertexShaderInputSemantics*)((byte*)ptr + 28), (VertexShaderInputSemantics*)((byte*)ptr + 60), &usage, &num6))
916 {
917 text = string.Format(args: new object[3]
918 {
919 text,
920 _003CModule_003E.ConvertDxVertexElementUsageToXna(usage),
921 num6
923 }
925 }
926 if (!willItBlend && *(int*)((byte*)pStateTracker + 112) != 0)
927 {
929 }
931 uint num7 = (*(uint*)((byte*)ptr2 + 124) | *(uint*)((byte*)ptr2 + 120) | *(uint*)((byte*)ptr2 + 116)) & *(uint*)((byte*)ptr2 + 136);
932 if (num7 != 0)
933 {
934 int num8 = 0;
935 if ((num7 & 1) == 0)
936 {
937 do
938 {
939 num8++;
940 }
941 while (((uint)(1 << num8) & num7) == 0);
942 if (num8 >= 16)
943 {
944 texture = pVertexTextureCollection[num8 - 16];
945 goto IL_0183;
946 }
947 }
948 texture = pTextureCollection[num8];
949 goto IL_0183;
950 }
951 goto IL_01ad;
952 }
954 IL_0183:
955 SurfaceFormat surfaceFormat = texture?.Format ?? ((SurfaceFormat)(-1));
957 goto IL_01ad;
958 IL_01ad:
959 ptr = pStateTracker;
960 if (((*(int*)((byte*)ptr + 132) | *(int*)((byte*)ptr + 128)) & *(int*)((byte*)ptr + 140)) != 0)
961 {
963 }
964 if (!bUserPrimitives)
965 {
966 if (bIndexedPrimitives && _currentIB == null)
967 {
969 }
971 {
973 }
974 }
975 }
976
977 [SpecialName]
978 protected void raise_DeviceResetting(object value0, EventArgs value1)
979 {
980 _003Cbacking_store_003EDeviceResetting?.Invoke(value0, value1);
981 }
982
983 [SpecialName]
984 protected void raise_DeviceReset(object value0, EventArgs value1)
985 {
986 _003Cbacking_store_003EDeviceReset?.Invoke(value0, value1);
987 }
988
989 [SpecialName]
990 protected void raise_DeviceLost(object value0, EventArgs value1)
991 {
992 _003Cbacking_store_003EDeviceLost?.Invoke(value0, value1);
993 }
994
995 [SpecialName]
996 protected void raise_ResourceCreated(object value0, ResourceCreatedEventArgs value1)
997 {
998 _003Cbacking_store_003EResourceCreated?.Invoke(value0, value1);
999 }
1000
1001 [SpecialName]
1002 protected void raise_ResourceDestroyed(object value0, ResourceDestroyedEventArgs value1)
1003 {
1004 _003Cbacking_store_003EResourceDestroyed?.Invoke(value0, value1);
1005 }
1006
1007 private unsafe void ConvertPresentationParametersToNative(GraphicsAdapter adapter, PresentationParameters presentationParameters, _D3DPRESENT_PARAMETERS_* pp)
1008 {
1009 if (presentationParameters.DeviceWindowHandle == IntPtr.Zero)
1010 {
1012 }
1013 Helpers.ValidateOrientation(presentationParameters.DisplayOrientation);
1014 if (presentationParameters.BackBufferWidth <= 0 || presentationParameters.BackBufferHeight <= 0)
1015 {
1016 System.Runtime.CompilerServices.Unsafe.SkipInit(out tagRECT tagRECT);
1017 if (!presentationParameters.IsFullScreen && _003CModule_003E.GetClientRect((HWND__*)presentationParameters.DeviceWindowHandle.ToPointer(), &tagRECT) != 0)
1018 {
1019 presentationParameters.BackBufferWidth = System.Runtime.CompilerServices.Unsafe.As<tagRECT, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref tagRECT, 8)) - *(int*)(&tagRECT);
1020 presentationParameters.BackBufferHeight = System.Runtime.CompilerServices.Unsafe.As<tagRECT, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref tagRECT, 12)) - System.Runtime.CompilerServices.Unsafe.As<tagRECT, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref tagRECT, 4));
1021 }
1022 else
1023 {
1024 presentationParameters.BackBufferWidth = adapter.CurrentDisplayMode.Width;
1025 presentationParameters.BackBufferHeight = adapter.CurrentDisplayMode.Height;
1026 }
1027 }
1028 SurfaceFormat selectedFormat = presentationParameters.BackBufferFormat;
1029 DepthFormat selectedDepthFormat = presentationParameters.DepthStencilFormat;
1030 int selectedMultiSampleCount = presentationParameters.MultiSampleCount;
1031 adapter.QueryFormat(isBackBuffer: true, _deviceType, _graphicsProfile, selectedFormat, selectedDepthFormat, selectedMultiSampleCount, out selectedFormat, out selectedDepthFormat, out selectedMultiSampleCount);
1032 *(int*)pp = presentationParameters.BackBufferWidth;
1033 *(int*)((byte*)pp + 4) = presentationParameters.BackBufferHeight;
1034 *(_D3DFORMAT*)((byte*)pp + 8) = _003CModule_003E.ConvertXnaFormatToWindows(selectedFormat);
1035 *(int*)((byte*)pp + 12) = 1;
1036 int num = (((*(_D3DFORMAT*)((byte*)pp + 40) = _003CModule_003E.ConvertXnaFormatToWindows(selectedDepthFormat)) != 0) ? 1 : 0);
1037 *(int*)((byte*)pp + 36) = num;
1038 *(int*)((byte*)pp + 16) = selectedMultiSampleCount;
1039 *(int*)((byte*)pp + 28) = (int)presentationParameters.DeviceWindowHandle.ToPointer();
1040 int num2 = ((!presentationParameters.IsFullScreen) ? 1 : 0);
1041 *(int*)((byte*)pp + 32) = num2;
1042 *(int*)((byte*)pp + 24) = 1;
1043 switch (presentationParameters.PresentationInterval)
1044 {
1045 default:
1046 *(int*)((byte*)pp + 52) = 0;
1047 break;
1048 case PresentInterval.Immediate:
1049 *(int*)((byte*)pp + 52) = int.MinValue;
1050 break;
1051 case PresentInterval.Two:
1052 if (presentationParameters.IsFullScreen && ((uint)(*(int*)((byte*)d3dCaps.t + 20)) & 2u) != 0)
1053 {
1054 *(int*)((byte*)pp + 52) = 2;
1055 }
1056 else
1057 {
1058 *(int*)((byte*)pp + 52) = 1;
1059 }
1060 break;
1061 case PresentInterval.One:
1062 *(int*)((byte*)pp + 52) = 1;
1063 break;
1064 }
1065 }
1066
1067 private unsafe void ConvertPresentationParametersToManaged(_D3DPRESENT_PARAMETERS_* pp, PresentationParameters presentationParameters)
1068 {
1069 presentationParameters.BackBufferWidth = *(int*)pp;
1070 presentationParameters.BackBufferHeight = *(int*)((byte*)pp + 4);
1071 presentationParameters.BackBufferFormat = _003CModule_003E.ConvertWindowsFormatToXna(*(_D3DFORMAT*)((byte*)pp + 8));
1072 DepthFormat depthStencilFormat = ((*(int*)((byte*)pp + 36) != 0) ? _003CModule_003E.ConvertWindowsDepthFormatToXna(*(_D3DFORMAT*)((byte*)pp + 40)) : DepthFormat.None);
1073 presentationParameters.DepthStencilFormat = depthStencilFormat;
1074 presentationParameters.MultiSampleCount = *(int*)((byte*)pp + 16);
1075 switch ((uint)(*(int*)((byte*)pp + 52)))
1076 {
1077 default:
1078 presentationParameters.PresentationInterval = PresentInterval.Default;
1079 break;
1080 case 2147483648u:
1081 presentationParameters.PresentationInterval = PresentInterval.Immediate;
1082 break;
1083 case 2u:
1084 presentationParameters.PresentationInterval = PresentInterval.Two;
1085 break;
1086 case 1u:
1087 presentationParameters.PresentationInterval = PresentInterval.One;
1088 break;
1089 }
1090 }
1091
1092 internal void ClearBlendState()
1093 {
1094 cachedBlendState = null;
1095 ref Color reference = ref cachedBlendFactor;
1096 reference = BlendState.Opaque.cachedBlendFactor;
1097 cachedMultiSampleMask = BlendState.Opaque.cachedMultiSampleMask;
1098 blendStateDirty = true;
1099 }
1100
1102 {
1104 cachedReferenceStencil = DepthStencilState.Default.cachedReferenceStencil;
1106 }
1107
1108 internal void ClearRasterizerState()
1109 {
1110 cachedRasterizerState = null;
1111 }
1112
1113 private unsafe GraphicsDevice(IDirect3DDevice9* pInterface, GraphicsDevice pDevice)
1114 {
1115 EmbeddedNativeType_003C_D3DCAPS9_003E embeddedNativeType_003C_D3DCAPS9_003E = new EmbeddedNativeType_003C_D3DCAPS9_003E();
1116 try
1117 {
1118 d3dCaps = embeddedNativeType_003C_D3DCAPS9_003E;
1119 _parent = pDevice;
1120 pComPtr = pInterface;
1121 base._002Ector();
1123 return;
1124 }
1125 catch
1126 {
1127 //try-fault
1128 ((IDisposable)d3dCaps).Dispose();
1129 throw;
1130 }
1131 }
1132
1133 public GraphicsDevice(GraphicsAdapter adapter, GraphicsProfile graphicsProfile, PresentationParameters presentationParameters)
1134 {
1135 EmbeddedNativeType_003C_D3DCAPS9_003E embeddedNativeType_003C_D3DCAPS9_003E = new EmbeddedNativeType_003C_D3DCAPS9_003E();
1136 try
1137 {
1138 d3dCaps = embeddedNativeType_003C_D3DCAPS9_003E;
1139 base._002Ector();
1140 if (presentationParameters == null)
1141 {
1142 throw new ArgumentNullException("presentationParameters", FrameworkResources.NullNotAllowed);
1143 }
1144 if (adapter == null)
1145 {
1147 }
1149 _graphicsProfile = graphicsProfile;
1152 {
1154 }
1155 CreateDevice(adapter, presentationParameters);
1156 pCurrentAdapter = adapter;
1157 _DrawGuideHandler = null;
1158 pInternalCachedParams = presentationParameters.Clone();
1159 pPublicCachedParams = presentationParameters.Clone();
1162 GuideRendererConnector.GuideRendererType = typeof(GuideRenderer);
1163 return;
1164 }
1165 catch
1166 {
1167 //try-fault
1168 ((IDisposable)d3dCaps).Dispose();
1169 throw;
1170 }
1171 }
1172
1173 public void Reset()
1174 {
1176 }
1177
1178 public void Reset(PresentationParameters presentationParameters)
1179 {
1180 Reset(presentationParameters, pCurrentAdapter);
1181 }
1182
1183 public unsafe void Reset(PresentationParameters presentationParameters, GraphicsAdapter graphicsAdapter)
1184 {
1185 IntPtr intPtr = (IntPtr)pComPtr;
1186 Helpers.CheckDisposed(this, intPtr);
1187 bool flag = false;
1188 if (presentationParameters == null)
1189 {
1190 throw new ArgumentNullException("presentationParameters", FrameworkResources.NullNotAllowed);
1191 }
1192 if (graphicsAdapter == null)
1193 {
1194 throw new ArgumentNullException("graphicsAdapter", FrameworkResources.NullNotAllowed);
1195 }
1196 EventArgs empty = EventArgs.Empty;
1197 _003Cbacking_store_003EDeviceResetting?.Invoke(this, empty);
1198 int num = ((currentRenderTargetCount == 0 && presentationParameters.BackBufferWidth == pInternalCachedParams.BackBufferWidth && presentationParameters.BackBufferHeight == pInternalCachedParams.BackBufferHeight) ? 1 : 0);
1199 bool saveViewport = (byte)num != 0;
1200 SavedDeviceState savedDeviceState = new SavedDeviceState(this, saveViewport);
1201 if (graphicsAdapter != pCurrentAdapter && _deviceType == (_D3DDEVTYPE)1 && graphicsAdapter.IsProfileSupported((_D3DDEVTYPE)1, _graphicsProfile))
1202 {
1203 flag = true;
1204 }
1205 EffectPass effectPass = activePass;
1206 if (effectPass != null)
1207 {
1208 effectPass.EndPass();
1209 activePass = null;
1210 }
1212 lazyClearFlags = 0;
1214 Indices = null;
1215 SetVertexBuffers(null, 0);
1216 SetRenderTargets(null, 0);
1220 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, IDirect3DVertexDeclaration9*, int>)(int)(*(uint*)(*(int*)ptr + 348)))((nint)ptr, null);
1221 ptr = pStateTracker;
1222 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, IDirect3DVertexShader9*, int>)(int)(*(uint*)(*(int*)ptr + 368)))((nint)ptr, null);
1223 ptr = pStateTracker;
1224 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, IDirect3DPixelShader9*, int>)(int)(*(uint*)(*(int*)ptr + 428)))((nint)ptr, null);
1226 IDirect3DSurface9* ptr2 = pImplicitDepthSurface;
1227 if (ptr2 != null)
1228 {
1229 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)ptr2 + 8)))((nint)ptr2);
1230 pImplicitDepthSurface = null;
1231 }
1232 if (flag)
1233 {
1235 ptr = pStateTracker;
1236 if (ptr != null)
1237 {
1238 StateTrackerDevice* intPtr2 = ptr;
1239 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)intPtr2 + 8)))((nint)intPtr2);
1240 pStateTracker = null;
1241 }
1242 IDirect3DDevice9* ptr3 = pComPtr;
1243 IDirect3DDevice9* intPtr3 = ptr3;
1244 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)intPtr3 + 8)))((nint)intPtr3);
1245 pComPtr = null;
1246 CreateDevice(graphicsAdapter, presentationParameters);
1247 pResourceManager.RecreateResources((_D3DPOOL)1, flag);
1248 pCurrentAdapter = graphicsAdapter;
1249 }
1250 else
1251 {
1252 System.Runtime.CompilerServices.Unsafe.SkipInit(out _D3DPRESENT_PARAMETERS_ d3DPRESENT_PARAMETERS_);
1253 *(int*)(&d3DPRESENT_PARAMETERS_) = 0;
1254 // IL initblk instruction
1255 System.Runtime.CompilerServices.Unsafe.InitBlock(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DPRESENT_PARAMETERS_, 4), 0, 52);
1256 ConvertPresentationParametersToNative(pCurrentAdapter, presentationParameters, &d3DPRESENT_PARAMETERS_);
1257 IDirect3DDevice9* ptr3 = pComPtr;
1258 int num2 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DPRESENT_PARAMETERS_*, int>)(int)(*(uint*)(*(int*)ptr3 + 64)))((nint)ptr3, &d3DPRESENT_PARAMETERS_);
1259 ConvertPresentationParametersToManaged(&d3DPRESENT_PARAMETERS_, presentationParameters);
1260 if (num2 < 0)
1261 {
1262 throw GraphicsHelpers.GetExceptionFromResult((uint)num2);
1263 }
1264 }
1265 fixed (IDirect3DSurface9** ptr4 = &pImplicitDepthSurface)
1266 {
1267 int num3 = *(int*)pComPtr + 160;
1268 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, IDirect3DSurface9**, int>)(int)(*(uint*)num3))((nint)pComPtr, ptr4);
1269 pResourceManager.RecreateResources((_D3DPOOL)0, flag);
1270 pInternalCachedParams = presentationParameters.Clone();
1271 pPublicCachedParams = presentationParameters.Clone();
1273 savedDeviceState.Restore();
1274 EventArgs empty2 = EventArgs.Empty;
1275 _003Cbacking_store_003EDeviceReset?.Invoke(this, empty2);
1276 _insideScene = false;
1277 }
1278 }
1279
1280 public unsafe void DrawPrimitives(PrimitiveType primitiveType, int startVertex, int primitiveCount)
1281 {
1282 IntPtr intPtr = (IntPtr)pComPtr;
1283 Helpers.CheckDisposed(this, intPtr);
1284 if (primitiveCount <= 0)
1285 {
1287 }
1288 int maxPrimitiveCount = _profileCapabilities.MaxPrimitiveCount;
1289 if (primitiveCount > maxPrimitiveCount)
1290 {
1292 }
1293 VerifyCanDraw(bUserPrimitives: false, bIndexedPrimitives: false);
1294 if (instanceStreamMask != 0)
1295 {
1297 }
1298 if (!_insideScene)
1299 {
1300 IDirect3DDevice9* intPtr2 = pComPtr;
1301 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, int>)(int)(*(uint*)(*(int*)intPtr2 + 164)))((nint)intPtr2);
1302 _insideScene = true;
1303 }
1304 int num = *(int*)pComPtr + 324;
1305 int num2 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DPRIMITIVETYPE, uint, uint, int>)(int)(*(uint*)num))((nint)pComPtr, _003CModule_003E.ConvertXnaPrimitiveTypeToDx(primitiveType), (uint)startVertex, (uint)primitiveCount);
1306 if (num2 < 0)
1307 {
1308 throw GraphicsHelpers.GetExceptionFromResult((uint)num2);
1309 }
1310 }
1311
1312 public unsafe void DrawIndexedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices, int startIndex, int primitiveCount)
1313 {
1314 IntPtr intPtr = (IntPtr)pComPtr;
1315 Helpers.CheckDisposed(this, intPtr);
1316 if (numVertices <= 0)
1317 {
1319 }
1320 if (primitiveCount <= 0)
1321 {
1323 }
1324 int maxPrimitiveCount = _profileCapabilities.MaxPrimitiveCount;
1325 if (primitiveCount > maxPrimitiveCount)
1326 {
1328 }
1329 VerifyCanDraw(bUserPrimitives: false, bIndexedPrimitives: true);
1330 if (instanceStreamMask != 0)
1331 {
1333 }
1334 if (!_insideScene)
1335 {
1336 IDirect3DDevice9* intPtr2 = pComPtr;
1337 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, int>)(int)(*(uint*)(*(int*)intPtr2 + 164)))((nint)intPtr2);
1338 _insideScene = true;
1339 }
1340 int num = *(int*)pComPtr + 328;
1341 int num2 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DPRIMITIVETYPE, int, uint, uint, uint, uint, int>)(int)(*(uint*)num))((nint)pComPtr, _003CModule_003E.ConvertXnaPrimitiveTypeToDx(primitiveType), baseVertex, (uint)minVertexIndex, (uint)numVertices, (uint)startIndex, (uint)primitiveCount);
1342 if (num2 < 0)
1343 {
1344 throw GraphicsHelpers.GetExceptionFromResult((uint)num2);
1345 }
1346 }
1347
1348 public unsafe void DrawInstancedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices, int startIndex, int primitiveCount, int instanceCount)
1349 {
1350 IntPtr intPtr = (IntPtr)pComPtr;
1351 Helpers.CheckDisposed(this, intPtr);
1352 if (numVertices <= 0)
1353 {
1355 }
1356 if (primitiveCount <= 0)
1357 {
1359 }
1360 int maxPrimitiveCount = _profileCapabilities.MaxPrimitiveCount;
1361 if (primitiveCount > maxPrimitiveCount)
1362 {
1364 }
1365 if (instanceCount <= 0)
1366 {
1368 }
1369 maxPrimitiveCount = _profileCapabilities.MaxPrimitiveCount;
1370 if (instanceCount > maxPrimitiveCount)
1371 {
1373 }
1374 VerifyCanDraw(bUserPrimitives: false, bIndexedPrimitives: true);
1375 int num = instanceStreamMask;
1376 bool flag = num == 0;
1377 bool flag2 = num == (1 << currentVertexBufferCount) - 1;
1378 if (!flag && !flag2)
1379 {
1380 _D3DPRIMITIVETYPE d3DPRIMITIVETYPE = _003CModule_003E.ConvertXnaPrimitiveTypeToDx(primitiveType);
1381 if (!_insideScene)
1382 {
1383 IDirect3DDevice9* intPtr2 = pComPtr;
1384 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, int>)(int)(*(uint*)(*(int*)intPtr2 + 164)))((nint)intPtr2);
1385 _insideScene = true;
1386 }
1387 if ((uint)(*(int*)((byte*)pStateTracker + 20)) >= 768u)
1388 {
1389 try
1390 {
1391 for (int i = 0; i < currentVertexBufferCount; i++)
1392 {
1393 uint num2 = 1073741823u;
1394 uint instanceFrequency = (uint)currentVertexBuffers[i]._instanceFrequency;
1395 uint num3 = ((instanceFrequency == 0) ? ((uint)instanceCount | 0x40000000u) : (((instanceFrequency >= 1073741823) ? 1073741823u : instanceFrequency) | 0x80000000u));
1396 IDirect3DDevice9* ptr = pComPtr;
1397 int num4 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, uint, int>)(int)(*(uint*)(*(int*)ptr + 408)))((nint)ptr, (uint)i, num3);
1398 if (num4 < 0)
1399 {
1400 throw GraphicsHelpers.GetExceptionFromResult((uint)num4);
1401 }
1402 }
1403 IDirect3DDevice9* ptr2 = pComPtr;
1404 int num5 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DPRIMITIVETYPE, int, uint, uint, uint, uint, int>)(int)(*(uint*)(*(int*)ptr2 + 328)))((nint)ptr2, d3DPRIMITIVETYPE, baseVertex, (uint)minVertexIndex, (uint)numVertices, (uint)startIndex, (uint)primitiveCount);
1405 if (num5 < 0)
1406 {
1407 throw GraphicsHelpers.GetExceptionFromResult((uint)num5);
1408 }
1409 return;
1410 }
1411 finally
1412 {
1413 int num6 = 0;
1415 {
1416 do
1417 {
1418 IDirect3DDevice9* ptr3 = pComPtr;
1419 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, uint, int>)(int)(*(uint*)(*(int*)ptr3 + 408)))((nint)ptr3, (uint)num6, 1u);
1420 num6++;
1421 }
1422 while (num6 < currentVertexBufferCount);
1423 }
1424 }
1425 }
1426 int num7 = 0;
1427 int num8 = 0;
1428 System.Runtime.CompilerServices.Unsafe.SkipInit(out _0024ArrayType_0024_0024_0024BY0BA_0040H _0024ArrayType_0024_0024_0024BY0BA_0040H);
1429 System.Runtime.CompilerServices.Unsafe.SkipInit(out _0024ArrayType_0024_0024_0024BY0BA_0040I _0024ArrayType_0024_0024_0024BY0BA_0040I);
1430 System.Runtime.CompilerServices.Unsafe.SkipInit(out _0024ArrayType_0024_0024_0024BY0BA_0040I _0024ArrayType_0024_0024_0024BY0BA_0040I2);
1431 System.Runtime.CompilerServices.Unsafe.SkipInit(out _0024ArrayType_0024_0024_0024BY0BA_0040I _0024ArrayType_0024_0024_0024BY0BA_0040I3);
1432 System.Runtime.CompilerServices.Unsafe.SkipInit(out _0024ArrayType_0024_0024_0024BY0BA_0040PAUIDirect3DVertexBuffer9_0040_0040 _0024ArrayType_0024_0024_0024BY0BA_0040PAUIDirect3DVertexBuffer9_0040_0040);
1434 {
1435 do
1436 {
1437 if (num8 < 16)
1438 {
1439 if ((instanceStreamMask & (1 << num8)) != 0)
1440 {
1441 *(int*)((ref *(_003F*)(num7 * 4)) + (ref *(_003F*)(&_0024ArrayType_0024_0024_0024BY0BA_0040H))) = num8;
1443 *(int*)((ref *(_003F*)(num7 * 4)) + (ref *(_003F*)(&_0024ArrayType_0024_0024_0024BY0BA_0040I))) = array[num8]._vertexOffset;
1444 *(int*)((ref *(_003F*)(num7 * 4)) + (ref *(_003F*)(&_0024ArrayType_0024_0024_0024BY0BA_0040I2))) = array[num8]._instanceFrequency;
1445 VertexBuffer vertexBuffer = array[num8]._vertexBuffer;
1446 *(int*)((ref *(_003F*)(num7 * 4)) + (ref *(_003F*)(&_0024ArrayType_0024_0024_0024BY0BA_0040I3))) = vertexBuffer._vertexDeclaration._vertexStride;
1447 *(int*)((ref *(_003F*)(num7 * 4)) + (ref *(_003F*)(&_0024ArrayType_0024_0024_0024BY0BA_0040PAUIDirect3DVertexBuffer9_0040_0040))) = (int)vertexBuffer.pComPtr;
1448 num7++;
1449 }
1450 num8++;
1451 continue;
1452 }
1453 throw new InvalidOperationException();
1454 }
1455 while (num8 < currentVertexBufferCount);
1456 }
1457 int num9 = 0;
1458 if (0 >= instanceCount)
1459 {
1460 return;
1461 }
1462 int num13;
1463 while (true)
1464 {
1465 int num10 = 0;
1466 if (0 < num7)
1467 {
1468 do
1469 {
1470 uint num11 = (uint)(((int)((uint)num9 / (uint)(*(int*)((ref *(_003F*)(num10 * 4)) + (ref *(_003F*)(&_0024ArrayType_0024_0024_0024BY0BA_0040I2))))) + *(int*)((ref *(_003F*)(num10 * 4)) + (ref *(_003F*)(&_0024ArrayType_0024_0024_0024BY0BA_0040I)))) * *(int*)((ref *(_003F*)(num10 * 4)) + (ref *(_003F*)(&_0024ArrayType_0024_0024_0024BY0BA_0040I3))));
1471 IDirect3DDevice9* ptr4 = pComPtr;
1472 int num12 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, IDirect3DVertexBuffer9*, uint, uint, int>)(int)(*(uint*)(*(int*)ptr4 + 400)))((nint)ptr4, *(uint*)((ref *(_003F*)(num10 * 4)) + (ref *(_003F*)(&_0024ArrayType_0024_0024_0024BY0BA_0040H))), (IDirect3DVertexBuffer9*)(int)(*(uint*)((ref *(_003F*)(num10 * 4)) + (ref *(_003F*)(&_0024ArrayType_0024_0024_0024BY0BA_0040PAUIDirect3DVertexBuffer9_0040_0040)))), num11, 0u);
1473 if (num12 >= 0)
1474 {
1475 num10++;
1476 continue;
1477 }
1478 throw GraphicsHelpers.GetExceptionFromResult((uint)num12);
1479 }
1480 while (num10 < num7);
1481 }
1482 IDirect3DDevice9* ptr5 = pComPtr;
1483 num13 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DPRIMITIVETYPE, int, uint, uint, uint, uint, int>)(int)(*(uint*)(*(int*)ptr5 + 328)))((nint)ptr5, d3DPRIMITIVETYPE, baseVertex, (uint)minVertexIndex, (uint)numVertices, (uint)startIndex, (uint)primitiveCount);
1484 if (num13 < 0)
1485 {
1486 break;
1487 }
1488 num9++;
1489 if (num9 >= instanceCount)
1490 {
1491 return;
1492 }
1493 }
1494 throw GraphicsHelpers.GetExceptionFromResult((uint)num13);
1495 }
1497 }
1498
1499 private uint GetElementCountFromPrimitiveType(PrimitiveType primitiveType, int primitiveCount)
1500 {
1501 uint result = uint.MaxValue;
1502 switch (primitiveType)
1503 {
1504 case PrimitiveType.LineList:
1505 result = (uint)(primitiveCount << 1);
1506 break;
1507 case PrimitiveType.TriangleList:
1508 result = (uint)(primitiveCount * 3);
1509 break;
1510 case PrimitiveType.LineStrip:
1511 result = (uint)(primitiveCount + 1);
1512 break;
1513 case PrimitiveType.TriangleStrip:
1514 result = (uint)(primitiveCount + 2);
1515 break;
1516 }
1517 return result;
1518 }
1519
1520 private unsafe void BeginUserPrimitives(VertexDeclaration vertexDeclaration)
1521 {
1522 int num = 0;
1524 {
1525 do
1526 {
1527 if (num > 0)
1528 {
1529 IDirect3DDevice9* ptr = pComPtr;
1530 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, IDirect3DVertexBuffer9*, uint, uint, int>)(int)(*(uint*)(*(int*)ptr + 400)))((nint)ptr, (uint)num, null, 0u, 0u);
1531 }
1533 num++;
1534 }
1535 while (num < currentVertexBufferCount);
1536 }
1540 if (!_insideScene)
1541 {
1542 IDirect3DDevice9* intPtr = pComPtr;
1543 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, int>)(int)(*(uint*)(*(int*)intPtr + 164)))((nint)intPtr);
1544 _insideScene = true;
1545 }
1546 }
1547
1548 public void DrawUserIndexedPrimitives<T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int numVertices, int[] indexData, int indexOffset, int primitiveCount) where T : struct, IVertexType
1549 {
1551 {
1553 }
1554 T[] vertexData2 = vertexData;
1555 DrawUserIndexedPrimitives(primitiveType, vertexData2, vertexOffset, numVertices, indexData, indexOffset, primitiveCount, VertexDeclarationFactory<T>.VertexDeclaration, (_D3DFORMAT)102);
1556 }
1557
1558 public void DrawUserIndexedPrimitives<T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int numVertices, short[] indexData, int indexOffset, int primitiveCount) where T : struct, IVertexType
1559 {
1560 T[] vertexData2 = vertexData;
1561 DrawUserIndexedPrimitives(primitiveType, vertexData2, vertexOffset, numVertices, indexData, indexOffset, primitiveCount, VertexDeclarationFactory<T>.VertexDeclaration, (_D3DFORMAT)101);
1562 }
1563
1564 public void DrawUserIndexedPrimitives<T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int numVertices, int[] indexData, int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct
1565 {
1567 {
1569 }
1570 DrawUserIndexedPrimitives(primitiveType, vertexData, vertexOffset, numVertices, indexData, indexOffset, primitiveCount, vertexDeclaration, (_D3DFORMAT)102);
1571 }
1572
1573 public void DrawUserIndexedPrimitives<T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int numVertices, short[] indexData, int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct
1574 {
1575 DrawUserIndexedPrimitives(primitiveType, vertexData, vertexOffset, numVertices, indexData, indexOffset, primitiveCount, vertexDeclaration, (_D3DFORMAT)101);
1576 }
1577
1578 private unsafe void DrawUserIndexedPrimitives<T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int numVertices, Array indexData, int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration, _D3DFORMAT indexFormat) where T : struct
1579 {
1580 IntPtr intPtr = (IntPtr)pComPtr;
1581 Helpers.CheckDisposed(this, intPtr);
1582 if (vertexData != null && vertexData.Length != 0)
1583 {
1584 if (indexData != null && indexData.Length != 0)
1585 {
1586 if (vertexDeclaration == null)
1587 {
1588 throw new ArgumentNullException("vertexDeclaration", FrameworkResources.NullNotAllowed);
1589 }
1590 if (numVertices <= 0)
1591 {
1593 }
1594 if (primitiveCount <= 0)
1595 {
1597 }
1598 int maxPrimitiveCount = _profileCapabilities.MaxPrimitiveCount;
1599 if (primitiveCount > maxPrimitiveCount)
1600 {
1602 }
1603 if (vertexOffset >= 0 && vertexOffset < (nint)vertexData.LongLength)
1604 {
1605 if (indexOffset >= 0 && indexOffset < indexData.Length)
1606 {
1607 if ((uint)((int)GetElementCountFromPrimitiveType(primitiveType, primitiveCount) + indexOffset) > (uint)indexData.Length)
1608 {
1610 }
1611 if (vertexOffset + numVertices > (nint)vertexData.LongLength)
1612 {
1614 }
1615 BeginUserPrimitives(vertexDeclaration);
1616 VerifyCanDraw(bUserPrimitives: true, bIndexedPrimitives: true);
1617 GCHandle gCHandle = GCHandle.Alloc(indexData, GCHandleType.Pinned);
1618 try
1619 {
1620 fixed (T* ptr2 = &vertexData[vertexOffset])
1621 {
1622 try
1623 {
1624 void* ptr = Marshal.UnsafeAddrOfPinnedArrayElement(indexData, indexOffset).ToPointer();
1625 int num = *(int*)pComPtr + 336;
1626 int num2 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DPRIMITIVETYPE, uint, uint, uint, void*, _D3DFORMAT, void*, uint, int>)(int)(*(uint*)num))((nint)pComPtr, _003CModule_003E.ConvertXnaPrimitiveTypeToDx(primitiveType), 0u, (uint)numVertices, (uint)primitiveCount, ptr, indexFormat, ptr2, (uint)System.Runtime.CompilerServices.Unsafe.SizeOf<T>());
1627 if (num2 >= 0)
1628 {
1629 return;
1630 }
1631 throw GraphicsHelpers.GetExceptionFromResult((uint)num2);
1632 }
1633 catch
1634 {
1635 //try-fault
1636 ptr2 = null;
1637 throw;
1638 }
1639 }
1640 }
1641 finally
1642 {
1643 if (gCHandle.IsAllocated)
1644 {
1645 gCHandle.Free();
1646 }
1647 _currentIB = null;
1648 }
1649 }
1651 }
1653 }
1655 }
1657 }
1658
1659 public void DrawUserPrimitives<T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int primitiveCount) where T : struct, IVertexType
1660 {
1661 DrawUserPrimitives(primitiveType, vertexData, vertexOffset, primitiveCount, VertexDeclarationFactory<T>.VertexDeclaration);
1662 }
1663
1664 public unsafe void DrawUserPrimitives<T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct
1665 {
1666 IntPtr intPtr = (IntPtr)pComPtr;
1667 Helpers.CheckDisposed(this, intPtr);
1668 if (vertexData == null)
1669 {
1671 }
1672 if (vertexDeclaration == null)
1673 {
1674 throw new ArgumentNullException("vertexDeclaration", FrameworkResources.NullNotAllowed);
1675 }
1676 if (primitiveCount <= 0)
1677 {
1679 }
1680 int maxPrimitiveCount = _profileCapabilities.MaxPrimitiveCount;
1681 if (primitiveCount > maxPrimitiveCount)
1682 {
1684 }
1685 if (vertexOffset >= 0)
1686 {
1687 int num = vertexData.Length;
1688 if (vertexOffset < num)
1689 {
1690 if ((uint)((int)GetElementCountFromPrimitiveType(primitiveType, primitiveCount) + vertexOffset) > (uint)num)
1691 {
1693 }
1694 BeginUserPrimitives(vertexDeclaration);
1695 VerifyCanDraw(bUserPrimitives: true, bIndexedPrimitives: false);
1696 fixed (T* ptr = &vertexData[vertexOffset])
1697 {
1698 int num2 = *(int*)pComPtr + 332;
1699 int num3 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DPRIMITIVETYPE, uint, void*, uint, int>)(int)(*(uint*)num2))((nint)pComPtr, _003CModule_003E.ConvertXnaPrimitiveTypeToDx(primitiveType), (uint)primitiveCount, ptr, (uint)System.Runtime.CompilerServices.Unsafe.SizeOf<T>());
1700 if (num3 < 0)
1701 {
1702 throw GraphicsHelpers.GetExceptionFromResult((uint)num3);
1703 }
1704 return;
1705 }
1706 }
1707 }
1709 }
1710
1711 public void Clear(ClearOptions options, Vector4 color, float depth, int stencil)
1712 {
1713 Color color2 = new Color(color);
1714 Clear(options, color2, depth, stencil);
1715 }
1716
1717 public unsafe void Clear(ClearOptions options, Color color, float depth, int stencil)
1718 {
1719 IntPtr intPtr = (IntPtr)pComPtr;
1720 Helpers.CheckDisposed(this, intPtr);
1721 uint num = 0u;
1722 IDirect3DDevice9* ptr = pComPtr;
1723 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DRENDERSTATETYPE, uint*, int>)(int)(*(uint*)(*(int*)ptr + 232)))((nint)ptr, (_D3DRENDERSTATETYPE)174, &num);
1724 if (num != 0)
1725 {
1726 ptr = pComPtr;
1727 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DRENDERSTATETYPE, uint, int>)(int)(*(uint*)(*(int*)ptr + 228)))((nint)ptr, (_D3DRENDERSTATETYPE)174, 0u);
1728 }
1729 int num2;
1730 int num3;
1732 {
1733 RenderTargetHelper renderTargetHelper = currentRenderTargets[0];
1734 num2 = renderTargetHelper.width;
1735 num3 = renderTargetHelper.height;
1736 }
1737 else
1738 {
1741 }
1742 bool flag = false;
1743 if (currentViewport.X != 0 || currentViewport.Y != 0 || currentViewport.Width != num2 || currentViewport.Height != num3)
1744 {
1745 System.Runtime.CompilerServices.Unsafe.SkipInit(out _D3DVIEWPORT9 d3DVIEWPORT);
1746 *(int*)(&d3DVIEWPORT) = 0;
1747 System.Runtime.CompilerServices.Unsafe.As<_D3DVIEWPORT9, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DVIEWPORT, 4)) = 0;
1748 System.Runtime.CompilerServices.Unsafe.As<_D3DVIEWPORT9, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DVIEWPORT, 8)) = num2;
1749 System.Runtime.CompilerServices.Unsafe.As<_D3DVIEWPORT9, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DVIEWPORT, 12)) = num3;
1750 System.Runtime.CompilerServices.Unsafe.As<_D3DVIEWPORT9, float>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DVIEWPORT, 16)) = 0f;
1751 System.Runtime.CompilerServices.Unsafe.As<_D3DVIEWPORT9, float>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DVIEWPORT, 20)) = 1f;
1752 ptr = pComPtr;
1753 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DVIEWPORT9*, int>)(int)(*(uint*)(*(int*)ptr + 188)))((nint)ptr, &d3DVIEWPORT);
1754 flag = true;
1755 }
1756 uint num4 = (uint)(color.A << 8);
1757 uint num5 = (color.R | num4) << 8;
1758 uint num6 = (color.G | num5) << 8;
1759 uint num7 = color.B | num6;
1760 IDirect3DDevice9* ptr2 = pComPtr;
1761 int num8 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, _D3DRECT*, uint, uint, float, uint, int>)(int)(*(uint*)(*(int*)ptr2 + 172)))((nint)ptr2, 0u, null, (uint)options, num7, depth, (uint)stencil);
1762 if (num != 0)
1763 {
1764 ptr2 = pComPtr;
1765 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DRENDERSTATETYPE, uint, int>)(int)(*(uint*)(*(int*)ptr2 + 228)))((nint)ptr2, (_D3DRENDERSTATETYPE)174, num);
1766 }
1767 if (flag)
1768 {
1769 Viewport viewport = currentViewport;
1770 ptr2 = pComPtr;
1771 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DVIEWPORT9*, int>)(int)(*(uint*)(*(int*)ptr2 + 188)))((nint)ptr2, (_D3DVIEWPORT9*)(int)(ref viewport));
1772 }
1773 if (num8 < 0)
1774 {
1775 ClearOptions clearOptions = options & (ClearOptions.DepthBuffer | ClearOptions.Stencil);
1776 if ((DefaultClearOptions & clearOptions) != clearOptions)
1777 {
1779 }
1780 throw GraphicsHelpers.GetExceptionFromResult((uint)num8);
1781 }
1782 int num9 = 0;
1784 {
1785 do
1786 {
1787 currentRenderTargets[num9].pTexture.SetContentLost(isContentLost: false);
1788 num9++;
1789 }
1790 while (num9 < currentRenderTargetCount);
1791 }
1792 lazyClearFlags &= (int)(~options);
1793 }
1794
1795 public void Clear(Color color)
1796 {
1797 Clear(DefaultClearOptions, color, 1f, 0);
1798 }
1799
1800 public unsafe void SetRenderTargets(params RenderTargetBinding[] renderTargets)
1801 {
1802 if (renderTargets != null && (nint)renderTargets.LongLength > 0)
1803 {
1804 fixed (RenderTargetBinding* pBindings = &renderTargets[0])
1805 {
1806 try
1807 {
1808 SetRenderTargets(pBindings, renderTargets.Length);
1809 }
1810 catch
1811 {
1812 //try-fault
1813 pBindings = null;
1814 throw;
1815 }
1816 }
1817 }
1818 else
1819 {
1820 SetRenderTargets(null, 0);
1821 }
1822 }
1823
1824 private unsafe void SetRenderTargets(RenderTargetBinding* pBindings, int renderTargetCount)
1825 {
1826 IntPtr intPtr = (IntPtr)pComPtr;
1827 Helpers.CheckDisposed(this, intPtr);
1828 if (renderTargetCount == currentRenderTargetCount)
1829 {
1830 int num = 0;
1831 if (0 >= renderTargetCount)
1832 {
1833 return;
1834 }
1837 RenderTargetBinding* ptr = pBindings;
1838 while (ptr->_renderTarget == array[num]._renderTarget && ptr->_cubeMapFace == array[num]._cubeMapFace)
1839 {
1840 num++;
1841 ptr = (RenderTargetBinding*)(num2 + (byte*)ptr);
1842 if (num >= renderTargetCount)
1843 {
1844 return;
1845 }
1846 }
1847 if (num >= renderTargetCount)
1848 {
1849 return;
1850 }
1851 }
1852 int maxRenderTargets = _profileCapabilities.MaxRenderTargets;
1853 if (renderTargetCount > maxRenderTargets)
1854 {
1856 }
1857 int num3 = 0;
1858 if (0 < renderTargetCount)
1859 {
1860 do
1861 {
1862 Texture renderTarget = ((RenderTargetBinding*)(System.Runtime.CompilerServices.Unsafe.SizeOf<RenderTargetBinding>() * num3 + (byte*)pBindings))->_renderTarget;
1863 if (renderTarget != null)
1864 {
1865 IntPtr intPtr2 = (IntPtr)renderTarget.GetComPtr();
1866 Helpers.CheckDisposed(renderTarget, intPtr2);
1867 if (renderTarget.GraphicsDevice == this)
1868 {
1869 if (num3 > 0)
1870 {
1871 int num4 = 0;
1872 if (0 < num3)
1873 {
1875 RenderTargetBinding* ptr2 = pBindings;
1876 do
1877 {
1878 if (renderTarget != ptr2->_renderTarget)
1879 {
1880 num4++;
1881 ptr2 = (RenderTargetBinding*)(num5 + (byte*)ptr2);
1882 continue;
1883 }
1885 }
1886 while (num4 < num3);
1887 }
1888 if (!RenderTargetHelper.IsSameSize(renderTarget, pBindings->_renderTarget))
1889 {
1891 }
1892 }
1893 num3++;
1894 continue;
1895 }
1897 }
1899 }
1900 while (num3 < renderTargetCount);
1901 }
1902 if (currentRenderTargetCount <= 0)
1903 {
1905 }
1906 else
1907 {
1908 if (lazyClearFlags != 0)
1909 {
1911 }
1912 int num6 = 0;
1914 {
1915 do
1916 {
1917 ResolveRenderTarget(num6);
1918 num6++;
1919 }
1920 while (num6 < currentRenderTargetCount);
1921 }
1922 }
1923 int num7 = 0;
1924 willItBlend = true;
1925 currentViewport = default(Viewport);
1926 currentViewport.MaxDepth = 1f;
1927 if (renderTargetCount <= 0)
1928 {
1929 IDirect3DSurface9* ptr3 = null;
1930 IDirect3DDevice9* ptr4 = pComPtr;
1931 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, uint, _D3DBACKBUFFER_TYPE, IDirect3DSurface9**, int>)(int)(*(uint*)(*(int*)ptr4 + 72)))((nint)ptr4, 0u, 0u, (_D3DBACKBUFFER_TYPE)0, &ptr3);
1932 IDirect3DDevice9* ptr5 = pComPtr;
1933 num7 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, IDirect3DSurface9*, int>)(int)(*(uint*)(*(int*)ptr5 + 148)))((nint)ptr5, 0u, ptr3);
1934 if (ptr3 != null)
1935 {
1936 IDirect3DSurface9* intPtr3 = ptr3;
1937 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)intPtr3 + 8)))((nint)intPtr3);
1938 ptr3 = null;
1939 }
1940 if (num7 >= 0)
1941 {
1942 ptr5 = pComPtr;
1943 num7 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, IDirect3DSurface9*, int>)(int)(*(uint*)(*(int*)ptr5 + 156)))((nint)ptr5, pImplicitDepthSurface);
1944 }
1946 {
1947 lazyClearFlags = 7;
1948 }
1949 else
1950 {
1952 }
1953 currentViewport.Width = pInternalCachedParams.BackBufferWidth;
1954 currentViewport.Height = pInternalCachedParams.BackBufferHeight;
1955 }
1956 else
1957 {
1958 lazyClearFlags = 0;
1959 int num8 = 0;
1960 if (0 < renderTargetCount)
1961 {
1962 do
1963 {
1964 Texture renderTarget2 = ((RenderTargetBinding*)(System.Runtime.CompilerServices.Unsafe.SizeOf<RenderTargetBinding>() * num8 + (byte*)pBindings))->_renderTarget;
1965 RenderTargetHelper renderTargetHelper = RenderTargetHelper.FromRenderTarget(renderTarget2);
1966 currentRenderTargets[num8] = renderTargetHelper;
1967 ref RenderTargetBinding reference = ref currentRenderTargetBindings[num8];
1969 renderTarget2.isActiveRenderTarget = true;
1970 if (!renderTargetHelper.willItBlend)
1971 {
1972 willItBlend = false;
1973 whyWontItBlend = renderTargetHelper.format;
1974 }
1975 if (num7 >= 0)
1976 {
1977 IDirect3DSurface9* renderTargetSurface = renderTargetHelper.GetRenderTargetSurface(((RenderTargetBinding*)(System.Runtime.CompilerServices.Unsafe.SizeOf<RenderTargetBinding>() * num8 + (byte*)pBindings))->_cubeMapFace);
1978 IDirect3DDevice9* ptr6 = pComPtr;
1979 num7 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, IDirect3DSurface9*, int>)(int)(*(uint*)(*(int*)ptr6 + 148)))((nint)ptr6, (uint)num8, renderTargetSurface);
1980 if (renderTargetSurface != null)
1981 {
1982 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)renderTargetSurface + 8)))((nint)renderTargetSurface);
1983 }
1984 if (num7 >= 0 && num8 == 0)
1985 {
1986 IDirect3DDevice9* ptr7 = pComPtr;
1987 num7 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, IDirect3DSurface9*, int>)(int)(*(uint*)(*(int*)ptr7 + 156)))((nint)ptr7, renderTargetHelper.pDepthSurface);
1988 }
1989 }
1990 if (renderTargetHelper.usage == RenderTargetUsage.DiscardContents)
1991 {
1992 int num9 = (lazyClearFlags |= 1);
1993 if (num8 == 0)
1994 {
1995 lazyClearFlags = num9 | 6;
1996 }
1997 }
1998 else if (renderTargetHelper.pRenderTargetSurface != null && (renderTargetHelper.isCubemap || renderTarget2.renderTargetContentsDirty) && num7 >= 0)
1999 {
2000 if (_insideScene)
2001 {
2002 IDirect3DDevice9* intPtr4 = pComPtr;
2003 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, int>)(int)(*(uint*)(*(int*)intPtr4 + 168)))((nint)intPtr4);
2004 }
2005 IDirect3DSurface9* destinationSurface = renderTargetHelper.GetDestinationSurface(((RenderTargetBinding*)(System.Runtime.CompilerServices.Unsafe.SizeOf<RenderTargetBinding>() * num8 + (byte*)pBindings))->_cubeMapFace, 0);
2006 IDirect3DSurface9* pRenderTargetSurface = renderTargetHelper.pRenderTargetSurface;
2007 IDirect3DDevice9* ptr8 = pComPtr;
2008 int num10 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, IDirect3DSurface9*, tagRECT*, IDirect3DSurface9*, tagRECT*, _D3DTEXTUREFILTERTYPE, int>)(int)(*(uint*)(*(int*)ptr8 + 136)))((nint)ptr8, destinationSurface, null, pRenderTargetSurface, null, (_D3DTEXTUREFILTERTYPE)0);
2009 num7 = ((num10 < 0) ? _003CModule_003E.D3DXLoadSurfaceFromSurface(pRenderTargetSurface, null, null, destinationSurface, null, null, uint.MaxValue, 0u) : num10);
2010 if (destinationSurface != null)
2011 {
2012 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)destinationSurface + 8)))((nint)destinationSurface);
2013 }
2014 if (num7 >= 0)
2015 {
2016 renderTarget2.renderTargetContentsDirty = false;
2017 }
2018 if (_insideScene)
2019 {
2020 IDirect3DDevice9* intPtr5 = pComPtr;
2021 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, int>)(int)(*(uint*)(*(int*)intPtr5 + 164)))((nint)intPtr5);
2022 }
2023 }
2024 num8++;
2025 }
2026 while (num8 < renderTargetCount);
2027 }
2028 currentViewport.Width = currentRenderTargets[0].width;
2029 currentViewport.Height = currentRenderTargets[0].height;
2030 }
2031 int num11 = renderTargetCount;
2032 if (renderTargetCount < currentRenderTargetCount)
2033 {
2034 do
2035 {
2036 currentRenderTargets[num11] = null;
2038 if (num11 > 0)
2039 {
2040 IDirect3DDevice9* ptr9 = pComPtr;
2041 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, IDirect3DSurface9*, int>)(int)(*(uint*)(*(int*)ptr9 + 148)))((nint)ptr9, (uint)num11, null);
2042 }
2043 num11++;
2044 }
2045 while (num11 < currentRenderTargetCount);
2046 }
2047 currentRenderTargetCount = renderTargetCount;
2049 if (num7 < 0)
2050 {
2051 throw GraphicsHelpers.GetExceptionFromResult((uint)num7);
2052 }
2053 }
2054
2055 private unsafe void ResolveRenderTarget(int index)
2056 {
2057 int num = 0;
2058 RenderTargetHelper renderTargetHelper = currentRenderTargets[index];
2060 Texture renderTarget = array[index]._renderTarget;
2061 CubeMapFace cubeMapFace = array[index]._cubeMapFace;
2062 renderTarget.isActiveRenderTarget = false;
2063 if (renderTarget.GetComPtr() == null)
2064 {
2065 return;
2066 }
2067 if (_insideScene)
2068 {
2069 IDirect3DDevice9* intPtr = pComPtr;
2070 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, int>)(int)(*(uint*)(*(int*)intPtr + 168)))((nint)intPtr);
2071 }
2072 IDirect3DSurface9* ptr = renderTargetHelper.GetDestinationSurface(cubeMapFace, 0);
2073 IDirect3DSurface9* pRenderTargetSurface = renderTargetHelper.pRenderTargetSurface;
2074 if (pRenderTargetSurface != null)
2075 {
2076 IDirect3DSurface9* ptr2 = pRenderTargetSurface;
2077 IDirect3DDevice9* ptr3 = pComPtr;
2078 int num2 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, IDirect3DSurface9*, tagRECT*, IDirect3DSurface9*, tagRECT*, _D3DTEXTUREFILTERTYPE, int>)(int)(*(uint*)(*(int*)ptr3 + 136)))((nint)ptr3, ptr2, null, ptr, null, (_D3DTEXTUREFILTERTYPE)2);
2079 if (num2 >= 0)
2080 {
2081 num = num2;
2082 }
2083 else
2084 {
2085 IDirect3DDevice9* ptr4 = pComPtr;
2086 int num3 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, IDirect3DSurface9*, tagRECT*, IDirect3DSurface9*, tagRECT*, _D3DTEXTUREFILTERTYPE, int>)(int)(*(uint*)(*(int*)ptr4 + 136)))((nint)ptr4, ptr2, null, ptr, null, (_D3DTEXTUREFILTERTYPE)0);
2087 num = ((num3 < 0) ? _003CModule_003E.D3DXLoadSurfaceFromSurface(ptr, null, null, ptr2, null, null, uint.MaxValue, 0u) : num3);
2088 }
2089 }
2090 uint levelCount = (uint)renderTarget.LevelCount;
2091 uint num4 = 1u;
2092 if (1 < levelCount)
2093 {
2094 do
2095 {
2096 if (num >= 0)
2097 {
2098 IDirect3DSurface9* destinationSurface = renderTargetHelper.GetDestinationSurface(cubeMapFace, (int)num4);
2099 IDirect3DDevice9* ptr5 = pComPtr;
2100 int num5 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, IDirect3DSurface9*, tagRECT*, IDirect3DSurface9*, tagRECT*, _D3DTEXTUREFILTERTYPE, int>)(int)(*(uint*)(*(int*)ptr5 + 136)))((nint)ptr5, ptr, null, destinationSurface, null, (_D3DTEXTUREFILTERTYPE)2);
2101 if (num5 >= 0)
2102 {
2103 num = num5;
2104 }
2105 else
2106 {
2107 ptr5 = pComPtr;
2108 num5 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, IDirect3DSurface9*, tagRECT*, IDirect3DSurface9*, tagRECT*, _D3DTEXTUREFILTERTYPE, int>)(int)(*(uint*)(*(int*)ptr5 + 136)))((nint)ptr5, ptr, null, destinationSurface, null, (_D3DTEXTUREFILTERTYPE)0);
2109 num = ((num5 < 0) ? _003CModule_003E.D3DXLoadSurfaceFromSurface(destinationSurface, null, null, ptr, null, null, uint.MaxValue, 0u) : num5);
2110 }
2111 if (ptr != null)
2112 {
2113 IDirect3DSurface9* intPtr2 = ptr;
2114 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)intPtr2 + 8)))((nint)intPtr2);
2115 }
2116 ptr = destinationSurface;
2117 }
2118 num4++;
2119 }
2120 while (num4 < levelCount);
2121 }
2122 if (ptr != null)
2123 {
2124 IDirect3DSurface9* intPtr3 = ptr;
2125 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)intPtr3 + 8)))((nint)intPtr3);
2126 }
2127 if (_insideScene)
2128 {
2129 IDirect3DDevice9* intPtr4 = pComPtr;
2130 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, int>)(int)(*(uint*)(*(int*)intPtr4 + 164)))((nint)intPtr4);
2131 }
2132 if (num < 0)
2133 {
2134 throw GraphicsHelpers.GetExceptionFromResult((uint)num);
2135 }
2136 }
2137
2138 private unsafe void ClearDirtyBuffers()
2139 {
2140 Color color = new Color(68, 34, 136, 255);
2141 int num = currentRenderTargetCount;
2142 if (num <= 0)
2143 {
2144 Clear((ClearOptions)lazyClearFlags, color, 1f, 0);
2145 }
2146 else
2147 {
2148 if (((uint)lazyClearFlags & (true ? 1u : 0u)) != 0)
2149 {
2150 int num2 = 0;
2151 if (0 < num)
2152 {
2153 do
2154 {
2155 RenderTargetHelper renderTargetHelper = currentRenderTargets[num2];
2156 if (renderTargetHelper.usage == RenderTargetUsage.DiscardContents)
2157 {
2158 IDirect3DSurface9* renderTargetSurface = renderTargetHelper.GetRenderTargetSurface(currentRenderTargetBindings[num2]._cubeMapFace);
2159 uint num3 = (uint)(color.A << 8);
2160 uint num4 = (color.R | num3) << 8;
2161 uint num5 = (color.G | num4) << 8;
2162 uint num6 = color.B | num5;
2163 IDirect3DDevice9* ptr = pComPtr;
2164 int num7 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, IDirect3DSurface9*, tagRECT*, uint, int>)(int)(*(uint*)(*(int*)ptr + 140)))((nint)ptr, renderTargetSurface, null, num6);
2165 if (renderTargetSurface != null)
2166 {
2167 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)renderTargetSurface + 8)))((nint)renderTargetSurface);
2168 }
2169 if (num7 < 0)
2170 {
2171 throw GraphicsHelpers.GetExceptionFromResult((uint)num7);
2172 }
2173 }
2174 num2++;
2175 }
2176 while (num2 < currentRenderTargetCount);
2177 }
2178 }
2179 int num8 = lazyClearFlags & 6;
2180 if (num8 != 0)
2181 {
2182 Clear((ClearOptions)num8, color, 1f, 0);
2183 }
2184 }
2185 lazyClearFlags = 0;
2186 }
2187
2188 public unsafe void SetRenderTarget(RenderTargetCube renderTarget, CubeMapFace cubeMapFace)
2189 {
2190 if (renderTarget != null)
2191 {
2192 RenderTargetBinding renderTargetBinding = new RenderTargetBinding(renderTarget, cubeMapFace);
2193 SetRenderTargets(&renderTargetBinding, 1);
2194 }
2195 else
2196 {
2197 SetRenderTargets(null, 0);
2198 }
2199 }
2200
2201 public unsafe void SetRenderTarget(RenderTarget2D renderTarget)
2202 {
2203 if (renderTarget != null)
2204 {
2205 RenderTargetBinding renderTargetBinding = new RenderTargetBinding(renderTarget);
2206 SetRenderTargets(&renderTargetBinding, 1);
2207 }
2208 else
2209 {
2210 SetRenderTargets(null, 0);
2211 }
2212 }
2213
2221
2222 public unsafe void GetBackBufferData<T>(Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct
2223 {
2224 IntPtr intPtr = (IntPtr)pComPtr;
2225 Helpers.CheckDisposed(this, intPtr);
2227 {
2229 }
2230 if (data != null)
2231 {
2232 int num = data.Length;
2233 if (num != 0)
2234 {
2235 Helpers.ValidateCopyParameters(num, startIndex, elementCount);
2237 {
2239 }
2240 if (lazyClearFlags != 0)
2241 {
2243 }
2244 IDirect3DSurface9* ptr = null;
2245 IDirect3DTexture9* ptr2 = null;
2246 IDirect3DSurface9* ptr3 = null;
2247 bool flag = false;
2248 try
2249 {
2250 IDirect3DDevice9* ptr4 = pComPtr;
2251 int num2 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, uint, _D3DBACKBUFFER_TYPE, IDirect3DSurface9**, int>)(int)(*(uint*)(*(int*)ptr4 + 72)))((nint)ptr4, 0u, 0u, (_D3DBACKBUFFER_TYPE)0, &ptr);
2252 if (num2 >= 0)
2253 {
2254 System.Runtime.CompilerServices.Unsafe.SkipInit(out _D3DSURFACE_DESC d3DSURFACE_DESC);
2255 num2 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DSURFACE_DESC*, int>)(int)(*(uint*)(*(int*)ptr + 48)))((nint)ptr, &d3DSURFACE_DESC);
2256 if (num2 >= 0)
2257 {
2258 System.Runtime.CompilerServices.Unsafe.SkipInit(out uint dwFormatSize);
2259 System.Runtime.CompilerServices.Unsafe.SkipInit(out uint dwElementSize);
2260 Texture.GetAndValidateSizes<T>(&d3DSURFACE_DESC, &dwFormatSize, &dwElementSize);
2261 System.Runtime.CompilerServices.Unsafe.SkipInit(out uint dwLockWidth);
2262 System.Runtime.CompilerServices.Unsafe.SkipInit(out uint dwLockHeight);
2263 Texture.GetAndValidateRect(&d3DSURFACE_DESC, &dwLockWidth, &dwLockHeight, rect);
2264 Texture.ValidateTotalSize(&d3DSURFACE_DESC, dwLockWidth, dwLockHeight, dwFormatSize, dwElementSize, (uint)elementCount);
2265 if (_insideScene)
2266 {
2267 ptr4 = pComPtr;
2268 IDirect3DDevice9* intPtr2 = ptr4;
2269 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, int>)(int)(*(uint*)(*(int*)intPtr2 + 168)))((nint)intPtr2);
2270 flag = true;
2271 }
2272 ptr4 = pComPtr;
2273 num2 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, uint, uint, uint, _D3DFORMAT, _D3DPOOL, IDirect3DTexture9**, void**, int>)(int)(*(uint*)(*(int*)ptr4 + 92)))((nint)ptr4, System.Runtime.CompilerServices.Unsafe.As<_D3DSURFACE_DESC, uint>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DSURFACE_DESC, 24)), System.Runtime.CompilerServices.Unsafe.As<_D3DSURFACE_DESC, uint>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DSURFACE_DESC, 28)), 1u, 0u, *(_D3DFORMAT*)(&d3DSURFACE_DESC), (_D3DPOOL)2, &ptr2, null);
2274 if (num2 >= 0)
2275 {
2276 num2 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, IDirect3DSurface9**, int>)(int)(*(uint*)(*(int*)ptr2 + 72)))((nint)ptr2, 0u, &ptr3);
2277 if (num2 >= 0)
2278 {
2279 num2 = _003CModule_003E.D3DXLoadSurfaceFromSurface(ptr3, null, null, ptr, null, null, uint.MaxValue, 0u);
2280 if (num2 >= 0)
2281 {
2282 tagRECT* ptr5 = null;
2283 Rectangle rectangle = default(Rectangle);
2284 if (rect.HasValue)
2285 {
2286 rectangle = rect.Value;
2287 ptr5 = (tagRECT*)(int)(ref rectangle);
2288 if (ptr5 != null)
2289 {
2290 *(int*)((byte*)ptr5 + 8) += *(int*)ptr5;
2291 *(int*)((byte*)ptr5 + 12) += *(int*)((byte*)ptr5 + 4);
2292 }
2293 }
2294 System.Runtime.CompilerServices.Unsafe.SkipInit(out _D3DLOCKED_RECT d3DLOCKED_RECT);
2295 num2 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DLOCKED_RECT*, tagRECT*, uint, int>)(int)(*(uint*)(*(int*)ptr3 + 52)))((nint)ptr3, &d3DLOCKED_RECT, ptr5, 0u);
2296 if (num2 >= 0)
2297 {
2298 try
2299 {
2300 Texture.CopyData((void*)(int)System.Runtime.CompilerServices.Unsafe.As<_D3DLOCKED_RECT, uint>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DLOCKED_RECT, 4)), *(int*)(&d3DLOCKED_RECT), data, startIndex, elementCount, &d3DSURFACE_DESC, dwLockWidth, dwLockHeight, isSetting: false);
2301 }
2302 finally
2303 {
2304 IDirect3DSurface9* intPtr3 = ptr3;
2305 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, int>)(int)(*(uint*)(*(int*)intPtr3 + 56)))((nint)intPtr3);
2306 }
2308 {
2310 }
2311 if (num2 >= 0)
2312 {
2313 return;
2314 }
2315 }
2316 }
2317 }
2318 }
2319 }
2320 }
2321 throw GraphicsHelpers.GetExceptionFromResult((uint)num2);
2322 }
2323 finally
2324 {
2325 if (ptr3 != null)
2326 {
2327 IDirect3DSurface9* intPtr4 = ptr3;
2328 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)intPtr4 + 8)))((nint)intPtr4);
2329 ptr3 = null;
2330 }
2331 if (ptr2 != null)
2332 {
2333 IDirect3DTexture9* intPtr5 = ptr2;
2334 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)intPtr5 + 8)))((nint)intPtr5);
2335 ptr2 = null;
2336 }
2337 if (ptr != null)
2338 {
2339 IDirect3DSurface9* intPtr6 = ptr;
2340 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)intPtr6 + 8)))((nint)intPtr6);
2341 ptr = null;
2342 }
2343 if (flag)
2344 {
2345 IDirect3DDevice9* intPtr7 = pComPtr;
2346 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, int>)(int)(*(uint*)(*(int*)intPtr7 + 164)))((nint)intPtr7);
2347 }
2348 }
2349 }
2350 }
2352 }
2353
2354 public void GetBackBufferData<T>(T[] data, int startIndex, int elementCount) where T : struct
2355 {
2356 GetBackBufferData(null, data, startIndex, elementCount);
2357 }
2358
2359 public void GetBackBufferData<T>(T[] data) where T : struct
2360 {
2361 int elementCount = ((data != null) ? data.Length : 0);
2362 GetBackBufferData(null, data, 0, elementCount);
2363 }
2364
2366 {
2367 int num = currentVertexBufferCount;
2370 return array;
2371 }
2372
2373 public unsafe void SetVertexBuffer(VertexBuffer vertexBuffer, int vertexOffset)
2374 {
2375 if (vertexBuffer != null)
2376 {
2377 VertexBufferBinding vertexBufferBinding = new VertexBufferBinding(vertexBuffer, vertexOffset);
2378 SetVertexBuffers(&vertexBufferBinding, 1);
2379 }
2380 else
2381 {
2382 SetVertexBuffers(null, 0);
2383 }
2384 }
2385
2386 public unsafe void SetVertexBuffer(VertexBuffer vertexBuffer)
2387 {
2388 if (vertexBuffer != null)
2389 {
2390 VertexBufferBinding vertexBufferBinding = new VertexBufferBinding(vertexBuffer);
2391 SetVertexBuffers(&vertexBufferBinding, 1);
2392 }
2393 else
2394 {
2395 SetVertexBuffers(null, 0);
2396 }
2397 }
2398
2399 internal unsafe void SetVertexBuffers(VertexBufferBinding* pBindings, int vertexBufferCount)
2400 {
2401 IntPtr intPtr = (IntPtr)pComPtr;
2402 Helpers.CheckDisposed(this, intPtr);
2403 int maxVertexStreams = _profileCapabilities.MaxVertexStreams;
2404 if (vertexBufferCount > maxVertexStreams)
2405 {
2407 }
2408 int i = 0;
2409 try
2410 {
2411 for (i = 0; i < vertexBufferCount; i++)
2412 {
2413 VertexBuffer vertexBuffer = ((VertexBufferBinding*)(System.Runtime.CompilerServices.Unsafe.SizeOf<VertexBufferBinding>() * i + (byte*)pBindings))->_vertexBuffer;
2414 if (vertexBuffer == null)
2415 {
2417 }
2418 IntPtr intPtr2 = (IntPtr)vertexBuffer.pComPtr;
2419 IntPtr intPtr3 = intPtr2;
2420 Helpers.CheckDisposed(vertexBuffer, intPtr2);
2421 if (vertexBuffer.GraphicsDevice != this)
2422 {
2424 }
2426 VertexBuffer vertexBuffer2 = array[i]._vertexBuffer;
2428 int vertexOffset = ptr->_vertexOffset;
2429 int instanceFrequency = ptr->_instanceFrequency;
2430 if (vertexBuffer != vertexBuffer2 || vertexOffset != array[i]._vertexOffset || instanceFrequency != array[i]._instanceFrequency)
2431 {
2432 int vertexStride = vertexBuffer._vertexDeclaration._vertexStride;
2433 IDirect3DDevice9* ptr2 = pComPtr;
2434 int num = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, IDirect3DVertexBuffer9*, uint, uint, int>)(int)(*(uint*)(*(int*)ptr2 + 400)))((nint)ptr2, (uint)i, vertexBuffer.pComPtr, (uint)(vertexStride * vertexOffset), (uint)vertexStride);
2435 if (num < 0)
2436 {
2437 throw GraphicsHelpers.GetExceptionFromResult((uint)num);
2438 }
2439 ref VertexBufferBinding reference = ref currentVertexBuffers[i];
2441 if (instanceFrequency != 0)
2442 {
2443 instanceStreamMask |= 1 << i;
2444 }
2445 else
2446 {
2447 instanceStreamMask &= ~(1 << i);
2448 }
2449 }
2450 }
2451 }
2452 finally
2453 {
2454 int num2 = i;
2456 {
2457 do
2458 {
2459 IDirect3DDevice9* ptr2 = pComPtr;
2460 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, IDirect3DVertexBuffer9*, uint, uint, int>)(int)(*(uint*)(*(int*)ptr2 + 400)))((nint)ptr2, (uint)num2, null, 0u, 0u);
2462 instanceStreamMask &= ~(1 << num2);
2463 num2++;
2464 }
2465 while (num2 < currentVertexBufferCount);
2466 }
2468 }
2469 if (vertexBufferCount > 0)
2470 {
2471 vertexDeclarationManager.SetVertexDeclaration(pBindings, vertexBufferCount);
2472 }
2473 }
2474
2475 public unsafe void SetVertexBuffers(params VertexBufferBinding[] vertexBuffers)
2476 {
2477 if (vertexBuffers != null && (nint)vertexBuffers.LongLength > 0)
2478 {
2479 fixed (VertexBufferBinding* pBindings = &vertexBuffers[0])
2480 {
2481 try
2482 {
2483 SetVertexBuffers(pBindings, vertexBuffers.Length);
2484 }
2485 catch
2486 {
2487 //try-fault
2488 pBindings = null;
2489 throw;
2490 }
2491 }
2492 }
2493 else
2494 {
2495 SetVertexBuffers(null, 0);
2496 }
2497 }
2498
2499 internal uint GetBufferUsage(uint usage)
2500 {
2501 usage = (((_creationFlags & 0x20) == 0) ? (usage & 0xFFFFFFEFu) : (usage | 0x10u));
2502 return usage;
2503 }
2504
2505 private unsafe int CopySurface(IDirect3DSurface9* pSourceSurface, IDirect3DSurface9* pDestinationSurface, [MarshalAs(UnmanagedType.U1)] bool useFilter)
2506 {
2507 IDirect3DDevice9* ptr;
2508 int num;
2509 if (useFilter)
2510 {
2511 ptr = pComPtr;
2512 num = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, IDirect3DSurface9*, tagRECT*, IDirect3DSurface9*, tagRECT*, _D3DTEXTUREFILTERTYPE, int>)(int)(*(uint*)(*(int*)ptr + 136)))((nint)ptr, pSourceSurface, null, pDestinationSurface, null, (_D3DTEXTUREFILTERTYPE)2);
2513 if (num >= 0)
2514 {
2515 return num;
2516 }
2517 }
2518 ptr = pComPtr;
2519 num = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, IDirect3DSurface9*, tagRECT*, IDirect3DSurface9*, tagRECT*, _D3DTEXTUREFILTERTYPE, int>)(int)(*(uint*)(*(int*)ptr + 136)))((nint)ptr, pSourceSurface, null, pDestinationSurface, null, (_D3DTEXTUREFILTERTYPE)0);
2520 if (num >= 0)
2521 {
2522 return num;
2523 }
2524 return _003CModule_003E.D3DXLoadSurfaceFromSurface(pDestinationSurface, null, null, pSourceSurface, null, null, uint.MaxValue, 0u);
2525 }
2526
2543
2544 [SpecialName]
2545 protected void raise_Disposing(object value0, EventArgs value1)
2546 {
2547 _003Cbacking_store_003EDisposing?.Invoke(value0, value1);
2548 }
2549
2550 private unsafe void _0021GraphicsDevice()
2551 {
2552 if (!isDisposed)
2553 {
2554 isDisposed = true;
2557 IDirect3DSurface9* ptr = pImplicitDepthSurface;
2558 if (ptr != null)
2559 {
2560 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)ptr + 8)))((nint)ptr);
2561 pImplicitDepthSurface = null;
2562 }
2564 if (ptr2 != null)
2565 {
2566 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)ptr2 + 8)))((nint)ptr2);
2567 pStateTracker = null;
2568 }
2569 IDirect3DDevice9* ptr3 = pComPtr;
2570 if (ptr3 != null)
2571 {
2572 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)ptr3 + 8)))((nint)ptr3);
2573 pComPtr = null;
2574 }
2575 }
2576 }
2577
2578 private void _007EGraphicsDevice()
2579 {
2580 if (!isDisposed)
2581 {
2583 EventArgs empty = EventArgs.Empty;
2584 _003Cbacking_store_003EDisposing?.Invoke(this, empty);
2585 }
2586 }
2587
2588 internal unsafe static GraphicsDevice GetManagedObject(IDirect3DDevice9* pInterface, GraphicsDevice pDevice, uint pool)
2589 {
2590 GraphicsDevice graphicsDevice = pDevice.pResourceManager.GetCachedObject(pInterface) as GraphicsDevice;
2591 if (graphicsDevice != null)
2592 {
2593 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)pInterface + 8)))((nint)pInterface);
2594 graphicsDevice.isDisposed = false;
2595 GC.ReRegisterForFinalize(graphicsDevice);
2596 }
2597 else
2598 {
2599 graphicsDevice = new GraphicsDevice(pInterface, pDevice);
2600 pDevice.pResourceManager.AddTrackedObject(graphicsDevice, pInterface, pool, 0uL, ref graphicsDevice._internalHandle);
2601 }
2602 return graphicsDevice;
2603 }
2604
2605 private void OnObjectCreation()
2606 {
2608 }
2609
2610 [SpecialName]
2611 internal void raise_DrawGuide(object sender, EventArgs e)
2612 {
2613 _DrawGuideHandler?.Invoke(sender, e);
2614 }
2615
2616 [HandleProcessCorruptedStateExceptions]
2617 protected virtual void Dispose([MarshalAs(UnmanagedType.U1)] bool P_0)
2618 {
2619 if (P_0)
2620 {
2621 try
2622 {
2624 return;
2625 }
2626 finally
2627 {
2628 ((IDisposable)d3dCaps).Dispose();
2629 }
2630 }
2631 try
2632 {
2634 }
2635 finally
2636 {
2637 base.Finalize();
2638 }
2639 }
2640
2641 public virtual sealed void Dispose()
2642 {
2643 Dispose(true);
2644 GC.SuppressFinalize(this);
2645 }
2646
2648 {
2649 Dispose(false);
2650 }
2651}
static readonly BlendState Opaque
Definition BlendState.cs:34
unsafe void SetVertexDeclaration(VertexBufferBinding *vertexBuffers, int count)
void RecreateResources(_D3DPOOL pool, [MarshalAs(UnmanagedType.U1)] bool deviceRecreated)
unsafe void AddTrackedObject(object managedObject, void *pComPtr, uint resourceManagementMode, ulong handle, ref ulong updatedHandle)
unsafe bool IsProfileSupported(_D3DDEVTYPE deviceType, GraphicsProfile graphicsProfile)
bool QueryFormat([MarshalAs(UnmanagedType.U1)] bool isBackBuffer, _D3DDEVTYPE deviceType, GraphicsProfile graphicsProfile, SurfaceFormat format, DepthFormat depthFormat, int multiSampleCount, out SurfaceFormat selectedFormat, out DepthFormat selectedDepthFormat, out int selectedMultiSampleCount)
unsafe void SetRenderTargets(params RenderTargetBinding[] renderTargets)
void raise_ResourceDestroyed(object value0, ResourceDestroyedEventArgs value1)
void raise_DeviceResetting(object value0, EventArgs value1)
unsafe void BeginUserPrimitives(VertexDeclaration vertexDeclaration)
uint GetElementCountFromPrimitiveType(PrimitiveType primitiveType, int primitiveCount)
EventHandler< EventArgs > _003Cbacking_store_003EDeviceReset
unsafe void Present(tagRECT *pSource, tagRECT *pDest, HWND__ *hOverride)
EventHandler< EventArgs > _003Cbacking_store_003EDisposing
unsafe void SetRenderTargets(RenderTargetBinding *pBindings, int renderTargetCount)
void DrawUserPrimitives< T >(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int primitiveCount)
void raise_ResourceCreated(object value0, ResourceCreatedEventArgs value1)
void raise_DrawGuide(object sender, EventArgs e)
void Clear(ClearOptions options, Vector4 color, float depth, int stencil)
unsafe void GetBackBufferData< T >(Rectangle? rect, T[] data, int startIndex, int elementCount)
unsafe void VerifyCanDraw([MarshalAs(UnmanagedType.U1)] bool bUserPrimitives, [MarshalAs(UnmanagedType.U1)] bool bIndexedPrimitives)
readonly EmbeddedNativeType_003C_D3DCAPS9_003E d3dCaps
unsafe void CreateDevice(GraphicsAdapter adapter, PresentationParameters presentationParameters)
virtual void Dispose([MarshalAs(UnmanagedType.U1)] bool P_0)
unsafe void SetVertexBuffers(VertexBufferBinding *pBindings, int vertexBufferCount)
EventHandler< ResourceCreatedEventArgs > _003Cbacking_store_003EResourceCreated
void FireDestroyedEvent(string name, object tag)
void raise_Disposing(object value0, EventArgs value1)
unsafe void SetRenderTarget(RenderTargetCube renderTarget, CubeMapFace cubeMapFace)
EventHandler< ResourceDestroyedEventArgs > _003Cbacking_store_003EResourceDestroyed
unsafe void SetRenderTarget(RenderTarget2D renderTarget)
void raise_DeviceReset(object value0, EventArgs value1)
unsafe void SetVertexBuffer(VertexBuffer vertexBuffer, int vertexOffset)
unsafe void Reset(PresentationParameters presentationParameters, GraphicsAdapter graphicsAdapter)
unsafe void ConvertPresentationParametersToManaged(_D3DPRESENT_PARAMETERS_ *pp, PresentationParameters presentationParameters)
unsafe void Clear(ClearOptions options, Color color, float depth, int stencil)
unsafe int CopySurface(IDirect3DSurface9 *pSourceSurface, IDirect3DSurface9 *pDestinationSurface, [MarshalAs(UnmanagedType.U1)] bool useFilter)
GraphicsDevice(GraphicsAdapter adapter, GraphicsProfile graphicsProfile, PresentationParameters presentationParameters)
void DrawUserIndexedPrimitives< T >(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int numVertices, int[] indexData, int indexOffset, int primitiveCount)
static unsafe GraphicsDevice GetManagedObject(IDirect3DDevice9 *pInterface, GraphicsDevice pDevice, uint pool)
unsafe GraphicsDevice(IDirect3DDevice9 *pInterface, GraphicsDevice pDevice)
EventHandler< ResourceDestroyedEventArgs > ResourceDestroyed
unsafe void SetVertexBuffers(params VertexBufferBinding[] vertexBuffers)
void raise_DeviceLost(object value0, EventArgs value1)
unsafe void SetVertexBuffer(VertexBuffer vertexBuffer)
EventHandler< EventArgs > _003Cbacking_store_003EDeviceResetting
EventHandler< ResourceCreatedEventArgs > ResourceCreated
unsafe void DrawIndexedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices, int startIndex, int primitiveCount)
unsafe void DrawPrimitives(PrimitiveType primitiveType, int startVertex, int primitiveCount)
unsafe void ConvertPresentationParametersToNative(GraphicsAdapter adapter, PresentationParameters presentationParameters, _D3DPRESENT_PARAMETERS_ *pp)
void Reset(PresentationParameters presentationParameters)
unsafe void Present(Rectangle? sourceRectangle, Rectangle? destinationRectangle, IntPtr overrideWindowHandle)
unsafe void DrawInstancedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices, int startIndex, int primitiveCount, int instanceCount)
EventHandler< EventArgs > _003Cbacking_store_003EDeviceLost
static Exception GetExceptionFromResult(uint result)
static ProfileCapabilities GetInstance(GraphicsProfile graphicsProfile)
static readonly RasterizerState CullCounterClockwise
unsafe IDirect3DSurface9 * GetRenderTargetSurface(CubeMapFace faceType)
static RenderTargetHelper FromRenderTarget(Texture renderTarget)
unsafe IDirect3DSurface9 * GetDestinationSurface(CubeMapFace faceType, int mipLevel)
static bool IsSameSize(Texture renderTargetA, Texture renderTargetB)
unsafe IDirect3DBaseTexture9 * GetComPtr()
static unsafe void GetAndValidateRect(_D3DSURFACE_DESC *__unnamed000, uint *pdwLockWidth, uint *pdwLockHeight, Rectangle? rect)
Definition Texture.cs:221
static unsafe void ValidateTotalSize(_D3DSURFACE_DESC *__unnamed000, uint dwLockWidth, uint dwLockHeight, uint dwFormatSize, uint dwElementSize, uint elementCount)
Definition Texture.cs:253
unsafe IDirect3DVertexBuffer9 * pComPtr
static void CheckDisposed(object obj, IntPtr pComPtr)
Definition Helpers.cs:188
static void ValidateCopyParameters(int dataLength, int dataIndex, int elementCount)
Definition Helpers.cs:66
static void ValidateOrientation(DisplayOrientation orientation)
Definition Helpers.cs:196
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
static ? Delegate Remove(Delegate? source, Delegate? value)
Definition Delegate.cs:463
static ? Delegate Combine(Delegate? a, Delegate? b)
Definition Delegate.cs:379
static readonly EventArgs Empty
Definition EventArgs.cs:9
static void SuppressFinalize(object obj)
Definition GC.cs:202
static void ReRegisterForFinalize(object obj)
Definition GC.cs:214
Definition GC.cs:8
static CultureInfo CurrentCulture
static unsafe void InitBlock(void *startAddress, byte value, uint byteCount)
Definition Unsafe.cs:117
static unsafe IntPtr UnsafeAddrOfPinnedArrayElement(Array arr, int index)
Definition Marshal.cs:775
void SetContentLost([MarshalAs(UnmanagedType.U1)] bool isContentLost)
static readonly IntPtr Zero
Definition IntPtr.cs:18
unsafe void * ToPointer()
Definition IntPtr.cs:210
static GCHandle Alloc(object? value)
Definition GCHandle.cs:81