Beispiel #1
0
        public void TestMipDimensions()
        {
            // Define variables and constants
            const uint ORIGINAL_WIDTH_TX = 1 << 10;
            Texture1DArray <TexelFormat.RGBA32UInt> textureArray = TextureFactory.NewTexture1D <TexelFormat.RGBA32UInt>()
                                                                   .WithWidth(ORIGINAL_WIDTH_TX)
                                                                   .WithMipAllocation(true)
                                                                   .WithUsage(ResourceUsage.Write)
                                                                   .CreateArray(10);

            // Set up context


            // Execute
            for (int i = 0; ORIGINAL_WIDTH_TX >> i > 0; ++i)
            {
                Assert.AreEqual(ORIGINAL_WIDTH_TX >> i, textureArray.MipWidth((uint)i));
            }

#if !DEVELOPMENT && !RELEASE
            try {
                textureArray.MipWidth(10000U);
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
#endif

            // Assert outcome
            textureArray.Dispose();
        }
Beispiel #2
0
        public void TestCopyTo()
        {
            LosgapSystem.InvokeOnMaster(() => {
                // Define variables and constants
                const uint MIP0_WIDTH   = 512U;
                const uint ARRAY_LENGTH = 10U;
                Texture1DArray <TexelFormat.RGBA32UInt> srcArray = TextureFactory.NewTexture1D <TexelFormat.RGBA32UInt>()
                                                                   .WithDynamicDetail(false)
                                                                   .WithInitialData(
                    Enumerable.Repeat(
                        Enumerable.Range(0, (int)TextureUtils.GetSizeTexels(true, MIP0_WIDTH))
                        .Select(i => (uint)i)
                        .Select(i => new TexelFormat.RGBA32UInt {
                    R = i, G = i * 2, B = i * 3, A = i * 4
                }),
                        (int)ARRAY_LENGTH
                        )
                    .Flatten()
                    .ToArray()
                    )
                                                                   .WithMipAllocation(true)
                                                                   .WithMipGenerationTarget(false)
                                                                   .WithPermittedBindings(GPUBindings.ReadableShaderResource)
                                                                   .WithUsage(ResourceUsage.Immutable)
                                                                   .WithMipAllocation(true)
                                                                   .WithUsage(ResourceUsage.Write)
                                                                   .WithWidth(MIP0_WIDTH)
                                                                   .CreateArray(ARRAY_LENGTH);

                // Set up context
                Texture1DArray <TexelFormat.RGBA32UInt> dstArray = srcArray.Clone()
                                                                   .WithUsage(ResourceUsage.StagingRead)
                                                                   .WithPermittedBindings(GPUBindings.None)
                                                                   .CreateArray(srcArray.ArrayLength);

                srcArray.CopyTo(dstArray);

                var data = dstArray[4].ReadAll();

                // Execute
                for (int i = 0, curMipIndex = 0; i < data.Length; ++curMipIndex)
                {
                    for (int j = 0; j < dstArray.MipWidth((uint)curMipIndex); ++j, ++i)
                    {
                        Assert.AreEqual((uint)i, data[i].R);
                        Assert.AreEqual((uint)i * 2, data[i].G);
                        Assert.AreEqual((uint)i * 3, data[i].B);
                        Assert.AreEqual((uint)i * 4, data[i].A);
                    }
                }

                // Assert outcome
                srcArray.Dispose();
                dstArray.Dispose();
            });
        }