using System; using System.Runtime.InteropServices; using FFXIVClientStructs.FFXIV.Client.Graphics.Kernel; using TerraFX.Interop.DirectX; namespace Auspex.Rendering.Direct3D; internal sealed class FrameRenderContext : IDisposable { public unsafe ID3D11Device* Device { get; private set; } public unsafe ID3D11DeviceContext* Context { get; private set; } public unsafe FrameRenderContext() { Device = (ID3D11Device*)FFXIVClientStructs.FFXIV.Client.Graphics.Kernel.Device.Instance()->D3D11Forwarder; Device->AddRef(); ID3D11DeviceContext* context = default(ID3D11DeviceContext*); Marshal.ThrowExceptionForHR(Device->CreateDeferredContext(0u, &context)); Context = context; } public unsafe void Dispose() { if (Context != null) { Context->Release(); Context = null; } if (Device != null) { Device->Release(); Device = null; } GC.SuppressFinalize(this); } public unsafe void Execute() { ID3D11CommandList* ptr = default(ID3D11CommandList*); Marshal.ThrowExceptionForHR(Context->FinishCommandList(false, &ptr)); ID3D11DeviceContext* ptr2 = default(ID3D11DeviceContext*); Device->GetImmediateContext(&ptr2); ptr2->ExecuteCommandList(ptr, true); ptr2->Release(); ptr->Release(); Context->ClearState(); } }