Skip to content

Commit

Permalink
Fixed DrawUserIndexedPrimitives() to work correctly with 32bit index …
Browse files Browse the repository at this point in the history
…data.
  • Loading branch information
tomspilman committed Feb 12, 2013
1 parent 62a1522 commit 5fef26b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions MonoGame.Framework/Graphics/GraphicsDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2047,23 +2047,25 @@ private int SetUserIndexBuffer<T>(T[] indexData, int indexOffset, int indexCount
{
DynamicIndexBuffer buffer;

var indexSize = typeof(T) == typeof(short) ? IndexElementSize.SixteenBits : IndexElementSize.ThirtyTwoBits;
var indexType = typeof(T);
var indexSize = Marshal.SizeOf(indexType);
var indexElementSize = indexSize == 2 ? IndexElementSize.SixteenBits : IndexElementSize.ThirtyTwoBits;

if (!_userIndexBuffers.TryGetValue(indexSize, out buffer) || buffer.IndexCount < indexCount)
if (!_userIndexBuffers.TryGetValue(indexElementSize, out buffer) || buffer.IndexCount < indexCount)
{
if (buffer != null)
buffer.Dispose();

buffer = new DynamicIndexBuffer(this, indexSize, Math.Max(indexCount, 6000), BufferUsage.WriteOnly);
_userIndexBuffers[indexSize] = buffer;
buffer = new DynamicIndexBuffer(this, indexElementSize, Math.Max(indexCount, 6000), BufferUsage.WriteOnly);
_userIndexBuffers[indexElementSize] = buffer;
}

var startIndex = buffer.UserOffset;

if ((indexCount + buffer.UserOffset) < buffer.IndexCount)
{
buffer.UserOffset += indexCount;
buffer.SetData(startIndex * 2, indexData, indexOffset, indexCount, SetDataOptions.NoOverwrite);
buffer.SetData(startIndex * indexSize, indexData, indexOffset, indexCount, SetDataOptions.NoOverwrite);
}
else
{
Expand Down

0 comments on commit 5fef26b

Please sign in to comment.