mirror of
https://github.com/maxartz15/MoonWorksDearImGuiScaffold.git
synced 2024-11-21 23:15:39 +01:00
tidying up the renderer
This commit is contained in:
parent
0cbf877de3
commit
b34d1444e7
BIN
Content/Shaders/ImGui.frag.refresh
(Stored with Git LFS)
BIN
Content/Shaders/ImGui.frag.refresh
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Shaders/ImGui.vert.refresh
(Stored with Git LFS)
BIN
Content/Shaders/ImGui.vert.refresh
(Stored with Git LFS)
Binary file not shown.
@ -1 +1 @@
|
||||
Subproject commit 178a5ea3cfa4ce4ccbcd9e0b6726a8cda791c810
|
||||
Subproject commit 9195e445b2473564563c917df611fcca4ea161d1
|
BIN
moonlibs/x64/Refresh.dll
(Stored with Git LFS)
BIN
moonlibs/x64/Refresh.dll
(Stored with Git LFS)
Binary file not shown.
@ -29,8 +29,9 @@ class MoonWorksDearImGuiScaffoldGame : Game
|
||||
public MoonWorksDearImGuiScaffoldGame(
|
||||
WindowCreateInfo windowCreateInfo,
|
||||
FrameLimiterSettings frameLimiterSettings,
|
||||
Span<Backend> 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<Position2DTextureColorVertex>((void*) cmdList.VtxBuffer.Data, cmdList.VtxBuffer.Size)
|
||||
new Span<Position2DTextureColorVertex>((void*) cmdList.VtxBuffer.Data, cmdList.VtxBuffer.Size),
|
||||
n == 0 ? WriteOptions.Cycle : WriteOptions.SafeOverwrite
|
||||
);
|
||||
|
||||
ResourceUploader.SetBufferData(
|
||||
ImGuiIndexBuffer,
|
||||
indexOffset,
|
||||
new Span<ushort>((void*) cmdList.IdxBuffer.Data, cmdList.IdxBuffer.Size)
|
||||
new Span<ushort>((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();
|
||||
|
@ -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
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user