update DrawIndirect

refresh2
cosmonaut 2024-02-23 12:51:42 -08:00
parent f71917310d
commit c878a26b74
1 changed files with 17 additions and 19 deletions

View File

@ -1,5 +1,4 @@
using MoonWorks; using MoonWorks.Graphics;
using MoonWorks.Graphics;
using MoonWorks.Math.Float; using MoonWorks.Math.Float;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -8,8 +7,8 @@ namespace MoonWorks.Test
class DrawIndirectGame : Game class DrawIndirectGame : Game
{ {
private GraphicsPipeline graphicsPipeline; private GraphicsPipeline graphicsPipeline;
private Buffer vertexBuffer; private GpuBuffer vertexBuffer;
private Buffer drawBuffer; private GpuBuffer drawBuffer;
public DrawIndirectGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true) public DrawIndirectGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{ {
@ -27,14 +26,10 @@ namespace MoonWorks.Test
graphicsPipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo); graphicsPipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create and populate the vertex buffer // Create and populate the vertex buffer
vertexBuffer = Buffer.Create<PositionColorVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 6); var resourceInitializer = new ResourceInitializer(GraphicsDevice);
drawBuffer = Buffer.Create<IndirectDrawCommand>(GraphicsDevice, BufferUsageFlags.Indirect, 2);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); vertexBuffer = resourceInitializer.CreateBuffer(
cmdbuf.SetBufferData( [
vertexBuffer,
new PositionColorVertex[]
{
new PositionColorVertex(new Vector3(-0.5f, -1, 0), Color.Blue), new PositionColorVertex(new Vector3(-0.5f, -1, 0), Color.Blue),
new PositionColorVertex(new Vector3(-1f, 1, 0), Color.Green), new PositionColorVertex(new Vector3(-1f, 1, 0), Color.Green),
new PositionColorVertex(new Vector3(0f, 1, 0), Color.Red), new PositionColorVertex(new Vector3(0f, 1, 0), Color.Red),
@ -42,17 +37,20 @@ namespace MoonWorks.Test
new PositionColorVertex(new Vector3(.5f, -1, 0), Color.Blue), new PositionColorVertex(new Vector3(.5f, -1, 0), Color.Blue),
new PositionColorVertex(new Vector3(1f, 1, 0), Color.Green), new PositionColorVertex(new Vector3(1f, 1, 0), Color.Green),
new PositionColorVertex(new Vector3(0f, 1, 0), Color.Red), new PositionColorVertex(new Vector3(0f, 1, 0), Color.Red),
} ],
BufferUsageFlags.Vertex
); );
cmdbuf.SetBufferData(
drawBuffer, drawBuffer = resourceInitializer.CreateBuffer(
new IndirectDrawCommand[] [
{
new IndirectDrawCommand(3, 1, 3, 0), new IndirectDrawCommand(3, 1, 3, 0),
new IndirectDrawCommand(3, 1, 0, 0), new IndirectDrawCommand(3, 1, 0, 0),
} ],
BufferUsageFlags.Indirect
); );
GraphicsDevice.Submit(cmdbuf);
resourceInitializer.Upload();
resourceInitializer.Dispose();
} }
protected override void Update(System.TimeSpan delta) { } protected override void Update(System.TimeSpan delta) { }
@ -66,7 +64,7 @@ namespace MoonWorks.Test
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.CornflowerBlue)); cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.CornflowerBlue));
cmdbuf.BindGraphicsPipeline(graphicsPipeline); cmdbuf.BindGraphicsPipeline(graphicsPipeline);
cmdbuf.BindVertexBuffers(new BufferBinding(vertexBuffer, 0)); cmdbuf.BindVertexBuffers(new BufferBinding(vertexBuffer, 0));
cmdbuf.DrawPrimitivesIndirect(drawBuffer, 0, 2, (uint) Marshal.SizeOf<IndirectDrawCommand>(), 0, 0); cmdbuf.DrawPrimitivesIndirect(drawBuffer, 0, 2, (uint) Marshal.SizeOf<IndirectDrawCommand>());
cmdbuf.EndRenderPass(); cmdbuf.EndRenderPass();
} }
GraphicsDevice.Submit(cmdbuf); GraphicsDevice.Submit(cmdbuf);