Tabs, not spaces

main
Caleb Cornett 2024-02-07 09:27:55 -06:00
parent a64db5d0e1
commit 74b6e00bc8
21 changed files with 2073 additions and 2073 deletions

View File

@ -4,139 +4,139 @@ using MoonWorks.Math.Float;
namespace MoonWorks.Test
{
class BasicComputeGame : Game
{
private GraphicsPipeline drawPipeline;
private Texture texture;
private Sampler sampler;
private Buffer vertexBuffer;
class BasicComputeGame : Game
{
private GraphicsPipeline drawPipeline;
private Texture texture;
private Sampler sampler;
private Buffer vertexBuffer;
public BasicComputeGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
// Create the compute pipeline that writes texture data
ShaderModule fillTextureComputeShaderModule = new ShaderModule(
GraphicsDevice,
TestUtils.GetShaderPath("FillTexture.comp")
);
public BasicComputeGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
// Create the compute pipeline that writes texture data
ShaderModule fillTextureComputeShaderModule = new ShaderModule(
GraphicsDevice,
TestUtils.GetShaderPath("FillTexture.comp")
);
ComputePipeline fillTextureComputePipeline = new ComputePipeline(
GraphicsDevice,
ComputeShaderInfo.Create(fillTextureComputeShaderModule, "main", 0, 1)
);
ComputePipeline fillTextureComputePipeline = new ComputePipeline(
GraphicsDevice,
ComputeShaderInfo.Create(fillTextureComputeShaderModule, "main", 0, 1)
);
// Create the compute pipeline that calculates squares of numbers
ShaderModule calculateSquaresComputeShaderModule = new ShaderModule(
GraphicsDevice,
TestUtils.GetShaderPath("CalculateSquares.comp")
);
// Create the compute pipeline that calculates squares of numbers
ShaderModule calculateSquaresComputeShaderModule = new ShaderModule(
GraphicsDevice,
TestUtils.GetShaderPath("CalculateSquares.comp")
);
ComputePipeline calculateSquaresComputePipeline = new ComputePipeline(
GraphicsDevice,
ComputeShaderInfo.Create(calculateSquaresComputeShaderModule, "main", 1, 0)
);
ComputePipeline calculateSquaresComputePipeline = new ComputePipeline(
GraphicsDevice,
ComputeShaderInfo.Create(calculateSquaresComputeShaderModule, "main", 1, 0)
);
// Create the graphics pipeline
ShaderModule vertShaderModule = new ShaderModule(
GraphicsDevice,
TestUtils.GetShaderPath("TexturedQuad.vert")
);
// Create the graphics pipeline
ShaderModule vertShaderModule = new ShaderModule(
GraphicsDevice,
TestUtils.GetShaderPath("TexturedQuad.vert")
);
ShaderModule fragShaderModule = new ShaderModule(
GraphicsDevice,
TestUtils.GetShaderPath("TexturedQuad.frag")
);
ShaderModule fragShaderModule = new ShaderModule(
GraphicsDevice,
TestUtils.GetShaderPath("TexturedQuad.frag")
);
GraphicsPipelineCreateInfo drawPipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
GraphicsPipelineCreateInfo drawPipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
drawPipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
drawPipelineCreateInfo.FragmentShaderInfo.SamplerBindingCount = 1;
vertShaderModule,
fragShaderModule
);
drawPipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
drawPipelineCreateInfo.FragmentShaderInfo.SamplerBindingCount = 1;
drawPipeline = new GraphicsPipeline(
GraphicsDevice,
drawPipelineCreateInfo
);
drawPipeline = new GraphicsPipeline(
GraphicsDevice,
drawPipelineCreateInfo
);
// Create buffers and textures
uint[] squares = new uint[64];
Buffer squaresBuffer = Buffer.Create<uint>(
GraphicsDevice,
BufferUsageFlags.Compute,
(uint) squares.Length
);
// Create buffers and textures
uint[] squares = new uint[64];
Buffer squaresBuffer = Buffer.Create<uint>(
GraphicsDevice,
BufferUsageFlags.Compute,
(uint) squares.Length
);
vertexBuffer = Buffer.Create<PositionTextureVertex>(
GraphicsDevice,
BufferUsageFlags.Vertex,
6
);
vertexBuffer = Buffer.Create<PositionTextureVertex>(
GraphicsDevice,
BufferUsageFlags.Vertex,
6
);
texture = Texture.CreateTexture2D(
GraphicsDevice,
MainWindow.Width,
MainWindow.Height,
TextureFormat.R8G8B8A8,
TextureUsageFlags.Compute | TextureUsageFlags.Sampler
);
texture = Texture.CreateTexture2D(
GraphicsDevice,
MainWindow.Width,
MainWindow.Height,
TextureFormat.R8G8B8A8,
TextureUsageFlags.Compute | TextureUsageFlags.Sampler
);
sampler = new Sampler(GraphicsDevice, new SamplerCreateInfo());
sampler = new Sampler(GraphicsDevice, new SamplerCreateInfo());
// Upload GPU resources and dispatch compute work
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
// Upload GPU resources and dispatch compute work
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, 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(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, 0)),
new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(1, 1)),
new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 1)),
});
// This should result in a bright yellow texture!
cmdbuf.BindComputePipeline(fillTextureComputePipeline);
cmdbuf.BindComputeTextures(texture);
cmdbuf.DispatchCompute(texture.Width / 8, texture.Height / 8, 1, 0);
// This should result in a bright yellow texture!
cmdbuf.BindComputePipeline(fillTextureComputePipeline);
cmdbuf.BindComputeTextures(texture);
cmdbuf.DispatchCompute(texture.Width / 8, texture.Height / 8, 1, 0);
// This calculates the squares of the first N integers!
cmdbuf.BindComputePipeline(calculateSquaresComputePipeline);
cmdbuf.BindComputeBuffers(squaresBuffer);
cmdbuf.DispatchCompute((uint) squares.Length / 8, 1, 1, 0);
// This calculates the squares of the first N integers!
cmdbuf.BindComputePipeline(calculateSquaresComputePipeline);
cmdbuf.BindComputeBuffers(squaresBuffer);
cmdbuf.DispatchCompute((uint) squares.Length / 8, 1, 1, 0);
var fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
GraphicsDevice.WaitForFences(fence);
var fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
GraphicsDevice.WaitForFences(fence);
GraphicsDevice.ReleaseFence(fence);
// Print the squares!
squaresBuffer.GetData(squares);
Logger.LogInfo("Squares of the first " + squares.Length + " integers: " + string.Join(", ", squares));
}
// Print the squares!
squaresBuffer.GetData(squares);
Logger.LogInfo("Squares of the first " + squares.Length + " integers: " + string.Join(", ", squares));
}
protected override void Update(System.TimeSpan delta) { }
protected override void Update(System.TimeSpan delta) { }
protected override void Draw(double alpha)
{
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.CornflowerBlue));
cmdbuf.BindGraphicsPipeline(drawPipeline);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(texture, sampler));
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.DrawPrimitives(0, 2, 0, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
protected override void Draw(double alpha)
{
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.CornflowerBlue));
cmdbuf.BindGraphicsPipeline(drawPipeline);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(texture, sampler));
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.DrawPrimitives(0, 2, 0, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
public static void Main(string[] args)
{
BasicComputeGame game = new BasicComputeGame();
game.Run();
}
}
public static void Main(string[] args)
{
BasicComputeGame game = new BasicComputeGame();
game.Run();
}
}
}

View File

@ -4,107 +4,107 @@ using MoonWorks.Math.Float;
namespace MoonWorks.Test
{
class BasicStencilGame : Game
{
private GraphicsPipeline maskerPipeline;
private GraphicsPipeline maskeePipeline;
private Buffer vertexBuffer;
private Texture depthStencilTexture;
class BasicStencilGame : Game
{
private GraphicsPipeline maskerPipeline;
private GraphicsPipeline maskeePipeline;
private Buffer vertexBuffer;
private Texture depthStencilTexture;
public BasicStencilGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("PositionColor.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("SolidColor.frag"));
public BasicStencilGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("PositionColor.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("SolidColor.frag"));
// Create the graphics pipelines
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipelineCreateInfo.AttachmentInfo.HasDepthStencilAttachment = true;
pipelineCreateInfo.AttachmentInfo.DepthStencilFormat = TextureFormat.D16S8;
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionColorVertex>();
pipelineCreateInfo.DepthStencilState = new DepthStencilState
{
StencilTestEnable = true,
FrontStencilState = new StencilOpState
{
Reference = 1,
WriteMask = 0xFF,
CompareOp = CompareOp.Never,
FailOp = StencilOp.Replace,
}
};
maskerPipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create the graphics pipelines
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipelineCreateInfo.AttachmentInfo.HasDepthStencilAttachment = true;
pipelineCreateInfo.AttachmentInfo.DepthStencilFormat = TextureFormat.D16S8;
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionColorVertex>();
pipelineCreateInfo.DepthStencilState = new DepthStencilState
{
StencilTestEnable = true,
FrontStencilState = new StencilOpState
{
Reference = 1,
WriteMask = 0xFF,
CompareOp = CompareOp.Never,
FailOp = StencilOp.Replace,
}
};
maskerPipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
pipelineCreateInfo.DepthStencilState = new DepthStencilState
{
StencilTestEnable = true,
FrontStencilState = new StencilOpState
{
Reference = 0,
CompareMask = 0xFF,
WriteMask = 0,
CompareOp = CompareOp.Equal,
}
};
maskeePipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
pipelineCreateInfo.DepthStencilState = new DepthStencilState
{
StencilTestEnable = true,
FrontStencilState = new StencilOpState
{
Reference = 0,
CompareMask = 0xFF,
WriteMask = 0,
CompareOp = CompareOp.Equal,
}
};
maskeePipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create and populate the GPU resources
depthStencilTexture = Texture.CreateTexture2D(
GraphicsDevice,
MainWindow.Width,
MainWindow.Height,
TextureFormat.D16S8,
TextureUsageFlags.DepthStencilTarget
);
vertexBuffer = Buffer.Create<PositionColorVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 6);
// Create and populate the GPU resources
depthStencilTexture = Texture.CreateTexture2D(
GraphicsDevice,
MainWindow.Width,
MainWindow.Height,
TextureFormat.D16S8,
TextureUsageFlags.DepthStencilTarget
);
vertexBuffer = Buffer.Create<PositionColorVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 6);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
vertexBuffer,
new PositionColorVertex[]
{
new PositionColorVertex(new Vector3(-0.5f, 0.5f, 0), Color.Yellow),
new PositionColorVertex(new Vector3(0.5f, 0.5f, 0), Color.Yellow),
new PositionColorVertex(new Vector3(0, -0.5f, 0), Color.Yellow),
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
vertexBuffer,
new PositionColorVertex[]
{
new PositionColorVertex(new Vector3(-0.5f, 0.5f, 0), Color.Yellow),
new PositionColorVertex(new Vector3(0.5f, 0.5f, 0), Color.Yellow),
new PositionColorVertex(new Vector3(0, -0.5f, 0), Color.Yellow),
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),
}
);
GraphicsDevice.Submit(cmdbuf);
}
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),
}
);
GraphicsDevice.Submit(cmdbuf);
}
protected override void Update(System.TimeSpan delta) { }
protected override void Update(System.TimeSpan delta) { }
protected override void Draw(double alpha)
{
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(
new DepthStencilAttachmentInfo(depthStencilTexture, new DepthStencilValue(0, 0), StoreOp.DontCare, StoreOp.DontCare),
new ColorAttachmentInfo(backbuffer, Color.Black)
);
cmdbuf.BindGraphicsPipeline(maskerPipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.DrawPrimitives(0, 1, 0, 0);
cmdbuf.BindGraphicsPipeline(maskeePipeline);
cmdbuf.DrawPrimitives(3, 1, 0, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
protected override void Draw(double alpha)
{
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(
new DepthStencilAttachmentInfo(depthStencilTexture, new DepthStencilValue(0, 0), StoreOp.DontCare, StoreOp.DontCare),
new ColorAttachmentInfo(backbuffer, Color.Black)
);
cmdbuf.BindGraphicsPipeline(maskerPipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.DrawPrimitives(0, 1, 0, 0);
cmdbuf.BindGraphicsPipeline(maskeePipeline);
cmdbuf.DrawPrimitives(3, 1, 0, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
public static void Main(string[] args)
{
BasicStencilGame p = new BasicStencilGame();
p.Run();
}
}
public static void Main(string[] args)
{
BasicStencilGame p = new BasicStencilGame();
p.Run();
}
}
}

View File

@ -17,7 +17,7 @@ namespace MoonWorks.Test
public BasicTriangleGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
Logger.LogInfo("Press Left to toggle wireframe mode\nPress Down to toggle small viewport\nPress Right to toggle scissor rect");
Logger.LogInfo("Press Left to toggle wireframe mode\nPress Down to toggle small viewport\nPress Right to toggle scissor rect");
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("RawTriangle.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("SolidColor.frag"));

View File

@ -5,129 +5,129 @@ using System.IO;
namespace MoonWorks.Test
{
class CompressedTexturesGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private Sampler sampler;
private Texture[] textures;
private string[] textureNames = new string[]
{
"BC1",
"BC2",
"BC3",
"BC7"
};
class CompressedTexturesGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private Sampler sampler;
private Texture[] textures;
private string[] textureNames = new string[]
{
"BC1",
"BC2",
"BC3",
"BC7"
};
private int currentTextureIndex;
private int currentTextureIndex;
public CompressedTexturesGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
Logger.LogInfo("Press Left and Right to cycle between textures");
Logger.LogInfo("Setting texture to: " + textureNames[0]);
public CompressedTexturesGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
Logger.LogInfo("Press Left and Right to cycle between textures");
Logger.LogInfo("Setting texture to: " + textureNames[0]);
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.frag"));
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.frag"));
// Create the graphics pipeline
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
pipelineCreateInfo.FragmentShaderInfo.SamplerBindingCount = 1;
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create the graphics pipeline
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
pipelineCreateInfo.FragmentShaderInfo.SamplerBindingCount = 1;
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create sampler
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.LinearWrap);
// Create sampler
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.LinearWrap);
// Create texture array
textures = new Texture[textureNames.Length];
// Create texture array
textures = new Texture[textureNames.Length];
// Create and populate the GPU resources
vertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 4);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6);
// Create and populate the GPU resources
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(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,
}
);
for (int i = 0; i < textureNames.Length; i += 1)
{
Logger.LogInfo(textureNames[i]);
using (FileStream fs = new FileStream(TestUtils.GetTexturePath(textureNames[i] + ".dds"), FileMode.Open, FileAccess.Read))
textures[i] = Texture.LoadDDS(GraphicsDevice, cmdbuf, fs);
}
GraphicsDevice.Submit(cmdbuf);
}
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,
}
);
for (int i = 0; i < textureNames.Length; i += 1)
{
Logger.LogInfo(textureNames[i]);
using (FileStream fs = new FileStream(TestUtils.GetTexturePath(textureNames[i] + ".dds"), FileMode.Open, FileAccess.Read))
textures[i] = Texture.LoadDDS(GraphicsDevice, cmdbuf, fs);
}
GraphicsDevice.Submit(cmdbuf);
}
protected override void Update(System.TimeSpan delta)
{
int prevSamplerIndex = currentTextureIndex;
protected override void Update(System.TimeSpan delta)
{
int prevSamplerIndex = currentTextureIndex;
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Left))
{
currentTextureIndex -= 1;
if (currentTextureIndex < 0)
{
currentTextureIndex = textureNames.Length - 1;
}
}
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Left))
{
currentTextureIndex -= 1;
if (currentTextureIndex < 0)
{
currentTextureIndex = textureNames.Length - 1;
}
}
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Right))
{
currentTextureIndex += 1;
if (currentTextureIndex >= textureNames.Length)
{
currentTextureIndex = 0;
}
}
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Right))
{
currentTextureIndex += 1;
if (currentTextureIndex >= textureNames.Length)
{
currentTextureIndex = 0;
}
}
if (prevSamplerIndex != currentTextureIndex)
{
Logger.LogInfo("Setting texture to: " + textureNames[currentTextureIndex]);
}
}
if (prevSamplerIndex != currentTextureIndex)
{
Logger.LogInfo("Setting texture to: " + textureNames[currentTextureIndex]);
}
}
protected override void Draw(double alpha)
{
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(textures[currentTextureIndex], sampler));
cmdbuf.DrawIndexedPrimitives(0, 0, 2, 0, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
protected override void Draw(double alpha)
{
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(textures[currentTextureIndex], sampler));
cmdbuf.DrawIndexedPrimitives(0, 0, 2, 0, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
public static void Main(string[] args)
{
CompressedTexturesGame game = new CompressedTexturesGame();
game.Run();
}
}
public static void Main(string[] args)
{
CompressedTexturesGame game = new CompressedTexturesGame();
game.Run();
}
}
}

