Skip to content

Commit e416f8c

Browse files
oledfishmellinoe
authored andcommitted
Fix up rendering logic in sample programs.
1 parent 22ead07 commit e416f8c

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

src/ImGui.NET.SampleProgram.XNA/ImGuiRenderer.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,11 @@ private unsafe void RenderCommandLists(ImDrawDataPtr drawData)
339339
{
340340
ImDrawCmdPtr drawCmd = cmdList.CmdBuffer[cmdi];
341341

342+
if (drawCmd.ElemCount == 0)
343+
{
344+
continue;
345+
}
346+
342347
if (!_loadedTextures.ContainsKey(drawCmd.TextureId))
343348
{
344349
throw new InvalidOperationException($"Could not find a texture with id '{drawCmd.TextureId}', please check your bindings");
@@ -360,19 +365,18 @@ private unsafe void RenderCommandLists(ImDrawDataPtr drawData)
360365
#pragma warning disable CS0618 // // FNA does not expose an alternative method.
361366
_graphicsDevice.DrawIndexedPrimitives(
362367
primitiveType: PrimitiveType.TriangleList,
363-
baseVertex: vtxOffset,
368+
baseVertex: (int)drawCmd.VtxOffset + vtxOffset,
364369
minVertexIndex: 0,
365370
numVertices: cmdList.VtxBuffer.Size,
366-
startIndex: idxOffset,
371+
startIndex: (int)drawCmd.IdxOffset + idxOffset,
367372
primitiveCount: (int)drawCmd.ElemCount / 3
368373
);
369374
#pragma warning restore CS0618
370375
}
371-
372-
idxOffset += (int)drawCmd.ElemCount;
373376
}
374377

375378
vtxOffset += cmdList.VtxBuffer.Size;
379+
idxOffset += cmdList.IdxBuffer.Size;
376380
}
377381
}
378382

src/ImGui.NET.SampleProgram/ImGuiController.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,12 +520,11 @@ private void RenderImDrawData(ImDrawDataPtr draw_data, GraphicsDevice gd, Comman
520520
(uint)(pcmd.ClipRect.Z - pcmd.ClipRect.X),
521521
(uint)(pcmd.ClipRect.W - pcmd.ClipRect.Y));
522522

523-
cl.DrawIndexed(pcmd.ElemCount, 1, (uint)idx_offset, vtx_offset, 0);
523+
cl.DrawIndexed(pcmd.ElemCount, 1, pcmd.IdxOffset + (uint)idx_offset, (int)pcmd.VtxOffset + vtx_offset, 0);
524524
}
525-
526-
idx_offset += (int)pcmd.ElemCount;
527525
}
528526
vtx_offset += cmd_list.VtxBuffer.Size;
527+
idx_offset += cmd_list.IdxBuffer.Size;
529528
}
530529
}
531530

0 commit comments

Comments
 (0)