From 683fffad16e45c1643a76a3c731408523918c60a Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Fri, 23 Feb 2024 13:06:53 -0800 Subject: [PATCH] update InstancingAndOffsets --- .../InstancingAndOffsetsGame.cs | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/InstancingAndOffsets/InstancingAndOffsetsGame.cs b/InstancingAndOffsets/InstancingAndOffsetsGame.cs index 01dd64c..2ab062e 100644 --- a/InstancingAndOffsets/InstancingAndOffsetsGame.cs +++ b/InstancingAndOffsets/InstancingAndOffsetsGame.cs @@ -7,8 +7,8 @@ namespace MoonWorks.Test class InstancingAndOffsetsGame : Game { private GraphicsPipeline pipeline; - private Buffer vertexBuffer; - private Buffer indexBuffer; + private GpuBuffer vertexBuffer; + private GpuBuffer indexBuffer; private bool useVertexOffset; private bool useIndexOffset; @@ -31,14 +31,10 @@ namespace MoonWorks.Test pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo); // Create and populate the vertex and index buffers - vertexBuffer = Buffer.Create(GraphicsDevice, BufferUsageFlags.Vertex, 9); - indexBuffer = Buffer.Create(GraphicsDevice, BufferUsageFlags.Index, 6); + var resourceInitializer = new ResourceInitializer(GraphicsDevice); - CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); - cmdbuf.SetBufferData( - vertexBuffer, - new PositionColorVertex[] - { + vertexBuffer = resourceInitializer.CreateBuffer( + [ 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), @@ -50,17 +46,20 @@ namespace MoonWorks.Test new PositionColorVertex(new Vector3(-1, 1, 0), Color.White), new PositionColorVertex(new Vector3(1, 1, 0), Color.White), new PositionColorVertex(new Vector3(0, -1, 0), Color.White), - } + ], + BufferUsageFlags.Vertex ); - cmdbuf.SetBufferData( - indexBuffer, - new ushort[] - { + + indexBuffer = resourceInitializer.CreateBuffer( + [ 0, 1, 2, 3, 4, 5, - } + ], + BufferUsageFlags.Index ); - GraphicsDevice.Submit(cmdbuf); + + resourceInitializer.Upload(); + resourceInitializer.Dispose(); } protected override void Update(System.TimeSpan delta) @@ -91,7 +90,7 @@ namespace MoonWorks.Test cmdbuf.BindGraphicsPipeline(pipeline); cmdbuf.BindVertexBuffers(vertexBuffer); cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen); - cmdbuf.DrawInstancedPrimitives(vertexOffset, indexOffset, 1, 16, 0, 0); + cmdbuf.DrawInstancedPrimitives(vertexOffset, indexOffset, 1, 16); cmdbuf.EndRenderPass(); } GraphicsDevice.Submit(cmdbuf);