View File

@ -4,126 +4,126 @@ using MoonWorks.Math.Float;
namespace MoonWorks.Test
{
class ComputeUniformsGame : Game
{
private GraphicsPipeline drawPipeline;
private Texture texture;
private Sampler sampler;
private Buffer vertexBuffer;
class ComputeUniformsGame : Game
{
private GraphicsPipeline drawPipeline;
private Texture texture;
private Sampler sampler;
private Buffer vertexBuffer;
struct GradientTextureComputeUniforms
{
public uint groupCountX;
public uint groupCountY;
struct GradientTextureComputeUniforms
{
public uint groupCountX;
public uint groupCountY;
public GradientTextureComputeUniforms(uint w, uint h)
{
groupCountX = w;
groupCountY = h;
}
}
public GradientTextureComputeUniforms(uint w, uint h)
{
groupCountX = w;
groupCountY = h;
}
}
public ComputeUniformsGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
// Create the compute pipeline that writes texture data
ShaderModule gradientTextureComputeShaderModule = new ShaderModule(
GraphicsDevice,
TestUtils.GetShaderPath("GradientTexture.comp")
);
public ComputeUniformsGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
// Create the compute pipeline that writes texture data
ShaderModule gradientTextureComputeShaderModule = new ShaderModule(
GraphicsDevice,
TestUtils.GetShaderPath("GradientTexture.comp")
);
ComputePipeline gradientTextureComputePipeline = new ComputePipeline(
GraphicsDevice,
ComputeShaderInfo.Create<GradientTextureComputeUniforms>(gradientTextureComputeShaderModule, "main", 0, 1)
);
ComputePipeline gradientTextureComputePipeline = new ComputePipeline(
GraphicsDevice,
ComputeShaderInfo.Create<GradientTextureComputeUniforms>(gradientTextureComputeShaderModule, "main", 0, 1)
);
// Create the graphics pipeline
ShaderModule vertShaderModule = new ShaderModule(
GraphicsDevice,
TestUtils.GetShaderPath("TexturedQuad.vert")
);
// Create the graphics pipeline
ShaderModule vertShaderModule = new ShaderModule(
GraphicsDevice,
TestUtils.GetShaderPath("TexturedQuad.vert")
);
ShaderModule fragShaderModule = new ShaderModule(
GraphicsDevice,
TestUtils.GetShaderPath("TexturedQuad.frag")
);
ShaderModule fragShaderModule = new ShaderModule(
GraphicsDevice,
TestUtils.GetShaderPath("TexturedQuad.frag")
);
GraphicsPipelineCreateInfo drawPipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
drawPipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
drawPipelineCreateInfo.FragmentShaderInfo.SamplerBindingCount = 1;
GraphicsPipelineCreateInfo drawPipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
drawPipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
drawPipelineCreateInfo.FragmentShaderInfo.SamplerBindingCount = 1;
drawPipeline = new GraphicsPipeline(
GraphicsDevice,
drawPipelineCreateInfo
);
drawPipeline = new GraphicsPipeline(
GraphicsDevice,
drawPipelineCreateInfo
);
// Create buffers and textures
vertexBuffer = Buffer.Create<PositionTextureVertex>(
GraphicsDevice,
BufferUsageFlags.Vertex,
6
);
// Create buffers and textures
vertexBuffer = Buffer.Create<PositionTextureVertex>(
GraphicsDevice,
BufferUsageFlags.Vertex,
6
);
texture = Texture.CreateTexture2D(
GraphicsDevice,
MainWindow.Width,
MainWindow.Height,
TextureFormat.R8G8B8A8,
TextureUsageFlags.Compute | TextureUsageFlags.Sampler
);
texture = Texture.CreateTexture2D(
GraphicsDevice,
MainWindow.Width,
MainWindow.Height,
TextureFormat.R8G8B8A8,
TextureUsageFlags.Compute | TextureUsageFlags.Sampler
);
sampler = new Sampler(GraphicsDevice, new SamplerCreateInfo());
sampler = new Sampler(GraphicsDevice, new SamplerCreateInfo());
// Upload GPU resources and dispatch compute work
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, 0)),
new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(1, 1)),
new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 1)),
});
// Upload GPU resources and dispatch compute work
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, 0)),
new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(1, 1)),
new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 1)),
});
GradientTextureComputeUniforms gradientUniforms = new GradientTextureComputeUniforms(
texture.Width / 8,
texture.Height / 8
);
GradientTextureComputeUniforms gradientUniforms = new GradientTextureComputeUniforms(
texture.Width / 8,
texture.Height / 8
);
cmdbuf.BindComputePipeline(gradientTextureComputePipeline);
cmdbuf.BindComputeTextures(texture);
uint offset = cmdbuf.PushComputeShaderUniforms(gradientUniforms);
cmdbuf.DispatchCompute(gradientUniforms.groupCountX, gradientUniforms.groupCountY, 1, offset);
cmdbuf.BindComputePipeline(gradientTextureComputePipeline);
cmdbuf.BindComputeTextures(texture);
uint offset = cmdbuf.PushComputeShaderUniforms(gradientUniforms);
cmdbuf.DispatchCompute(gradientUniforms.groupCountX, gradientUniforms.groupCountY, 1, offset);
GraphicsDevice.Submit(cmdbuf);
}
GraphicsDevice.Submit(cmdbuf);
}
protected override void Update(System.TimeSpan delta) { }
protected override void Update(System.TimeSpan delta) { }
protected override void Draw(double alpha)
{
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.CornflowerBlue));
cmdbuf.BindGraphicsPipeline(drawPipeline);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(texture, sampler));
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.DrawPrimitives(0, 2, 0, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
protected override void Draw(double alpha)
{
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.CornflowerBlue));
cmdbuf.BindGraphicsPipeline(drawPipeline);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(texture, sampler));
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.DrawPrimitives(0, 2, 0, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
public static void Main(string[] args)
{
ComputeUniformsGame game = new ComputeUniformsGame();
game.Run();
}
}
public static void Main(string[] args)
{
ComputeUniformsGame game = new ComputeUniformsGame();
game.Run();
}
}
}

View File

@ -5,72 +5,72 @@ using MoonWorks.Math.Float;
namespace MoonWorks.Test
{
class CopyTextureGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private Texture originalTexture;
private Texture textureCopy;
private Texture textureSmallCopy;
private Sampler sampler;
class CopyTextureGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private Texture originalTexture;
private Texture textureCopy;
private Texture textureSmallCopy;
private Sampler sampler;
public unsafe CopyTextureGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.frag"));
public unsafe CopyTextureGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.frag"));
// Create the graphics pipeline
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipelineCreateInfo.AttachmentInfo.ColorAttachmentDescriptions[0].BlendState = ColorAttachmentBlendState.AlphaBlend;
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
pipelineCreateInfo.FragmentShaderInfo.SamplerBindingCount = 1;
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create the graphics pipeline
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipelineCreateInfo.AttachmentInfo.ColorAttachmentDescriptions[0].BlendState = ColorAttachmentBlendState.AlphaBlend;
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
pipelineCreateInfo.FragmentShaderInfo.SamplerBindingCount = 1;
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create sampler
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointClamp);
// Create sampler
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointClamp);
// Create and populate the GPU resources
vertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 12);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 12);
// Create and populate the GPU resources
vertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 12);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 12);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
vertexBuffer,
new PositionTextureVertex[]
{
new PositionTextureVertex(new Vector3(-1f, 0f, 0), new Vector2(0, 0)),
new PositionTextureVertex(new Vector3( 0f, 0f, 0), new Vector2(1, 0)),
new PositionTextureVertex(new Vector3( 0f, 1f, 0), new Vector2(1, 1)),
new PositionTextureVertex(new Vector3(-1f, 1f, 0), new Vector2(0, 1)),
cmdbuf.SetBufferData(
vertexBuffer,
new PositionTextureVertex[]
{
new PositionTextureVertex(new Vector3(-1f, 0f, 0), new Vector2(0, 0)),
new PositionTextureVertex(new Vector3( 0f, 0f, 0), new Vector2(1, 0)),
new PositionTextureVertex(new Vector3( 0f, 1f, 0), new Vector2(1, 1)),
new PositionTextureVertex(new Vector3(-1f, 1f, 0), new Vector2(0, 1)),
new PositionTextureVertex(new Vector3(0f, 0f, 0), new Vector2(0, 0)),
new PositionTextureVertex(new Vector3(1f, 0f, 0), new Vector2(1, 0)),
new PositionTextureVertex(new Vector3(1f, 1f, 0), new Vector2(1, 1)),
new PositionTextureVertex(new Vector3(0f, 1f, 0), new Vector2(0, 1)),
new PositionTextureVertex(new Vector3(0f, 0f, 0), new Vector2(0, 0)),
new PositionTextureVertex(new Vector3(1f, 0f, 0), new Vector2(1, 0)),
new PositionTextureVertex(new Vector3(1f, 1f, 0), new Vector2(1, 1)),
new PositionTextureVertex(new Vector3(0f, 1f, 0), new Vector2(0, 1)),
new PositionTextureVertex(new Vector3(-0.5f, -1f, 0), new Vector2(0, 0)),
new PositionTextureVertex(new Vector3( 0.5f, -1f, 0), new Vector2(1, 0)),
new PositionTextureVertex(new Vector3( 0.5f, 0f, 0), new Vector2(1, 1)),
new PositionTextureVertex(new Vector3(-0.5f, 0f, 0), new Vector2(0, 1))
}
);
cmdbuf.SetBufferData(
indexBuffer,
new ushort[]
{
0, 1, 2,
0, 2, 3,
}
);
new PositionTextureVertex(new Vector3(-0.5f, -1f, 0), new Vector2(0, 0)),
new PositionTextureVertex(new Vector3( 0.5f, -1f, 0), new Vector2(1, 0)),
new PositionTextureVertex(new Vector3( 0.5f, 0f, 0), new Vector2(1, 1)),
new PositionTextureVertex(new Vector3(-0.5f, 0f, 0), new Vector2(0, 1))
}
);
cmdbuf.SetBufferData(
indexBuffer,
new ushort[]
{
0, 1, 2,
0, 2, 3,
}
);
// Load the texture. Storing the texture bytes so we can compare them.
// Load the texture. Storing the texture bytes so we can compare them.
var fileStream = new System.IO.FileStream(TestUtils.GetTexturePath("ravioli.png"), System.IO.FileMode.Open, System.IO.FileAccess.Read);
var fileLength = fileStream.Length;
var fileBuffer = NativeMemory.Alloc((nuint) fileLength);
@ -87,54 +87,54 @@ namespace MoonWorks.Test
NativeMemory.Free(fileBuffer);
TextureCreateInfo textureCreateInfo = new TextureCreateInfo();
textureCreateInfo.Width = (uint) width;
textureCreateInfo.Height = (uint) height;
textureCreateInfo.Depth = 1;
textureCreateInfo.Format = TextureFormat.R8G8B8A8;
textureCreateInfo.IsCube = false;
textureCreateInfo.LevelCount = 1;
textureCreateInfo.UsageFlags = TextureUsageFlags.Sampler;
TextureCreateInfo textureCreateInfo = new TextureCreateInfo();
textureCreateInfo.Width = (uint) width;
textureCreateInfo.Height = (uint) height;
textureCreateInfo.Depth = 1;
textureCreateInfo.Format = TextureFormat.R8G8B8A8;
textureCreateInfo.IsCube = false;
textureCreateInfo.LevelCount = 1;
textureCreateInfo.UsageFlags = TextureUsageFlags.Sampler;
originalTexture = new Texture(GraphicsDevice, textureCreateInfo);
cmdbuf.SetTextureData(originalTexture, pixels, (uint) byteCount);
originalTexture = new Texture(GraphicsDevice, textureCreateInfo);
cmdbuf.SetTextureData(originalTexture, pixels, (uint) byteCount);
// Create a 1:1 copy of the texture
textureCopy = new Texture(GraphicsDevice, textureCreateInfo);
cmdbuf.CopyTextureToTexture(
new TextureSlice(originalTexture),
new TextureSlice(textureCopy),
Filter.Linear
);
// Create a 1:1 copy of the texture
textureCopy = new Texture(GraphicsDevice, textureCreateInfo);
cmdbuf.CopyTextureToTexture(
new TextureSlice(originalTexture),
new TextureSlice(textureCopy),
Filter.Linear
);
// Create a half-sized copy of this texture
textureCreateInfo.Width /= 2;
textureCreateInfo.Height /= 2;
textureSmallCopy = new Texture(GraphicsDevice, textureCreateInfo);
cmdbuf.CopyTextureToTexture(
new TextureSlice(originalTexture),
new TextureSlice(
textureSmallCopy,
new Rect(
(int) textureCreateInfo.Width,
(int) textureCreateInfo.Height
)
),
Filter.Linear
);
// Create a half-sized copy of this texture
textureCreateInfo.Width /= 2;
textureCreateInfo.Height /= 2;
textureSmallCopy = new Texture(GraphicsDevice, textureCreateInfo);
cmdbuf.CopyTextureToTexture(
new TextureSlice(originalTexture),
new TextureSlice(
textureSmallCopy,
new Rect(
(int) textureCreateInfo.Width,
(int) textureCreateInfo.Height
)
),
Filter.Linear
);
// Copy the texture to a buffer
Buffer compareBuffer = Buffer.Create<byte>(GraphicsDevice, 0, (uint) byteCount);
cmdbuf.CopyTextureToBuffer(new TextureSlice(originalTexture), compareBuffer);
// Copy the texture to a buffer
Buffer compareBuffer = Buffer.Create<byte>(GraphicsDevice, 0, (uint) byteCount);
cmdbuf.CopyTextureToBuffer(new TextureSlice(originalTexture), compareBuffer);
var fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
GraphicsDevice.WaitForFences(fence);
var fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
GraphicsDevice.WaitForFences(fence);
GraphicsDevice.ReleaseFence(fence);
// Compare the original bytes to the copied bytes.
var copiedBytes = NativeMemory.Alloc((nuint) byteCount);
// Compare the original bytes to the copied bytes.
var copiedBytes = NativeMemory.Alloc((nuint) byteCount);
var copiedSpan = new System.Span<byte>(copiedBytes, byteCount);
compareBuffer.GetData(copiedSpan);
compareBuffer.GetData(copiedSpan);
var originalSpan = new System.Span<byte>((void*) pixels, byteCount);
@ -149,35 +149,35 @@ namespace MoonWorks.Test
}
RefreshCS.Refresh.Refresh_Image_Free(pixels);
}
}
protected override void Update(System.TimeSpan delta) { }
protected override void Update(System.TimeSpan delta) { }
protected override void Draw(double alpha)
{
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(originalTexture, sampler));
cmdbuf.DrawIndexedPrimitives(0, 0, 2, 0, 0);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(textureCopy, sampler));
cmdbuf.DrawIndexedPrimitives(4, 0, 2, 0, 0);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(textureSmallCopy, sampler));
cmdbuf.DrawIndexedPrimitives(8, 0, 2, 0, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
protected override void Draw(double alpha)
{
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(originalTexture, sampler));
cmdbuf.DrawIndexedPrimitives(0, 0, 2, 0, 0);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(textureCopy, sampler));
cmdbuf.DrawIndexedPrimitives(4, 0, 2, 0, 0);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(textureSmallCopy, sampler));
cmdbuf.DrawIndexedPrimitives(8, 0, 2, 0, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
public static void Main(string[] args)
{
CopyTextureGame game = new CopyTextureGame();
game.Run();
}
}
public static void Main(string[] args)
{
CopyTextureGame game = new CopyTextureGame();
game.Run();
}
}
}

