Permalink
Browse files

Fixed DrawUserIndexedPrimitives() to work correctly with 32bit index …

…data.
  • Loading branch information...
tomspilman committed Feb 12, 2013
1 parent 62a1522 commit 5fef26b198e7764d91af3f70b7924a49e903a6a0
Showing with 7 additions and 5 deletions.
  1. +7 −5 MonoGame.Framework/Graphics/GraphicsDevice.cs
@@ -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
{

0 comments on commit 5fef26b

Please sign in to comment.