Fix up rendering logic in sample programs.

internals
oledfish 2 years ago committed by Eric Mellino
parent 22ead07a89
commit e416f8c3ba
  1. 12
      src/ImGui.NET.SampleProgram.XNA/ImGuiRenderer.cs
  2. 5
      src/ImGui.NET.SampleProgram/ImGuiController.cs

@ -339,6 +339,11 @@ namespace ImGuiNET.SampleProgram.XNA
{
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");
@ -360,19 +365,18 @@ namespace ImGuiNET.SampleProgram.XNA
#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;
}
}

@ -520,12 +520,11 @@ namespace ImGuiNET
(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;
}
}

Loading…
Cancel
Save