MoonWorksGraphicsTests/WindowResizing/WindowResizingGame.cs

86 lines
2.4 KiB
C#
Raw Normal View History

2023-02-05 03:59:56 +00:00
using MoonWorks;
using MoonWorks.Graphics;
namespace MoonWorks.Test
{
2024-02-07 15:27:55 +00:00
class WindowResizingGame : Game
{
private GraphicsPipeline pipeline;
2023-02-05 03:59:56 +00:00
2024-02-07 15:27:55 +00:00
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),
};
2023-02-05 03:59:56 +00:00
public WindowResizingGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.Backend, 60, true)
2024-02-07 15:27:55 +00:00
{
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("RawTriangle.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("SolidColor.frag"));
2023-02-05 03:59:56 +00:00
2024-02-07 15:27:55 +00:00
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
}
2023-02-05 03:59:56 +00:00
2024-02-07 15:27:55 +00:00
protected override void Update(System.TimeSpan delta)
{
int prevResolutionIndex = currentResolutionIndex;
2023-02-05 03:59:56 +00:00
2024-02-07 15:27:55 +00:00
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Left))
{
currentResolutionIndex -= 1;
if (currentResolutionIndex < 0)
{
currentResolutionIndex = resolutions.Length - 1;
}
}
2023-02-05 03:59:56 +00:00
2024-02-07 15:27:55 +00:00
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Right))
{
currentResolutionIndex += 1;
if (currentResolutionIndex >= resolutions.Length)
{
currentResolutionIndex = 0;
}
}
2023-02-05 03:59:56 +00:00
2024-02-07 15:27:55 +00:00
if (prevResolutionIndex != currentResolutionIndex)
{
Logger.LogInfo("Setting resolution to: " + resolutions[currentResolutionIndex]);
MainWindow.SetWindowSize(resolutions[currentResolutionIndex].Width, resolutions[currentResolutionIndex].Height);
}
}
2023-02-05 03:59:56 +00:00
2024-02-07 15:27:55 +00:00
protected override void Draw(double alpha)
{
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
2024-03-01 23:03:29 +00:00
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.Black));
2024-02-07 15:27:55 +00:00
cmdbuf.BindGraphicsPipeline(pipeline);
2024-02-23 22:54:46 +00:00
cmdbuf.DrawPrimitives(0, 1);
2024-02-07 15:27:55 +00:00
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
2023-02-05 03:59:56 +00:00
2024-02-07 15:27:55 +00:00
public static void Main(string[] args)
{
WindowResizingGame game = new WindowResizingGame();
game.Run();
}
}
2023-02-05 03:59:56 +00:00
}