本文整理汇总了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);
}
示例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);
}
}
}
}
}
}
示例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);
//.........这里部分代码省略.........