using Ghost.Graphics.Contracts; namespace Ghost.Graphics.RHI; /// /// Swap chain interface for presentation /// public interface ISwapChain : IDisposable { /// /// Width of the swap chain back buffers /// uint Width { get; } /// /// Height of the swap chain back buffers /// uint Height { get; } /// /// Number of back buffers /// uint BufferCount { get; } /// /// Gets the current back buffer texture /// /// Current back buffer texture IRenderTarget GetCurrentBackBuffer(); /// /// Presents the rendered frame /// /// Enable vertical synchronization void Present(bool vsync = true); /// /// Resizes the swap chain back buffers /// /// New width /// New height 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 }