update InstancingAndOffsets

refresh2
cosmonaut 2024-02-23 13:06:53 -08:00
parent c2f1a02ba3
commit 683fffad16
1 changed files with 16 additions and 17 deletions

View File

@ -7,8 +7,8 @@ namespace MoonWorks.Test
class InstancingAndOffsetsGame : Game class InstancingAndOffsetsGame : Game
{ {
private GraphicsPipeline pipeline; private GraphicsPipeline pipeline;
private Buffer vertexBuffer; private GpuBuffer vertexBuffer;
private Buffer indexBuffer; private GpuBuffer indexBuffer;
private bool useVertexOffset; private bool useVertexOffset;
private bool useIndexOffset; private bool useIndexOffset;
@ -31,14 +31,10 @@ namespace MoonWorks.Test
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo); pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create and populate the vertex and index buffers // Create and populate the vertex and index buffers
vertexBuffer = Buffer.Create<PositionColorVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 9); var resourceInitializer = new ResourceInitializer(GraphicsDevice);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); vertexBuffer = resourceInitializer.CreateBuffer(
cmdbuf.SetBufferData( [
vertexBuffer,
new PositionColorVertex[]
{
new PositionColorVertex(new Vector3(-1, 1, 0), Color.Red), new PositionColorVertex(new Vector3(-1, 1, 0), Color.Red),
new PositionColorVertex(new Vector3(1, 1, 0), Color.Lime), new PositionColorVertex(new Vector3(1, 1, 0), Color.Lime),
new PositionColorVertex(new Vector3(0, -1, 0), Color.Blue), 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(1, 1, 0), Color.White), new PositionColorVertex(new Vector3(1, 1, 0), Color.White),
new PositionColorVertex(new Vector3(0, -1, 0), Color.White), new PositionColorVertex(new Vector3(0, -1, 0), Color.White),
} ],
BufferUsageFlags.Vertex
); );
cmdbuf.SetBufferData(
indexBuffer, indexBuffer = resourceInitializer.CreateBuffer<ushort>(
new ushort[] [
{
0, 1, 2, 0, 1, 2,
3, 4, 5, 3, 4, 5,
} ],
BufferUsageFlags.Index
); );
GraphicsDevice.Submit(cmdbuf);
resourceInitializer.Upload();
resourceInitializer.Dispose();
} }
protected override void Update(System.TimeSpan delta) protected override void Update(System.TimeSpan delta)
@ -91,7 +90,7 @@ namespace MoonWorks.Test
cmdbuf.BindGraphicsPipeline(pipeline); cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer); cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen); cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.DrawInstancedPrimitives(vertexOffset, indexOffset, 1, 16, 0, 0); cmdbuf.DrawInstancedPrimitives(vertexOffset, indexOffset, 1, 16);
cmdbuf.EndRenderPass(); cmdbuf.EndRenderPass();
} }
GraphicsDevice.Submit(cmdbuf); GraphicsDevice.Submit(cmdbuf);