Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ CreateDevice()

unsafe void Microsoft.Xna.Framework.Graphics.GraphicsDevice.CreateDevice ( GraphicsAdapter adapter,
PresentationParameters presentationParameters )
inlineprivate

Definition at line 638 of file GraphicsDevice.cs.

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 {
714 StateTrackerDevice* ptr6 = pStateTracker;
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 }
726 _profileCapabilities.ThrowNotSupportedException(FrameworkResources.ProfileInvalidDevice);
727 }
728 }
729 try
730 {
731 return;
732 }
733 catch
734 {
735 //try-fault
736 throw;
737 }
738 }
readonly EmbeddedNativeType_003C_D3DCAPS9_003E d3dCaps
unsafe void ConvertPresentationParametersToManaged(_D3DPRESENT_PARAMETERS_ *pp, PresentationParameters presentationParameters)
unsafe void ConvertPresentationParametersToNative(GraphicsAdapter adapter, PresentationParameters presentationParameters, _D3DPRESENT_PARAMETERS_ *pp)
static unsafe void InitBlock(void *startAddress, byte value, uint byteCount)
Definition Unsafe.cs:117

References Microsoft.Xna.Framework.Graphics.GraphicsDevice._creationFlags, Microsoft.Xna.Framework.Graphics.GraphicsDevice._deviceType, Microsoft.Xna.Framework.Graphics.GraphicsDevice._profileCapabilities, Microsoft.Xna.Framework.Graphics.GraphicsAdapter.adapter, Microsoft.Xna.Framework.Graphics.GraphicsDevice.ConvertPresentationParametersToManaged(), Microsoft.Xna.Framework.Graphics.GraphicsDevice.ConvertPresentationParametersToNative(), Microsoft.Xna.Framework.Graphics.GraphicsDevice.d3dCaps, Microsoft.Xna.Framework.Graphics.GraphicsHelpers.GetExceptionFromResult(), System.Runtime.CompilerServices.Unsafe.InitBlock(), Microsoft.Xna.Framework.Graphics.ProfileCapabilities.OcclusionQuery, Microsoft.Xna.Framework.Graphics.GraphicsAdapter.pComPtr, Microsoft.Xna.Framework.Graphics.GraphicsDevice.pComPtr, Microsoft.Xna.Framework.Graphics.ProfileCapabilities.PixelShaderVersion, Microsoft.Xna.Framework.FrameworkResources.ProfileInvalidDevice, Microsoft.Xna.Framework.Graphics.GraphicsDevice.pStateTracker, Microsoft.Xna.Framework.Graphics.ProfileCapabilities.ThrowNotSupportedException(), and Microsoft.Xna.Framework.Graphics.ProfileCapabilities.VertexShaderVersion.

Referenced by Microsoft.Xna.Framework.Graphics.GraphicsDevice.GraphicsDevice(), and Microsoft.Xna.Framework.Graphics.GraphicsDevice.Reset().