Exemplo n.º 1
0
        public unsafe void TestIndexAccessors()
        {
            // Define variables and constants
            const int WIDTH  = 4;
            const int HEIGHT = 8;
            const int DEPTH  = 2;

            TexelFormat.Int8[] data = new TexelFormat.Int8[WIDTH * HEIGHT * DEPTH];

            TexelArray1D <TexelFormat.Int8> array1D = new TexelArray1D <TexelFormat.Int8>(data);
            TexelArray2D <TexelFormat.Int8> array2D = new TexelArray2D <TexelFormat.Int8>(data, WIDTH);
            TexelArray3D <TexelFormat.Int8> array3D = new TexelArray3D <TexelFormat.Int8>(data, WIDTH, HEIGHT);

            // Set up context
            for (int i = 0; i < WIDTH * HEIGHT * DEPTH; ++i)
            {
                data[i].Value = (sbyte)i;
            }

            // Execute


            // Assert outcome
            Assert.AreEqual((sbyte)3, array1D[3].Value);
            Assert.AreEqual((sbyte)22, array2D[2, 5].Value);
            Assert.AreEqual((sbyte)54, array3D[2, 5, 1].Value);
        }
Exemplo n.º 2
0
        public void TestWrite()
        {
            LosgapSystem.InvokeOnMaster(() => {
                // Define variables and constants
                const uint WIDTH_TX  = 100U;
                const uint HEIGHT_TX = 100U;

                const uint WRITE_OFFSET_U = 30U;
                const uint WRITE_OFFSET_V = 30U;

                SubresourceBox writeTarget = new SubresourceBox(
                    WRITE_OFFSET_U, WIDTH_TX,
                    WRITE_OFFSET_V, HEIGHT_TX
                    );

                Texture2D <TexelFormat.RGBA8Int> srcTex = TextureFactory.NewTexture2D <TexelFormat.RGBA8Int>()
                                                          .WithUsage(ResourceUsage.Write)
                                                          .WithMultisampling(true)
                                                          .WithWidth(WIDTH_TX)
                                                          .WithHeight(HEIGHT_TX);

                // Set up context


                // Execute
                srcTex.Write(
                    Enumerable.Range(0, (int)writeTarget.Volume)
                    .Select(i => new TexelFormat.RGBA8Int {
                    R = (sbyte)i, G = (sbyte)(i * 2), B = (sbyte)(i * 3), A = (sbyte)(i * 4)
                })
                    .ToArray(),
                    writeTarget
                    );

                Texture2D <TexelFormat.RGBA8Int> dstTex = srcTex.Clone()
                                                          .WithUsage(ResourceUsage.StagingRead)
                                                          .WithPermittedBindings(GPUBindings.None);

                srcTex.CopyTo(dstTex);

                // Assert outcome
                TexelArray2D <TexelFormat.RGBA8Int> copiedData = dstTex.Read(0U);
                for (uint v = WRITE_OFFSET_V, value = 0U; v < HEIGHT_TX; ++v)
                {
                    for (uint u = WRITE_OFFSET_U; u < WIDTH_TX; ++u, ++value)
                    {
                        Assert.AreEqual((sbyte)value, copiedData[(int)u, (int)v].R);
                        Assert.AreEqual((sbyte)(value * 2U), copiedData[(int)u, (int)v].G);
                        Assert.AreEqual((sbyte)(value * 3U), copiedData[(int)u, (int)v].B);
                        Assert.AreEqual((sbyte)(value * 4U), copiedData[(int)u, (int)v].A);
                    }
                }

                srcTex.Dispose();
                dstTex.Dispose();
            });
        }
