2024-02-23 19:03:04 +00:00
|
|
|
|
using MoonWorks.Graphics;
|
2022-11-09 19:54:42 +00:00
|
|
|
|
|
|
|
|
|
namespace MoonWorks.Test
|
|
|
|
|
{
|
|
|
|
|
class BasicTriangleGame : Game
|
|
|
|
|
{
|
|
|
|
|
private GraphicsPipeline fillPipeline;
|
|
|
|
|
private GraphicsPipeline linePipeline;
|
|
|
|
|
|
|
|
|
|
private Viewport smallViewport = new Viewport(160, 120, 320, 240);
|
|
|
|
|
private Rect scissorRect = new Rect(320, 240, 320, 240);
|
|
|
|
|
|
|
|
|
|
private bool useWireframeMode;
|
|
|
|
|
private bool useSmallViewport;
|
|
|
|
|
private bool useScissorRect;
|
|
|
|
|
|
2024-03-07 18:35:12 +00:00
|
|
|
|
public BasicTriangleGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
|
2022-11-09 19:54:42 +00:00
|
|
|
|
{
|
2024-02-07 15:27:55 +00:00
|
|
|
|
Logger.LogInfo("Press Left to toggle wireframe mode\nPress Down to toggle small viewport\nPress Right to toggle scissor rect");
|
2022-11-09 19:54:42 +00:00
|
|
|
|
|
2023-07-01 17:41:42 +00:00
|
|
|
|
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("RawTriangle.vert"));
|
|
|
|
|
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("SolidColor.frag"));
|
2022-11-09 19:54:42 +00:00
|
|
|
|
|
2022-11-12 16:42:12 +00:00
|
|
|
|
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
|
2022-11-17 20:33:58 +00:00
|
|
|
|
MainWindow.SwapchainFormat,
|
2022-11-12 16:42:12 +00:00
|
|
|
|
vertShaderModule,
|
|
|
|
|
fragShaderModule
|
|
|
|
|
);
|
2022-11-09 19:54:42 +00:00
|
|
|
|
fillPipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
|
|
|
|
|
|
|
|
|
|
pipelineCreateInfo.RasterizerState.FillMode = FillMode.Line;
|
|
|
|
|
linePipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update(System.TimeSpan delta)
|
|
|
|
|
{
|
2022-12-23 04:48:07 +00:00
|
|
|
|
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Left))
|
2022-11-09 19:54:42 +00:00
|
|
|
|
{
|
|
|
|
|
useWireframeMode = !useWireframeMode;
|
|
|
|
|
Logger.LogInfo("Using wireframe mode: " + useWireframeMode);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-23 04:48:07 +00:00
|
|
|
|
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Bottom))
|
2022-11-09 19:54:42 +00:00
|
|
|
|
{
|
|
|
|
|
useSmallViewport = !useSmallViewport;
|
|
|
|
|
Logger.LogInfo("Using small viewport: " + useSmallViewport);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-23 04:48:07 +00:00
|
|
|
|
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Right))
|
2022-11-09 19:54:42 +00:00
|
|
|
|
{
|
|
|
|
|
useScissorRect = !useScissorRect;
|
|
|
|
|
Logger.LogInfo("Using scissor rect: " + useScissorRect);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Draw(double alpha)
|
|
|
|
|
{
|
|
|
|
|
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
|
|
|
|
|
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
|
|
|
|
|
if (backbuffer != null)
|
|
|
|
|
{
|
2024-03-07 22:24:54 +00:00
|
|
|
|
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.Black));
|
2022-11-09 19:54:42 +00:00
|
|
|
|
cmdbuf.BindGraphicsPipeline(useWireframeMode ? linePipeline : fillPipeline);
|
|
|
|
|
|
|
|
|
|
if (useSmallViewport)
|
|
|
|
|
{
|
|
|
|
|
cmdbuf.SetViewport(smallViewport);
|
|
|
|
|
}
|
|
|
|
|
if (useScissorRect)
|
|
|
|
|
{
|
|
|
|
|
cmdbuf.SetScissor(scissorRect);
|
|
|
|
|
}
|
2022-11-17 20:33:58 +00:00
|
|
|
|
|
2024-02-23 19:03:04 +00:00
|
|
|
|
cmdbuf.DrawPrimitives(0, 1);
|
2022-11-09 19:54:42 +00:00
|
|
|
|
cmdbuf.EndRenderPass();
|
|
|
|
|
}
|
|
|
|
|
GraphicsDevice.Submit(cmdbuf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
BasicTriangleGame game = new BasicTriangleGame();
|
|
|
|
|
game.Run();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|