本文整理汇总了C#中Texture.SetData方法的典型用法代码示例。如果您正苦于以下问题:C# Texture.SetData方法的具体用法?C# Texture.SetData怎么用?C# Texture.SetData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Texture
的用法示例。
在下文中一共展示了Texture.SetData方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Import
public override Asset Import(string path)
{
Texture texture = new Texture();
texture.FileName = path;
if (string.Compare(Path.GetExtension(path), ".tdx", true) == 0)
{
TDX tdx = TDX.Load(path);
texture.SetData(tdx.Name, tdx.Format.ToString(), tdx.MipMaps[0].Width, tdx.MipMaps[0].Height, tdx.MipMaps[0].Data);
texture.SupportingDocuments["Source"] = tdx;
}
else
{
texture = (Texture)(new IMGImporter()).Import(path);
}
return texture;
}
示例2: 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);
}
示例3: LoadNewHeightMap
public void LoadNewHeightMap(float[,] heightmap, float heightmapPixelPerWorldUnit, GraphicsDevice graphicsDevice)
{
this.heightmapPixelPerWorldUnit = heightmapPixelPerWorldUnit;
// remove old textures
terrainShader.Effect.Parameters["Heightmap"].SetResource<ShaderResourceViewSelector>((ShaderResourceViewSelector)null);
if (heightmapTexture != null)
heightmapTexture.Dispose();
#if CONEMAPPING_RAYMARCH
computeRelaxedConeShader.Effect.Parameters["HeightInput"].SetResource<ShaderResourceViewSelector>((ShaderResourceViewSelector)null);
computeRelaxedConeShader.Effect.Parameters["ConesOutput"].SetResource<ShaderResourceViewSelector>((ShaderResourceViewSelector)null);
computeRelaxedConeShader.Effect.Parameters["CombinedOutput"].SetResource<ShaderResourceViewSelector>((ShaderResourceViewSelector)null);
if (tempSingleChannelHeightmap != null)
tempSingleChannelHeightmap.Dispose();
if (tempSingleChannelCones != null)
tempSingleChannelCones.Dispose();
// generate jobs
conemapProcessingWorkItems.Clear();
const int TILE_SIZE = 32; // if you change this value, you also have to change " AreaPerCall in computerelaxedconemap.fx
for (int x = 0; x < heightmap.GetLength(0); x += TILE_SIZE)
{
for (int y = 0; y < heightmap.GetLength(1); y += TILE_SIZE)
conemapProcessingWorkItems.Push(new Vector2(x, y));
}
// create temp-textures
tempSingleChannelHeightmap = Texture2D.New(GraphicsDevice, heightmap.GetLength(0), heightmap.GetLength(1), 0, PixelFormat.R32.Float, TextureFlags.ShaderResource);
tempSingleChannelHeightmap.SetData<float>(heightmap.Cast<float>().ToArray());
tempSingleChannelCones = Texture2D.New(GraphicsDevice, heightmap.GetLength(0), heightmap.GetLength(1), 0, PixelFormat.R32.Float, TextureFlags.ShaderResource | TextureFlags.UnorderedAccess);
GraphicsDevice.Clear(tempSingleChannelCones, new Color4(2.0f));
// compose to heightmap texture
heightmapTexture = Texture2D.New(GraphicsDevice, heightmap.GetLength(0), heightmap.GetLength(1), 0, PixelFormat.R16G16.Float, TextureFlags.ShaderResource | TextureFlags.UnorderedAccess);
CombineTempMapsToCombined();
#else
// Create new heightmap.
heightmapTexture = RenderTarget2D.New(graphicsDevice, heightmap.GetLength(0), heightmap.GetLength(1), MipMapCount.Auto, PixelFormat.R32.Float,
TextureFlags.RenderTarget | TextureFlags.ShaderResource);
unsafe
{
fixed (float* p = heightmap)
{
heightmapTexture.SetData(new DataPointer(p, heightmap.GetLength(0) * heightmap.GetLength(1) * sizeof(float)), 0, 0);
}
}
GenerateMaxMap((RenderTarget2D)heightmapTexture, graphicsDevice);
#endif
Translation = new Vector3(-heightmapTexture.Width * 0.5f / heightmapPixelPerWorldUnit, 0, -heightmapTexture.Height * 0.5f / heightmapPixelPerWorldUnit);
// setup heightmap cbuffer
SetupTerrainConstants(graphicsDevice);
}
示例4: load
private void load(OsuConfigManager config)
{
snakingIn = config.GetBindable<bool>(OsuConfig.SnakingInSliders);
snakingOut = config.GetBindable<bool>(OsuConfig.SnakingOutSliders);
int textureWidth = (int)PathWidth * 2;
//initialise background
var upload = new TextureUpload(textureWidth * 4);
var bytes = upload.Data;
const float aa_portion = 0.02f;
const float border_portion = 0.18f;
const float gradient_portion = 1 - border_portion;
const float opacity_at_centre = 0.3f;
const float opacity_at_edge = 0.8f;
for (int i = 0; i < textureWidth; i++)
{
float progress = (float)i / (textureWidth - 1);
if (progress <= border_portion)
{
bytes[i * 4] = 255;
bytes[i * 4 + 1] = 255;
bytes[i * 4 + 2] = 255;
bytes[i * 4 + 3] = (byte)(Math.Min(progress / aa_portion, 1) * 255);
}
else
{
progress -= border_portion;
bytes[i * 4] = (byte)(slider.Colour.R * 255);
bytes[i * 4 + 1] = (byte)(slider.Colour.G * 255);
bytes[i * 4 + 2] = (byte)(slider.Colour.B * 255);
bytes[i * 4 + 3] = (byte)((opacity_at_edge - (opacity_at_edge - opacity_at_centre) * progress / gradient_portion) * (slider.Colour.A * 255));
}
}
var texture = new Texture(textureWidth, 1);
texture.SetData(upload);
path.Texture = texture;
}