当前位置: 首页>>代码示例>>C#>>正文


C# IndexBuffer.GetData方法代码示例

本文整理汇总了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();
        }
开发者ID:Cardanis,项目名称:MonoGame,代码行数:14,代码来源:IndexBufferTest.cs

示例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();
        }
开发者ID:Cardanis,项目名称:MonoGame,代码行数:15,代码来源:IndexBufferTest.cs

示例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;
        }
开发者ID:yxrkt,项目名称:outbreak,代码行数:73,代码来源:InstancedIndexBuffer.cs


注:本文中的IndexBuffer.GetData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。