StoreLoadExample
parent
b826ff6a89
commit
2efb502cd4
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -44,6 +44,7 @@
|
|||
<Compile Include="Examples\RenderTexture2DExample.cs" />
|
||||
<Compile Include="Examples\RenderTextureCubeExample.cs" />
|
||||
<Compile Include="Examples\RenderTextureMipmapsExample.cs" />
|
||||
<Compile Include="Examples\StoreLoadExample.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project=".\CopyMoonlibs.targets" />
|
||||
|
|
|
@ -27,7 +27,8 @@ class Program : Game
|
|||
new RenderTexture2DArrayExample(),
|
||||
new RenderTexture2DExample(),
|
||||
new RenderTextureCubeExample(),
|
||||
new RenderTextureMipmapsExample()
|
||||
new RenderTextureMipmapsExample(),
|
||||
new StoreLoadExample()
|
||||
];
|
||||
|
||||
int ExampleIndex = 0;
|
||||
|
|
Loading…
Reference in New Issue