diff --git a/Content/Shaders/ImGui.frag.refresh b/Content/Shaders/ImGui.frag.refresh index 2a77dac..226a37d 100644 --- a/Content/Shaders/ImGui.frag.refresh +++ b/Content/Shaders/ImGui.frag.refresh @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d119f9d64fa6ed20ad6f8aa2065b0d5bbcb5d989f55ae0b23b3e4371daf1d774 -size 741 +oid sha256:ccae7bc3adb878941a3f1e251e0db4c6d556a8f6d2bb72b8fbef30baf63ab782 +size 1438 diff --git a/Content/Shaders/ImGui.vert.refresh b/Content/Shaders/ImGui.vert.refresh index fa7eff8..6173d96 100644 --- a/Content/Shaders/ImGui.vert.refresh +++ b/Content/Shaders/ImGui.vert.refresh @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ec6523170c4add2325152f2cae4a71d6d6402b663582221e17bdf34a8fbf128d -size 1521 +oid sha256:116e48c51b30a5fc54779b4a1a1d68998b0b2ac651eed1cde9076d2b8c377cdc +size 2688 diff --git a/lib/MoonWorks b/lib/MoonWorks index 178a5ea..9195e44 160000 --- a/lib/MoonWorks +++ b/lib/MoonWorks @@ -1 +1 @@ -Subproject commit 178a5ea3cfa4ce4ccbcd9e0b6726a8cda791c810 +Subproject commit 9195e445b2473564563c917df611fcca4ea161d1 diff --git a/moonlibs/x64/Refresh.dll b/moonlibs/x64/Refresh.dll index 83ac3e9..4838a93 100644 --- a/moonlibs/x64/Refresh.dll +++ b/moonlibs/x64/Refresh.dll @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a83bbfe1deea0aca2dc52ce54b2f28836d5a7629e41cd34df190814c04e5548c -size 134144 +oid sha256:8e30082799aebc9c49ee1c80aa07ccb2b35b7177818b305fd4f5d4a0445b8ba1 +size 418304 diff --git a/src/MoonWorksDearImGuiScaffoldGame.cs b/src/MoonWorksDearImGuiScaffoldGame.cs index c5948bb..41a7fac 100644 --- a/src/MoonWorksDearImGuiScaffoldGame.cs +++ b/src/MoonWorksDearImGuiScaffoldGame.cs @@ -29,8 +29,9 @@ class MoonWorksDearImGuiScaffoldGame : Game public MoonWorksDearImGuiScaffoldGame( WindowCreateInfo windowCreateInfo, FrameLimiterSettings frameLimiterSettings, + Span preferredBackends, bool debugMode - ) : base(windowCreateInfo, frameLimiterSettings, 60, debugMode) + ) : base(windowCreateInfo, frameLimiterSettings, preferredBackends, 60, debugMode) { TextureStorage = new TextureStorage(); ResourceUploader = new ResourceUploader(GraphicsDevice); @@ -161,7 +162,9 @@ class MoonWorksDearImGuiScaffoldGame : Game RenderCommandLists(commandBuffer, swapchainTexture, drawDataPtr, io); } - GraphicsDevice.Submit(commandBuffer); + var fence = GraphicsDevice.SubmitAndAcquireFence(commandBuffer); + GraphicsDevice.WaitForFences(fence); + GraphicsDevice.ReleaseFence(fence); } protected override void Destroy() @@ -173,8 +176,6 @@ class MoonWorksDearImGuiScaffoldGame : Game { if (drawDataPtr.TotalVtxCount == 0) { return; } - var commandBuffer = GraphicsDevice.AcquireCommandBuffer(); - if (drawDataPtr.TotalVtxCount > VertexCount) { ImGuiVertexBuffer?.Dispose(); @@ -209,13 +210,15 @@ class MoonWorksDearImGuiScaffoldGame : Game ResourceUploader.SetBufferData( ImGuiVertexBuffer, vertexOffset, - new Span((void*) cmdList.VtxBuffer.Data, cmdList.VtxBuffer.Size) + new Span((void*) cmdList.VtxBuffer.Data, cmdList.VtxBuffer.Size), + n == 0 ? WriteOptions.Cycle : WriteOptions.SafeOverwrite ); ResourceUploader.SetBufferData( ImGuiIndexBuffer, indexOffset, - new Span((void*) cmdList.IdxBuffer.Data, cmdList.IdxBuffer.Size) + new Span((void*) cmdList.IdxBuffer.Data, cmdList.IdxBuffer.Size), + n == 0 ? WriteOptions.Cycle : WriteOptions.SafeOverwrite ); vertexOffset += (uint) cmdList.VtxBuffer.Size; @@ -223,31 +226,12 @@ class MoonWorksDearImGuiScaffoldGame : Game } ResourceUploader.Upload(); - - GraphicsDevice.Submit(commandBuffer); } private void RenderCommandLists(CommandBuffer commandBuffer, Texture renderTexture, ImDrawDataPtr drawDataPtr, ImGuiIOPtr ioPtr) { - var view = Matrix4x4.CreateLookAt( - new Vector3(0, 0, 1), - Vector3.Zero, - Vector3.Up - ); - - var projection = Matrix4x4.CreateOrthographicOffCenter( - 0, - 480, - 270, - 0, - 0.01f, - 4000f - ); - - var viewProjectionMatrix = view * projection; - commandBuffer.BeginRenderPass( - new ColorAttachmentInfo(renderTexture, MoonWorks.Graphics.Color.CornflowerBlue) + new ColorAttachmentInfo(renderTexture, WriteOptions.Cycle, Color.CornflowerBlue) ); commandBuffer.BindGraphicsPipeline(ImGuiPipeline); @@ -274,9 +258,6 @@ class MoonWorksDearImGuiScaffoldGame : Game new TextureSamplerBinding(TextureStorage.GetTexture(drawCmd.TextureId), ImGuiSampler) ); - var topLeft = Vector2.Transform(new Vector2(drawCmd.ClipRect.X, drawCmd.ClipRect.Y), viewProjectionMatrix); - var bottomRight = Vector2.Transform(new Vector2(drawCmd.ClipRect.Z, drawCmd.ClipRect.W), viewProjectionMatrix); - var width = drawCmd.ClipRect.Z - (int)drawCmd.ClipRect.X; var height = drawCmd.ClipRect.W - (int)drawCmd.ClipRect.Y; @@ -295,15 +276,14 @@ class MoonWorksDearImGuiScaffoldGame : Game ); commandBuffer.DrawIndexedPrimitives( - vertexOffset, - indexOffset, + drawCmd.VtxOffset + vertexOffset, + drawCmd.IdxOffset + indexOffset, drawCmd.ElemCount / 3 ); - - indexOffset += drawCmd.ElemCount; } - vertexOffset += (uint)cmdList.VtxBuffer.Size; + vertexOffset += (uint) cmdList.VtxBuffer.Size; + indexOffset += (uint) cmdList.IdxBuffer.Size; } commandBuffer.EndRenderPass(); diff --git a/src/Program.cs b/src/Program.cs index d49cbe5..3e3ab76 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -1,4 +1,5 @@ using MoonWorks; +using MoonWorks.Graphics; namespace MoonWorksDearImGuiScaffold; @@ -31,6 +32,7 @@ class Program MoonWorksDearImGuiScaffoldGame game = new MoonWorksDearImGuiScaffoldGame( windowCreateInfo, frameLimiterSettings, + [Backend.Vulkan, Backend.D3D11], debugMode );