Exemplo n.º 3
0
        public void TestCopyTo()
        {
            LosgapSystem.InvokeOnMaster(() => {
                // Define variables and constants
                const uint WIDTH_TX  = 512U;
                const uint HEIGHT_TX = 32U;

                const uint NUM_TEXELS_TO_COPY_PER_ROW = 25U;
                const uint FIRST_TEXEL_TO_COPY_IN_ROW = 25U;
                const uint NUM_ROWS_TO_COPY           = 5U;
                const uint FIRST_ROW_TO_COPY          = 1U;
                const uint SRC_MIP_INDEX      = 0U;
                const uint DST_MIP_INDEX      = 2U;
                const uint DST_WRITE_OFFSET_X = 15U;
                const uint DST_WRITE_OFFSET_Y = 2U;

                const float DATA_VALUE_START_R_ROW_ADDITION = (float)WIDTH_TX;
                const float DATA_VALUE_START_R = FIRST_TEXEL_TO_COPY_IN_ROW + DATA_VALUE_START_R_ROW_ADDITION * FIRST_ROW_TO_COPY;

                TexelFormat.RGBA32Float[] initialData = Enumerable.Range(0, (int)TextureUtils.GetSizeTexels(true, WIDTH_TX, HEIGHT_TX))
                                                        .Select(i => new TexelFormat.RGBA32Float {
                    R = (float)i, G = (float)i * 2f, B = (float)i * 4f, A = (float)i * 8f
                })
                                                        .ToArray();

                Texture2D <TexelFormat.RGBA32Float> srcTex = TextureFactory.NewTexture2D <TexelFormat.RGBA32Float>()
                                                             .WithDynamicDetail(false)
                                                             .WithMultisampling(false)
                                                             .WithInitialData(initialData)
                                                             .WithMipAllocation(true)
                                                             .WithMipGenerationTarget(false)
                                                             .WithPermittedBindings(GPUBindings.ReadableShaderResource)
                                                             .WithUsage(ResourceUsage.Immutable)
                                                             .WithWidth(WIDTH_TX)
                                                             .WithHeight(HEIGHT_TX);

                // Set up context

                // Execute
                Texture2D <TexelFormat.RGBA32Float> dstTex = srcTex.Clone()
                                                             .WithUsage(ResourceUsage.StagingRead)
                                                             .WithPermittedBindings(GPUBindings.None);
                SubresourceBox targetBox = new SubresourceBox(
                    FIRST_TEXEL_TO_COPY_IN_ROW, FIRST_TEXEL_TO_COPY_IN_ROW + NUM_TEXELS_TO_COPY_PER_ROW,
                    FIRST_ROW_TO_COPY, FIRST_ROW_TO_COPY + NUM_ROWS_TO_COPY
                    );
                srcTex.CopyTo(
                    dstTex,
                    targetBox,
                    SRC_MIP_INDEX,
                    DST_MIP_INDEX,
                    DST_WRITE_OFFSET_X,
                    DST_WRITE_OFFSET_Y
                    );

                // Assert outcome
                TexelArray2D <TexelFormat.RGBA32Float> copiedData = dstTex.Read(DST_MIP_INDEX);
                for (int v = 0; v < NUM_ROWS_TO_COPY; ++v)
                {
                    for (int u = 0; u < NUM_TEXELS_TO_COPY_PER_ROW; ++u)
                    {
                        var thisTexel = copiedData[u + (int)DST_WRITE_OFFSET_X, v + (int)DST_WRITE_OFFSET_Y];
                        Assert.AreEqual((float)(DATA_VALUE_START_R + DATA_VALUE_START_R_ROW_ADDITION * v + u), thisTexel.R);
                        Assert.AreEqual((float)(DATA_VALUE_START_R + DATA_VALUE_START_R_ROW_ADDITION * v + u) * 2f, thisTexel.G);
                        Assert.AreEqual((float)(DATA_VALUE_START_R + DATA_VALUE_START_R_ROW_ADDITION * v + u) * 4f, thisTexel.B);
                        Assert.AreEqual((float)(DATA_VALUE_START_R + DATA_VALUE_START_R_ROW_ADDITION * v + u) * 8f, thisTexel.A);
                    }
                }

                srcTex.Dispose();
                dstTex.Dispose();
            });
        }
Exemplo n.º 4
0
 /// <summary>
 /// Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 /// <returns>
 /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
 /// </returns>
 /// <param name="other">An object to compare with this object.</param>
 public bool Equals(TexelArray2D <TTexel> other)
 {
     return(Equals(Data, other.Data) && Width == other.Width && Height == other.Height);
 }