View File

@ -6,52 +6,52 @@ using System.Threading.Tasks;
namespace MoonWorks.Test
{
class CubeGame : Game
{
private GraphicsPipeline cubePipeline;
private GraphicsPipeline cubePipelineDepthOnly;
private GraphicsPipeline skyboxPipeline;
private GraphicsPipeline skyboxPipelineDepthOnly;
private GraphicsPipeline blitPipeline;
class CubeGame : Game
{
private GraphicsPipeline cubePipeline;
private GraphicsPipeline cubePipelineDepthOnly;
private GraphicsPipeline skyboxPipeline;
private GraphicsPipeline skyboxPipelineDepthOnly;
private GraphicsPipeline blitPipeline;
private Texture depthTexture;
private Sampler depthSampler;
private DepthUniforms depthUniforms;
private Texture depthTexture;
private Sampler depthSampler;
private DepthUniforms depthUniforms;
private Buffer cubeVertexBuffer;
private Buffer skyboxVertexBuffer;
private Buffer blitVertexBuffer;
private Buffer indexBuffer;
private Buffer cubeVertexBuffer;
private Buffer skyboxVertexBuffer;
private Buffer blitVertexBuffer;
private Buffer indexBuffer;
private Texture skyboxTexture;
private Sampler skyboxSampler;
private Texture skyboxTexture;
private Sampler skyboxSampler;
private bool finishedLoading = false;
private float cubeTimer = 0f;
private Quaternion cubeRotation = Quaternion.Identity;
private Quaternion previousCubeRotation = Quaternion.Identity;
private bool depthOnlyEnabled = false;
private Vector3 camPos = new Vector3(0, 1.5f, 4f);
private bool finishedLoading = false;
private float cubeTimer = 0f;
private Quaternion cubeRotation = Quaternion.Identity;
private Quaternion previousCubeRotation = Quaternion.Identity;
private bool depthOnlyEnabled = false;
private Vector3 camPos = new Vector3(0, 1.5f, 4f);
private TaskFactory taskFactory = new TaskFactory();
private bool takeScreenshot;
struct DepthUniforms
{
public float ZNear;
public float ZFar;
struct DepthUniforms
{
public float ZNear;
public float ZFar;
public DepthUniforms(float zNear, float zFar)
{
ZNear = zNear;
ZFar = zFar;
}
}
public DepthUniforms(float zNear, float zFar)
{
ZNear = zNear;
ZFar = zFar;
}
}
void LoadCubemap(CommandBuffer cmdbuf, string[] imagePaths)
{
for (uint i = 0; i < imagePaths.Length; i++)
{
void LoadCubemap(CommandBuffer cmdbuf, string[] imagePaths)
{
for (uint i = 0; i < imagePaths.Length; i++)
{
var textureSlice = new TextureSlice(
skyboxTexture,
new Rect(0, 0, (int) skyboxTexture.Width, (int) skyboxTexture.Height),
@ -61,383 +61,383 @@ namespace MoonWorks.Test
);
Texture.SetDataFromImageFile(cmdbuf, textureSlice, imagePaths[i]);
}
}
}
}
public CubeGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
ShaderModule cubeVertShaderModule = new ShaderModule(
GraphicsDevice,
TestUtils.GetShaderPath("PositionColorWithMatrix.vert")
);
ShaderModule cubeFragShaderModule = new ShaderModule(
GraphicsDevice,
TestUtils.GetShaderPath("SolidColor.frag")
);
public CubeGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
ShaderModule cubeVertShaderModule = new ShaderModule(
GraphicsDevice,
TestUtils.GetShaderPath("PositionColorWithMatrix.vert")
);
ShaderModule cubeFragShaderModule = new ShaderModule(
GraphicsDevice,
TestUtils.GetShaderPath("SolidColor.frag")
);
ShaderModule skyboxVertShaderModule = new ShaderModule(
GraphicsDevice,
TestUtils.GetShaderPath("Skybox.vert")
);
ShaderModule skyboxFragShaderModule = new ShaderModule(
GraphicsDevice,
TestUtils.GetShaderPath("Skybox.frag")
);
ShaderModule skyboxVertShaderModule = new ShaderModule(
GraphicsDevice,
TestUtils.GetShaderPath("Skybox.vert")
);
ShaderModule skyboxFragShaderModule = new ShaderModule(
GraphicsDevice,
TestUtils.GetShaderPath("Skybox.frag")
);
ShaderModule blitVertShaderModule = new ShaderModule(
GraphicsDevice,
TestUtils.GetShaderPath("TexturedQuad.vert")
);
ShaderModule blitFragShaderModule = new ShaderModule(
GraphicsDevice,
TestUtils.GetShaderPath("TexturedDepthQuad.frag")
);
ShaderModule blitVertShaderModule = new ShaderModule(
GraphicsDevice,
TestUtils.GetShaderPath("TexturedQuad.vert")
);
ShaderModule blitFragShaderModule = new ShaderModule(
GraphicsDevice,
TestUtils.GetShaderPath("TexturedDepthQuad.frag")
);
depthTexture = Texture.CreateTexture2D(
GraphicsDevice,
MainWindow.Width,
MainWindow.Height,
TextureFormat.D16,
TextureUsageFlags.DepthStencilTarget | TextureUsageFlags.Sampler
);
depthSampler = new Sampler(GraphicsDevice, new SamplerCreateInfo());
depthUniforms = new DepthUniforms(0.01f, 100f);
depthTexture = Texture.CreateTexture2D(
GraphicsDevice,
MainWindow.Width,
MainWindow.Height,
TextureFormat.D16,
TextureUsageFlags.DepthStencilTarget | TextureUsageFlags.Sampler
);
depthSampler = new Sampler(GraphicsDevice, new SamplerCreateInfo());
depthUniforms = new DepthUniforms(0.01f, 100f);
skyboxTexture = Texture.CreateTextureCube(
GraphicsDevice,
2048,
TextureFormat.R8G8B8A8,
TextureUsageFlags.Sampler
);
skyboxSampler = new Sampler(GraphicsDevice, new SamplerCreateInfo());
skyboxTexture = Texture.CreateTextureCube(
GraphicsDevice,
2048,
TextureFormat.R8G8B8A8,
TextureUsageFlags.Sampler
);
skyboxSampler = new Sampler(GraphicsDevice, new SamplerCreateInfo());
cubeVertexBuffer = Buffer.Create<PositionColorVertex>(
GraphicsDevice,
BufferUsageFlags.Vertex,
24
);
skyboxVertexBuffer = Buffer.Create<PositionVertex>(
GraphicsDevice,
BufferUsageFlags.Vertex,
24
);
indexBuffer = Buffer.Create<uint>(
GraphicsDevice,
BufferUsageFlags.Index,
36
); // Using uint here just to test IndexElementSize=32
cubeVertexBuffer = Buffer.Create<PositionColorVertex>(
GraphicsDevice,
BufferUsageFlags.Vertex,
24
);
skyboxVertexBuffer = Buffer.Create<PositionVertex>(
GraphicsDevice,
BufferUsageFlags.Vertex,
24
);
indexBuffer = Buffer.Create<uint>(
GraphicsDevice,
BufferUsageFlags.Index,
36
); // Using uint here just to test IndexElementSize=32
blitVertexBuffer = Buffer.Create<PositionTextureVertex>(
GraphicsDevice,
BufferUsageFlags.Vertex,
6
);
blitVertexBuffer = Buffer.Create<PositionTextureVertex>(
GraphicsDevice,
BufferUsageFlags.Vertex,
6
);
Task loadingTask = Task.Run(() => UploadGPUAssets());
Task loadingTask = Task.Run(() => UploadGPUAssets());
// Create the cube pipelines
// Create the cube pipelines
GraphicsPipelineCreateInfo cubePipelineCreateInfo = new GraphicsPipelineCreateInfo
{
AttachmentInfo = new GraphicsPipelineAttachmentInfo(
TextureFormat.D16,
new ColorAttachmentDescription(
MainWindow.SwapchainFormat,
ColorAttachmentBlendState.Opaque
)
),
DepthStencilState = DepthStencilState.DepthReadWrite,
VertexShaderInfo = GraphicsShaderInfo.Create<TransformVertexUniform>(cubeVertShaderModule, "main", 0),
VertexInputState = VertexInputState.CreateSingleBinding<PositionColorVertex>(),
PrimitiveType = PrimitiveType.TriangleList,
FragmentShaderInfo = GraphicsShaderInfo.Create(cubeFragShaderModule, "main", 0),
RasterizerState = RasterizerState.CW_CullBack,
MultisampleState = MultisampleState.None
};
cubePipeline = new GraphicsPipeline(GraphicsDevice, cubePipelineCreateInfo);
GraphicsPipelineCreateInfo cubePipelineCreateInfo = new GraphicsPipelineCreateInfo
{
AttachmentInfo = new GraphicsPipelineAttachmentInfo(
TextureFormat.D16,
new ColorAttachmentDescription(
MainWindow.SwapchainFormat,
ColorAttachmentBlendState.Opaque
)
),
DepthStencilState = DepthStencilState.DepthReadWrite,
VertexShaderInfo = GraphicsShaderInfo.Create<TransformVertexUniform>(cubeVertShaderModule, "main", 0),
VertexInputState = VertexInputState.CreateSingleBinding<PositionColorVertex>(),
PrimitiveType = PrimitiveType.TriangleList,
FragmentShaderInfo = GraphicsShaderInfo.Create(cubeFragShaderModule, "main", 0),
RasterizerState = RasterizerState.CW_CullBack,
MultisampleState = MultisampleState.None
};
cubePipeline = new GraphicsPipeline(GraphicsDevice, cubePipelineCreateInfo);
cubePipelineCreateInfo.AttachmentInfo = new GraphicsPipelineAttachmentInfo(TextureFormat.D16);
cubePipelineDepthOnly = new GraphicsPipeline(GraphicsDevice, cubePipelineCreateInfo);
cubePipelineCreateInfo.AttachmentInfo = new GraphicsPipelineAttachmentInfo(TextureFormat.D16);
cubePipelineDepthOnly = new GraphicsPipeline(GraphicsDevice, cubePipelineCreateInfo);
// Create the skybox pipelines
// Create the skybox pipelines
GraphicsPipelineCreateInfo skyboxPipelineCreateInfo = new GraphicsPipelineCreateInfo
{
AttachmentInfo = new GraphicsPipelineAttachmentInfo(
TextureFormat.D16,
new ColorAttachmentDescription(
MainWindow.SwapchainFormat,
ColorAttachmentBlendState.Opaque
)
),
DepthStencilState = DepthStencilState.DepthReadWrite,
VertexShaderInfo = GraphicsShaderInfo.Create<TransformVertexUniform>(skyboxVertShaderModule, "main", 0),
VertexInputState = VertexInputState.CreateSingleBinding<PositionVertex>(),
PrimitiveType = PrimitiveType.TriangleList,
FragmentShaderInfo = GraphicsShaderInfo.Create(skyboxFragShaderModule, "main", 1),
RasterizerState = RasterizerState.CW_CullNone,
MultisampleState = MultisampleState.None,
};
skyboxPipeline = new GraphicsPipeline(GraphicsDevice, skyboxPipelineCreateInfo);
GraphicsPipelineCreateInfo skyboxPipelineCreateInfo = new GraphicsPipelineCreateInfo
{
AttachmentInfo = new GraphicsPipelineAttachmentInfo(
TextureFormat.D16,
new ColorAttachmentDescription(
MainWindow.SwapchainFormat,
ColorAttachmentBlendState.Opaque
)
),
DepthStencilState = DepthStencilState.DepthReadWrite,
VertexShaderInfo = GraphicsShaderInfo.Create<TransformVertexUniform>(skyboxVertShaderModule, "main", 0),
VertexInputState = VertexInputState.CreateSingleBinding<PositionVertex>(),
PrimitiveType = PrimitiveType.TriangleList,
FragmentShaderInfo = GraphicsShaderInfo.Create(skyboxFragShaderModule, "main", 1),
RasterizerState = RasterizerState.CW_CullNone,
MultisampleState = MultisampleState.None,
};
skyboxPipeline = new GraphicsPipeline(GraphicsDevice, skyboxPipelineCreateInfo);
skyboxPipelineCreateInfo.AttachmentInfo = new GraphicsPipelineAttachmentInfo(TextureFormat.D16);
skyboxPipelineDepthOnly = new GraphicsPipeline(GraphicsDevice, skyboxPipelineCreateInfo);
skyboxPipelineCreateInfo.AttachmentInfo = new GraphicsPipelineAttachmentInfo(TextureFormat.D16);
skyboxPipelineDepthOnly = new GraphicsPipeline(GraphicsDevice, skyboxPipelineCreateInfo);
// Create the blit pipeline
// Create the blit pipeline
GraphicsPipelineCreateInfo blitPipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
GraphicsPipelineCreateInfo blitPipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
blitVertShaderModule,
blitFragShaderModule
);
blitPipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
blitPipelineCreateInfo.FragmentShaderInfo = GraphicsShaderInfo.Create<DepthUniforms>(blitFragShaderModule, "main", 1);
blitVertShaderModule,
blitFragShaderModule
);
blitPipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
blitPipelineCreateInfo.FragmentShaderInfo = GraphicsShaderInfo.Create<DepthUniforms>(blitFragShaderModule, "main", 1);
blitPipeline = new GraphicsPipeline(GraphicsDevice, blitPipelineCreateInfo);
}
}
private void UploadGPUAssets()
{
Logger.LogInfo("Loading...");
private void UploadGPUAssets()
{
Logger.LogInfo("Loading...");
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
cubeVertexBuffer,
new PositionColorVertex[]
{
new PositionColorVertex(new Vector3(-1, -1, -1), new Color(1f, 0f, 0f)),
new PositionColorVertex(new Vector3(1, -1, -1), new Color(1f, 0f, 0f)),
new PositionColorVertex(new Vector3(1, 1, -1), new Color(1f, 0f, 0f)),
new PositionColorVertex(new Vector3(-1, 1, -1), new Color(1f, 0f, 0f)),
cmdbuf.SetBufferData(
cubeVertexBuffer,
new PositionColorVertex[]
{
new PositionColorVertex(new Vector3(-1, -1, -1), new Color(1f, 0f, 0f)),
new PositionColorVertex(new Vector3(1, -1, -1), new Color(1f, 0f, 0f)),
new PositionColorVertex(new Vector3(1, 1, -1), new Color(1f, 0f, 0f)),
new PositionColorVertex(new Vector3(-1, 1, -1), new Color(1f, 0f, 0f)),
new PositionColorVertex(new Vector3(-1, -1, 1), new Color(0f, 1f, 0f)),
new PositionColorVertex(new Vector3(1, -1, 1), new Color(0f, 1f, 0f)),
new PositionColorVertex(new Vector3(1, 1, 1), new Color(0f, 1f, 0f)),
new PositionColorVertex(new Vector3(-1, 1, 1), new Color(0f, 1f, 0f)),
new PositionColorVertex(new Vector3(-1, -1, 1), new Color(0f, 1f, 0f)),
new PositionColorVertex(new Vector3(1, -1, 1), new Color(0f, 1f, 0f)),
new PositionColorVertex(new Vector3(1, 1, 1), new Color(0f, 1f, 0f)),
new PositionColorVertex(new Vector3(-1, 1, 1), new Color(0f, 1f, 0f)),
new PositionColorVertex(new Vector3(-1, -1, -1), new Color(0f, 0f, 1f)),
new PositionColorVertex(new Vector3(-1, 1, -1), new Color(0f, 0f, 1f)),
new PositionColorVertex(new Vector3(-1, 1, 1), new Color(0f, 0f, 1f)),
new PositionColorVertex(new Vector3(-1, -1, 1), new Color(0f, 0f, 1f)),
new PositionColorVertex(new Vector3(-1, -1, -1), new Color(0f, 0f, 1f)),
new PositionColorVertex(new Vector3(-1, 1, -1), new Color(0f, 0f, 1f)),
new PositionColorVertex(new Vector3(-1, 1, 1), new Color(0f, 0f, 1f)),
new PositionColorVertex(new Vector3(-1, -1, 1), new Color(0f, 0f, 1f)),
new PositionColorVertex(new Vector3(1, -1, -1), new Color(1f, 0.5f, 0f)),
new PositionColorVertex(new Vector3(1, 1, -1), new Color(1f, 0.5f, 0f)),
new PositionColorVertex(new Vector3(1, 1, 1), new Color(1f, 0.5f, 0f)),
new PositionColorVertex(new Vector3(1, -1, 1), new Color(1f, 0.5f, 0f)),
new PositionColorVertex(new Vector3(1, -1, -1), new Color(1f, 0.5f, 0f)),
new PositionColorVertex(new Vector3(1, 1, -1), new Color(1f, 0.5f, 0f)),
new PositionColorVertex(new Vector3(1, 1, 1), new Color(1f, 0.5f, 0f)),
new PositionColorVertex(new Vector3(1, -1, 1), new Color(1f, 0.5f, 0f)),
new PositionColorVertex(new Vector3(-1, -1, -1), new Color(1f, 0f, 0.5f)),
new PositionColorVertex(new Vector3(-1, -1, 1), new Color(1f, 0f, 0.5f)),
new PositionColorVertex(new Vector3(1, -1, 1), new Color(1f, 0f, 0.5f)),
new PositionColorVertex(new Vector3(1, -1, -1), new Color(1f, 0f, 0.5f)),
new PositionColorVertex(new Vector3(-1, -1, -1), new Color(1f, 0f, 0.5f)),
new PositionColorVertex(new Vector3(-1, -1, 1), new Color(1f, 0f, 0.5f)),
new PositionColorVertex(new Vector3(1, -1, 1), new Color(1f, 0f, 0.5f)),
new PositionColorVertex(new Vector3(1, -1, -1), new Color(1f, 0f, 0.5f)),
new PositionColorVertex(new Vector3(-1, 1, -1), new Color(0f, 0.5f, 0f)),
new PositionColorVertex(new Vector3(-1, 1, 1), new Color(0f, 0.5f, 0f)),
new PositionColorVertex(new Vector3(1, 1, 1), new Color(0f, 0.5f, 0f)),
new PositionColorVertex(new Vector3(1, 1, -1), new Color(0f, 0.5f, 0f))
}
);
new PositionColorVertex(new Vector3(-1, 1, -1), new Color(0f, 0.5f, 0f)),
new PositionColorVertex(new Vector3(-1, 1, 1), new Color(0f, 0.5f, 0f)),
new PositionColorVertex(new Vector3(1, 1, 1), new Color(0f, 0.5f, 0f)),
new PositionColorVertex(new Vector3(1, 1, -1), new Color(0f, 0.5f, 0f))
}
);
cmdbuf.SetBufferData(
skyboxVertexBuffer,
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)),
cmdbuf.SetBufferData(
skyboxVertexBuffer,
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)),
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)),
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)),
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)),
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)),
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)),
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)),
new PositionVertex(new Vector3(10, 10, 10)),
new PositionVertex(new Vector3(10, 10, -10))
}
);
cmdbuf.SetBufferData(
indexBuffer,
new uint[]
{
0, 1, 2, 0, 2, 3,
6, 5, 4, 7, 6, 4,
8, 9, 10, 8, 10, 11,
14, 13, 12, 15, 14, 12,
16, 17, 18, 16, 18, 19,
22, 21, 20, 23, 22, 20
}
);
cmdbuf.SetBufferData(
indexBuffer,
new uint[]
{
0, 1, 2, 0, 2, 3,
6, 5, 4, 7, 6, 4,
8, 9, 10, 8, 10, 11,
14, 13, 12, 15, 14, 12,
16, 17, 18, 16, 18, 19,
22, 21, 20, 23, 22, 20
}
);
cmdbuf.SetBufferData(
blitVertexBuffer,
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, 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(
blitVertexBuffer,
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, 0)),
new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(1, 1)),
new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 1)),
}
);
LoadCubemap(cmdbuf, new string[]
{
TestUtils.GetTexturePath("right.png"),
TestUtils.GetTexturePath("left.png"),
TestUtils.GetTexturePath("top.png"),
TestUtils.GetTexturePath("bottom.png"),
TestUtils.GetTexturePath("front.png"),
TestUtils.GetTexturePath("back.png")
});
LoadCubemap(cmdbuf, new string[]
{
TestUtils.GetTexturePath("right.png"),
TestUtils.GetTexturePath("left.png"),
TestUtils.GetTexturePath("top.png"),
TestUtils.GetTexturePath("bottom.png"),
TestUtils.GetTexturePath("front.png"),
TestUtils.GetTexturePath("back.png")
});
GraphicsDevice.Submit(cmdbuf);
GraphicsDevice.Submit(cmdbuf);
finishedLoading = true;
Logger.LogInfo("Finished loading!");
Logger.LogInfo("Press Left to toggle Depth-Only Mode");
Logger.LogInfo("Press Down to move the camera upwards");
finishedLoading = true;
Logger.LogInfo("Finished loading!");
Logger.LogInfo("Press Left to toggle Depth-Only Mode");
Logger.LogInfo("Press Down to move the camera upwards");
Logger.LogInfo("Press Right to save a screenshot");
}
}
protected override void Update(System.TimeSpan delta)
{
cubeTimer += (float) delta.TotalSeconds;
protected override void Update(System.TimeSpan delta)
{
cubeTimer += (float) delta.TotalSeconds;
previousCubeRotation = cubeRotation;
previousCubeRotation = cubeRotation;
cubeRotation = Quaternion.CreateFromYawPitchRoll(
cubeTimer * 2f,
0,
cubeTimer * 2f
);
cubeRotation = Quaternion.CreateFromYawPitchRoll(
cubeTimer * 2f,
0,
cubeTimer * 2f
);
if (TestUtils.CheckButtonDown(Inputs, TestUtils.ButtonType.Bottom))
{
camPos.Y = System.MathF.Min(camPos.Y + 0.2f, 15f);
}
else
{
camPos.Y = System.MathF.Max(camPos.Y - 0.4f, 1.5f);
}
if (TestUtils.CheckButtonDown(Inputs, TestUtils.ButtonType.Bottom))
{
camPos.Y = System.MathF.Min(camPos.Y + 0.2f, 15f);
}
else
{
camPos.Y = System.MathF.Max(camPos.Y - 0.4f, 1.5f);
}
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Left))
{
depthOnlyEnabled = !depthOnlyEnabled;
Logger.LogInfo("Depth-Only Mode enabled: " + depthOnlyEnabled);
}
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Left))
{
depthOnlyEnabled = !depthOnlyEnabled;
Logger.LogInfo("Depth-Only Mode enabled: " + depthOnlyEnabled);
}
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Right))
{
takeScreenshot = true;
}
}
}
protected override void Draw(double alpha)
{
Matrix4x4 proj = Matrix4x4.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(75f),
(float) MainWindow.Width / MainWindow.Height,
depthUniforms.ZNear,
depthUniforms.ZFar
);
Matrix4x4 view = Matrix4x4.CreateLookAt(
camPos,
Vector3.Zero,
Vector3.Up
);
TransformVertexUniform skyboxUniforms = new TransformVertexUniform(view * proj);
protected override void Draw(double alpha)
{
Matrix4x4 proj = Matrix4x4.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(75f),
(float) MainWindow.Width / MainWindow.Height,
depthUniforms.ZNear,
depthUniforms.ZFar
);
Matrix4x4 view = Matrix4x4.CreateLookAt(
camPos,
Vector3.Zero,
Vector3.Up
);
TransformVertexUniform skyboxUniforms = new TransformVertexUniform(view * proj);
Matrix4x4 model = Matrix4x4.CreateFromQuaternion(
Quaternion.Slerp(
previousCubeRotation,
cubeRotation,
(float) alpha
)
);
TransformVertexUniform cubeUniforms = new TransformVertexUniform(model * view * proj);
Matrix4x4 model = Matrix4x4.CreateFromQuaternion(
Quaternion.Slerp(
previousCubeRotation,
cubeRotation,
(float) alpha
)
);
TransformVertexUniform cubeUniforms = new TransformVertexUniform(model * view * proj);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture swapchainTexture = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (swapchainTexture != null)
{
if (!finishedLoading)
{
float sine = System.MathF.Abs(System.MathF.Sin(cubeTimer));
Color clearColor = new Color(sine, sine, sine);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture swapchainTexture = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (swapchainTexture != null)
{
if (!finishedLoading)
{
float sine = System.MathF.Abs(System.MathF.Sin(cubeTimer));
Color clearColor = new Color(sine, sine, sine);
// Just show a clear screen.
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(swapchainTexture, clearColor));
cmdbuf.EndRenderPass();
}
else
{
if (!depthOnlyEnabled)
{
cmdbuf.BeginRenderPass(
new DepthStencilAttachmentInfo(depthTexture, new DepthStencilValue(1f, 0)),
new ColorAttachmentInfo(swapchainTexture, LoadOp.DontCare)
);
}
else
{
cmdbuf.BeginRenderPass(
new DepthStencilAttachmentInfo(depthTexture, new DepthStencilValue(1f, 0))
);
}
// Just show a clear screen.
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(swapchainTexture, clearColor));
cmdbuf.EndRenderPass();
}
else
{
if (!depthOnlyEnabled)
{
cmdbuf.BeginRenderPass(
new DepthStencilAttachmentInfo(depthTexture, new DepthStencilValue(1f, 0)),
new ColorAttachmentInfo(swapchainTexture, LoadOp.DontCare)
);
}
else
{
cmdbuf.BeginRenderPass(
new DepthStencilAttachmentInfo(depthTexture, new DepthStencilValue(1f, 0))
);
}
// Draw cube
cmdbuf.BindGraphicsPipeline(depthOnlyEnabled ? cubePipelineDepthOnly : cubePipeline);
cmdbuf.BindVertexBuffers(cubeVertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.ThirtyTwo);
uint vertexParamOffset = cmdbuf.PushVertexShaderUniforms(cubeUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 12, vertexParamOffset, 0);
// Draw cube
cmdbuf.BindGraphicsPipeline(depthOnlyEnabled ? cubePipelineDepthOnly : cubePipeline);
cmdbuf.BindVertexBuffers(cubeVertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.ThirtyTwo);
uint vertexParamOffset = cmdbuf.PushVertexShaderUniforms(cubeUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 12, vertexParamOffset, 0);
// Draw skybox
cmdbuf.BindGraphicsPipeline(depthOnlyEnabled ? skyboxPipelineDepthOnly : skyboxPipeline);
cmdbuf.BindVertexBuffers(skyboxVertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.ThirtyTwo);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(skyboxTexture, skyboxSampler));
vertexParamOffset = cmdbuf.PushVertexShaderUniforms(skyboxUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 12, vertexParamOffset, 0);
// Draw skybox
cmdbuf.BindGraphicsPipeline(depthOnlyEnabled ? skyboxPipelineDepthOnly : skyboxPipeline);
cmdbuf.BindVertexBuffers(skyboxVertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.ThirtyTwo);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(skyboxTexture, skyboxSampler));
vertexParamOffset = cmdbuf.PushVertexShaderUniforms(skyboxUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 12, vertexParamOffset, 0);
cmdbuf.EndRenderPass();
cmdbuf.EndRenderPass();
if (depthOnlyEnabled)
{
// Draw the depth buffer as a grayscale image
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(swapchainTexture, LoadOp.DontCare));
if (depthOnlyEnabled)
{
// Draw the depth buffer as a grayscale image
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(swapchainTexture, LoadOp.DontCare));
cmdbuf.BindGraphicsPipeline(blitPipeline);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(depthTexture, depthSampler));
cmdbuf.BindVertexBuffers(blitVertexBuffer);
uint fragParamOffset = cmdbuf.PushFragmentShaderUniforms(depthUniforms);
cmdbuf.DrawPrimitives(0, 2, vertexParamOffset, fragParamOffset);
cmdbuf.BindGraphicsPipeline(blitPipeline);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(depthTexture, depthSampler));
cmdbuf.BindVertexBuffers(blitVertexBuffer);
uint fragParamOffset = cmdbuf.PushFragmentShaderUniforms(depthUniforms);
cmdbuf.DrawPrimitives(0, 2, vertexParamOffset, fragParamOffset);
cmdbuf.EndRenderPass();
}
}
}
cmdbuf.EndRenderPass();
}
}
}
GraphicsDevice.Submit(cmdbuf);
GraphicsDevice.Submit(cmdbuf);
if (takeScreenshot)
{
@ -448,7 +448,7 @@ namespace MoonWorks.Test
takeScreenshot = false;
}
}
}
private System.Action<object?> TakeScreenshot = texture =>
{
@ -458,10 +458,10 @@ namespace MoonWorks.Test
}
};
public static void Main(string[] args)
{
CubeGame game = new CubeGame();
game.Run();
}
}
public static void Main(string[] args)
{
CubeGame game = new CubeGame();
game.Run();
}
}
}

