From ffd7f76843211d4bbeb92b643f7613aa282ea72c Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Fri, 23 Feb 2024 13:27:36 -0800 Subject: [PATCH] update RenderTexture3D --- RenderTexture3D/RenderTexture3DGame.cs | 55 +++++++++++++------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/RenderTexture3D/RenderTexture3DGame.cs b/RenderTexture3D/RenderTexture3DGame.cs index 03113a1..a98b7d1 100644 --- a/RenderTexture3D/RenderTexture3DGame.cs +++ b/RenderTexture3D/RenderTexture3DGame.cs @@ -1,15 +1,13 @@ -using MoonWorks; -using MoonWorks.Graphics; +using MoonWorks.Graphics; using MoonWorks.Math.Float; -using RefreshCS; namespace MoonWorks.Test { class RenderTexture3DGame : Game { private GraphicsPipeline pipeline; - private Buffer vertexBuffer; - private Buffer indexBuffer; + private GpuBuffer vertexBuffer; + private GpuBuffer indexBuffer; private Texture rt; private Sampler sampler; @@ -51,8 +49,29 @@ namespace MoonWorks.Test sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.LinearWrap); // Create and populate the GPU resources - vertexBuffer = Buffer.Create(GraphicsDevice, BufferUsageFlags.Vertex, 4); - indexBuffer = Buffer.Create(GraphicsDevice, BufferUsageFlags.Index, 6); + var resourceInitializer = new ResourceInitializer(GraphicsDevice); + + vertexBuffer = resourceInitializer.CreateBuffer( + [ + new PositionTextureVertex(new Vector3(-1, -1, 0), new Vector2(0, 0)), + new PositionTextureVertex(new Vector3(1, -1, 0), new Vector2(1, 0)), + new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(1, 1)), + new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 1)), + ], + BufferUsageFlags.Vertex + ); + + indexBuffer = resourceInitializer.CreateBuffer( + [ + 0, 1, 2, + 0, 2, 3, + ], + BufferUsageFlags.Index + ); + + resourceInitializer.Upload(); + resourceInitializer.Dispose(); + rt = Texture.CreateTexture3D( GraphicsDevice, 16, @@ -63,24 +82,6 @@ namespace MoonWorks.Test ); CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); - cmdbuf.SetBufferData( - vertexBuffer, - new PositionTextureVertex[] - { - new PositionTextureVertex(new Vector3(-1, -1, 0), new Vector2(0, 0)), - new PositionTextureVertex(new Vector3(1, -1, 0), new Vector2(1, 0)), - new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(1, 1)), - new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 1)), - } - ); - cmdbuf.SetBufferData( - indexBuffer, - new ushort[] - { - 0, 1, 2, - 0, 2, 3, - } - ); // Clear each depth slice of the RT to a different color for (uint i = 0; i < colors.Length; i += 1) @@ -118,8 +119,8 @@ namespace MoonWorks.Test cmdbuf.BindVertexBuffers(vertexBuffer); cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen); cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(rt, sampler)); - uint fragParamOffset = cmdbuf.PushFragmentShaderUniforms(fragUniform); - cmdbuf.DrawIndexedPrimitives(0, 0, 2, 0, fragParamOffset); + cmdbuf.PushFragmentShaderUniforms(fragUniform); + cmdbuf.DrawIndexedPrimitives(0, 0, 2); cmdbuf.EndRenderPass(); } GraphicsDevice.Submit(cmdbuf);