Exemplo n.º 5
0
        public void TestCreationWithInitialData()
        {
            // Define variables and constants
            const uint TEXTURE_WIDTH  = 1 << 6;
            const uint TEXTURE_HEIGHT = 1 << 4;
            Texture2DBuilder <TexelFormat.RGBA8UInt> texBuilder = TextureFactory.NewTexture2D <TexelFormat.RGBA8UInt>()
                                                                  .WithUsage(ResourceUsage.StagingRead)
                                                                  .WithPermittedBindings(GPUBindings.None)
                                                                  .WithWidth(TEXTURE_WIDTH)
                                                                  .WithHeight(TEXTURE_HEIGHT);

            TexelFormat.RGBA8UInt[]           initialDataA = new TexelFormat.RGBA8UInt[TEXTURE_WIDTH * TEXTURE_HEIGHT];
            TexelFormat.RGBA8UInt[]           initialDataB = new TexelFormat.RGBA8UInt[TextureUtils.GetSizeTexels(true, TEXTURE_WIDTH, TEXTURE_HEIGHT)];
            Texture2D <TexelFormat.RGBA8UInt> testTextureA, testTextureB;

            TexelArray2D <TexelFormat.RGBA8UInt> texAData;

            TexelArray2D <TexelFormat.RGBA8UInt>[] texBData = new TexelArray2D <TexelFormat.RGBA8UInt> [TextureUtils.GetNumMips(TEXTURE_WIDTH, TEXTURE_HEIGHT)];

            // Set up context
            for (uint i = 0; i < initialDataA.Length; ++i)
            {
                initialDataA[i].R = (byte)i;
                initialDataA[i].G = (byte)(i * 2);
                initialDataA[i].B = (byte)(i * 3);
                initialDataA[i].A = (byte)(i * 4);
            }
            testTextureA = texBuilder.WithInitialData(initialDataA).Create();

            uint mipWidth   = TEXTURE_WIDTH;
            uint mipHeight  = TEXTURE_HEIGHT;
            uint texelIndex = 0U;

            while (mipWidth > 1U || mipHeight > 1U)
            {
                for (uint v = 0; v < mipHeight; ++v)
                {
                    for (uint u = 0; u < mipWidth; ++u, ++texelIndex)
                    {
                        initialDataB[texelIndex].R = (byte)(u + mipWidth + v + mipHeight);
                        initialDataB[texelIndex].G = (byte)(u + mipWidth + v + mipHeight * 2);
                        initialDataB[texelIndex].B = (byte)(u + mipWidth + v + mipHeight * 3);
                        initialDataB[texelIndex].A = (byte)(u + mipWidth + v + mipHeight * 4);
                    }
                }
                mipWidth  = Math.Max(1U, mipWidth >> 1);
                mipHeight = Math.Max(1U, mipHeight >> 1);
            }
            initialDataB[initialDataB.Length - 1] = new TexelFormat.RGBA8UInt {
                R = 2, G = 3, B = 4, A = 5
            };
            testTextureB = texBuilder.WithMipAllocation(true).WithInitialData(initialDataB).Create();

            // Execute
            texAData = testTextureA.Read(0U);
            for (uint i = 0; i < texBData.Length; ++i)
            {
                texBData[i] = testTextureB.Read(i);
            }

            // Assert outcome
            for (uint i = 0; i < texAData.Width; ++i)
            {
                Assert.AreEqual((byte)i, initialDataA[i].R);
                Assert.AreEqual((byte)(i * 2), initialDataA[i].G);
                Assert.AreEqual((byte)(i * 3), initialDataA[i].B);
                Assert.AreEqual((byte)(i * 4), initialDataA[i].A);
            }

            for (uint mipIndex = 0U; mipIndex < testTextureB.NumMips; ++mipIndex)
            {
                for (uint v = 0; v < testTextureB.MipHeight(mipIndex); ++v)
                {
                    for (uint u = 0; u < testTextureB.MipWidth(mipIndex); ++u)
                    {
                        Assert.AreEqual((byte)(u + testTextureB.MipWidth(mipIndex) + v + testTextureB.MipHeight(mipIndex)), texBData[mipIndex][u, v].R);
                        Assert.AreEqual((byte)(u + testTextureB.MipWidth(mipIndex) + v + testTextureB.MipHeight(mipIndex) * 2), texBData[mipIndex][u, v].G);
                        Assert.AreEqual((byte)(u + testTextureB.MipWidth(mipIndex) + v + testTextureB.MipHeight(mipIndex) * 3), texBData[mipIndex][u, v].B);
                        Assert.AreEqual((byte)(u + testTextureB.MipWidth(mipIndex) + v + testTextureB.MipHeight(mipIndex) * 4), texBData[mipIndex][u, v].A);
                    }
                }
            }

            testTextureA.Dispose();
            testTextureB.Dispose();
        }