Files
GhostEngine/Ghost.Graphics/Contracts/ISwapChainPanelNative.cs
Misaki 0720444c2c Refactor and enhance resource management and rendering
Updated multiple components to improve encapsulation, maintainability, and performance. Key changes include:

- Upgraded package dependencies in project files.
- Refactored `Mesh` and `RenderingContext` to use properties and added support for per-object constant buffers.
- Improved resource management in `D3D12CommandBuffer`, `D3D12CommandQueue`, and `D3D12ResourceAllocator` with better encapsulation and disposal handling.
- Added validation for constant buffer sizes in `D3D12PipelineLibrary`.
- Simplified `MeshBuilder` methods to accept allocators and removed hardcoded values.
- Enhanced debugging with `GPUResourceLeakException` and resource tracking updates.
- Updated shaders and rendering logic for testing, including hardcoded triangle rendering.
- Removed redundant base classes and interfaces for cleaner code structure.
2025-11-26 01:48:24 +09:00

74 lines
2.0 KiB
C#

using System.Runtime.InteropServices;
using TerraFX.Interop.Windows;
namespace Ghost.Graphics.Contracts;
public unsafe readonly struct ISwapChainPanelNative : ISwapChainPanelNative.Interface, IDisposable
{
[ComImport]
[Guid("63aad0b8-7c24-40ff-85a8-640d944cc325")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface Interface
{
// IUnknown: QueryInterface, AddRef, Release
void QueryInterface(in Guid riid, out IntPtr ppvObject);
uint AddRef();
uint Release();
// SetSwapChain is the 4th slot in the vtable (0-based index 3)
int SetSwapChain(IntPtr swapChainPtr);
}
private readonly IntPtr _nativePtr;
public ISwapChainPanelNative(IntPtr nativePtr)
{
_nativePtr = nativePtr;
}
public void QueryInterface(in Guid riid, out nint ppvObject)
{
throw new NotImplementedException();
}
public uint AddRef()
{
throw new NotImplementedException();
}
public uint Release()
{
throw new NotImplementedException();
}
public static ISwapChainPanelNative FromSwapChainPanel(object panel)
{
// Get the IUnknown/IInspectable pointer
var unknown = Marshal.GetIUnknownForObject(panel);
try
{
// Query for ISwapChainPanelNative
var iid = typeof(Interface).GUID;
var result = Marshal.QueryInterface(unknown, in iid, out var nativePtr);
if (result < 0)
{
Marshal.ThrowExceptionForHR(result);
}
return new ISwapChainPanelNative(nativePtr);
}
finally
{
Marshal.Release(unknown);
}
}
public int SetSwapChain(IntPtr swapChainPtr)
{
var vtbl = *(void***)_nativePtr;
var setSwapChainFn = (delegate* unmanaged<IntPtr, IntPtr, int>)vtbl[3];
return setSwapChainFn(_nativePtr, swapChainPtr);
}
public void Dispose() => Marshal.Release(_nativePtr);
}