예제 #1
0
        public void SetDataStructWithElementCountAndVertexStride(bool dynamic, int elementCount, int vertexStride, bool shouldSucceed, Type expectedExceptionType)
        {
            var vertexBuffer = (dynamic)
                ? new DynamicVertexBuffer(gd, typeof(VertexPositionTexture), savedData.Length,
                                          BufferUsage.None)
                : new VertexBuffer(gd, typeof(VertexPositionTexture), savedData.Length,
                                   BufferUsage.None);

            if (!shouldSucceed)
            {
                Assert.Throws(expectedExceptionType, () => vertexBuffer.SetData(0, savedData, 0, elementCount, vertexStride));
            }
            else
            {
                vertexBuffer.SetData(0, savedData, 0, elementCount, vertexStride);

                var readData = new VertexPositionTexture[savedData.Length];
                vertexBuffer.GetData(0, readData, 0, elementCount, vertexStride);
                Assert.AreEqual(
                    savedData.Take(elementCount).ToArray(),
                    readData.Take(elementCount).ToArray());
            }

            vertexBuffer.Dispose();
        }