Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

…data.
  • Loading branch information...
commit 5fef26b198e7764d91af3f70b7924a49e903a6a0 1 parent 62a1522
@tomspilman tomspilman authored
Showing with 7 additions and 5 deletions.
  1. +7 −5 MonoGame.Framework/Graphics/GraphicsDevice.cs
View
12 MonoGame.Framework/Graphics/GraphicsDevice.cs
@@ -2047,15 +2047,17 @@ 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;
@@ -2063,7 +2065,7 @@ private int SetUserIndexBuffer<T>(T[] indexData, int indexOffset, int indexCount
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
{
Please sign in to comment.
Something went wrong with that request. Please try again.