diff --git a/Examples/StoreLoadExample.cs b/Examples/StoreLoadExample.cs new file mode 100644 index 0000000..bc30bcc --- /dev/null +++ b/Examples/StoreLoadExample.cs @@ -0,0 +1,83 @@ +using System; +using MoonWorks; +using MoonWorks.Graphics; +using MoonWorks.Input; + +namespace MoonWorksGraphicsTests; + +class StoreLoadExample : Example +{ + private GraphicsPipeline FillPipeline; + + public override void Init(Window window, GraphicsDevice graphicsDevice, Inputs inputs) + { + Window = window; + GraphicsDevice = graphicsDevice; + + Window.SetTitle("StoreLoad"); + + Shader vertShader = new Shader( + GraphicsDevice, + TestUtils.GetShaderPath("RawTriangle.vert"), + "main", + ShaderStage.Vertex, + ShaderFormat.SPIRV + ); + + Shader fragShader = new Shader( + GraphicsDevice, + TestUtils.GetShaderPath("SolidColor.frag"), + "main", + ShaderStage.Fragment, + ShaderFormat.SPIRV + ); + + GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo( + Window.SwapchainFormat, + vertShader, + fragShader + ); + FillPipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo); + } + + public override void Update(TimeSpan delta) + { + + } + + public override void Draw(double alpha) + { + CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); + Texture swapchainTexture = cmdbuf.AcquireSwapchainTexture(Window); + if (swapchainTexture != null) + { + var renderPass = cmdbuf.BeginRenderPass( + new ColorAttachmentInfo( + swapchainTexture, + false, + Color.Blue + ) + ); + renderPass.BindGraphicsPipeline(FillPipeline); + renderPass.DrawPrimitives(0, 1); + cmdbuf.EndRenderPass(renderPass); + + renderPass = cmdbuf.BeginRenderPass( + new ColorAttachmentInfo( + swapchainTexture, + false, + LoadOp.Load, + StoreOp.Store + ) + ); + cmdbuf.EndRenderPass(renderPass); + } + + GraphicsDevice.Submit(cmdbuf); + } + + public override void Destroy() + { + FillPipeline.Dispose(); + } +} diff --git a/Examples/StoreLoadGame.cs b/Examples/StoreLoadGame.cs deleted file mode 100644 index 8e4c728..0000000 --- a/Examples/StoreLoadGame.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using MoonWorks.Graphics; - -namespace MoonWorks.Test -{ - class StoreLoadGame : Game - { - private GraphicsPipeline fillPipeline; - - public StoreLoadGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true) - { - ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("RawTriangle.vert")); - ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("SolidColor.frag")); - - GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo( - MainWindow.SwapchainFormat, - vertShaderModule, - fragShaderModule - ); - fillPipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo); - } - - protected override void Update(TimeSpan delta) - { - - } - - protected override void Draw(double alpha) - { - CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); - Texture? swapchain = cmdbuf.AcquireSwapchainTexture(MainWindow); - if (swapchain != null) - { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(swapchain, WriteOptions.Cycle, Color.Blue)); - cmdbuf.BindGraphicsPipeline(fillPipeline); - cmdbuf.DrawPrimitives(0, 1); - cmdbuf.EndRenderPass(); - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(swapchain, WriteOptions.Safe, LoadOp.Load, StoreOp.Store)); - cmdbuf.EndRenderPass(); - } - GraphicsDevice.Submit(cmdbuf); - } - - public static void Main(string[] args) - { - StoreLoadGame game = new StoreLoadGame(); - game.Run(); - } - } -} diff --git a/MoonWorksGraphicsTests.csproj b/MoonWorksGraphicsTests.csproj index 53a6410..35df9e6 100644 --- a/MoonWorksGraphicsTests.csproj +++ b/MoonWorksGraphicsTests.csproj @@ -44,6 +44,7 @@ + diff --git a/Program.cs b/Program.cs index 6319e34..094583c 100644 --- a/Program.cs +++ b/Program.cs @@ -27,7 +27,8 @@ class Program : Game new RenderTexture2DArrayExample(), new RenderTexture2DExample(), new RenderTextureCubeExample(), - new RenderTextureMipmapsExample() + new RenderTextureMipmapsExample(), + new StoreLoadExample() ]; int ExampleIndex = 0;