Files
GhostEngine/Ghost.Graphics/RHI/ISwapChain.cs
Misaki 78cc64b1d2 feat: Implement D3D12 resource factory and improve swap chain management
- Added D3D12ResourceFactory for creating render targets, textures, and buffers.
- Enhanced D3D12SwapChain to manage back buffer render targets and provide access to them.
- Updated D3D12Texture to utilize resource handles for better resource management.
- Removed legacy ResourceAllocator and integrated improvements for resource handling.
- Introduced new interfaces for resource factory and swap chain to streamline resource creation.
- Added support for mip levels and texture dimensions in render target and texture descriptions.
- Created new markdown files to document allocator and swap chain improvements.
2025-09-02 19:39:34 +09:00

139 lines
3.2 KiB
C#

using Ghost.Graphics.Contracts;
namespace Ghost.Graphics.RHI;
/// <summary>
/// Swap chain interface for presentation
/// </summary>
public interface ISwapChain : IDisposable
{
/// <summary>
/// Width of the swap chain back buffers
/// </summary>
uint Width { get; }
/// <summary>
/// Height of the swap chain back buffers
/// </summary>
uint Height { get; }
/// <summary>
/// Number of back buffers
/// </summary>
uint BufferCount { get; }
/// <summary>
/// Gets the current back buffer texture
/// </summary>
/// <returns>Current back buffer texture</returns>
ITexture GetCurrentBackBuffer();
/// <summary>
/// Gets the current back buffer as a render target
/// </summary>
/// <returns>Current back buffer render target</returns>
IRenderTarget GetCurrentBackBufferRenderTarget();
/// <summary>
/// Presents the rendered frame
/// </summary>
/// <param name="vsync">Enable vertical synchronization</param>
void Present(bool vsync = true);
/// <summary>
/// Resizes the swap chain back buffers
/// </summary>
/// <param name="width">New width</param>
/// <param name="height">New height</param>
void Resize(uint width, uint height);
}
/// <summary>
/// Swap chain description
/// </summary>
public struct SwapChainDesc
{
/// <summary>
/// Width of the swap chain
/// </summary>
public uint Width;
/// <summary>
/// Height of the swap chain
/// </summary>
public uint Height;
/// <summary>
/// Back buffer format
/// </summary>
public TextureFormat Format;
/// <summary>
/// Number of back buffers
/// </summary>
public uint BufferCount;
/// <summary>
/// Target for presentation (window handle or composition target)
/// </summary>
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;
}
}
/// <summary>
/// Swap chain target (window handle or composition surface)
/// </summary>
public struct SwapChainTarget
{
/// <summary>
/// Target type
/// </summary>
public SwapChainTargetType Type;
/// <summary>
/// Window handle for HWND targets
/// </summary>
public nint WindowHandle;
/// <summary>
/// Composition surface for UWP/WinUI targets
/// </summary>
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
};
}
}
/// <summary>
/// Swap chain target types
/// </summary>
public enum SwapChainTargetType
{
WindowHandle,
Composition
}