From 89dea810ccf7b485eb42081a5d34d9789f66c9b9 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Fri, 23 Feb 2024 14:54:01 -0800 Subject: [PATCH] update examples that load from compressed image files --- CopyTexture/CopyTextureGame.cs | 2 +- .../TexturedAnimatedQuadGame.cs | 2 +- TexturedQuad/TexturedQuadGame.cs | 8 +++--- .../TriangleVertexBufferGame.cs | 20 +++++++------- VertexSampler/VertexSamplerGame.cs | 27 +++++++++++-------- 5 files changed, 32 insertions(+), 27 deletions(-) diff --git a/CopyTexture/CopyTextureGame.cs b/CopyTexture/CopyTextureGame.cs index 8342502..ec0fdb1 100644 --- a/CopyTexture/CopyTextureGame.cs +++ b/CopyTexture/CopyTextureGame.cs @@ -65,7 +65,7 @@ namespace MoonWorks.Test BufferUsageFlags.Index ); - originalTexture = resourceUploader.CreateTexture2D( + originalTexture = resourceUploader.CreateTexture2DFromCompressed( TestUtils.GetTexturePath("ravioli.png") ); diff --git a/TexturedAnimatedQuad/TexturedAnimatedQuadGame.cs b/TexturedAnimatedQuad/TexturedAnimatedQuadGame.cs index f7065fe..d6ee025 100644 --- a/TexturedAnimatedQuad/TexturedAnimatedQuadGame.cs +++ b/TexturedAnimatedQuad/TexturedAnimatedQuadGame.cs @@ -66,7 +66,7 @@ namespace MoonWorks.Test BufferUsageFlags.Index ); - texture = resourceUploader.CreateTexture2D(TestUtils.GetTexturePath("ravioli.png")); + texture = resourceUploader.CreateTexture2DFromCompressed(TestUtils.GetTexturePath("ravioli.png")); resourceUploader.Upload(); resourceUploader.Dispose(); diff --git a/TexturedQuad/TexturedQuadGame.cs b/TexturedQuad/TexturedQuadGame.cs index 080bc50..9cd8660 100644 --- a/TexturedQuad/TexturedQuadGame.cs +++ b/TexturedQuad/TexturedQuadGame.cs @@ -90,10 +90,10 @@ namespace MoonWorks.Test vertexBuffer = resourceUploader.CreateBuffer(vertexData, BufferUsageFlags.Vertex); indexBuffer = resourceUploader.CreateBuffer(indexData, BufferUsageFlags.Index); - textures[0] = resourceUploader.CreateTexture2D(TestUtils.GetTexturePath("ravioli.png")); - textures[1] = resourceUploader.CreateTexture2D(pngBytes); - textures[2] = resourceUploader.CreateTexture2D(TestUtils.GetTexturePath("ravioli.qoi")); - textures[3] = resourceUploader.CreateTexture2D(qoiBytes); + textures[0] = resourceUploader.CreateTexture2DFromCompressed(TestUtils.GetTexturePath("ravioli.png")); + textures[1] = resourceUploader.CreateTexture2DFromCompressed(pngBytes); + textures[2] = resourceUploader.CreateTexture2DFromCompressed(TestUtils.GetTexturePath("ravioli.qoi")); + textures[3] = resourceUploader.CreateTexture2DFromCompressed(qoiBytes); resourceUploader.Upload(); resourceUploader.Dispose(); diff --git a/TriangleVertexBuffer/TriangleVertexBufferGame.cs b/TriangleVertexBuffer/TriangleVertexBufferGame.cs index b3d4d11..7976036 100644 --- a/TriangleVertexBuffer/TriangleVertexBufferGame.cs +++ b/TriangleVertexBuffer/TriangleVertexBufferGame.cs @@ -7,7 +7,7 @@ namespace MoonWorks.Test class TriangleVertexBufferGame : Game { private GraphicsPipeline pipeline; - private Buffer vertexBuffer; + private GpuBuffer vertexBuffer; public TriangleVertexBufferGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true) { @@ -25,19 +25,19 @@ namespace MoonWorks.Test pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo); // Create and populate the vertex buffer - vertexBuffer = Buffer.Create(GraphicsDevice, BufferUsageFlags.Vertex, 3); + var resourceUploader = new ResourceUploader(GraphicsDevice); - CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); - cmdbuf.SetBufferData( - vertexBuffer, - new PositionColorVertex[] - { + vertexBuffer = resourceUploader.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), - } + ], + BufferUsageFlags.Vertex ); - GraphicsDevice.Submit(cmdbuf); + + resourceUploader.Upload(); + resourceUploader.Dispose(); } protected override void Update(System.TimeSpan delta) { } @@ -51,7 +51,7 @@ namespace MoonWorks.Test cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black)); cmdbuf.BindGraphicsPipeline(pipeline); cmdbuf.BindVertexBuffers(vertexBuffer); - cmdbuf.DrawPrimitives(0, 1, 0, 0); + cmdbuf.DrawPrimitives(0, 1); cmdbuf.EndRenderPass(); } GraphicsDevice.Submit(cmdbuf); diff --git a/VertexSampler/VertexSamplerGame.cs b/VertexSampler/VertexSamplerGame.cs index f213d87..0ed61fc 100644 --- a/VertexSampler/VertexSamplerGame.cs +++ b/VertexSampler/VertexSamplerGame.cs @@ -7,7 +7,7 @@ namespace MoonWorks.Test class VertexSamplerGame : Game { private GraphicsPipeline pipeline; - private Buffer vertexBuffer; + private GpuBuffer vertexBuffer; private Texture texture; private Sampler sampler; @@ -28,22 +28,27 @@ namespace MoonWorks.Test pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo); // Create and populate the GPU resources - vertexBuffer = Buffer.Create(GraphicsDevice, BufferUsageFlags.Vertex, 3); texture = Texture.CreateTexture2D(GraphicsDevice, 3, 1, TextureFormat.R8G8B8A8, TextureUsageFlags.Sampler); sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointClamp); - CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); - cmdbuf.SetBufferData( - vertexBuffer, - new PositionTextureVertex[] - { + var resourceUploader = new ResourceUploader(GraphicsDevice); + + vertexBuffer = resourceUploader.CreateBuffer( + [ new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 0)), new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(0.334f, 0)), new PositionTextureVertex(new Vector3(0, -1, 0), new Vector2(0.667f, 0)), - } + ], + BufferUsageFlags.Vertex ); - cmdbuf.SetTextureData(texture, new Color[] { Color.Yellow, Color.Indigo, Color.HotPink }); - GraphicsDevice.Submit(cmdbuf); + + resourceUploader.SetTextureData( + texture, + [Color.Yellow, Color.Indigo, Color.HotPink] + ); + + resourceUploader.Upload(); + resourceUploader.Dispose(); } protected override void Update(System.TimeSpan delta) { } @@ -58,7 +63,7 @@ namespace MoonWorks.Test cmdbuf.BindGraphicsPipeline(pipeline); cmdbuf.BindVertexBuffers(vertexBuffer); cmdbuf.BindVertexSamplers(new TextureSamplerBinding(texture, sampler)); - cmdbuf.DrawPrimitives(0, 1, 0, 0); + cmdbuf.DrawPrimitives(0, 1); cmdbuf.EndRenderPass(); } GraphicsDevice.Submit(cmdbuf);