MoonWorksGraphicsTests/Examples/StoreLoadExample.cs

90 lines
1.9 KiB
C#
Raw Permalink Normal View History

2024-06-06 22:20:20 +00:00
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",
new ShaderCreateInfo
{
ShaderStage = ShaderStage.Vertex,
ShaderFormat = ShaderFormat.SPIRV
}
2024-06-06 22:20:20 +00:00
);
Shader fragShader = new Shader(
GraphicsDevice,
TestUtils.GetShaderPath("SolidColor.frag"),
"main",
new ShaderCreateInfo
{
ShaderStage = ShaderStage.Fragment,
ShaderFormat = ShaderFormat.SPIRV
}
2024-06-06 22:20:20 +00:00
);
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();
}
}