update RenderTexture3D

refresh2
cosmonaut 2024-02-23 13:27:36 -08:00
parent d3ae483074
commit ffd7f76843
1 changed files with 28 additions and 27 deletions

View File

@ -1,15 +1,13 @@
using MoonWorks; using MoonWorks.Graphics;
using MoonWorks.Graphics;
using MoonWorks.Math.Float; using MoonWorks.Math.Float;
using RefreshCS;
namespace MoonWorks.Test namespace MoonWorks.Test
{ {
class RenderTexture3DGame : Game class RenderTexture3DGame : Game
{ {
private GraphicsPipeline pipeline; private GraphicsPipeline pipeline;
private Buffer vertexBuffer; private GpuBuffer vertexBuffer;
private Buffer indexBuffer; private GpuBuffer indexBuffer;
private Texture rt; private Texture rt;
private Sampler sampler; private Sampler sampler;
@ -51,8 +49,29 @@ namespace MoonWorks.Test
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.LinearWrap); sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.LinearWrap);
// Create and populate the GPU resources // Create and populate the GPU resources
vertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 4); var resourceInitializer = new ResourceInitializer(GraphicsDevice);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6);
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<ushort>(
[
0, 1, 2,
0, 2, 3,
],
BufferUsageFlags.Index
);
resourceInitializer.Upload();
resourceInitializer.Dispose();
rt = Texture.CreateTexture3D( rt = Texture.CreateTexture3D(
GraphicsDevice, GraphicsDevice,
16, 16,
@ -63,24 +82,6 @@ namespace MoonWorks.Test
); );
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); 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 // Clear each depth slice of the RT to a different color
for (uint i = 0; i < colors.Length; i += 1) for (uint i = 0; i < colors.Length; i += 1)
@ -118,8 +119,8 @@ namespace MoonWorks.Test
cmdbuf.BindVertexBuffers(vertexBuffer); cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen); cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(rt, sampler)); cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(rt, sampler));
uint fragParamOffset = cmdbuf.PushFragmentShaderUniforms(fragUniform); cmdbuf.PushFragmentShaderUniforms(fragUniform);
cmdbuf.DrawIndexedPrimitives(0, 0, 2, 0, fragParamOffset); cmdbuf.DrawIndexedPrimitives(0, 0, 2);
cmdbuf.EndRenderPass(); cmdbuf.EndRenderPass();
} }
GraphicsDevice.Submit(cmdbuf); GraphicsDevice.Submit(cmdbuf);