update TexturedQuad

refresh2
cosmonaut 2024-02-23 00:07:51 -08:00
parent 59c99daa9c
commit 91aecfd13c
1 changed files with 29 additions and 31 deletions

View File

@ -1,4 +1,4 @@
using MoonWorks; using System;
using MoonWorks.Graphics; using MoonWorks.Graphics;
using MoonWorks.Math.Float; using MoonWorks.Math.Float;
@ -7,8 +7,8 @@ namespace MoonWorks.Test
class TexturedQuadGame : Game class TexturedQuadGame : Game
{ {
private GraphicsPipeline pipeline; private GraphicsPipeline pipeline;
private Buffer vertexBuffer; private GpuBuffer vertexBuffer;
private Buffer indexBuffer; private GpuBuffer indexBuffer;
private Sampler[] samplers = new Sampler[6]; private Sampler[] samplers = new Sampler[6];
private string[] samplerNames = new string[] private string[] samplerNames = new string[]
{ {
@ -71,34 +71,32 @@ namespace MoonWorks.Test
samplers[4] = new Sampler(GraphicsDevice, SamplerCreateInfo.AnisotropicClamp); samplers[4] = new Sampler(GraphicsDevice, SamplerCreateInfo.AnisotropicClamp);
samplers[5] = new Sampler(GraphicsDevice, SamplerCreateInfo.AnisotropicWrap); samplers[5] = new Sampler(GraphicsDevice, SamplerCreateInfo.AnisotropicWrap);
// Create and populate the GPU resources var vertexData = new Span<PositionTextureVertex>([
vertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 4); new PositionTextureVertex(new Vector3(-1, -1, 0), new Vector2(0, 0)),
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6); new PositionTextureVertex(new Vector3(1, -1, 0), new Vector2(4, 0)),
new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(4, 4)),
new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 4)),
]);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); var indexData = new Span<ushort>([
cmdbuf.SetBufferData( 0, 1, 2,
vertexBuffer, 0, 2, 3,
new PositionTextureVertex[] ]);
{
new PositionTextureVertex(new Vector3(-1, -1, 0), new Vector2(0, 0)), // Create and populate the GPU resources
new PositionTextureVertex(new Vector3(1, -1, 0), new Vector2(4, 0)),
new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(4, 4)), var resourceInitializer = new ResourceInitializer(GraphicsDevice);
new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 4)),
} vertexBuffer = resourceInitializer.CreateBuffer(vertexData, BufferUsageFlags.Vertex);
); indexBuffer = resourceInitializer.CreateBuffer(indexData, BufferUsageFlags.Index);
cmdbuf.SetBufferData(
indexBuffer, textures[0] = resourceInitializer.CreateTexture2D(TestUtils.GetTexturePath("ravioli.png"));
new ushort[] textures[1] = resourceInitializer.CreateTexture2D(pngBytes);
{ textures[2] = resourceInitializer.CreateTexture2D(TestUtils.GetTexturePath("ravioli.qoi"));
0, 1, 2, textures[3] = resourceInitializer.CreateTexture2D(qoiBytes);
0, 2, 3,
} resourceInitializer.Upload();
); resourceInitializer.Dispose();
textures[0] = Texture.FromImageFile(GraphicsDevice, cmdbuf, TestUtils.GetTexturePath("ravioli.png"));
textures[1] = Texture.FromImageBytes(GraphicsDevice, cmdbuf, pngBytes);
textures[2] = Texture.FromImageFile(GraphicsDevice, cmdbuf, TestUtils.GetTexturePath("ravioli.qoi"));
textures[3] = Texture.FromImageBytes(GraphicsDevice, cmdbuf, qoiBytes);
GraphicsDevice.Submit(cmdbuf);
} }
protected override void Update(System.TimeSpan delta) protected override void Update(System.TimeSpan delta)
@ -152,7 +150,7 @@ namespace MoonWorks.Test
cmdbuf.BindVertexBuffers(vertexBuffer); cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen); cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(textures[currentTextureIndex], samplers[currentSamplerIndex])); cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(textures[currentTextureIndex], samplers[currentSamplerIndex]));
cmdbuf.DrawIndexedPrimitives(0, 0, 2, 0, 0); cmdbuf.DrawIndexedPrimitives(0, 0, 2);
cmdbuf.EndRenderPass(); cmdbuf.EndRenderPass();
} }
GraphicsDevice.Submit(cmdbuf); GraphicsDevice.Submit(cmdbuf);