Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vertex/index buffer offset handling in sample programs, fix modals in XNA #294

Merged
merged 1 commit into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/ImGui.NET.SampleProgram.XNA/ImGuiRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@ private unsafe void RenderCommandLists(ImDrawDataPtr drawData)
{
ImDrawCmdPtr drawCmd = cmdList.CmdBuffer[cmdi];

if (drawCmd.ElemCount == 0)
{
continue;
}

if (!_loadedTextures.ContainsKey(drawCmd.TextureId))
{
throw new InvalidOperationException($"Could not find a texture with id '{drawCmd.TextureId}', please check your bindings");
Expand All @@ -360,19 +365,18 @@ private unsafe void RenderCommandLists(ImDrawDataPtr drawData)
#pragma warning disable CS0618 // // FNA does not expose an alternative method.
_graphicsDevice.DrawIndexedPrimitives(
primitiveType: PrimitiveType.TriangleList,
baseVertex: vtxOffset,
baseVertex: (int)drawCmd.VtxOffset + vtxOffset,
minVertexIndex: 0,
numVertices: cmdList.VtxBuffer.Size,
startIndex: idxOffset,
startIndex: (int)drawCmd.IdxOffset + idxOffset,
primitiveCount: (int)drawCmd.ElemCount / 3
);
#pragma warning restore CS0618
}

idxOffset += (int)drawCmd.ElemCount;
}

vtxOffset += cmdList.VtxBuffer.Size;
idxOffset += cmdList.IdxBuffer.Size;
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/ImGui.NET.SampleProgram/ImGuiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -520,12 +520,11 @@ private void RenderImDrawData(ImDrawDataPtr draw_data, GraphicsDevice gd, Comman
(uint)(pcmd.ClipRect.Z - pcmd.ClipRect.X),
(uint)(pcmd.ClipRect.W - pcmd.ClipRect.Y));

cl.DrawIndexed(pcmd.ElemCount, 1, (uint)idx_offset, vtx_offset, 0);
cl.DrawIndexed(pcmd.ElemCount, 1, pcmd.IdxOffset + (uint)idx_offset, (int)pcmd.VtxOffset + vtx_offset, 0);
}

idx_offset += (int)pcmd.ElemCount;
}
vtx_offset += cmd_list.VtxBuffer.Size;
idx_offset += cmd_list.IdxBuffer.Size;
}
}

Expand Down