View File

@ -5,77 +5,77 @@ using System.Runtime.InteropServices;
namespace MoonWorks.Test
{
class DrawIndirectGame : Game
{
private GraphicsPipeline graphicsPipeline;
private Buffer vertexBuffer;
private Buffer drawBuffer;
class DrawIndirectGame : Game
{
private GraphicsPipeline graphicsPipeline;
private Buffer vertexBuffer;
private Buffer drawBuffer;
public DrawIndirectGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("PositionColor.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("SolidColor.frag"));
public DrawIndirectGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("PositionColor.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("SolidColor.frag"));
// Create the graphics pipeline
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionColorVertex>();
graphicsPipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create the graphics pipeline
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionColorVertex>();
graphicsPipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create and populate the vertex buffer
vertexBuffer = Buffer.Create<PositionColorVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 6);
drawBuffer = Buffer.Create<IndirectDrawCommand>(GraphicsDevice, BufferUsageFlags.Indirect, 2);
// Create and populate the vertex buffer
vertexBuffer = Buffer.Create<PositionColorVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 6);
drawBuffer = Buffer.Create<IndirectDrawCommand>(GraphicsDevice, BufferUsageFlags.Indirect, 2);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
vertexBuffer,
new PositionColorVertex[]
{
new PositionColorVertex(new Vector3(-0.5f, -1, 0), Color.Blue),
new PositionColorVertex(new Vector3(-1f, 1, 0), Color.Green),
new PositionColorVertex(new Vector3(0f, 1, 0), Color.Red),
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
vertexBuffer,
new PositionColorVertex[]
{
new PositionColorVertex(new Vector3(-0.5f, -1, 0), Color.Blue),
new PositionColorVertex(new Vector3(-1f, 1, 0), Color.Green),
new PositionColorVertex(new Vector3(0f, 1, 0), Color.Red),
new PositionColorVertex(new Vector3(.5f, -1, 0), Color.Blue),
new PositionColorVertex(new Vector3(1f, 1, 0), Color.Green),
new PositionColorVertex(new Vector3(0f, 1, 0), Color.Red),
}
);
cmdbuf.SetBufferData(
drawBuffer,
new IndirectDrawCommand[]
{
new IndirectDrawCommand(3, 1, 3, 0),
new IndirectDrawCommand(3, 1, 0, 0),
}
);
GraphicsDevice.Submit(cmdbuf);
}
new PositionColorVertex(new Vector3(.5f, -1, 0), Color.Blue),
new PositionColorVertex(new Vector3(1f, 1, 0), Color.Green),
new PositionColorVertex(new Vector3(0f, 1, 0), Color.Red),
}
);
cmdbuf.SetBufferData(
drawBuffer,
new IndirectDrawCommand[]
{
new IndirectDrawCommand(3, 1, 3, 0),
new IndirectDrawCommand(3, 1, 0, 0),
}
);
GraphicsDevice.Submit(cmdbuf);
}
protected override void Update(System.TimeSpan delta) { }
protected override void Update(System.TimeSpan delta) { }
protected override void Draw(double alpha)
{
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.CornflowerBlue));
cmdbuf.BindGraphicsPipeline(graphicsPipeline);
cmdbuf.BindVertexBuffers(new BufferBinding(vertexBuffer, 0));
cmdbuf.DrawPrimitivesIndirect(drawBuffer, 0, 2, (uint) Marshal.SizeOf<IndirectDrawCommand>(), 0, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
protected override void Draw(double alpha)
{
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.CornflowerBlue));
cmdbuf.BindGraphicsPipeline(graphicsPipeline);
cmdbuf.BindVertexBuffers(new BufferBinding(vertexBuffer, 0));
cmdbuf.DrawPrimitivesIndirect(drawBuffer, 0, 2, (uint) Marshal.SizeOf<IndirectDrawCommand>(), 0, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
public static void Main(string[] args)
{
DrawIndirectGame game = new DrawIndirectGame();
game.Run();
}
}
public static void Main(string[] args)
{
DrawIndirectGame game = new DrawIndirectGame();
game.Run();
}
}
}

