Example #1
0
        public void TestReadWrite()
        {
            // Define variables and constants
            const uint WIDTH_TX               = 512U;
            const uint HEIGHT_TX              = 512U;
            const uint TARGET_MIP_INDEX       = 2U;
            const uint DATA_WRITE_OFFSET_U    = 10U;
            const uint DATA_WRITE_OFFSET_V    = 10U;
            const uint DATA_WRITE_SQUARE_SIZE = 80U;

            Texture2D <TexelFormat.RGBA32UInt> srcTex = TextureFactory.NewTexture2D <TexelFormat.RGBA32UInt>()
                                                        .WithInitialData(
                Enumerable.Range(0, (int)TextureUtils.GetSizeTexels(true, WIDTH_TX, HEIGHT_TX))
                .Select(i => (uint)i)
                .Select(i => new TexelFormat.RGBA32UInt {
                R = i, G = i * 2, B = i * 3, A = i * 4
            })
                .ToArray()
                )
                                                        .WithMipAllocation(true)
                                                        .WithPermittedBindings(GPUBindings.None)
                                                        .WithUsage(ResourceUsage.StagingReadWrite)
                                                        .WithWidth(WIDTH_TX)
                                                        .WithHeight(HEIGHT_TX);

            srcTex.ReadWrite(data => {
                for (uint u = DATA_WRITE_OFFSET_U; u < DATA_WRITE_OFFSET_U + DATA_WRITE_SQUARE_SIZE; ++u)
                {
                    for (uint v = DATA_WRITE_OFFSET_V; v < DATA_WRITE_OFFSET_V + DATA_WRITE_SQUARE_SIZE; ++v)
                    {
                        data[(int)u, (int)v] = new TexelFormat.RGBA32UInt {
                            R = u, G = v, B = u + v, A = u - v
                        };
                    }
                }
            },
                             TARGET_MIP_INDEX);

            var readData = srcTex.Read(TARGET_MIP_INDEX);

            for (uint u = DATA_WRITE_OFFSET_U; u < DATA_WRITE_OFFSET_U + DATA_WRITE_SQUARE_SIZE; ++u)
            {
                for (uint v = DATA_WRITE_OFFSET_V; v < DATA_WRITE_OFFSET_V + DATA_WRITE_SQUARE_SIZE; ++v)
                {
                    Assert.AreEqual(u, readData[(int)u, (int)v].R);
                    Assert.AreEqual(v, readData[(int)u, (int)v].G);
                    Assert.AreEqual(u + v, readData[(int)u, (int)v].B);
                    Assert.AreEqual(u - v, readData[(int)u, (int)v].A);
                }
            }

            srcTex.Dispose();
        }
Example #2
0
        public void TestReadWrite()
        {
            // Define variables and constants
            const uint WIDTH_TX          = 512U;
            const uint TARGET_MIP_INDEX  = 4U;
            const uint DATA_WRITE_OFFSET = 10U;
            const uint DATA_WRITE_COUNT  = 10U;

            Texture1D <TexelFormat.RGBA32UInt> srcTex = TextureFactory.NewTexture1D <TexelFormat.RGBA32UInt>()
                                                        .WithInitialData(
                Enumerable.Range(0, (int)TextureUtils.GetSizeTexels(true, WIDTH_TX))
                .Select(i => (uint)i)
                .Select(i => new TexelFormat.RGBA32UInt {
                R = i, G = i * 2, B = i * 3, A = i * 4
            })
                .ToArray()
                )
                                                        .WithMipAllocation(true)
                                                        .WithPermittedBindings(GPUBindings.None)
                                                        .WithUsage(ResourceUsage.StagingReadWrite)
                                                        .WithWidth(WIDTH_TX);

            srcTex.ReadWrite(data => {
                for (uint i = DATA_WRITE_OFFSET; i < DATA_WRITE_OFFSET + DATA_WRITE_COUNT; ++i)
                {
                    data[(int)i] = new TexelFormat.RGBA32UInt {
                        R = i, G = i * 3, B = i * 6, A = i * 9
                    };
                }
            },
                             TARGET_MIP_INDEX);

            var readData = srcTex.Read(TARGET_MIP_INDEX);

            for (uint i = DATA_WRITE_OFFSET; i < DATA_WRITE_OFFSET + DATA_WRITE_COUNT; ++i)
            {
                Assert.AreEqual(i, readData[(int)i].R);
                Assert.AreEqual(i * 3, readData[(int)i].G);
                Assert.AreEqual(i * 6, readData[(int)i].B);
                Assert.AreEqual(i * 9, readData[(int)i].A);
            }

            srcTex.Dispose();
        }