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
ITexture GetCurrentBackBuffer();
///
/// Gets the current back buffer as a render target
///
/// Current back buffer render target
IRenderTarget GetCurrentBackBufferRenderTarget();
///
/// 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;
///
/// Number of back buffers
///
public uint BufferCount;
///
/// 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)
{
Width = width;
Height = height;
Format = format;
BufferCount = bufferCount;
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
}