View File

@ -5,109 +5,109 @@ using System.Runtime.InteropServices;
namespace MoonWorks.Test
{
class GetBufferDataGame : Game
{
public GetBufferDataGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
PositionVertex[] vertices = new PositionVertex[]
{
new PositionVertex(new Vector3(0, 0, 0)),
new PositionVertex(new Vector3(0, 0, 1)),
new PositionVertex(new Vector3(0, 1, 0)),
new PositionVertex(new Vector3(0, 1, 1)),
new PositionVertex(new Vector3(1, 0, 0)),
new PositionVertex(new Vector3(1, 0, 1)),
new PositionVertex(new Vector3(1, 1, 0)),
new PositionVertex(new Vector3(1, 1, 1)),
};
class GetBufferDataGame : Game
{
public GetBufferDataGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
PositionVertex[] vertices = new PositionVertex[]
{
new PositionVertex(new Vector3(0, 0, 0)),
new PositionVertex(new Vector3(0, 0, 1)),
new PositionVertex(new Vector3(0, 1, 0)),
new PositionVertex(new Vector3(0, 1, 1)),
new PositionVertex(new Vector3(1, 0, 0)),
new PositionVertex(new Vector3(1, 0, 1)),
new PositionVertex(new Vector3(1, 1, 0)),
new PositionVertex(new Vector3(1, 1, 1)),
};
PositionVertex[] otherVerts = new PositionVertex[]
{
new PositionVertex(new Vector3(1, 2, 3)),
new PositionVertex(new Vector3(4, 5, 6)),
new PositionVertex(new Vector3(7, 8, 9))
};
PositionVertex[] otherVerts = new PositionVertex[]
{
new PositionVertex(new Vector3(1, 2, 3)),
new PositionVertex(new Vector3(4, 5, 6)),
new PositionVertex(new Vector3(7, 8, 9))
};
int vertexSize = Marshal.SizeOf<PositionVertex>();
int vertexSize = Marshal.SizeOf<PositionVertex>();
Buffer vertexBuffer = Buffer.Create<PositionVertex>(
GraphicsDevice,
BufferUsageFlags.Vertex,
(uint) vertices.Length
);
Buffer vertexBuffer = Buffer.Create<PositionVertex>(
GraphicsDevice,
BufferUsageFlags.Vertex,
(uint) vertices.Length
);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(vertexBuffer, vertices);
var fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(vertexBuffer, vertices);
var fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
// Wait for the vertices to finish uploading...
GraphicsDevice.WaitForFences(fence);
// Wait for the vertices to finish uploading...
GraphicsDevice.WaitForFences(fence);
GraphicsDevice.ReleaseFence(fence);
// Read back and print out the vertex values
PositionVertex[] readbackVertices = new PositionVertex[vertices.Length];
vertexBuffer.GetData(readbackVertices);
for (int i = 0; i < readbackVertices.Length; i += 1)
{
Logger.LogInfo(readbackVertices[i].ToString());
}
// Read back and print out the vertex values
PositionVertex[] readbackVertices = new PositionVertex[vertices.Length];
vertexBuffer.GetData(readbackVertices);
for (int i = 0; i < readbackVertices.Length; i += 1)
{
Logger.LogInfo(readbackVertices[i].ToString());
}
// Change the first three vertices
cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(vertexBuffer, otherVerts);
fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
GraphicsDevice.WaitForFences(fence);
// Change the first three vertices
cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(vertexBuffer, otherVerts);
fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
GraphicsDevice.WaitForFences(fence);
GraphicsDevice.ReleaseFence(fence);
// Read the updated buffer
vertexBuffer.GetData(readbackVertices);
Logger.LogInfo("=== Change first three vertices ===");
for (int i = 0; i < readbackVertices.Length; i += 1)
{
Logger.LogInfo(readbackVertices[i].ToString());
}
// Read the updated buffer
vertexBuffer.GetData(readbackVertices);
Logger.LogInfo("=== Change first three vertices ===");
for (int i = 0; i < readbackVertices.Length; i += 1)
{
Logger.LogInfo(readbackVertices[i].ToString());
}
// Change the last two vertices
cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
vertexBuffer,
otherVerts,
(uint) (vertexSize * (vertices.Length - 2)),
1,
2
);
fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
GraphicsDevice.WaitForFences(fence);
// Change the last two vertices
cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
vertexBuffer,
otherVerts,
(uint) (vertexSize * (vertices.Length - 2)),
1,
2
);
fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
GraphicsDevice.WaitForFences(fence);
GraphicsDevice.ReleaseFence(fence);
// Read the updated buffer
vertexBuffer.GetData(readbackVertices);
Logger.LogInfo("=== Change last two vertices ===");
for (int i = 0; i < readbackVertices.Length; i += 1)
{
Logger.LogInfo(readbackVertices[i].ToString());
}
}
// Read the updated buffer
vertexBuffer.GetData(readbackVertices);
Logger.LogInfo("=== Change last two vertices ===");
for (int i = 0; i < readbackVertices.Length; i += 1)
{
Logger.LogInfo(readbackVertices[i].ToString());
}
}
protected override void Update(System.TimeSpan delta) { }
protected override void Update(System.TimeSpan delta) { }
protected override void Draw(double alpha)
{
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? swapchainTexture = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (swapchainTexture != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(swapchainTexture, Color.Black));
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
protected override void Draw(double alpha)
{
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? swapchainTexture = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (swapchainTexture != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(swapchainTexture, Color.Black));
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
public static void Main(string[] args)
{
GetBufferDataGame game = new GetBufferDataGame();
game.Run();
}
}
public static void Main(string[] args)
{
GetBufferDataGame game = new GetBufferDataGame();
game.Run();
}
}
}

View File

