private int GetVertexCountFromIndexBuffer( AMemory Memory, long IndexPosition, int IndexCount, int IndexSize) { int MaxIndex = -1; if (IndexSize == 2) { while (IndexCount-- > 0) { ushort Value = Memory.ReadUInt16(IndexPosition); IndexPosition += 2; if (MaxIndex < Value) { MaxIndex = Value; } } } else if (IndexSize == 1) { while (IndexCount-- > 0) { byte Value = Memory.ReadByte(IndexPosition++); if (MaxIndex < Value) { MaxIndex = Value; } } } else if (IndexSize == 4) { while (IndexCount-- > 0) { uint Value = Memory.ReadUInt32(IndexPosition); IndexPosition += 2; if (MaxIndex < Value) { MaxIndex = (int)Value; } } } else { throw new ArgumentOutOfRangeException(nameof(IndexSize)); } return(MaxIndex + 1); }