mirror of
https://github.com/maxartz15/MoonWorksDearImGuiScaffold.git
synced 2024-11-22 15:35:36 +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(
|
public MoonWorksDearImGuiScaffoldGame(
|
||||||
WindowCreateInfo windowCreateInfo,
|
WindowCreateInfo windowCreateInfo,
|
||||||
FrameLimiterSettings frameLimiterSettings,
|
FrameLimiterSettings frameLimiterSettings,
|
||||||
|
Span<Backend> preferredBackends,
|
||||||
bool debugMode
|
bool debugMode
|
||||||
) : base(windowCreateInfo, frameLimiterSettings, 60, debugMode)
|
) : base(windowCreateInfo, frameLimiterSettings, preferredBackends, 60, debugMode)
|
||||||
{
|
{
|
||||||
TextureStorage = new TextureStorage();
|
TextureStorage = new TextureStorage();
|
||||||
ResourceUploader = new ResourceUploader(GraphicsDevice);
|
ResourceUploader = new ResourceUploader(GraphicsDevice);
|
||||||
@ -161,7 +162,9 @@ class MoonWorksDearImGuiScaffoldGame : Game
|
|||||||
RenderCommandLists(commandBuffer, swapchainTexture, drawDataPtr, io);
|
RenderCommandLists(commandBuffer, swapchainTexture, drawDataPtr, io);
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicsDevice.Submit(commandBuffer);
|
var fence = GraphicsDevice.SubmitAndAcquireFence(commandBuffer);
|
||||||
|
GraphicsDevice.WaitForFences(fence);
|
||||||
|
GraphicsDevice.ReleaseFence(fence);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Destroy()
|
protected override void Destroy()
|
||||||
@ -173,8 +176,6 @@ class MoonWorksDearImGuiScaffoldGame : Game
|
|||||||
{
|
{
|
||||||
if (drawDataPtr.TotalVtxCount == 0) { return; }
|
if (drawDataPtr.TotalVtxCount == 0) { return; }
|
||||||
|
|
||||||
var commandBuffer = GraphicsDevice.AcquireCommandBuffer();
|
|
||||||
|
|
||||||
if (drawDataPtr.TotalVtxCount > VertexCount)
|
if (drawDataPtr.TotalVtxCount > VertexCount)
|
||||||
{
|
{
|
||||||
ImGuiVertexBuffer?.Dispose();
|
ImGuiVertexBuffer?.Dispose();
|
||||||
@ -209,13 +210,15 @@ class MoonWorksDearImGuiScaffoldGame : Game
|
|||||||
ResourceUploader.SetBufferData(
|
ResourceUploader.SetBufferData(
|
||||||
ImGuiVertexBuffer,
|
ImGuiVertexBuffer,
|
||||||
vertexOffset,
|
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(
|
ResourceUploader.SetBufferData(
|
||||||
ImGuiIndexBuffer,
|
ImGuiIndexBuffer,
|
||||||
indexOffset,
|
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;
|
vertexOffset += (uint) cmdList.VtxBuffer.Size;
|
||||||
@ -223,31 +226,12 @@ class MoonWorksDearImGuiScaffoldGame : Game
|
|||||||
}
|
}
|
||||||
|
|
||||||
ResourceUploader.Upload();
|
ResourceUploader.Upload();
|
||||||
|
|
||||||
GraphicsDevice.Submit(commandBuffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RenderCommandLists(CommandBuffer commandBuffer, Texture renderTexture, ImDrawDataPtr drawDataPtr, ImGuiIOPtr ioPtr)
|
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(
|
commandBuffer.BeginRenderPass(
|
||||||
new ColorAttachmentInfo(renderTexture, MoonWorks.Graphics.Color.CornflowerBlue)
|
new ColorAttachmentInfo(renderTexture, WriteOptions.Cycle, Color.CornflowerBlue)
|
||||||
);
|
);
|
||||||
|
|
||||||
commandBuffer.BindGraphicsPipeline(ImGuiPipeline);
|
commandBuffer.BindGraphicsPipeline(ImGuiPipeline);
|
||||||
@ -274,9 +258,6 @@ class MoonWorksDearImGuiScaffoldGame : Game
|
|||||||
new TextureSamplerBinding(TextureStorage.GetTexture(drawCmd.TextureId), ImGuiSampler)
|
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 width = drawCmd.ClipRect.Z - (int)drawCmd.ClipRect.X;
|
||||||
var height = drawCmd.ClipRect.W - (int)drawCmd.ClipRect.Y;
|
var height = drawCmd.ClipRect.W - (int)drawCmd.ClipRect.Y;
|
||||||
|
|
||||||
@ -295,15 +276,14 @@ class MoonWorksDearImGuiScaffoldGame : Game
|
|||||||
);
|
);
|
||||||
|
|
||||||
commandBuffer.DrawIndexedPrimitives(
|
commandBuffer.DrawIndexedPrimitives(
|
||||||
vertexOffset,
|
drawCmd.VtxOffset + vertexOffset,
|
||||||
indexOffset,
|
drawCmd.IdxOffset + indexOffset,
|
||||||
drawCmd.ElemCount / 3
|
drawCmd.ElemCount / 3
|
||||||
);
|
);
|
||||||
|
|
||||||
indexOffset += drawCmd.ElemCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vertexOffset += (uint) cmdList.VtxBuffer.Size;
|
vertexOffset += (uint) cmdList.VtxBuffer.Size;
|
||||||
|
indexOffset += (uint) cmdList.IdxBuffer.Size;
|
||||||
}
|
}
|
||||||
|
|
||||||
commandBuffer.EndRenderPass();
|
commandBuffer.EndRenderPass();
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using MoonWorks;
|
using MoonWorks;
|
||||||
|
using MoonWorks.Graphics;
|
||||||
|
|
||||||
namespace MoonWorksDearImGuiScaffold;
|
namespace MoonWorksDearImGuiScaffold;
|
||||||
|
|
||||||
@ -31,6 +32,7 @@ class Program
|
|||||||
MoonWorksDearImGuiScaffoldGame game = new MoonWorksDearImGuiScaffoldGame(
|
MoonWorksDearImGuiScaffoldGame game = new MoonWorksDearImGuiScaffoldGame(
|
||||||
windowCreateInfo,
|
windowCreateInfo,
|
||||||
frameLimiterSettings,
|
frameLimiterSettings,
|
||||||
|
[Backend.Vulkan, Backend.D3D11],
|
||||||
debugMode
|
debugMode
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user