From c9d929dc1f8f06585fa8ec26656f96fade6fdd2f Mon Sep 17 00:00:00 2001 From: Caleb Cornett Date: Sat, 4 Feb 2023 22:59:56 -0500 Subject: [PATCH] Add WindowResizing test --- MoonWorksGraphicsTests.sln | 6 ++ README.md | 4 ++ WindowResizing/WindowResizing.csproj | 17 ++++++ WindowResizing/WindowResizingGame.cs | 85 ++++++++++++++++++++++++++++ 4 files changed, 112 insertions(+) create mode 100644 WindowResizing/WindowResizing.csproj create mode 100644 WindowResizing/WindowResizingGame.cs diff --git a/MoonWorksGraphicsTests.sln b/MoonWorksGraphicsTests.sln index 5f0bd9e..74c9073 100644 --- a/MoonWorksGraphicsTests.sln +++ b/MoonWorksGraphicsTests.sln @@ -57,6 +57,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BasicStencil", "BasicStenci EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DepthMSAA", "DepthMSAA\DepthMSAA.csproj", "{B36C9F65-F3F4-4EB4-8EBF-A1EDCD4261F8}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowResizing", "WindowResizing\WindowResizing.csproj", "{AF5F2804-663D-4C46-BD02-AB178002180B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -171,6 +173,10 @@ Global {B36C9F65-F3F4-4EB4-8EBF-A1EDCD4261F8}.Debug|x64.Build.0 = Debug|x64 {B36C9F65-F3F4-4EB4-8EBF-A1EDCD4261F8}.Release|x64.ActiveCfg = Release|x64 {B36C9F65-F3F4-4EB4-8EBF-A1EDCD4261F8}.Release|x64.Build.0 = Release|x64 + {AF5F2804-663D-4C46-BD02-AB178002180B}.Debug|x64.ActiveCfg = Debug|x64 + {AF5F2804-663D-4C46-BD02-AB178002180B}.Debug|x64.Build.0 = Debug|x64 + {AF5F2804-663D-4C46-BD02-AB178002180B}.Release|x64.ActiveCfg = Release|Any CPU + {AF5F2804-663D-4C46-BD02-AB178002180B}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/README.md b/README.md index f61dcbf..43b6904 100644 --- a/README.md +++ b/README.md @@ -99,3 +99,7 @@ Demonstrates stencil masking using two triangles. Tests stencil buffers and basi **DepthMSAA** Displays two cubes floating around each other on a multisampled surface. Tests multisampled depth buffers. + +**WindowResizing** + +Tests resizing the window to various resolutions. diff --git a/WindowResizing/WindowResizing.csproj b/WindowResizing/WindowResizing.csproj new file mode 100644 index 0000000..2868e63 --- /dev/null +++ b/WindowResizing/WindowResizing.csproj @@ -0,0 +1,17 @@ + + + + + + + + + Exe + net7.0 + enable + x64 + + + + + diff --git a/WindowResizing/WindowResizingGame.cs b/WindowResizing/WindowResizingGame.cs new file mode 100644 index 0000000..b1fb778 --- /dev/null +++ b/WindowResizing/WindowResizingGame.cs @@ -0,0 +1,85 @@ +using MoonWorks; +using MoonWorks.Graphics; + +namespace MoonWorks.Test +{ + class WindowResizingGame : Game + { + private GraphicsPipeline pipeline; + + private int currentResolutionIndex; + private record struct Res(uint Width, uint Height); + private Res[] resolutions = new Res[] + { + new Res(640, 480), + new Res(1280, 720), + new Res(1024, 1024), + new Res(1600, 900), + new Res(1920, 1080), + new Res(3200, 1800), + new Res(3840, 2160), + }; + + public WindowResizingGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true) + { + ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("RawTriangleVertices")); + ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("SolidColor")); + + GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo( + MainWindow.SwapchainFormat, + vertShaderModule, + fragShaderModule + ); + pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo); + } + + protected override void Update(System.TimeSpan delta) + { + int prevResolutionIndex = currentResolutionIndex; + + if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Left)) + { + currentResolutionIndex -= 1; + if (currentResolutionIndex < 0) + { + currentResolutionIndex = resolutions.Length - 1; + } + } + + if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Right)) + { + currentResolutionIndex += 1; + if (currentResolutionIndex >= resolutions.Length) + { + currentResolutionIndex = 0; + } + } + + if (prevResolutionIndex != currentResolutionIndex) + { + Logger.LogInfo("Setting resolution to: " + resolutions[currentResolutionIndex]); + MainWindow.SetWindowSize(resolutions[currentResolutionIndex].Width, resolutions[currentResolutionIndex].Height); + } + } + + protected override void Draw(double alpha) + { + CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); + Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); + if (backbuffer != null) + { + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black)); + cmdbuf.BindGraphicsPipeline(pipeline); + cmdbuf.DrawPrimitives(0, 1, 0, 0); + cmdbuf.EndRenderPass(); + } + GraphicsDevice.Submit(cmdbuf); + } + + public static void Main(string[] args) + { + WindowResizingGame game = new WindowResizingGame(); + game.Run(); + } + } +}