本文整理汇总了C#中IndexBuffer.GetData方法的典型用法代码示例。如果您正苦于以下问题:C# IndexBuffer.GetData方法的具体用法?C# IndexBuffer.GetData怎么用?C# IndexBuffer.GetData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IndexBuffer
的用法示例。
在下文中一共展示了IndexBuffer.GetData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldSetAndGetData
public void ShouldSetAndGetData()
{
Game.DrawWith += (sender, e) =>
{
var savedData = new short[] { 1, 2, 3, 4 };
var indexBuffer = new IndexBuffer(Game.GraphicsDevice, IndexElementSize.SixteenBits, savedData.Length, BufferUsage.None);
indexBuffer.SetData(savedData);
var readData = new short[4];
indexBuffer.GetData(readData, 0, 4);
Assert.AreEqual(savedData, readData);
};
Game.Run();
}
示例2: ShouldSetAndGetData_offsetInBytes
public void ShouldSetAndGetData_offsetInBytes()
{
Game.DrawWith += (sender, e) =>
{
var savedData = new short[] { 1, 2, 3, 4 };
var indexBuffer = new IndexBuffer(Game.GraphicsDevice, IndexElementSize.SixteenBits, savedData.Length, BufferUsage.None);
indexBuffer.SetData(savedData);
var readData = new short[2];
indexBuffer.GetData(sizeof(short) * 2, readData, 0, 2);
Assert.AreEqual(3, readData[0]);
Assert.AreEqual(4, readData[1]);
};
Game.Run();
}
示例3: Create
public static InstancedIndexBuffer Create( IndexBuffer orignalIndexBuffer,
int leastInstances, bool allow32bitIndex)
{
if ( orignalIndexBuffer.IndexElementSize != IndexElementSize.SixteenBits )
{
throw new ArgumentOutOfRangeException( "32-bit index buffer is not supported." );
}
GraphicsDevice gd = orignalIndexBuffer.GraphicsDevice;
int indexCount = orignalIndexBuffer.SizeInBytes / sizeof( ushort );
ushort[] originalIndices = new ushort[indexCount];
orignalIndexBuffer.GetData<ushort>( originalIndices );
int instanceCount = Math.Max( ushort.MaxValue / indexCount, leastInstances );
int newSize = instanceCount * indexCount;
InstancedIndexBuffer indexBuffer = null;
if ( newSize >= ushort.MaxValue )
{
if ( allow32bitIndex == false )
{
throw new InvalidOperationException(
"Number of indices cannot fit in a 16-bit index buffer." +
"HWInstancePart.cs, Allow32BitIndexBuffer should be true." +
"Or reduce the number of vertices in the model and pray." );
}
uint[] newIndices = new uint[newSize];
int index = 0;
for ( int i = 0; i < instanceCount; ++i )
{
uint packInstanceValue = (uint)( i * indexCount );
for ( int j = 0; j < originalIndices.Length; ++j )
newIndices[index++] = packInstanceValue + originalIndices[j];
}
indexBuffer = new InstancedIndexBuffer( gd, newSize * sizeof( uint ),
IndexElementSize.ThirtyTwoBits );
indexBuffer.SetData<uint>( newIndices );
}
else
{
// using 16-bit index buffer
ushort[] newIndices = new ushort[newSize];
int index = 0;
for ( int i = 0; i < instanceCount; ++i )
{
ushort packInstanceValue = (ushort)( i * indexCount );
for ( int j = 0; j < originalIndices.Length; ++j )
{
newIndices[index++] =
(ushort)( packInstanceValue + originalIndices[j] );
}
}
indexBuffer = new InstancedIndexBuffer( gd, newSize * sizeof( ushort ),
IndexElementSize.SixteenBits );
indexBuffer.SetData<ushort>( newIndices );
}
indexBuffer.MaxInstances = instanceCount;
return indexBuffer;
}