update RenderTextureCube

refresh2
cosmonaut 2024-02-23 13:30:29 -08:00
parent ffd7f76843
commit 59d25a0ee7
1 changed files with 29 additions and 28 deletions

View File

@ -1,5 +1,4 @@
using MoonWorks; using MoonWorks.Graphics;
using MoonWorks.Graphics;
using MoonWorks.Math.Float; using MoonWorks.Math.Float;
using MoonWorks.Math; using MoonWorks.Math;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -9,8 +8,8 @@ namespace MoonWorks.Test
class RenderTextureCubeGame : Game class RenderTextureCubeGame : Game
{ {
private GraphicsPipeline pipeline; private GraphicsPipeline pipeline;
private Buffer vertexBuffer; private GpuBuffer vertexBuffer;
private Buffer indexBuffer; private GpuBuffer indexBuffer;
private Texture cubemap; private Texture cubemap;
private Sampler sampler; private Sampler sampler;
@ -49,20 +48,10 @@ namespace MoonWorks.Test
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointClamp); sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointClamp);
// Create and populate the GPU resources // Create and populate the GPU resources
vertexBuffer = Buffer.Create<PositionVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 24); var resourceInitializer = new ResourceInitializer(GraphicsDevice);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 36);
cubemap = Texture.CreateTextureCube(
GraphicsDevice,
16,
TextureFormat.R8G8B8A8,
TextureUsageFlags.ColorTarget | TextureUsageFlags.Sampler
);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); vertexBuffer = resourceInitializer.CreateBuffer(
cmdbuf.SetBufferData( [
vertexBuffer,
new PositionVertex[]
{
new PositionVertex(new Vector3(-10, -10, -10)), new PositionVertex(new Vector3(-10, -10, -10)),
new PositionVertex(new Vector3(10, -10, -10)), new PositionVertex(new Vector3(10, -10, -10)),
new PositionVertex(new Vector3(10, 10, -10)), new PositionVertex(new Vector3(10, 10, -10)),
@ -92,22 +81,34 @@ namespace MoonWorks.Test
new PositionVertex(new Vector3(-10, 10, 10)), new PositionVertex(new Vector3(-10, 10, 10)),
new PositionVertex(new Vector3(10, 10, 10)), new PositionVertex(new Vector3(10, 10, 10)),
new PositionVertex(new Vector3(10, 10, -10)) new PositionVertex(new Vector3(10, 10, -10))
} ],
BufferUsageFlags.Vertex
); );
cmdbuf.SetBufferData( indexBuffer = resourceInitializer.CreateBuffer<ushort>(
indexBuffer, [
new ushort[] 0, 1, 2, 0, 2, 3,
{ 6, 5, 4, 7, 6, 4,
0, 1, 2, 0, 2, 3, 8, 9, 10, 8, 10, 11,
6, 5, 4, 7, 6, 4,
8, 9, 10, 8, 10, 11,
14, 13, 12, 15, 14, 12, 14, 13, 12, 15, 14, 12,
16, 17, 18, 16, 18, 19, 16, 17, 18, 16, 18, 19,
22, 21, 20, 23, 22, 20 22, 21, 20, 23, 22, 20
} ],
BufferUsageFlags.Index
); );
resourceInitializer.Upload();
resourceInitializer.Dispose();
cubemap = Texture.CreateTextureCube(
GraphicsDevice,
16,
TextureFormat.R8G8B8A8,
TextureUsageFlags.ColorTarget | TextureUsageFlags.Sampler
);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
// Clear each slice of the cubemap to a different color // Clear each slice of the cubemap to a different color
for (uint i = 0; i < 6; i += 1) for (uint i = 0; i < 6; i += 1)
{ {
@ -160,8 +161,8 @@ namespace MoonWorks.Test
cmdbuf.BindVertexBuffers(vertexBuffer); cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen); cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(cubemap, sampler)); cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(cubemap, sampler));
uint vertexUniformOffset = cmdbuf.PushVertexShaderUniforms(vertUniforms); cmdbuf.PushVertexShaderUniforms(vertUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 12, vertexUniformOffset, 0); cmdbuf.DrawIndexedPrimitives(0, 0, 12);
cmdbuf.EndRenderPass(); cmdbuf.EndRenderPass();
} }
GraphicsDevice.Submit(cmdbuf); GraphicsDevice.Submit(cmdbuf);