@ -4,103 +4,103 @@ using MoonWorks.Math.Float;
namespace MoonWorks.Test
{
class InstancingAndOffsetsGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
class InstancingAndOffsetsGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private bool useVertexOffset;
private bool useIndexOffset;
private bool useVertexOffset;
private bool useIndexOffset;
public InstancingAndOffsetsGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
Logger.LogInfo("Press Left to toggle vertex offset\nPress Right to toggle index offset");
public InstancingAndOffsetsGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
Logger.LogInfo("Press Left to toggle vertex offset\nPress Right to toggle index offset");
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("PositionColorInstanced.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("SolidColor.frag"));
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("PositionColorInstanced.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("SolidColor.frag"));
// Create the graphics pipeline
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionColorVertex>();
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create the graphics pipeline
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionColorVertex>();
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create and populate the vertex and index buffers
vertexBuffer = Buffer.Create<PositionColorVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 9);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6);
// Create and populate the vertex and index buffers
vertexBuffer = Buffer.Create<PositionColorVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 9);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
vertexBuffer,
new PositionColorVertex[]
{
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),
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
vertexBuffer,
new PositionColorVertex[]
{
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),
new PositionColorVertex(new Vector3(-1, 1, 0), Color.Orange),
new PositionColorVertex(new Vector3(1, 1, 0), Color.Green),
new PositionColorVertex(new Vector3(0, -1, 0), Color.Aqua),
new PositionColorVertex(new Vector3(-1, 1, 0), Color.Orange),
new PositionColorVertex(new Vector3(1, 1, 0), Color.Green),
new PositionColorVertex(new Vector3(0, -1, 0), Color.Aqua),
new PositionColorVertex(new Vector3(-1, 1, 0), Color.White),
new PositionColorVertex(new Vector3(1, 1, 0), Color.White),
new PositionColorVertex(new Vector3(0, -1, 0), Color.White),
}
);
cmdbuf.SetBufferData(
indexBuffer,
new ushort[]
{
0, 1, 2,
3, 4, 5,
}
);
GraphicsDevice.Submit(cmdbuf);
}
new PositionColorVertex(new Vector3(-1, 1, 0), Color.White),
new PositionColorVertex(new Vector3(1, 1, 0), Color.White),
new PositionColorVertex(new Vector3(0, -1, 0), Color.White),
}
);
cmdbuf.SetBufferData(
indexBuffer,
new ushort[]
{
0, 1, 2,
3, 4, 5,
}
);
GraphicsDevice.Submit(cmdbuf);
}
protected override void Update(System.TimeSpan delta)
{
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Left))
{
useVertexOffset = !useVertexOffset;
Logger.LogInfo("Using vertex offset: " + useVertexOffset);
}
protected override void Update(System.TimeSpan delta)
{
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Left))
{
useVertexOffset = !useVertexOffset;
Logger.LogInfo("Using vertex offset: " + useVertexOffset);
}
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Right))
{
useIndexOffset = !useIndexOffset;
Logger.LogInfo("Using index offset: " + useIndexOffset);
}
}
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Right))
{
useIndexOffset = !useIndexOffset;
Logger.LogInfo("Using index offset: " + useIndexOffset);
}
}
protected override void Draw(double alpha)
{
uint vertexOffset = useVertexOffset ? 3u : 0;
uint indexOffset = useIndexOffset ? 3u : 0;
protected override void Draw(double alpha)
{
uint vertexOffset = useVertexOffset ? 3u : 0;
uint indexOffset = useIndexOffset ? 3u : 0;
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.DrawInstancedPrimitives(vertexOffset, indexOffset, 1, 16, 0, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.DrawInstancedPrimitives(vertexOffset, indexOffset, 1, 16, 0, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
public static void Main(string[] args)
{
InstancingAndOffsetsGame p = new InstancingAndOffsetsGame();
p.Run();
}
}
public static void Main(string[] args)
{
InstancingAndOffsetsGame p = new InstancingAndOffsetsGame();
p.Run();
}
}
}

View File

@ -56,80 +56,80 @@ namespace MoonWorks.Test
return SDL2.SDL.SDL_GetBasePath() + "Content/Textures/" + textureName;
}
public static string GetVideoPath(string videoName)
{
return SDL2.SDL.SDL_GetBasePath() + "Content/Videos/" + videoName;
}
public static string GetVideoPath(string videoName)
{
return SDL2.SDL.SDL_GetBasePath() + "Content/Videos/" + videoName;
}
public enum ButtonType
{
Left, // A/left arrow on keyboard, left face button on gamepad
Bottom, // S/down arrow on keyboard, bottom face button on gamepad
Right // D/right arrow on keyboard, right face button on gamepad
}
public enum ButtonType
{
Left, // A/left arrow on keyboard, left face button on gamepad
Bottom, // S/down arrow on keyboard, bottom face button on gamepad
Right // D/right arrow on keyboard, right face button on gamepad
}
public static bool CheckButtonPressed(Input.Inputs inputs, ButtonType buttonType)
{
bool pressed = false;
public static bool CheckButtonPressed(Input.Inputs inputs, ButtonType buttonType)
{
bool pressed = false;
if (buttonType == ButtonType.Left)
{
pressed = (
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadLeft.IsPressed) ||
inputs.Keyboard.IsPressed(Input.KeyCode.A) ||
inputs.Keyboard.IsPressed(Input.KeyCode.Left)
);
}
else if (buttonType == ButtonType.Bottom)
{
pressed = (
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadDown.IsPressed) ||
inputs.Keyboard.IsPressed(Input.KeyCode.S) ||
inputs.Keyboard.IsPressed(Input.KeyCode.Down)
);
}
else if (buttonType == ButtonType.Right)
{
pressed = (
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadRight.IsPressed) ||
inputs.Keyboard.IsPressed(Input.KeyCode.D) ||
inputs.Keyboard.IsPressed(Input.KeyCode.Right)
);
}
if (buttonType == ButtonType.Left)
{
pressed = (
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadLeft.IsPressed) ||
inputs.Keyboard.IsPressed(Input.KeyCode.A) ||
inputs.Keyboard.IsPressed(Input.KeyCode.Left)
);
}
else if (buttonType == ButtonType.Bottom)
{
pressed = (
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadDown.IsPressed) ||
inputs.Keyboard.IsPressed(Input.KeyCode.S) ||
inputs.Keyboard.IsPressed(Input.KeyCode.Down)
);
}
else if (buttonType == ButtonType.Right)
{
pressed = (
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadRight.IsPressed) ||
inputs.Keyboard.IsPressed(Input.KeyCode.D) ||
inputs.Keyboard.IsPressed(Input.KeyCode.Right)
);
}
return pressed;
}
return pressed;
}
public static bool CheckButtonDown(Input.Inputs inputs, ButtonType buttonType)
{
bool down = false;
public static bool CheckButtonDown(Input.Inputs inputs, ButtonType buttonType)
{
bool down = false;
if (buttonType == ButtonType.Left)
{
down = (
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadLeft.IsDown) ||
inputs.Keyboard.IsDown(Input.KeyCode.A) ||
inputs.Keyboard.IsDown(Input.KeyCode.Left)
);
}
else if (buttonType == ButtonType.Bottom)
{
down = (
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadDown.IsDown) ||
inputs.Keyboard.IsDown(Input.KeyCode.S) ||
inputs.Keyboard.IsDown(Input.KeyCode.Down)
);
}
else if (buttonType == ButtonType.Right)
{
down = (
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadRight.IsDown) ||
inputs.Keyboard.IsDown(Input.KeyCode.D) ||
inputs.Keyboard.IsDown(Input.KeyCode.Right)
);
}
if (buttonType == ButtonType.Left)
{
down = (
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadLeft.IsDown) ||
inputs.Keyboard.IsDown(Input.KeyCode.A) ||
inputs.Keyboard.IsDown(Input.KeyCode.Left)
);
}
else if (buttonType == ButtonType.Bottom)
{
down = (
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadDown.IsDown) ||
inputs.Keyboard.IsDown(Input.KeyCode.S) ||
inputs.Keyboard.IsDown(Input.KeyCode.Down)
);
}
else if (buttonType == ButtonType.Right)
{
down = (
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadRight.IsDown) ||
inputs.Keyboard.IsDown(Input.KeyCode.D) ||
inputs.Keyboard.IsDown(Input.KeyCode.Right)
);
}
return down;
}
}
return down;
}
}
}

View File

@ -2,13 +2,13 @@
namespace MoonWorks.Test
{
public struct TransformVertexUniform
{
public Matrix4x4 ViewProjection;
public struct TransformVertexUniform
{
public Matrix4x4 ViewProjection;
public TransformVertexUniform(Matrix4x4 viewProjection)
{
ViewProjection = viewProjection;
}
}
public TransformVertexUniform(Matrix4x4 viewProjection)
{
ViewProjection = viewProjection;
}
}
}

View File

@ -20,12 +20,12 @@ namespace MoonWorks.Test
};
public override string ToString()
{
{
return Position.ToString();
}
}
[StructLayout(LayoutKind.Sequential)]
[StructLayout(LayoutKind.Sequential)]
public struct PositionColorVertex : IVertexType
{
public Vector3 Position;
@ -67,9 +67,9 @@ namespace MoonWorks.Test
VertexElementFormat.Vector2
};
public override string ToString()
{
public override string ToString()
{
return Position + " | " + TexCoord;
}
}
}
}
}

View File

@ -5,130 +5,130 @@ using RefreshCS;
namespace MoonWorks.Test
{
class RenderTexture3DGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private Texture rt;
private Sampler sampler;
class RenderTexture3DGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private Texture rt;
private Sampler sampler;
private float t;
private Color[] colors = new Color[]
{
Color.Red,
Color.Green,
Color.Blue,
};
private float t;
private Color[] colors = new Color[]
{
Color.Red,
Color.Green,
Color.Blue,
};
struct FragUniform
{
public float Depth;
struct FragUniform
{
public float Depth;
public FragUniform(float depth)
{
Depth = depth;
}
}
public FragUniform(float depth)
{
Depth = depth;
}
}
public RenderTexture3DGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad3D.frag"));
public RenderTexture3DGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad3D.frag"));
// Create the graphics pipeline
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
pipelineCreateInfo.FragmentShaderInfo = GraphicsShaderInfo.Create<FragUniform>(fragShaderModule, "main", 1);
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create the graphics pipeline
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
pipelineCreateInfo.FragmentShaderInfo = GraphicsShaderInfo.Create<FragUniform>(fragShaderModule, "main", 1);
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create samplers
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.LinearWrap);
// Create samplers
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.LinearWrap);
// Create and populate the GPU resources
vertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 4);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6);
rt = Texture.CreateTexture3D(
GraphicsDevice,
16,
16,
(uint) colors.Length,
TextureFormat.R8G8B8A8,
TextureUsageFlags.ColorTarget | TextureUsageFlags.Sampler
);
// Create and populate the GPU resources
vertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 4);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6);
rt = Texture.CreateTexture3D(
GraphicsDevice,
16,
16,
(uint) colors.Length,
TextureFormat.R8G8B8A8,
TextureUsageFlags.ColorTarget | TextureUsageFlags.Sampler
);
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,
}
);
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
for (uint i = 0; i < colors.Length; i += 1)
{
ColorAttachmentInfo attachmentInfo = new ColorAttachmentInfo
{
Texture = rt,
ClearColor = colors[i],
Depth = i,
Layer = 0,
Level = 0,
LoadOp = LoadOp.Clear,
StoreOp = StoreOp.Store
};
cmdbuf.BeginRenderPass(attachmentInfo);
cmdbuf.EndRenderPass();
}
// Clear each depth slice of the RT to a different color
for (uint i = 0; i < colors.Length; i += 1)
{
ColorAttachmentInfo attachmentInfo = new ColorAttachmentInfo
{
Texture = rt,
ClearColor = colors[i],
Depth = i,
Layer = 0,
Level = 0,
LoadOp = LoadOp.Clear,
StoreOp = StoreOp.Store
};
cmdbuf.BeginRenderPass(attachmentInfo);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
GraphicsDevice.Submit(cmdbuf);
}
protected override void Update(System.TimeSpan delta) { }
protected override void Update(System.TimeSpan delta) { }
protected override void Draw(double alpha)
{
t += 0.01f;
FragUniform fragUniform = new FragUniform(t);
protected override void Draw(double alpha)
{
t += 0.01f;
FragUniform fragUniform = new FragUniform(t);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(rt, sampler));
uint fragParamOffset = cmdbuf.PushFragmentShaderUniforms(fragUniform);
cmdbuf.DrawIndexedPrimitives(0, 0, 2, 0, fragParamOffset);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(rt, sampler));
uint fragParamOffset = cmdbuf.PushFragmentShaderUniforms(fragUniform);
cmdbuf.DrawIndexedPrimitives(0, 0, 2, 0, fragParamOffset);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
public static void Main(string[] args)
{
RenderTexture3DGame game = new RenderTexture3DGame();
game.Run();
}
}
public static void Main(string[] args)
{
RenderTexture3DGame game = new RenderTexture3DGame();
game.Run();
}
}
}

View File

