Skip to content

Commit

Permalink
support ImGui 1.89.9
Browse files Browse the repository at this point in the history
  • Loading branch information
pkdawson committed Sep 19, 2023
1 parent d90f879 commit 371c348
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Dear ImGui for Godot Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
<EmbeddedResource Remove="doc\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ImGui.NET" Version="1.89.7.1" />
<PackageReference Include="ImGui.NET" Version="1.89.9.1" />
</ItemGroup>
</Project>
8 changes: 4 additions & 4 deletions addons/imgui-godot/ImGuiGodot/Internal/CanvasRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ private void RenderOne(Rid vprid, ImDrawDataPtr drawData)

// allocate our CanvasItem pool as needed
int neededNodes = 0;
for (int i = 0; i < drawData.CmdListsCount; ++i)
for (int i = 0; i < drawData.CmdLists.Size; ++i)
{
var cmdBuf = drawData.CmdListsRange[i].CmdBuffer;
var cmdBuf = drawData.CmdLists[i].CmdBuffer;
neededNodes += cmdBuf.Size;
for (int j = 0; j < cmdBuf.Size; ++j)
{
Expand Down Expand Up @@ -96,9 +96,9 @@ private void RenderOne(Rid vprid, ImDrawDataPtr drawData)
drawData.ScaleClipRects(ImGui.GetIO().DisplayFramebufferScale);
int nodeN = 0;

for (int n = 0; n < drawData.CmdListsCount; ++n)
for (int n = 0; n < drawData.CmdLists.Size; ++n)
{
ImDrawListPtr cmdList = drawData.CmdListsRange[n];
ImDrawListPtr cmdList = drawData.CmdLists[n];

int nVert = cmdList.VtxBuffer.Size;

Expand Down
3 changes: 1 addition & 2 deletions addons/imgui-godot/ImGuiGodot/Internal/Fonts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ private static unsafe void ResetStyle()
style.TabRounding = defaultStyle.TabRounding;
style.TabMinWidthForCloseButton = defaultStyle.TabMinWidthForCloseButton;
style.SeparatorTextPadding = defaultStyle.SeparatorTextPadding;
// TODO: 1.89.8
// style.DockingSeparatorSize = defaultStyle.DockingSeparatorSize;
style.DockingSeparatorSize = defaultStyle.DockingSeparatorSize;
style.DisplayWindowPadding = defaultStyle.DisplayWindowPadding;
style.DisplaySafeAreaPadding = defaultStyle.DisplaySafeAreaPadding;
style.MouseCursorScale = defaultStyle.MouseCursorScale;
Expand Down
12 changes: 6 additions & 6 deletions addons/imgui-godot/ImGuiGodot/Internal/RdRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ private void SetupBuffers(ImDrawDataPtr drawData)
byte[] idxBuf = _bufPool.Rent(idxBufSize);
int vertBufSize = drawData.TotalVtxCount * vertSize;
byte[] vertBuf = _bufPool.Rent(vertBufSize);
for (int i = 0; i < drawData.CmdListsCount; ++i)
for (int i = 0; i < drawData.CmdLists.Size; ++i)
{
ImDrawListPtr cmdList = drawData.CmdListsRange[i];
ImDrawListPtr cmdList = drawData.CmdLists[i];

int vertBytes = cmdList.VtxBuffer.Size * vertSize;
Marshal.Copy(cmdList.VtxBuffer.Data, vertBuf, globalVtxOffset, vertBytes);
Expand Down Expand Up @@ -227,9 +227,9 @@ private void SetupBuffers(ImDrawDataPtr drawData)

protected static void ReplaceTextureRids(ImDrawDataPtr drawData)
{
for (int i = 0; i < drawData.CmdListsCount; ++i)
for (int i = 0; i < drawData.CmdLists.Size; ++i)
{
ImDrawListPtr cmdList = drawData.CmdListsRange[i];
ImDrawListPtr cmdList = drawData.CmdLists[i];
for (int cmdi = 0; cmdi < cmdList.CmdBuffer.Size; ++cmdi)
{
ImDrawCmdPtr drawCmd = cmdList.CmdBuffer[cmdi];
Expand Down Expand Up @@ -326,9 +326,9 @@ protected void RenderOne(Rid fb, ImDrawDataPtr drawData)

int globalIdxOffset = 0;
int globalVtxOffset = 0;
for (int i = 0; i < drawData.CmdListsCount; ++i)
for (int i = 0; i < drawData.CmdLists.Size; ++i)
{
ImDrawListPtr cmdList = drawData.CmdListsRange[i];
ImDrawListPtr cmdList = drawData.CmdLists[i];

for (int cmdi = 0; cmdi < cmdList.CmdBuffer.Size; ++cmdi)
{
Expand Down
14 changes: 9 additions & 5 deletions addons/imgui-godot/ImGuiGodot/Internal/RdRendererThreadSafe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@ internal sealed class ClonedDrawData : IDisposable

public unsafe ClonedDrawData(ImDrawDataPtr inp)
{
// deep swap is difficult because ImGui still owns the draw lists
// TODO: revisit when Godot's threaded renderer is stable

long ddsize = Marshal.SizeOf<ImDrawData>();

// start with a shallow copy
Data = new(ImGui.MemAlloc((uint)ddsize));
Buffer.MemoryCopy(inp.NativePtr, Data.NativePtr, ddsize, ddsize);

// clone the draw data
Data.NativePtr->CmdLists = (ImDrawList**)ImGui.MemAlloc((uint)(Marshal.SizeOf<IntPtr>() * inp.CmdListsCount));
for (int i = 0; i < inp.CmdListsCount; ++i)
int numLists = inp.CmdLists.Size;
IntPtr cmdListPtrs = ImGui.MemAlloc((uint)(Marshal.SizeOf<IntPtr>() * numLists));
Data.NativePtr->CmdLists = new ImVector(numLists, numLists, cmdListPtrs);
for (int i = 0; i < inp.CmdLists.Size; ++i)
{
Data.NativePtr->CmdLists[i] = inp.CmdListsRange[i].CloneOutput().NativePtr;
Data.CmdLists[i] = (IntPtr)inp.CmdLists[i].CloneOutput().NativePtr;
}
}

Expand All @@ -35,9 +40,8 @@ public unsafe void Dispose()

for (int i = 0; i < Data.CmdListsCount; ++i)
{
Data.CmdListsRange[i].Destroy();
Data.CmdLists[i].Destroy();
}
ImGui.MemFree(Data.CmdLists);
Data.Destroy();
Data = new(null);
}
Expand Down

0 comments on commit 371c348

Please sign in to comment.