diff --git a/CompressedTextures/CompressedTextures.csproj b/CompressedTextures/CompressedTextures.csproj new file mode 100644 index 0000000..7becfeb --- /dev/null +++ b/CompressedTextures/CompressedTextures.csproj @@ -0,0 +1,17 @@ + + + + + + + + + Exe + net7.0 + enable + x64 + + + + + diff --git a/CompressedTextures/CompressedTexturesGame.cs b/CompressedTextures/CompressedTexturesGame.cs new file mode 100644 index 0000000..c701d8f --- /dev/null +++ b/CompressedTextures/CompressedTexturesGame.cs @@ -0,0 +1,134 @@ +using MoonWorks; +using MoonWorks.Graphics; +using MoonWorks.Math.Float; +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" + }; + + 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]); + + // Load the shaders + ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuadVert.spv")); + ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuadFrag.spv")); + + // Create the graphics pipeline + GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo( + MainWindow.SwapchainFormat, + vertShaderModule, + fragShaderModule + ); + pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding(); + pipelineCreateInfo.FragmentShaderInfo.SamplerBindingCount = 1; + pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo); + + // Create sampler + sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.LinearWrap); + + // Create texture array + textures = new Texture[textureNames.Length]; + + // Create and populate the GPU resources + vertexBuffer = Buffer.Create(GraphicsDevice, BufferUsageFlags.Vertex, 4); + indexBuffer = Buffer.Create(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); + GraphicsDevice.Wait(); + } + + 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.Right)) + { + currentTextureIndex += 1; + if (currentTextureIndex >= textureNames.Length) + { + currentTextureIndex = 0; + } + } + + 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); + } + + public static void Main(string[] args) + { + CompressedTexturesGame game = new CompressedTexturesGame(); + game.Run(); + } + } +} diff --git a/MoonWorks.Test.Common/Content/Textures/BC1.dds b/MoonWorks.Test.Common/Content/Textures/BC1.dds new file mode 100644 index 0000000..1fee667 Binary files /dev/null and b/MoonWorks.Test.Common/Content/Textures/BC1.dds differ diff --git a/MoonWorks.Test.Common/Content/Textures/BC2.dds b/MoonWorks.Test.Common/Content/Textures/BC2.dds new file mode 100644 index 0000000..364c36f Binary files /dev/null and b/MoonWorks.Test.Common/Content/Textures/BC2.dds differ diff --git a/MoonWorks.Test.Common/Content/Textures/BC3.dds b/MoonWorks.Test.Common/Content/Textures/BC3.dds new file mode 100644 index 0000000..e4d6b0c Binary files /dev/null and b/MoonWorks.Test.Common/Content/Textures/BC3.dds differ diff --git a/MoonWorks.Test.Common/Content/Textures/BC7.dds b/MoonWorks.Test.Common/Content/Textures/BC7.dds new file mode 100644 index 0000000..e55e296 Binary files /dev/null and b/MoonWorks.Test.Common/Content/Textures/BC7.dds differ diff --git a/MoonWorksGraphicsTests.sln b/MoonWorksGraphicsTests.sln index c499ce9..18d6ad5 100644 --- a/MoonWorksGraphicsTests.sln +++ b/MoonWorksGraphicsTests.sln @@ -31,7 +31,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BasicCompute", "BasicComput EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeUniforms", "ComputeUniforms\ComputeUniforms.csproj", "{5F8BBD49-6C39-4186-A4A3-91D6662D3ABD}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DrawIndirect", "DrawIndirect\DrawIndirect.csproj", "{CA6E0ACF-3698-452F-B71F-51286EB5E1B2}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DrawIndirect", "DrawIndirect\DrawIndirect.csproj", "{CA6E0ACF-3698-452F-B71F-51286EB5E1B2}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CompressedTextures", "CompressedTextures\CompressedTextures.csproj", "{E90D236C-BD0F-4420-ADD0-867D21F4DCA5}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -99,6 +101,10 @@ Global {CA6E0ACF-3698-452F-B71F-51286EB5E1B2}.Debug|x64.Build.0 = Debug|x64 {CA6E0ACF-3698-452F-B71F-51286EB5E1B2}.Release|x64.ActiveCfg = Release|Any CPU {CA6E0ACF-3698-452F-B71F-51286EB5E1B2}.Release|x64.Build.0 = Release|Any CPU + {E90D236C-BD0F-4420-ADD0-867D21F4DCA5}.Debug|x64.ActiveCfg = Debug|x64 + {E90D236C-BD0F-4420-ADD0-867D21F4DCA5}.Debug|x64.Build.0 = Debug|x64 + {E90D236C-BD0F-4420-ADD0-867D21F4DCA5}.Release|x64.ActiveCfg = Release|Any CPU + {E90D236C-BD0F-4420-ADD0-867D21F4DCA5}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/README.md b/README.md index 2a56b56..80a9beb 100644 --- a/README.md +++ b/README.md @@ -51,3 +51,7 @@ Uses a compute pipeline to fill a texture with a color gradient. Tests compute u **DrawIndirect** Draws two triangles via indirect commands. Tests DrawPrimitivesIndirect. + +**CompressedTextures** + +Loads a series of compressed textures, then displays them for viewing. Tests compressed texture loading.