当前位置: 首页>>代码示例>>C#>>正文


C# Texture.GetData方法代码示例

本文整理汇总了C#中Texture.GetData方法的典型用法代码示例。如果您正苦于以下问题:C# Texture.GetData方法的具体用法?C# Texture.GetData怎么用?C# Texture.GetData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Texture的用法示例。


在下文中一共展示了Texture.GetData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CheckTexture

        private void CheckTexture(GraphicsContext graphicsContext, Texture texture, byte[] data)
        {
            // Get back the data from the gpu
            var data2 = texture.GetData<byte>(graphicsContext.CommandList);

            // Assert that data are the same
            Assert.That(Utilities.Compare(data, data2), Is.True);

            // Sets new data on the gpu
            data[0] = 1;
            data[31] = 255;
            texture.SetData(graphicsContext.CommandList, data);

            // Get back the data from the gpu
            data2 = texture.GetData<byte>(graphicsContext.CommandList);

            // Assert that data are the same
            Assert.That(Utilities.Compare(data, data2), Is.True);
        }
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:19,代码来源:TestTexture.cs

示例2: CheckDebugTextureData

        private void CheckDebugTextureData(GraphicsContext graphicsContext, Texture debugTexture, int width, int height, int mipmaps, int arraySize,
            PixelFormat format, TextureFlags flags, GraphicsResourceUsage usage, Func<int, int, int, int, int, byte> dataComputer)
        {
            var pixelSize = format.SizeInBytes();

            for (int arraySlice = 0; arraySlice < arraySize; arraySlice++)
            {
                for (int mipSlice = 0; mipSlice < mipmaps; mipSlice++)
                {
                    var w = width >> mipSlice;
                    var h = height >> mipSlice;

                    var readData = debugTexture.GetData<byte>(graphicsContext.CommandList, arraySlice, mipSlice);

                    for (int r = 0; r < h; r++)
                    {
                        for (int c = 0; c < w; c++)
                        {
                            for (int i = 0; i < pixelSize; i++)
                            {
                                var value = readData[(r * w + c) * pixelSize + i];
                                var expectedValue = dataComputer(c, r, mipSlice, arraySlice, i);

                                if (!expectedValue.Equals(value))
                                    Assert.Fail("The texture data get at [{0}, {1}] for mipmap level '{2}' and slice '{3}' with flags '{4}', usage '{5}' and format '{6}' is not valid. " +
                                                "Expected '{7}' but was '{8}' at index '{9}'",
                                                c, r, mipSlice, arraySlice, flags, usage, format, expectedValue, value, i);
                            }
                        }
                    }
                }
            }
        }
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:33,代码来源:TestTexture.cs

示例3: UpdateNinePatchData

        /// <summary>
        /// Updates the strechable rectangles and inner texture.
        /// </summary>
        /// <param name="textureId">The nine patch texture id</param>
        /// <param name="sourceTexture">The source texture.</param>
        /// <param name="sourceRectangle">The source rectangle.</param>
        private void UpdateNinePatchData(string textureId, Texture sourceTexture, Rectangle sourceRectangle)
        {
            NinePatchTextureInfo textureInfo;

            if (innerTextureInfoCache.TryGetValue(textureId, out textureInfo))
            {
                this.ninePatchTexture = textureInfo;
            }
            else
            {
                var stretchableRectangle = RectangleF.Empty;
                var stretchableRectangleCoords = RectangleF.Empty;

                var innerTexture = new Texture2D()
                {
                    Width = sourceRectangle.Width - 2,
                    Height = sourceRectangle.Height - 2,
                    Format = PixelFormat.R8G8B8A8,
                    Levels = 1,
                    Data = new byte[1][][]
                };

                var textureData = sourceTexture.GetData();

                // Horizontal stretchable area search
                int index = 0;
                bool startFound = false;
                var rectangleOffset = (sourceTexture.Width * sourceRectangle.Y) + sourceRectangle.X;
                for (; index < sourceRectangle.Width; index++)
                {
                    var pixelColor = textureData[rectangleOffset + index];

                    if (startFound ^ (pixelColor == Color.Black))
                    {
                        if (!startFound)
                        {
                            stretchableRectangle.X = index - 1;
                            stretchableRectangleCoords.X = stretchableRectangle.X / innerTexture.Width;
                            startFound = true;
                        }
                        else
                        {
                            stretchableRectangle.Width = index - stretchableRectangle.X - 1;
                            stretchableRectangleCoords.Width = stretchableRectangle.Width / innerTexture.Width;
                            break;
                        }
                    }
                }

                // Vertical stretchable area search
                index = 0;
                startFound = false;
                for (; index < sourceRectangle.Height; index++)
                {
                    var pixelColor = textureData[rectangleOffset + (index * sourceTexture.Width)];

                    if (startFound ^ (pixelColor == Color.Black))
                    {
                        if (!startFound)
                        {
                            stretchableRectangle.Y = index - 1;
                            stretchableRectangleCoords.Y = stretchableRectangle.Y / innerTexture.Height;
                            startFound = true;
                        }
                        else
                        {
                            stretchableRectangle.Height = index - stretchableRectangle.Y - 1;
                            stretchableRectangleCoords.Height = stretchableRectangle.Height / innerTexture.Height;

                            break;
                        }
                    }
                }

                // Fill innerTexture data
                innerTexture.Data[0] = new byte[1][];
                innerTexture.Data[0][0] = new byte[4 * innerTexture.Width * innerTexture.Height];

                int destinationIndex = 0;
                for (int i = 1; i < sourceRectangle.Height - 1; i++)
                {
                    for (int j = 1; j < sourceRectangle.Width - 1; j++)
                    {
                        var pixelColor = textureData[rectangleOffset + (i * (sourceTexture.Width)) + j];

                        innerTexture.Data[0][0][destinationIndex++] = pixelColor.R;
                        innerTexture.Data[0][0][destinationIndex++] = pixelColor.G;
                        innerTexture.Data[0][0][destinationIndex++] = pixelColor.B;
                        innerTexture.Data[0][0][destinationIndex++] = pixelColor.A;
                    }
                }

                WaveServices.GraphicsDevice.Textures.UploadTexture(innerTexture);

//.........这里部分代码省略.........
开发者ID:WaveEngine,项目名称:Samples,代码行数:101,代码来源:NinePatchBase.cs


注:本文中的Texture.GetData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。