Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixed DrawUserIndexedPrimitives With 32bit Index Buffer #1354

Merged
merged 1 commit into from

2 participants

@tomspilman
Owner

This fixes #1039 by making DrawUserIndexedPrimitives() properly work with 32bit index data.

Tested on Windows DX. Has no affect on any other platform.

@dellis1972
Owner

merging

@dellis1972 dellis1972 merged commit 48759f7 into mono:develop3d
@tomspilman tomspilman deleted the SickheadGames:UserIB branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
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
{
Something went wrong with that request. Please try again.