コード例 #1
0
    public unsafe void Allocate_ReadBackTexture2D_Copy_Range(Device device, int x, int y, int width, int height)
    {
        int[,] source = new int[2048, 2048];

        fixed(int *p = source)
        {
            new Random(42).NextBytes(new Span <int>(p, source.Length).AsBytes());
        }

        using ReadOnlyTexture2D <int> readOnlyTexture2D = device.Get().AllocateReadOnlyTexture2D(source);
        using ReadBackTexture2D <int> readBackTexture2D = device.Get().AllocateReadBackTexture2D <int>(2048, 2048);

        readOnlyTexture2D.CopyTo(readBackTexture2D, x, y, width, height);

        fixed(int *p = source)
        {
            for (int i = 0; i < height; i++)
            {
                Span <int> sourceRow      = new Span <int>(Unsafe.AsPointer(ref source[i + y, 0]), source.GetLength(1)).Slice(x, width);
                Span <int> destinationRow = readBackTexture2D.View.GetRowSpan(i).Slice(0, width);

                Assert.IsTrue(sourceRow.SequenceEqual(destinationRow));
            }
        }
    }
コード例 #2
0
    public unsafe void Allocate_ReadBackTexture2D_Copy_Full(Device device)
    {
        int[,] source = new int[256, 256];

        fixed(int *p = source)
        {
            new Random(42).NextBytes(new Span <int>(p, source.Length).AsBytes());
        }

        using ReadOnlyTexture2D <int> readOnlyTexture2D = device.Get().AllocateReadOnlyTexture2D(source);
        using ReadBackTexture2D <int> readBackTexture2D = device.Get().AllocateReadBackTexture2D <int>(256, 256);

        readOnlyTexture2D.CopyTo(readBackTexture2D);

        Assert.AreEqual(readBackTexture2D.Width, 256);
        Assert.AreEqual(readBackTexture2D.Height, 256);

        fixed(int *p = source)
        {
            for (int i = 0; i < readBackTexture2D.Height; i++)
            {
                Assert.IsTrue(readBackTexture2D.View.GetRowSpan(i).SequenceEqual(new Span <int>(Unsafe.AsPointer(ref source[i, 0]), source.GetLength(1))));
            }
        }
    }
コード例 #3
0
        public void Allocate_ReadBackTexture2D_Copy_Range(Device device, int x, int y, int width, int height)
        {
            int[,] source = new int[2048, 2048];

            for (int i = 0; i < 2048; i++)
            {
                new Random(42).NextBytes(source.GetRowSpan(i).AsBytes());
            }

            using ReadOnlyTexture2D <int> readOnlyTexture2D = device.Get().AllocateReadOnlyTexture2D(source);
            using ReadBackTexture2D <int> readBackTexture2D = device.Get().AllocateReadBackTexture2D <int>(2048, 2048);

            readOnlyTexture2D.CopyTo(readBackTexture2D, x, y, width, height);

            for (int i = 0; i < height; i++)
            {
                Span <int> sourceRow      = source.GetRowSpan(i + y).Slice(x, width);
                Span <int> destinationRow = readBackTexture2D.View.GetRowSpan(i).Slice(0, width);

                Assert.IsTrue(sourceRow.SequenceEqual(destinationRow));
            }
        }
コード例 #4
0
        public void Allocate_ReadBackTexture2D_Copy_Full(Device device)
        {
            int[,] source = new int[256, 256];

            for (int i = 0; i < 256; i++)
            {
                new Random(42).NextBytes(source.GetRowSpan(i).AsBytes());
            }

            using ReadOnlyTexture2D <int> readOnlyTexture2D = device.Get().AllocateReadOnlyTexture2D(source);
            using ReadBackTexture2D <int> readBackTexture2D = device.Get().AllocateReadBackTexture2D <int>(256, 256);

            readOnlyTexture2D.CopyTo(readBackTexture2D);

            Assert.AreEqual(readBackTexture2D.Width, 256);
            Assert.AreEqual(readBackTexture2D.Height, 256);

            for (int i = 0; i < readBackTexture2D.Height; i++)
            {
                Assert.IsTrue(readBackTexture2D.View.GetRowSpan(i).SequenceEqual(source.GetRowSpan(i)));
            }
        }