ImGui.NET
ImGui.NET copied to clipboard
Expose Spans for vertex and index ranges
I was implementing imgui into Monogame with an eye on reducing the amount of unsafe
code that the library needs, and I was able to remove just about every instance of unsafe
except for copying vertices out of unmanaged memory and into managed memory.
The only place you must use unsafe is constructing a Span
unsafe
{
Span<byte> cmdListVtx = new Span<byte>(cmdList.VtxBuffer.Data.ToPointer(), cmdList.VtxBuffer.Size * ImVertexSize);
}
If the VtxBuffer.Data object were able to return a Span itself, then you could do something like:
Span<byte> cmdListVtx = cmdList.VtxBuffer.Data.ToSpan();
Span<byte> vtxDst = new Span<byte>(_VertexData, vtxOffset * ImVertexSize, cmdList.VtxBuffer.Size * ImVertexSize);
cmdListVtx.CopyTo(vtxDst);
And not need to use unsafe
when implementing an imgui renderer.
Furthermore, being able to acquire a Span from these buffer pointers would allow users to just push those spans around, potentially removing the need to copy data out of unmanaged memory entirely when submitting these to vertex buffers (although, monogame doesn't support this, so the results wouldn't be immediate).
This would help quite a bit with the ergonomics of the API and library.
Thanks!
I dont think the owner of this library really wanna do these changes himself anymore I feel, we have to kinda get used to manipulate the code ourself..