update TexturedQuad
parent
59c99daa9c
commit
91aecfd13c
|
@ -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);
|
|
||||||
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6);
|
|
||||||
|
|
||||||
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(0, 0)),
|
||||||
new PositionTextureVertex(new Vector3(1, -1, 0), new Vector2(4, 0)),
|
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(4, 4)),
|
||||||
new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 4)),
|
new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 4)),
|
||||||
}
|
]);
|
||||||
);
|
|
||||||
cmdbuf.SetBufferData(
|
var indexData = new Span<ushort>([
|
||||||
indexBuffer,
|
|
||||||
new ushort[]
|
|
||||||
{
|
|
||||||
0, 1, 2,
|
0, 1, 2,
|
||||||
0, 2, 3,
|
0, 2, 3,
|
||||||
}
|
]);
|
||||||
);
|
|
||||||
textures[0] = Texture.FromImageFile(GraphicsDevice, cmdbuf, TestUtils.GetTexturePath("ravioli.png"));
|
// Create and populate the GPU resources
|
||||||
textures[1] = Texture.FromImageBytes(GraphicsDevice, cmdbuf, pngBytes);
|
|
||||||
textures[2] = Texture.FromImageFile(GraphicsDevice, cmdbuf, TestUtils.GetTexturePath("ravioli.qoi"));
|
var resourceInitializer = new ResourceInitializer(GraphicsDevice);
|
||||||
textures[3] = Texture.FromImageBytes(GraphicsDevice, cmdbuf, qoiBytes);
|
|
||||||
GraphicsDevice.Submit(cmdbuf);
|
vertexBuffer = resourceInitializer.CreateBuffer(vertexData, BufferUsageFlags.Vertex);
|
||||||
|
indexBuffer = resourceInitializer.CreateBuffer(indexData, BufferUsageFlags.Index);
|
||||||
|
|
||||||
|
textures[0] = resourceInitializer.CreateTexture2D(TestUtils.GetTexturePath("ravioli.png"));
|
||||||
|
textures[1] = resourceInitializer.CreateTexture2D(pngBytes);
|
||||||
|
textures[2] = resourceInitializer.CreateTexture2D(TestUtils.GetTexturePath("ravioli.qoi"));
|
||||||
|
textures[3] = resourceInitializer.CreateTexture2D(qoiBytes);
|
||||||
|
|
||||||
|
resourceInitializer.Upload();
|
||||||
|
resourceInitializer.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
Loading…
Reference in New Issue