using Ghost.Core; using Ghost.Graphics.Data; namespace Ghost.Graphics.RHI; /// /// Swap chain interface for presentation /// public interface ISwapChain : IDisposable { /// /// Width of the swap chain back buffers /// public uint Width { get; } /// /// Height of the swap chain back buffers /// public uint Height { get; } /// /// Number of back buffers /// public uint BufferCount { get; } /// /// Gets the current back buffer texture /// /// Current back buffer texture public Handle GetCurrentBackBuffer(); /// /// Presents the rendered frame /// /// Enable vertical synchronization public void Present(bool vsync = true); /// /// Resizes the swap chain back buffers /// /// New width /// New height public void Resize(uint width, uint height); } /// /// Swap chain description /// public struct SwapChainDesc { /// /// Width of the swap chain /// public uint width; /// /// Height of the swap chain /// public uint height; /// /// Back buffer format /// public TextureFormat format; /// /// Target for presentation (window handle or composition target) /// public SwapChainTarget target; public SwapChainDesc(uint width, uint height, SwapChainTarget target, TextureFormat format = TextureFormat.B8G8R8A8_UNorm, uint bufferCount = 2) { this.width = width; this.height = height; this.format = format; this.target = target; } } /// /// Swap chain target (window handle or composition surface) /// public struct SwapChainTarget { /// /// Target type /// public SwapChainTargetType type; /// /// Window handle for HWND targets /// public nint windowHandle; /// /// Composition surface for UWP/WinUI targets /// public object? compositionSurface; public static SwapChainTarget FromWindowHandle(nint hwnd) { return new SwapChainTarget { type = SwapChainTargetType.WindowHandle, windowHandle = hwnd, compositionSurface = null }; } public static SwapChainTarget FromCompositionSurface(object surface) { return new SwapChainTarget { type = SwapChainTargetType.Composition, windowHandle = nint.Zero, compositionSurface = surface }; } } /// /// Swap chain target types /// public enum SwapChainTargetType { WindowHandle, Composition }