diff --git a/src/DirectX12GameEngine.Graphics/Buffer.Index.cs b/src/DirectX12GameEngine.Graphics/Buffer.Index.cs index 6c4be0bf..398811fd 100644 --- a/src/DirectX12GameEngine.Graphics/Buffer.Index.cs +++ b/src/DirectX12GameEngine.Graphics/Buffer.Index.cs @@ -22,25 +22,6 @@ namespace DirectX12GameEngine.Graphics { return Buffer.New(device, data, BufferFlags.IndexBuffer, heapType); } - - public static IndexBufferView CreateIndexBufferView(Buffer indexBuffer, PixelFormat format, int size) - { - switch (format) - { - case PixelFormat.R16_UInt: - case PixelFormat.R32_UInt: - break; - default: - throw new NotSupportedException("Index buffer type must be ushort or uint"); - } - - return new IndexBufferView - { - BufferLocation = indexBuffer.NativeResource.GPUVirtualAddress, - Format = (Format)format, - SizeInBytes = size - }; - } } } } diff --git a/src/DirectX12GameEngine.Graphics/CoreWindowSwapChainGraphicsPresenter.cs b/src/DirectX12GameEngine.Graphics/CoreWindowSwapChainGraphicsPresenter.cs deleted file mode 100644 index e52d61f2..00000000 --- a/src/DirectX12GameEngine.Graphics/CoreWindowSwapChainGraphicsPresenter.cs +++ /dev/null @@ -1,41 +0,0 @@ -using SharpDX; -using SharpDX.DXGI; -using Windows.UI.Core; - -namespace DirectX12GameEngine.Graphics -{ - public class CoreWindowSwapChainGraphicsPresenter : SwapChainGraphicsPresenter - { - private readonly CoreWindow coreWindow; - - public CoreWindowSwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters, CoreWindow coreWindow) - : base(device, presentationParameters, CreateSwapChain(device, presentationParameters, coreWindow)) - { - this.coreWindow = coreWindow; - } - - private static SwapChain3 CreateSwapChain(GraphicsDevice device, PresentationParameters presentationParameters, CoreWindow coreWindow) - { - SwapChainDescription1 swapChainDescription = new SwapChainDescription1 - { - Width = presentationParameters.BackBufferWidth, - Height = presentationParameters.BackBufferHeight, - SampleDescription = new SampleDescription(1, 0), - Stereo = presentationParameters.Stereo, - Usage = Usage.RenderTargetOutput, - BufferCount = BufferCount, - Scaling = Scaling.Stretch, - SwapEffect = SwapEffect.FlipSequential, - Format = (Format)presentationParameters.BackBufferFormat, - Flags = SwapChainFlags.None, - AlphaMode = AlphaMode.Unspecified - }; - - using Factory4 factory = new Factory4(); - using ComObject window = new ComObject(coreWindow); - using SwapChain1 tempSwapChain = new SwapChain1(factory, device.NativeDirectCommandQueue, window, ref swapChainDescription); - - return tempSwapChain.QueryInterface(); - } - } -} diff --git a/src/DirectX12GameEngine.Graphics/GraphicsDevice.cs b/src/DirectX12GameEngine.Graphics/GraphicsDevice.cs index 31752402..a5f67e05 100644 --- a/src/DirectX12GameEngine.Graphics/GraphicsDevice.cs +++ b/src/DirectX12GameEngine.Graphics/GraphicsDevice.cs @@ -54,8 +54,6 @@ namespace DirectX12GameEngine.Graphics public FeatureLevel FeatureLevel { get; } - public GraphicsPresenter? Presenter { get; set; } - internal Device NativeDevice { get; } internal SharpDX.Direct3D11.Device NativeDirect3D11Device => NativeDirect3D11Device ?? (nativeDirect3D11Device = SharpDX.Direct3D11.Device.CreateFromDirect3D12( diff --git a/src/DirectX12GameEngine.Graphics/GraphicsPresenter.cs b/src/DirectX12GameEngine.Graphics/GraphicsPresenter.cs deleted file mode 100644 index 8db786ce..00000000 --- a/src/DirectX12GameEngine.Graphics/GraphicsPresenter.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; - -namespace DirectX12GameEngine.Graphics -{ - public abstract class GraphicsPresenter : IDisposable - { - protected GraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters) - { - GraphicsDevice = device; - PresentationParameters = presentationParameters; - } - - public GraphicsDevice GraphicsDevice { get; } - - public abstract object NativePresenter { get; } - - public PresentationParameters PresentationParameters { get; } - - public virtual void BeginDraw(CommandList commandList) - { - } - - public virtual void Dispose() - { - } - - public abstract void Present(); - - public void Resize(int width, int height) - { - PresentationParameters.BackBufferWidth = width; - PresentationParameters.BackBufferHeight = height; - - ResizeBackBuffer(width, height); - } - - protected abstract void ResizeBackBuffer(int width, int height); - } -} diff --git a/src/DirectX12GameEngine.Graphics/HwndSwapChainGraphicsPresenter.cs b/src/DirectX12GameEngine.Graphics/HwndSwapChainGraphicsPresenter.cs deleted file mode 100644 index a441d3cb..00000000 --- a/src/DirectX12GameEngine.Graphics/HwndSwapChainGraphicsPresenter.cs +++ /dev/null @@ -1,38 +0,0 @@ -using SharpDX.DXGI; - -namespace DirectX12GameEngine.Graphics -{ - public class HwndSwapChainGraphicsPresenter : SwapChainGraphicsPresenter - { - private readonly WindowHandle windowHandle; - - public HwndSwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters, WindowHandle windowHandle) - : base(device, presentationParameters, CreateSwapChain(device, presentationParameters, windowHandle)) - { - this.windowHandle = windowHandle; - } - - private static SwapChain3 CreateSwapChain(GraphicsDevice device, PresentationParameters presentationParameters, WindowHandle windowHandle) - { - SwapChainDescription1 swapChainDescription = new SwapChainDescription1 - { - Width = presentationParameters.BackBufferWidth, - Height = presentationParameters.BackBufferHeight, - SampleDescription = new SampleDescription(1, 0), - Stereo = presentationParameters.Stereo, - Usage = Usage.RenderTargetOutput, - BufferCount = BufferCount, - Scaling = Scaling.Stretch, - SwapEffect = SwapEffect.FlipSequential, - Format = (Format)presentationParameters.BackBufferFormat, - Flags = SwapChainFlags.None, - AlphaMode = AlphaMode.Unspecified - }; - - using Factory4 factory = new Factory4(); - using SwapChain1 tempSwapChain = new SwapChain1(factory, device.NativeDirectCommandQueue, windowHandle.Handle, ref swapChainDescription); - - return tempSwapChain.QueryInterface(); - } - } -} diff --git a/src/DirectX12GameEngine.Graphics/PixelFormat.cs b/src/DirectX12GameEngine.Graphics/PixelFormat.cs deleted file mode 100644 index e0e88a21..00000000 --- a/src/DirectX12GameEngine.Graphics/PixelFormat.cs +++ /dev/null @@ -1,125 +0,0 @@ -namespace DirectX12GameEngine.Graphics -{ - public enum PixelFormat - { - Unknown = 0, - R32G32B32A32_Typeless = 1, - R32G32B32A32_Float = 2, - R32G32B32A32_UInt = 3, - R32G32B32A32_SInt = 4, - R32G32B32_Typeless = 5, - R32G32B32_Float = 6, - R32G32B32_UInt = 7, - R32G32B32_SInt = 8, - R16G16B16A16_Typeless = 9, - R16G16B16A16_Float = 10, - R16G16B16A16_UNorm = 11, - R16G16B16A16_UInt = 12, - R16G16B16A16_SNorm = 13, - R16G16B16A16_SInt = 14, - R32G32_Typeless = 15, - R32G32_Float = 16, - R32G32_UInt = 17, - R32G32_SInt = 18, - R32G8X24_Typeless = 19, - D32_Float_S8X24_UInt = 20, - R32_Float_X8X24_Typeless = 21, - X32_Typeless_G8X24_UInt = 22, - R10G10B10A2_Typeless = 23, - R10G10B10A2_UNorm = 24, - R10G10B10A2_UInt = 25, - R11G11B10_Float = 26, - R8G8B8A8_Typeless = 27, - R8G8B8A8_UNorm = 28, - R8G8B8A8_UNorm_SRgb = 29, - R8G8B8A8_UInt = 30, - R8G8B8A8_SNorm = 31, - R8G8B8A8_SInt = 32, - R16G16_Typeless = 33, - R16G16_Float = 34, - R16G16_UNorm = 35, - R16G16_UInt = 36, - R16G16_SNorm = 37, - R16G16_SInt = 38, - R32_Typeless = 39, - D32_Float = 40, - R32_Float = 41, - R32_UInt = 42, - R32_SInt = 43, - R24G8_Typeless = 44, - D24_UNorm_S8_UInt = 45, - R24_UNorm_X8_Typeless = 46, - X24_Typeless_G8_UInt = 47, - R8G8_Typeless = 48, - R8G8_UNorm = 49, - R8G8_UInt = 50, - R8G8_SNorm = 51, - R8G8_SInt = 52, - R16_Typeless = 53, - R16_Float = 54, - D16_UNorm = 55, - R16_UNorm = 56, - R16_UInt = 57, - R16_SNorm = 58, - R16_SInt = 59, - R8_Typeless = 60, - R8_UNorm = 61, - R8_UInt = 62, - R8_SNorm = 63, - R8_SInt = 64, - A8_UNorm = 65, - R1_UNorm = 66, - R9G9B9E5_Sharedexp = 67, - R8G8_B8G8_UNorm = 68, - G8R8_G8B8_UNorm = 69, - BC1_Typeless = 70, - BC1_UNorm = 71, - BC1_UNorm_SRgb = 72, - BC2_Typeless = 73, - BC2_UNorm = 74, - BC2_UNorm_SRgb = 75, - BC3_Typeless = 76, - BC3_UNorm = 77, - BC3_UNorm_SRgb = 78, - BC4_Typeless = 79, - BC4_UNorm = 80, - BC4_SNorm = 81, - BC5_Typeless = 82, - BC5_UNorm = 83, - BC5_SNorm = 84, - B5G6R5_UNorm = 85, - B5G5R5A1_UNorm = 86, - B8G8R8A8_UNorm = 87, - B8G8R8X8_UNorm = 88, - R10G10B10_Xr_Bias_A2_UNorm = 89, - B8G8R8A8_Typeless = 90, - B8G8R8A8_UNorm_SRgb = 91, - B8G8R8X8_Typeless = 92, - B8G8R8X8_UNorm_SRgb = 93, - BC6H_Typeless = 94, - BC6H_Uf16 = 95, - BC6H_Sf16 = 96, - BC7_Typeless = 97, - BC7_UNorm = 98, - BC7_UNorm_SRgb = 99, - AYUV = 100, - Y410 = 101, - Y416 = 102, - NV12 = 103, - P010 = 104, - P016 = 105, - Opaque420 = 106, - YUY2 = 107, - Y210 = 108, - Y216 = 109, - NV11 = 110, - AI44 = 111, - IA44 = 112, - P8 = 113, - A8P8 = 114, - B4G4R4A4_UNorm = 115, - P208 = 130, - V208 = 131, - V408 = 132 - } -} diff --git a/src/DirectX12GameEngine.Graphics/PresentationParameters.cs b/src/DirectX12GameEngine.Graphics/PresentationParameters.cs deleted file mode 100644 index b5ca8801..00000000 --- a/src/DirectX12GameEngine.Graphics/PresentationParameters.cs +++ /dev/null @@ -1,37 +0,0 @@ -using SharpDX.DXGI; - -namespace DirectX12GameEngine.Graphics -{ - public class PresentationParameters - { - public PresentationParameters() - { - } - - public PresentationParameters(int backBufferWidth, int backBufferHeight) - : this(backBufferWidth, backBufferHeight, PixelFormat.B8G8R8A8_UNorm) - { - } - - public PresentationParameters(int backBufferWidth, int backBufferHeight, PixelFormat backBufferFomat) - { - BackBufferWidth = backBufferWidth; - BackBufferHeight = backBufferHeight; - BackBufferFormat = backBufferFomat; - } - - public int BackBufferWidth { get; set; } - - public int BackBufferHeight { get; set; } - - public PixelFormat BackBufferFormat { get; set; } = PixelFormat.B8G8R8A8_UNorm; - - public PixelFormat DepthStencilFormat { get; set; } = PixelFormat.D32_Float; - - public PresentParameters PresentParameters { get; set; } - - public bool Stereo { get; set; } - - public int SyncInterval { get; set; } = 1; - } -} diff --git a/src/DirectX12GameEngine.Graphics/SwapChainGraphicsPresenter.cs b/src/DirectX12GameEngine.Graphics/SwapChainGraphicsPresenter.cs deleted file mode 100644 index 8dc3198b..00000000 --- a/src/DirectX12GameEngine.Graphics/SwapChainGraphicsPresenter.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System.Numerics; -using SharpDX.Direct3D12; -using SharpDX.DXGI; - -using Resource = SharpDX.Direct3D12.Resource; - -namespace DirectX12GameEngine.Graphics -{ - public class SwapChainGraphicsPresenter : GraphicsPresenter - { - protected const int BufferCount = 2; - - public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters, SwapChain3 swapChain) - : base(device, presentationParameters) - { - SwapChain = swapChain; - - if (GraphicsDevice.RenderTargetViewAllocator.DescriptorHeap.Description.DescriptorCount != BufferCount) - { - GraphicsDevice.RenderTargetViewAllocator.Dispose(); - GraphicsDevice.RenderTargetViewAllocator = new DescriptorAllocator(GraphicsDevice, DescriptorHeapType.RenderTargetView, descriptorCount: BufferCount); - } - } - - public Matrix3x2 MatrixTransform { get => SwapChain.MatrixTransform.ToMatrix3x2(); set => SwapChain.MatrixTransform = value.ToMatrix3x2(); } - - public override object NativePresenter => SwapChain; - - protected SwapChain3 SwapChain { get; } - - public override void Dispose() - { - SwapChain.Dispose(); - - base.Dispose(); - } - - public override void Present() - { - SwapChain.Present(PresentationParameters.SyncInterval, PresentFlags.None, PresentationParameters.PresentParameters); - } - - protected override void ResizeBackBuffer(int width, int height) - { - - SwapChain.ResizeBuffers(BufferCount, width, height, (Format)PresentationParameters.BackBufferFormat, SwapChainFlags.None); - - } - } - - internal static class MatrixExtensions - { - public static unsafe SharpDX.Mathematics.Interop.RawMatrix3x2 ToMatrix3x2(this Matrix3x2 value) - { - return *(SharpDX.Mathematics.Interop.RawMatrix3x2*)&value; - } - - public static unsafe Matrix3x2 ToMatrix3x2(this SharpDX.Mathematics.Interop.RawMatrix3x2 value) - { - return *(Matrix3x2*)&value; - } - } -} diff --git a/src/DirectX12GameEngine.Graphics/WindowHandle.cs b/src/DirectX12GameEngine.Graphics/WindowHandle.cs deleted file mode 100644 index 15fa43d6..00000000 --- a/src/DirectX12GameEngine.Graphics/WindowHandle.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace DirectX12GameEngine.Graphics -{ - public class WindowHandle - { - public WindowHandle(IntPtr handle) - { - Handle = handle; - } - - public IntPtr Handle { get; } - } -} diff --git a/src/DirectX12GameEngine.Graphics/XamlSwapChainGraphicsPresenter.cs b/src/DirectX12GameEngine.Graphics/XamlSwapChainGraphicsPresenter.cs deleted file mode 100644 index 75850567..00000000 --- a/src/DirectX12GameEngine.Graphics/XamlSwapChainGraphicsPresenter.cs +++ /dev/null @@ -1,63 +0,0 @@ -using SharpDX; -using SharpDX.DXGI; -using Windows.UI.Xaml.Controls; - -namespace DirectX12GameEngine.Graphics -{ - public class XamlSwapChainGraphicsPresenter : SwapChainGraphicsPresenter - { - private readonly SwapChainPanel swapChainPanel; - - public XamlSwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters, SwapChainPanel swapChainPanel) - : base(device, presentationParameters, CreateSwapChain(device, presentationParameters, swapChainPanel)) - { - this.swapChainPanel = swapChainPanel; - } - - protected override void ResizeBackBuffer(int width, int height) - { - MatrixTransform = new System.Numerics.Matrix3x2 - { - M11 = 1.0f / swapChainPanel.CompositionScaleX, - M22 = 1.0f / swapChainPanel.CompositionScaleY - }; - - base.ResizeBackBuffer(width, height); - } - - private static SwapChain3 CreateSwapChain(GraphicsDevice device, PresentationParameters presentationParameters, SwapChainPanel swapChainPanel) - { - SwapChainDescription1 swapChainDescription = new SwapChainDescription1 - { - Width = presentationParameters.BackBufferWidth, - Height = presentationParameters.BackBufferHeight, - SampleDescription = new SampleDescription(1, 0), - Stereo = presentationParameters.Stereo, - Usage = Usage.RenderTargetOutput, - BufferCount = BufferCount, - Scaling = Scaling.Stretch, - SwapEffect = SwapEffect.FlipSequential, - Format = (Format)presentationParameters.BackBufferFormat, - Flags = SwapChainFlags.None, - AlphaMode = AlphaMode.Unspecified - }; - - swapChainDescription.AlphaMode = AlphaMode.Premultiplied; - - using Factory4 factory = new Factory4(); - using ISwapChainPanelNative nativePanel = ComObject.As(swapChainPanel); - using SwapChain1 tempSwapChain = new SwapChain1(factory, device.NativeDirectCommandQueue, ref swapChainDescription); - - SwapChain3 swapChain = tempSwapChain.QueryInterface(); - nativePanel.SwapChain = swapChain; - - swapChain.MatrixTransform = new SharpDX.Mathematics.Interop.RawMatrix3x2 - { - M11 = 1.0f / swapChainPanel.CompositionScaleX, - M22 = 1.0f / swapChainPanel.CompositionScaleY - }; - - return swapChain; - } - } -}