@ -6,171 +6,171 @@ using System.Runtime.InteropServices;
namespace MoonWorks.Test
{
class RenderTextureCubeGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private Texture cubemap;
private Sampler sampler;
class RenderTextureCubeGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private Texture cubemap;
private Sampler sampler;
private Vector3 camPos = new Vector3(0, 0, 4f);
private Vector3 camPos = new Vector3(0, 0, 4f);
private Color[] colors = new Color[]
{
Color.Red,
Color.Green,
Color.Blue,
Color.Orange,
Color.Yellow,
Color.Purple,
};
private Color[] colors = new Color[]
{
Color.Red,
Color.Green,
Color.Blue,
Color.Orange,
Color.Yellow,
Color.Purple,
};
public RenderTextureCubeGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
Logger.LogInfo("Press Down to view the other side of the cubemap");
public RenderTextureCubeGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
Logger.LogInfo("Press Down to view the other side of the cubemap");
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("Skybox.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("Skybox.frag"));
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("Skybox.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("Skybox.frag"));
// Create the graphics pipeline
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionVertex>();
pipelineCreateInfo.VertexShaderInfo.UniformBufferSize = (uint) Marshal.SizeOf<TransformVertexUniform>();
pipelineCreateInfo.FragmentShaderInfo.SamplerBindingCount = 1;
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create the graphics pipeline
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionVertex>();
pipelineCreateInfo.VertexShaderInfo.UniformBufferSize = (uint) Marshal.SizeOf<TransformVertexUniform>();
pipelineCreateInfo.FragmentShaderInfo.SamplerBindingCount = 1;
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create samplers
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointClamp);
// Create samplers
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointClamp);
// Create and populate the GPU resources
vertexBuffer = Buffer.Create<PositionVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 24);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 36);
cubemap = Texture.CreateTextureCube(
GraphicsDevice,
16,
TextureFormat.R8G8B8A8,
TextureUsageFlags.ColorTarget | TextureUsageFlags.Sampler
);
// Create and populate the GPU resources
vertexBuffer = Buffer.Create<PositionVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 24);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 36);
cubemap = Texture.CreateTextureCube(
GraphicsDevice,
16,
TextureFormat.R8G8B8A8,
TextureUsageFlags.ColorTarget | TextureUsageFlags.Sampler
);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
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)),
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
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)),
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)),
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)),
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)),
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)),
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)),
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)),
new PositionVertex(new Vector3(10, 10, 10)),
new PositionVertex(new Vector3(10, 10, -10))
}
);
cmdbuf.SetBufferData(
indexBuffer,
new ushort[]
{
0, 1, 2, 0, 2, 3,
6, 5, 4, 7, 6, 4,
8, 9, 10, 8, 10, 11,
14, 13, 12, 15, 14, 12,
16, 17, 18, 16, 18, 19,
22, 21, 20, 23, 22, 20
}
);
cmdbuf.SetBufferData(
indexBuffer,
new ushort[]
{
0, 1, 2, 0, 2, 3,
6, 5, 4, 7, 6, 4,
8, 9, 10, 8, 10, 11,
14, 13, 12, 15, 14, 12,
16, 17, 18, 16, 18, 19,
22, 21, 20, 23, 22, 20
}
);
// Clear each slice of the cubemap to a different color
for (uint i = 0; i < 6; i += 1)
{
ColorAttachmentInfo attachmentInfo = new ColorAttachmentInfo
{
Texture = cubemap,
ClearColor = colors[i],
Depth = 0,
Layer = i,
Level = 0,
LoadOp = LoadOp.Clear,
StoreOp = StoreOp.Store
};
cmdbuf.BeginRenderPass(attachmentInfo);
cmdbuf.EndRenderPass();
}
// Clear each slice of the cubemap to a different color
for (uint i = 0; i < 6; i += 1)
{
ColorAttachmentInfo attachmentInfo = new ColorAttachmentInfo
{
Texture = cubemap,
ClearColor = colors[i],
Depth = 0,
Layer = i,
Level = 0,
LoadOp = LoadOp.Clear,
StoreOp = StoreOp.Store
};
cmdbuf.BeginRenderPass(attachmentInfo);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
GraphicsDevice.Submit(cmdbuf);
}
protected override void Update(System.TimeSpan delta)
{
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Bottom))
{
camPos.Z *= -1;
}
}
protected override void Update(System.TimeSpan delta)
{
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Bottom))
{
camPos.Z *= -1;
}
}
protected override void Draw(double alpha)
{
Matrix4x4 proj = Matrix4x4.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(75f),
(float) MainWindow.Width / MainWindow.Height,
0.01f,
100f
);
Matrix4x4 view = Matrix4x4.CreateLookAt(
camPos,
Vector3.Zero,
Vector3.Up
);
TransformVertexUniform vertUniforms = new TransformVertexUniform(view * proj);
protected override void Draw(double alpha)
{
Matrix4x4 proj = Matrix4x4.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(75f),
(float) MainWindow.Width / MainWindow.Height,
0.01f,
100f
);
Matrix4x4 view = Matrix4x4.CreateLookAt(
camPos,
Vector3.Zero,
Vector3.Up
);
TransformVertexUniform vertUniforms = new TransformVertexUniform(view * proj);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(cubemap, sampler));
uint vertexUniformOffset = cmdbuf.PushVertexShaderUniforms(vertUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 12, vertexUniformOffset, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(cubemap, sampler));
uint vertexUniformOffset = cmdbuf.PushVertexShaderUniforms(vertUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 12, vertexUniformOffset, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
public static void Main(string[] args)
{
RenderTextureCubeGame game = new RenderTextureCubeGame();
game.Run();
}
}
public static void Main(string[] args)
{
RenderTextureCubeGame game = new RenderTextureCubeGame();
game.Run();
}
}
}

View File

@ -4,179 +4,179 @@ using MoonWorks.Math.Float;
namespace MoonWorks.Test
{
class RenderTextureMipmapsGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private Texture texture;
class RenderTextureMipmapsGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private Texture texture;
private Sampler[] samplers = new Sampler[5];
private Sampler[] samplers = new Sampler[5];
private float scale = 0.5f;
private int currentSamplerIndex = 0;
private Color[] colors = new Color[]
{
Color.Red,
Color.Green,
Color.Blue,
Color.Yellow,
};
private float scale = 0.5f;
private int currentSamplerIndex = 0;
private Color[] colors = new Color[]
{
Color.Red,
Color.Green,
Color.Blue,
Color.Yellow,
};
private string GetSamplerString(int index)
{
switch (index)
{
case 0:
return "PointClamp";
case 1:
return "LinearClamp";
case 2:
return "PointClamp with Mip LOD Bias = 0.25";
case 3:
return "PointClamp with Min LOD = 1";
case 4:
return "PointClamp with Max LOD = 1";
default:
throw new System.Exception("Unknown sampler!");
}
}
private string GetSamplerString(int index)
{
switch (index)
{
case 0:
return "PointClamp";
case 1:
return "LinearClamp";
case 2:
return "PointClamp with Mip LOD Bias = 0.25";
case 3:
return "PointClamp with Min LOD = 1";
case 4:
return "PointClamp with Max LOD = 1";
default:
throw new System.Exception("Unknown sampler!");
}
}
public RenderTextureMipmapsGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
Logger.LogInfo("Press Left and Right to shrink/expand the scale of the quad");
Logger.LogInfo("Press Down to cycle through sampler states");
Logger.LogInfo(GetSamplerString(currentSamplerIndex));
public RenderTextureMipmapsGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
Logger.LogInfo("Press Left and Right to shrink/expand the scale of the quad");
Logger.LogInfo("Press Down to cycle through sampler states");
Logger.LogInfo(GetSamplerString(currentSamplerIndex));
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuadWithMatrix.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.frag"));
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuadWithMatrix.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.frag"));
// Create the graphics pipeline
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
pipelineCreateInfo.VertexShaderInfo = GraphicsShaderInfo.Create<TransformVertexUniform>(vertShaderModule, "main", 0);
pipelineCreateInfo.FragmentShaderInfo.SamplerBindingCount = 1;
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create the graphics pipeline
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
pipelineCreateInfo.VertexShaderInfo = GraphicsShaderInfo.Create<TransformVertexUniform>(vertShaderModule, "main", 0);
pipelineCreateInfo.FragmentShaderInfo.SamplerBindingCount = 1;
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create samplers
SamplerCreateInfo samplerCreateInfo = SamplerCreateInfo.PointClamp;
samplers[0] = new Sampler(GraphicsDevice, samplerCreateInfo);
// Create samplers
SamplerCreateInfo samplerCreateInfo = SamplerCreateInfo.PointClamp;
samplers[0] = new Sampler(GraphicsDevice, samplerCreateInfo);
samplerCreateInfo = SamplerCreateInfo.LinearClamp;
samplers[1] = new Sampler(GraphicsDevice, samplerCreateInfo);
samplerCreateInfo = SamplerCreateInfo.LinearClamp;
samplers[1] = new Sampler(GraphicsDevice, samplerCreateInfo);
samplerCreateInfo = SamplerCreateInfo.PointClamp;
samplerCreateInfo.MipLodBias = 0.25f;
samplers[2] = new Sampler(GraphicsDevice, samplerCreateInfo);
samplerCreateInfo = SamplerCreateInfo.PointClamp;
samplerCreateInfo.MipLodBias = 0.25f;
samplers[2] = new Sampler(GraphicsDevice, samplerCreateInfo);
samplerCreateInfo = SamplerCreateInfo.PointClamp;
samplerCreateInfo.MinLod = 1;
samplers[3] = new Sampler(GraphicsDevice, samplerCreateInfo);
samplerCreateInfo = SamplerCreateInfo.PointClamp;
samplerCreateInfo.MinLod = 1;
samplers[3] = new Sampler(GraphicsDevice, samplerCreateInfo);
samplerCreateInfo = SamplerCreateInfo.PointClamp;
samplerCreateInfo.MaxLod = 1;
samplers[4] = new Sampler(GraphicsDevice, samplerCreateInfo);
samplerCreateInfo = SamplerCreateInfo.PointClamp;
samplerCreateInfo.MaxLod = 1;
samplers[4] = new Sampler(GraphicsDevice, samplerCreateInfo);
// Create and populate the GPU resources
vertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 4);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6);
texture = Texture.CreateTexture2D(
GraphicsDevice,
MainWindow.Width,
MainWindow.Height,
TextureFormat.R8G8B8A8,
TextureUsageFlags.ColorTarget | TextureUsageFlags.Sampler,
4
);
// Create and populate the GPU resources
vertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 4);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6);
texture = Texture.CreateTexture2D(
GraphicsDevice,
MainWindow.Width,
MainWindow.Height,
TextureFormat.R8G8B8A8,
TextureUsageFlags.ColorTarget | TextureUsageFlags.Sampler,
4
);
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,
}
);
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 mip level to a different color
for (uint i = 0; i < texture.LevelCount; i += 1)
{
ColorAttachmentInfo attachmentInfo = new ColorAttachmentInfo
{
Texture = texture,
ClearColor = colors[i],
Depth = 0,
Layer = 0,
Level = i,
LoadOp = LoadOp.Clear,
StoreOp = StoreOp.Store
};
cmdbuf.BeginRenderPass(attachmentInfo);
cmdbuf.EndRenderPass();
}
// Clear each mip level to a different color
for (uint i = 0; i < texture.LevelCount; i += 1)
{
ColorAttachmentInfo attachmentInfo = new ColorAttachmentInfo
{
Texture = texture,
ClearColor = colors[i],
Depth = 0,
Layer = 0,
Level = i,
LoadOp = LoadOp.Clear,
StoreOp = StoreOp.Store
};
cmdbuf.BeginRenderPass(attachmentInfo);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
GraphicsDevice.Submit(cmdbuf);
}
protected override void Update(System.TimeSpan delta)
{
if (TestUtils.CheckButtonDown(Inputs, TestUtils.ButtonType.Left))
{
scale = System.MathF.Max(0.01f, scale - 0.01f);
}
protected override void Update(System.TimeSpan delta)
{
if (TestUtils.CheckButtonDown(Inputs, TestUtils.ButtonType.Left))
{
scale = System.MathF.Max(0.01f, scale - 0.01f);
}
if (TestUtils.CheckButtonDown(Inputs, TestUtils.ButtonType.Right))
{
scale = System.MathF.Min(1f, scale + 0.01f);
}
if (TestUtils.CheckButtonDown(Inputs, TestUtils.ButtonType.Right))
{
scale = System.MathF.Min(1f, scale + 0.01f);
}
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Bottom))
{
currentSamplerIndex = (currentSamplerIndex + 1) % samplers.Length;
Logger.LogInfo(GetSamplerString(currentSamplerIndex));
}
}
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Bottom))
{
currentSamplerIndex = (currentSamplerIndex + 1) % samplers.Length;
Logger.LogInfo(GetSamplerString(currentSamplerIndex));
}
}
protected override void Draw(double alpha)
{
TransformVertexUniform vertUniforms = new TransformVertexUniform(Matrix4x4.CreateScale(scale, scale, 1));
protected override void Draw(double alpha)
{
TransformVertexUniform vertUniforms = new TransformVertexUniform(Matrix4x4.CreateScale(scale, scale, 1));
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(texture, samplers[currentSamplerIndex]));
uint vertParamOffset = cmdbuf.PushVertexShaderUniforms(vertUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 2, vertParamOffset, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(texture, samplers[currentSamplerIndex]));
uint vertParamOffset = cmdbuf.PushVertexShaderUniforms(vertUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 2, vertParamOffset, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
public static void Main(string[] args)
{
RenderTextureMipmapsGame game = new RenderTextureMipmapsGame();
game.Run();
}
}
public static void Main(string[] args)
{
RenderTextureMipmapsGame game = new RenderTextureMipmapsGame();
game.Run();
}
}
}

View File

