2022-11-09 19:54:42 +00:00
|
|
|
|
using MoonWorks;
|
|
|
|
|
using MoonWorks.Graphics;
|
|
|
|
|
using MoonWorks.Math.Float;
|
|
|
|
|
|
|
|
|
|
namespace MoonWorks.Test
|
|
|
|
|
{
|
|
|
|
|
class TriangleVertexBufferGame : Game
|
|
|
|
|
{
|
|
|
|
|
private GraphicsPipeline pipeline;
|
2024-02-23 22:54:01 +00:00
|
|
|
|
private GpuBuffer vertexBuffer;
|
2022-11-09 19:54:42 +00:00
|
|
|
|
|
2024-03-07 18:35:12 +00:00
|
|
|
|
public TriangleVertexBufferGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
|
2022-11-09 19:54:42 +00:00
|
|
|
|
{
|
|
|
|
|
// Load the shaders
|
2023-07-01 17:41:42 +00:00
|
|
|
|
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("PositionColor.vert"));
|
|
|
|
|
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("SolidColor.frag"));
|
2022-11-09 19:54:42 +00:00
|
|
|
|
|
|
|
|
|
// Create the graphics pipeline
|
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
|
|
|
|
|
);
|
2023-01-06 20:38:30 +00:00
|
|
|
|
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionColorVertex>();
|
2022-11-09 19:54:42 +00:00
|
|
|
|
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
|
|
|
|
|
|
|
|
|
|
// Create and populate the vertex buffer
|
2024-02-23 22:54:01 +00:00
|
|
|
|
var resourceUploader = new ResourceUploader(GraphicsDevice);
|
2022-11-09 19:54:42 +00:00
|
|
|
|
|
2024-02-23 22:54:01 +00:00
|
|
|
|
vertexBuffer = resourceUploader.CreateBuffer(
|
|
|
|
|
[
|
2022-11-09 19:54:42 +00:00
|
|
|
|
new PositionColorVertex(new Vector3(-1, 1, 0), Color.Red),
|
|
|
|
|
new PositionColorVertex(new Vector3(1, 1, 0), Color.Lime),
|
|
|
|
|
new PositionColorVertex(new Vector3(0, -1, 0), Color.Blue),
|
2024-02-23 22:54:01 +00:00
|
|
|
|
],
|
|
|
|
|
BufferUsageFlags.Vertex
|
2022-11-09 19:54:42 +00:00
|
|
|
|
);
|
2024-02-23 22:54:01 +00:00
|
|
|
|
|
|
|
|
|
resourceUploader.Upload();
|
|
|
|
|
resourceUploader.Dispose();
|
2022-11-09 19:54:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update(System.TimeSpan delta) { }
|
|
|
|
|
|
|
|
|
|
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(pipeline);
|
|
|
|
|
cmdbuf.BindVertexBuffers(vertexBuffer);
|
2024-02-23 22:54:01 +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)
|
|
|
|
|
{
|
|
|
|
|
TriangleVertexBufferGame p = new TriangleVertexBufferGame();
|
|
|
|
|
p.Run();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|