@ -5,143 +5,143 @@ using RefreshCS;
namespace MoonWorks.Test
{
class Texture3DGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private Texture texture;
private Sampler sampler;
class Texture3DGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private Texture texture;
private Sampler sampler;
private int currentDepth = 0;
private int currentDepth = 0;
struct FragUniform
{
public float Depth;
struct FragUniform
{
public float Depth;
public FragUniform(float depth)
{
Depth = depth;
}
}
public FragUniform(float depth)
{
Depth = depth;
}
}
public Texture3DGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
Logger.LogInfo("Press Left and Right to cycle between depth slices");
public Texture3DGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
Logger.LogInfo("Press Left and Right to cycle between depth slices");
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad3D.frag"));
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad3D.frag"));
// Create the graphics pipeline
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
pipelineCreateInfo.FragmentShaderInfo = GraphicsShaderInfo.Create<FragUniform>(fragShaderModule, "main", 1);
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create the graphics pipeline
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
pipelineCreateInfo.FragmentShaderInfo = GraphicsShaderInfo.Create<FragUniform>(fragShaderModule, "main", 1);
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create samplers
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointClamp);
// Create samplers
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointClamp);
// Create and populate the GPU resources
vertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 4);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6);
texture = Texture.CreateTexture3D(GraphicsDevice, 16, 16, 7, TextureFormat.R8G8B8A8, TextureUsageFlags.Sampler);
// Create and populate the GPU resources
vertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 4);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6);
texture = Texture.CreateTexture3D(GraphicsDevice, 16, 16, 7, TextureFormat.R8G8B8A8, TextureUsageFlags.Sampler);
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,
}
);
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,
}
);
// Load each depth subimage of the 3D texture
for (uint i = 0; i < texture.Depth; i += 1)
{
TextureSlice slice = new TextureSlice(
texture,
new Rect(0, 0, (int) texture.Width, (int) texture.Height),
i
);
// Load each depth subimage of the 3D texture
for (uint i = 0; i < texture.Depth; i += 1)
{
TextureSlice slice = new TextureSlice(
texture,
new Rect(0, 0, (int) texture.Width, (int) texture.Height),
i
);
Texture.SetDataFromImageFile(
cmdbuf,
slice,
TestUtils.GetTexturePath($"tex3d_{i}.png")
);
}
}
GraphicsDevice.Submit(cmdbuf);
}
GraphicsDevice.Submit(cmdbuf);
}
protected override void Update(System.TimeSpan delta)
{
int prevDepth = currentDepth;
protected override void Update(System.TimeSpan delta)
{
int prevDepth = currentDepth;
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Left))
{
currentDepth -= 1;
if (currentDepth < 0)
{
currentDepth = (int) texture.Depth - 1;
}
}
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Left))
{
currentDepth -= 1;
if (currentDepth < 0)
{
currentDepth = (int) texture.Depth - 1;
}
}
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Right))
{
currentDepth += 1;
if (currentDepth >= texture.Depth)
{
currentDepth = 0;
}
}
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Right))
{
currentDepth += 1;
if (currentDepth >= texture.Depth)
{
currentDepth = 0;
}
}
if (prevDepth != currentDepth)
{
Logger.LogInfo("Setting depth to: " + currentDepth);
}
}
if (prevDepth != currentDepth)
{
Logger.LogInfo("Setting depth to: " + currentDepth);
}
}
protected override void Draw(double alpha)
{
FragUniform fragUniform = new FragUniform((float) currentDepth / texture.Depth);
protected override void Draw(double alpha)
{
FragUniform fragUniform = new FragUniform((float) currentDepth / texture.Depth);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(texture, sampler));
uint fragParamOffset = cmdbuf.PushFragmentShaderUniforms(fragUniform);
cmdbuf.DrawIndexedPrimitives(0, 0, 2, 0, fragParamOffset);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(texture, sampler));
uint fragParamOffset = cmdbuf.PushFragmentShaderUniforms(fragUniform);
cmdbuf.DrawIndexedPrimitives(0, 0, 2, 0, fragParamOffset);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
public static void Main(string[] args)
{
Texture3DGame game = new Texture3DGame();
game.Run();
}
}
public static void Main(string[] args)
{
Texture3DGame game = new Texture3DGame();
game.Run();
}
}
}

View File

@ -5,124 +5,124 @@ using RefreshCS;
namespace MoonWorks.Test
{
class TextureMipmapsGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private Texture texture;
private Sampler sampler;
class TextureMipmapsGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private Texture texture;
private Sampler sampler;
private float scale = 0.5f;
private float scale = 0.5f;
public TextureMipmapsGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
Logger.LogInfo("Press Left and Right to shrink/expand the scale of the quad");
public TextureMipmapsGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
Logger.LogInfo("Press Left and Right to shrink/expand the scale of the quad");
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuadWithMatrix.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.frag"));
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuadWithMatrix.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.frag"));
// Create the graphics pipeline
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
pipelineCreateInfo.VertexShaderInfo = GraphicsShaderInfo.Create<TransformVertexUniform>(vertShaderModule, "main", 0);
pipelineCreateInfo.FragmentShaderInfo.SamplerBindingCount = 1;
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create the graphics pipeline
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
pipelineCreateInfo.VertexShaderInfo = GraphicsShaderInfo.Create<TransformVertexUniform>(vertShaderModule, "main", 0);
pipelineCreateInfo.FragmentShaderInfo.SamplerBindingCount = 1;
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create and populate the GPU resources
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointClamp);
vertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 4);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6);
texture = Texture.CreateTexture2D(
GraphicsDevice,
256,
256,
TextureFormat.R8G8B8A8,
TextureUsageFlags.Sampler,
4
);
// Create and populate the GPU resources
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointClamp);
vertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 4);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6);
texture = Texture.CreateTexture2D(
GraphicsDevice,
256,
256,
TextureFormat.R8G8B8A8,
TextureUsageFlags.Sampler,
4
);
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,
}
);
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,
}
);
// Set the various mip levels
for (int i = 0; i < texture.LevelCount; i += 1)
{
int w = (int) texture.Width >> i;
int h = (int) texture.Height >> i;
TextureSlice slice = new TextureSlice(
texture,
new Rect(0, 0, w, h),
0,
0,
(uint) i
);
// Set the various mip levels
for (int i = 0; i < texture.LevelCount; i += 1)
{
int w = (int) texture.Width >> i;
int h = (int) texture.Height >> i;
TextureSlice slice = new TextureSlice(
texture,
new Rect(0, 0, w, h),
0,
0,
(uint) i
);
Texture.SetDataFromImageFile(cmdbuf, slice, TestUtils.GetTexturePath($"mip{i}.png"));
}
}
GraphicsDevice.Submit(cmdbuf);
}
GraphicsDevice.Submit(cmdbuf);
}
protected override void Update(System.TimeSpan delta)
{
if (TestUtils.CheckButtonDown(Inputs, TestUtils.ButtonType.Left))
{
scale = System.MathF.Max(0.01f, scale - 0.01f);
}
protected override void Update(System.TimeSpan delta)
{
if (TestUtils.CheckButtonDown(Inputs, TestUtils.ButtonType.Left))
{
scale = System.MathF.Max(0.01f, scale - 0.01f);
}
if (TestUtils.CheckButtonDown(Inputs, TestUtils.ButtonType.Right))
{
scale = System.MathF.Min(1f, scale + 0.01f);
}
}
if (TestUtils.CheckButtonDown(Inputs, TestUtils.ButtonType.Right))
{
scale = System.MathF.Min(1f, scale + 0.01f);
}
}
protected override void Draw(double alpha)
{
TransformVertexUniform vertUniforms = new TransformVertexUniform(Matrix4x4.CreateScale(scale, scale, 1));
protected override void Draw(double alpha)
{
TransformVertexUniform vertUniforms = new TransformVertexUniform(Matrix4x4.CreateScale(scale, scale, 1));
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(texture, sampler));
uint vertParamOffset = cmdbuf.PushVertexShaderUniforms(vertUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 2, vertParamOffset, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(texture, sampler));
uint vertParamOffset = cmdbuf.PushVertexShaderUniforms(vertUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 2, vertParamOffset, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
public static void Main(string[] args)
{
TextureMipmapsGame game = new TextureMipmapsGame();
game.Run();
}
}
public static void Main(string[] args)
{
TextureMipmapsGame game = new TextureMipmapsGame();
game.Run();
}
}
}

View File

@ -4,70 +4,70 @@ using MoonWorks.Math.Float;
namespace MoonWorks.Test
{
class VertexSamplerGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Texture texture;
private Sampler sampler;
class VertexSamplerGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Texture texture;
private Sampler sampler;
public VertexSamplerGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("PositionSampler.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("SolidColor.frag"));
public VertexSamplerGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("PositionSampler.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("SolidColor.frag"));
// Create the graphics pipeline
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
pipelineCreateInfo.VertexShaderInfo.SamplerBindingCount = 1;
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create the graphics pipeline
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
pipelineCreateInfo.VertexShaderInfo.SamplerBindingCount = 1;
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create and populate the GPU resources
vertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 3);
texture = Texture.CreateTexture2D(GraphicsDevice, 3, 1, TextureFormat.R8G8B8A8, TextureUsageFlags.Sampler);
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointClamp);
// Create and populate the GPU resources
vertexBuffer = Buffer.Create<PositionTextureVertex>(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[]
{
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)),
}
);
cmdbuf.SetTextureData(texture, new Color[] { Color.Yellow, Color.Indigo, Color.HotPink });
GraphicsDevice.Submit(cmdbuf);
}
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.334f, 0)),
new PositionTextureVertex(new Vector3(0, -1, 0), new Vector2(0.667f, 0)),
}
);
cmdbuf.SetTextureData(texture, new Color[] { Color.Yellow, Color.Indigo, Color.HotPink });
GraphicsDevice.Submit(cmdbuf);
}
protected override void Update(System.TimeSpan delta) { }
protected override void Update(System.TimeSpan delta) { }
protected override void Draw(double alpha)
{
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindVertexSamplers(new TextureSamplerBinding(texture, sampler));
cmdbuf.DrawPrimitives(0, 1, 0, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
protected override void Draw(double alpha)
{
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindVertexSamplers(new TextureSamplerBinding(texture, sampler));
cmdbuf.DrawPrimitives(0, 1, 0, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
public static void Main(string[] args)
{
VertexSamplerGame p = new VertexSamplerGame();
p.Run();
}
}
public static void Main(string[] args)
{
VertexSamplerGame p = new VertexSamplerGame();
p.Run();
}
}
}

View File

@ -4,96 +4,96 @@ using MoonWorks.Video;
namespace MoonWorks.Test
{
class VideoPlayerGame : Game
{
private GraphicsPipeline pipeline;
private Sampler sampler;
private Buffer vertexBuffer;
private Buffer indexBuffer;
class VideoPlayerGame : Game
{
private GraphicsPipeline pipeline;
private Sampler sampler;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private Video.VideoAV1 video;
private VideoPlayer videoPlayer;
private Video.VideoAV1 video;
private VideoPlayer videoPlayer;
public VideoPlayerGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.frag"));
public VideoPlayerGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.frag"));
// Create the graphics pipeline
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
pipelineCreateInfo.FragmentShaderInfo.SamplerBindingCount = 1;
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create the graphics pipeline
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionTextureVertex>();
pipelineCreateInfo.FragmentShaderInfo.SamplerBindingCount = 1;
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create the sampler
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.LinearClamp);
// Create the sampler
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.LinearClamp);
// Create and populate the GPU resources
vertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 4);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6);
// Create and populate the GPU resources
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(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,
}
);
GraphicsDevice.Submit(cmdbuf);
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,
}
);
GraphicsDevice.Submit(cmdbuf);
// Load the video
video = new VideoAV1(GraphicsDevice, TestUtils.GetVideoPath("hello.obu"), 25);
// Load the video
video = new VideoAV1(GraphicsDevice, TestUtils.GetVideoPath("hello.obu"), 25);
// Play the video
videoPlayer = new VideoPlayer(GraphicsDevice);
videoPlayer.Load(video);
videoPlayer.Loop = true;
videoPlayer.Play();
}
// Play the video
videoPlayer = new VideoPlayer(GraphicsDevice);
videoPlayer.Load(video);
videoPlayer.Loop = true;
videoPlayer.Play();
}
protected override void Update(System.TimeSpan delta)
{
videoPlayer.Render();
}
protected override void Update(System.TimeSpan delta)
{
videoPlayer.Render();
}
protected override void Draw(double alpha)
{
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.CornflowerBlue));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(videoPlayer.RenderTexture, sampler));
cmdbuf.DrawIndexedPrimitives(0, 0, 2, 0, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
protected override void Draw(double alpha)
{
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.CornflowerBlue));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(videoPlayer.RenderTexture, sampler));
cmdbuf.DrawIndexedPrimitives(0, 0, 2, 0, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
public static void Main(string[] args)
{
VideoPlayerGame game = new VideoPlayerGame();
game.Run();
}
}
public static void Main(string[] args)
{
VideoPlayerGame game = new VideoPlayerGame();
game.Run();
}
}
}

View File

@ -3,83 +3,83 @@ using MoonWorks.Graphics;
namespace MoonWorks.Test
{
class WindowResizingGame : Game
{
private GraphicsPipeline pipeline;
class WindowResizingGame : Game
{
private GraphicsPipeline pipeline;
private int currentResolutionIndex;
private record struct Res(uint Width, uint Height);
private Res[] resolutions = new Res[]
{
new Res(640, 480),
new Res(1280, 720),
new Res(1024, 1024),
new Res(1600, 900),
new Res(1920, 1080),
new Res(3200, 1800),
new Res(3840, 2160),
};
private int currentResolutionIndex;
private record struct Res(uint Width, uint Height);
private Res[] resolutions = new Res[]
{
new Res(640, 480),
new Res(1280, 720),
new Res(1024, 1024),
new Res(1600, 900),
new Res(1920, 1080),
new Res(3200, 1800),
new Res(3840, 2160),
};
public WindowResizingGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("RawTriangle.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("SolidColor.frag"));
public WindowResizingGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("RawTriangle.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("SolidColor.frag"));
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
}
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
}
protected override void Update(System.TimeSpan delta)
{
int prevResolutionIndex = currentResolutionIndex;
protected override void Update(System.TimeSpan delta)
{
int prevResolutionIndex = currentResolutionIndex;
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Left))
{
currentResolutionIndex -= 1;
if (currentResolutionIndex < 0)
{
currentResolutionIndex = resolutions.Length - 1;
}
}
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Left))
{
currentResolutionIndex -= 1;
if (currentResolutionIndex < 0)
{
currentResolutionIndex = resolutions.Length - 1;
}
}
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Right))
{
currentResolutionIndex += 1;
if (currentResolutionIndex >= resolutions.Length)
{
currentResolutionIndex = 0;
}
}
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Right))
{
currentResolutionIndex += 1;
if (currentResolutionIndex >= resolutions.Length)
{
currentResolutionIndex = 0;
}
}
if (prevResolutionIndex != currentResolutionIndex)
{
Logger.LogInfo("Setting resolution to: " + resolutions[currentResolutionIndex]);
MainWindow.SetWindowSize(resolutions[currentResolutionIndex].Width, resolutions[currentResolutionIndex].Height);
}
}
if (prevResolutionIndex != currentResolutionIndex)
{
Logger.LogInfo("Setting resolution to: " + resolutions[currentResolutionIndex]);
MainWindow.SetWindowSize(resolutions[currentResolutionIndex].Width, resolutions[currentResolutionIndex].Height);
}
}
protected override void Draw(double alpha)
{
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.DrawPrimitives(0, 1, 0, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
protected override void Draw(double alpha)
{
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.DrawPrimitives(0, 1, 0, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
public static void Main(string[] args)
{
WindowResizingGame game = new WindowResizingGame();
game.Run();
}
}
public static void Main(string[] args)
{
WindowResizingGame game = new WindowResizingGame();
game.Run();
}
}
}