本文整理汇总了C#中Texture.LockRectangle方法的典型用法代码示例。如果您正苦于以下问题:C# Texture.LockRectangle方法的具体用法?C# Texture.LockRectangle怎么用?C# Texture.LockRectangle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Texture
的用法示例。
在下文中一共展示了Texture.LockRectangle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitEmptyTextures
private void InitEmptyTextures()
{
if (emptyLightMap != null && emptyTexture != null)
return;
//algunos mesh no tienen textura o lightmap. Por compatibilidad con el exporter es conveniente que todas tengan Una textura
//para eso creo una textura vacia de 1x1 negro como textura y una de 1x1 blanco para lightmap.
var texture = new Texture(GuiController.Instance.D3dDevice, 1, 1, 1, Usage.None, Format.A8R8G8B8, Pool.Managed);
GraphicsStream graphicsStream = texture.LockRectangle(0, LockFlags.None);
uint color = 0x00000000;
graphicsStream.Write(color);
texture.UnlockRectangle(0);
TextureLoader.Save("emptyTexture.jpg", ImageFileFormat.Jpg, texture);
emptyTexture = new TgcTexture("emptyTexture.jpg","emptyTexture.jpg", texture, false);
texture = new Texture(GuiController.Instance.D3dDevice, 1, 1, 1, Usage.None, Format.A8R8G8B8, Pool.Managed);
graphicsStream = texture.LockRectangle(0, LockFlags.None);
color = 0x00000000;
graphicsStream.Write(color);
texture.UnlockRectangle(0);
TextureLoader.Save("emptyLightMap.jpg", ImageFileFormat.Jpg, texture);
emptyLightMap = new TgcTexture("emptyLightMap.jpg", "emptyLightMap.jpg", texture, false);
}
示例2: CreateTexture
// Create a systemmem texture, fill with the given color and copy it to a more hardware-friendly memory pool
public static Texture CreateTexture(int w, int h, Format format, Color4 color)
{
Texture texture = new Texture(Renderer.Instance.device, w, h, 1, Usage.None, format, Pool.SystemMemory);
DataRectangle drect = texture.LockRectangle(0, LockFlags.None);
DataStream ds = drect.Data;
// pixelsize in bytes
int fieldsize = 8;
switch (format)
{
case Format.A8R8G8B8:
fieldsize = 4;
break;
case Format.A16B16G16R16F:
fieldsize = 8;
break;
}
// Fill texture with color
for (int j = 0; j < (w * h); j++)
{
int x = ((j) % (w));
int y = ((j) / (w));
ds.Seek((long)(y * fieldsize) + (long)(x * fieldsize), System.IO.SeekOrigin.Begin);
switch (format)
{
case Format.A8R8G8B8:
ds.Write<int>(color.ToArgb());
break;
case Format.A16B16G16R16F:
Half[] half = Half.ConvertToHalf(new float[] { color.Red, color.Green, color.Blue, color.Alpha });
ds.Write<Half4>(new Half4(half[0], half[1], half[2], half[3]));
break;
}
}
texture.UnlockRectangle(0);
Texture realtexture = new Texture(Renderer.Instance.device, w, h, 1, Usage.None, format, Pool.Default);
Renderer.Instance.device.UpdateTexture(texture, realtexture);
texture.Dispose();
return realtexture;
}
示例3: AnalogCamera
public AnalogCamera(DsDevice device, Device d3dDevice)
{
this.d3dDevice = d3dDevice;
texture = new Texture(d3dDevice, 720, 576, 1, Usage.Dynamic, Format.A8R8G8B8, Pool.Default);
var desc = texture.GetLevelDescription(0);
DataRectangle dr = texture.LockRectangle(0, LockFlags.Discard);
int rowPitch = dr.Pitch;
texture.UnlockRectangle(0);
try
{
BuildGraph(device);
}
catch
{
Dispose();
throw;
}
}
示例4: NewTextureFromBitmap
Texture NewTextureFromBitmap( Device device, Bitmap bitmap )
{
int w = bitmap.Width;
int h = bitmap.Height;
var t = new Texture( device, w, h, 1, Usage.None, Format.A8R8G8B8, Pool.Managed );
var dest = t.LockRectangle(0,LockFlags.None);
var src = bitmap.LockBits( new Rectangle(0,0,w,h), ImageLockMode.ReadOnly,PixelFormat.Format32bppPArgb );
try {
for ( int y=0 ; y<h ; ++y ) {
dest.Data.Seek( y * dest.Pitch, SeekOrigin.Begin );
dest.Data.WriteRange( new IntPtr( src.Scan0.ToInt64() + src.Stride*y ), 4*w );
}
} finally {
bitmap.UnlockBits(src);
t.UnlockRectangle(0);
}
return t;
}
示例5: WriteToR32F
public Texture WriteToR32F(Rectangle area, int numLevels, Usage usage, Pool pool)
{
// create texture
Texture tex = new Texture(device, area.Width, area.Height, numLevels, usage, Format.R32F, pool);
// fill with data
//TextureLoader.FillTexture(tex, new Fill2DTextureCallback(FillR32FTexture));
if (areaData == null || areaData.Length != area.Width * area.Height)
areaData = new double[area.Width * area.Height];
dataSource.Sample(area.Location, area.Size, ref areaData);
GraphicsStream gs = tex.LockRectangle(0, LockFlags.None);
for (int i = 0; i < areaData.Length; i++)
{
gs.Write((float)areaData[i]);
}
tex.UnlockRectangle(0);
return tex;
}
示例6: WebCamera
public WebCamera(DsDevice device, Device d3dDevice)
{
//bitmapWindow = new Test();
//bitmapWindow.Show();
this.d3dDevice = d3dDevice;
texture = new Texture(d3dDevice, 1280, 720, 1, Usage.Dynamic, Format.A8R8G8B8, Pool.Default);
//texture = Texture.FromFile(d3dDevice, ".\\Images\\checkerboard.jpg", D3DX.DefaultNonPowerOf2, D3DX.DefaultNonPowerOf2, 1, Usage.Dynamic, Format.A8R8G8B8, Pool.Default, Filter.None, Filter.None, 0);
var desc = texture.GetLevelDescription(0);
DataRectangle dr = texture.LockRectangle(0, LockFlags.Discard);
int rowPitch = dr.Pitch;
texture.UnlockRectangle(0);
try
{
BuildGraph(device);
}
catch
{
Dispose();
throw;
}
}
示例7: TextureManager
public TextureManager()
{
device = GlobalRenderSettings.Instance.Device;
defaultTexture = new Texture(device, 1, 1, 1, Usage.None, Format.X8R8G8B8, Pool.Managed);
var dataRect = defaultTexture.LockRectangle(0, LockFlags.None);
dataRect.Data.Write(defaultData, 0, 4);
enviroMap = new CubeTexture(device, 256, 1, Usage.None, Format.X8R8G8B8, Pool.Managed);
LoadCubeMapFace(enviroMap, CubeMapFace.NegativeX, "ModelViewer.Resources.landscape_negative_x.png", 256, Format.X8R8G8B8);
LoadCubeMapFace(enviroMap, CubeMapFace.NegativeY, "ModelViewer.Resources.landscape_negative_y.png", 256, Format.X8R8G8B8);
LoadCubeMapFace(enviroMap, CubeMapFace.NegativeZ, "ModelViewer.Resources.landscape_negative_z.png", 256, Format.X8R8G8B8);
LoadCubeMapFace(enviroMap, CubeMapFace.PositiveX, "ModelViewer.Resources.landscape_positive_x.png", 256, Format.X8R8G8B8);
LoadCubeMapFace(enviroMap, CubeMapFace.PositiveY, "ModelViewer.Resources.landscape_positive_y.png", 256, Format.X8R8G8B8);
LoadCubeMapFace(enviroMap, CubeMapFace.PositiveZ, "ModelViewer.Resources.landscape_positive_z.png", 256, Format.X8R8G8B8);
lightDiffuseMap = new CubeTexture(device, 1, 1, Usage.None, Format.X8R8G8B8, Pool.Managed);
FillLightDiffuseMap(CubeMapFace.NegativeX, 0xFFDDDDDD);
FillLightDiffuseMap(CubeMapFace.NegativeY, 0xFFCCCCCC);
FillLightDiffuseMap(CubeMapFace.NegativeZ, 0xFFDDDDDD);
FillLightDiffuseMap(CubeMapFace.PositiveX, 0xFFDDDDDD);
FillLightDiffuseMap(CubeMapFace.PositiveY, 0xFFFFFFFF);
FillLightDiffuseMap(CubeMapFace.PositiveZ, 0xFFDDDDDD);
}
示例8: CreateTexture
public unsafe void CreateTexture(BinaryReader reader)
{
int w = Width;// + (4 - Width % 4) % 4;
int h = Height;// + (4 - Height % 4) % 4;
GraphicsStream stream = null;
Image = new Texture(DXManager.Device, w, h, 1, Usage.None, Format.A8R8G8B8, Pool.Managed);
stream = Image.LockRectangle(0, LockFlags.Discard);
Data = (byte*)stream.InternalDataPointer;
byte[] decomp = DecompressImage(reader.ReadBytes(Length));
stream.Write(decomp, 0, decomp.Length);
stream.Dispose();
Image.UnlockRectangle(0);
if (HasMask)
{
reader.ReadBytes(12);
w = Width;// + (4 - Width % 4) % 4;
h = Height;// + (4 - Height % 4) % 4;
MaskImage = new Texture(DXManager.Device, w, h, 1, Usage.None, Format.A8R8G8B8, Pool.Managed);
stream = Image.LockRectangle(0, LockFlags.Discard);
decomp = DecompressImage(reader.ReadBytes(Length));
stream.Write(decomp, 0, decomp.Length);
stream.Dispose();
MaskImage.UnlockRectangle(0);
}
DXManager.TextureList.Add(this);
TextureValid = true;
Image.Disposing += (o, e) =>
{
TextureValid = false;
Image = null;
MaskImage = null;
Data = null;
DXManager.TextureList.Remove(this);
};
CleanTime = CMain.Time + Settings.CleanDelay;
}
示例9: CreateLights
//FAR - createlights
private static unsafe void CreateLights()
{
for (int i = Lights.Count - 1; i >= 0; i--)
Lights[i].Dispose();
Lights.Clear();
for (int i = 1; i < LightSizes.Length; i++)
{
// int width = 125 + (57 *i);
//int height = 110 + (57 * i);
int width = LightSizes[i].X;
int height = LightSizes[i].Y;
Texture light = new Texture(Device, width, height, 1, Usage.None, Format.A8R8G8B8, Pool.Managed);
using (GraphicsStream stream = light.LockRectangle(0, LockFlags.Discard))
using (Bitmap image = new Bitmap(width, height, width*4, PixelFormat.Format32bppArgb, (IntPtr) stream.InternalDataPointer))
{
using (Graphics graphics = Graphics.FromImage(image))
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddEllipse(new Rectangle(0, 0, width, height));
using (PathGradientBrush brush = new PathGradientBrush(path))
{
graphics.Clear(Color.FromArgb(0, 0, 0, 0));
brush.SurroundColors = new[] {Color.FromArgb(0, 255, 255, 255)};
brush.CenterColor = Color.FromArgb(255, 255, 255, 255);
graphics.FillPath(brush, path);
graphics.Save();
}
}
}
}
light.Disposing += (o, e) => Lights.Remove(light);
Lights.Add(light);
}
}
示例10: InitTextures
public static void InitTextures()
{
TeamTextures = new Dictionary<int, Dictionary<Common.Classes.Unit, Texture>>();
var m = Program.Instance.Map;
foreach (Common.Map.Team team in m.Teams)
{
TeamTextures[team.Id] = new Dictionary<Common.Classes.Unit, Texture>();
}
foreach (Common.Classes.Unit u in m.UnitClasses.Values)
{
Texture texture_input = models.GetModel(u.Model).Texture;
foreach (Common.Map.Team team in m.Teams)
{
ClientCommon.TextureColor.B8G8R8A8 c = new ClientCommon.TextureColor.B8G8R8A8();
c.A = team.Color.A;
c.B = team.Color.B;
c.G = team.Color.G;
c.R = team.Color.R;
SurfaceDescription d = texture_input.GetLevelDescription(0);
Texture texture_output = new Texture(Program.Instance.Device, d.Width, d.Height, 0, Usage.Dynamic | Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Default);
DataRectangle DRread = texture_input.LockRectangle(0, LockFlags.ReadOnly);
DataRectangle DRwrite = texture_output.LockRectangle(0, LockFlags.None);
for (int y = 0; y < d.Height; y++)
{
for (int x = 0; x < d.Width; x++)
{
if (d.Format == Format.A8R8G8B8 || d.Format == Format.X8R8G8B8)
{
var col = DRread.Data.Read<ClientCommon.TextureColor.B8G8R8A8>();
if (col.A >= 1 && col.A < 255)
{
float B = c.B;
float G = c.G;
float R = c.R;
float A = c.A;
float colB = col.B;
float colG = col.G;
float colR = col.R;
float colA = col.A;
float newCB = B * (255 - colA) / 255;
float newCG = G * (255 - colA) / 255;
float newCR = R * (255 - colA) / 255;
float newCA = A * (255 - colA) / 255;
float newColB = colB * colA / 255;
float newColG = colG * colA / 255;
float newColR = colR * colA / 255;
float newColA = colA * colA / 255;
float newFinalB = newCB + newColB;
float newFinalG = newCG + newColG;
float newFinalR = newCR + newColR;
float newFinalA = 255;
ClientCommon.TextureColor.B8G8R8A8 final = new ClientCommon.TextureColor.B8G8R8A8 { B = (byte)(newFinalB), G = (byte)(newFinalG), R = (byte)(newFinalR), A = (byte)(newFinalA) };
DRwrite.Data.Write(final);
}
else
{
DRwrite.Data.Write(col);
}
}
}
}
texture_input.UnlockRectangle(0);
texture_output.UnlockRectangle(0);
//Console.WriteLine(texture_output.LevelCount);
//Program.Instance.content.Register(team + " " + u.Model.ToString(), texture_output);
//texture_output.au
TeamTextures[team.Id].Add(u, texture_output);
}
}
}
示例11: d3d_DxRestore
/// <summary>
/// Restore the mesh when the DirectX device is restored
/// </summary>
void d3d_DxRestore(Direct3d d3d, Device dx)
{
// If the direct3d device wasn't lost in the first place, don't restore it.
// This happens the first timeMs around.
if (mTexture != null)
return;
// Create mesh
int width = mSurfDesc.Width;
int height = mSurfDesc.Height;
mTexture = new Texture(d3d.Dx, width, height,
1, mSurfDesc.Usage, mSurfDesc.Format, mSurfDesc.Pool);
// Write the texture data
int pitch;
GraphicsStream stream = mTexture.LockRectangle(0, LockFlags.Discard | LockFlags.NoDirtyUpdate, out pitch);
//Debug.Assert(pitch == mPixelSizeBits*width/8); // New versions of DX fixes Pitch for us
//Debug.Assert(pitch*height == mTextureData.Length);
stream.Write(mTextureData);
mTexture.UnlockRectangle(0);
mTextureData = null;
}
示例12: ConstructFromPixelMap
/// <summary>
/// Constructs a DirectX9 surface for this image from a PixelMap.
/// </summary>
/// <param name="pixelMap">PixelMap to construct surface from.</param>
void ConstructFromPixelMap(PixelMap pixelMap)
{
_pixelMap = pixelMap;
// Work out size of texture to create so that we have a nice square texture.
if (_dx9Driver.DX9Device.DeviceCaps.TextureCaps.SupportsSquareOnly == true || _dx9Driver.DX9Device.DeviceCaps.TextureCaps.SupportsPower2 == true)
{
if (pixelMap.Width > pixelMap.Height)
{
_textureWidth = MathMethods.Pow(pixelMap.Width, 2);
_textureHeight = _textureWidth;
}
else
{
_textureHeight = MathMethods.Pow(pixelMap.Height, 2);
_textureWidth = _textureHeight;
}
}
else
{
_textureWidth = pixelMap.Width;
_textureHeight = pixelMap.Height;
}
// Create texture.
_texture = new Texture(_dx9Driver.DX9Device, _textureWidth, _textureHeight, 1, Usage.None, Format.A8R8G8B8, Pool.Managed);
// Copy the pixelMap and resize it.
PixelMap copy = new PixelMap(_textureWidth, _textureHeight);
copy.Fill(0x00000000);
copy.Paste(pixelMap, 0, 0);
// Add memory pressure so the GC collects faster.
_memoryPressure = copy.Data.Length;
GC.AddMemoryPressure(_memoryPressure);
// Create a buffer and then write the image data into it.
int pitch;
GraphicsStream stream = _texture.LockRectangle(0, 0, out pitch);
stream.Write(copy.Data);
_texture.UnlockRectangle(0);
// Sets up the vertex-buffer so all our data is correct
_vertexArray[0].X = 0;
_vertexArray[0].Y = 0;
_vertexArray[1].X = _textureWidth;
_vertexArray[1].Y = 0;
_vertexArray[2].X = _textureWidth;
_vertexArray[2].Y = _textureHeight;
_vertexArray[3].X = 0;
_vertexArray[3].Y = _textureHeight;
// Hook into the dx9 disposal event so we can clean up.
_dx9Driver.DX9Device.Disposing += new EventHandler(DX9Device_Disposing);
}
示例13: Allocate
public override void Allocate()
{
lock (_syncObj)
{
if (!IsAllocated)
{
byte[] buffer = new byte[TEXTURE_SIZE*TEXTURE_SIZE*4];
int offset = 0;
while (offset < TEXTURE_SIZE*TEXTURE_SIZE*4)
{
buffer[offset++] = _color.R;
buffer[offset++] = _color.G;
buffer[offset++] = _color.B;
buffer[offset++] = _color.A;
}
_texture = new Texture(GraphicsDevice.Device, TEXTURE_SIZE, TEXTURE_SIZE, 1, Usage.Dynamic, Format.A8R8G8B8,
Pool.Default);
DataRectangle rect = _texture.LockRectangle(0, LockFlags.Discard);
rect.Data.Write(buffer, 0, buffer.Length);
_texture.UnlockRectangle(0);
_width = TEXTURE_SIZE;
_height = TEXTURE_SIZE;
_allocationSize = TEXTURE_SIZE*TEXTURE_SIZE*4;
}
}
// Don't hold a lock while calling external code
FireAllocationChanged(_allocationSize);
}
示例14: CreateTexture
public unsafe void CreateTexture(BinaryReader reader)
{
int w = Width + (4 - Width % 4) % 4;
int h = Height + (4 - Height % 4) % 4;
Image = new Texture(DXManager.Device, w, h, 1, Usage.None, Format.Dxt1, Pool.Managed);
GraphicsStream stream = Image.LockRectangle(0, LockFlags.Discard);
Data = (byte*)stream.InternalDataPointer;
stream.Write(reader.ReadBytes(Length), 0, Length);
stream.Dispose();
Image.UnlockRectangle(0);
DXManager.TextureList.Add(this);
TextureValid = true;
Image.Disposing += (o, e) =>
{
TextureValid = false;
Image = null;
Data = null;
DXManager.TextureList.Remove(this);
};
CleanTime = CMain.Time + Settings.CleanDelay;
}
示例15: loadLightMaps
/// <summary>
/// Cargar lightmaps
/// </summary>
private void loadLightMaps(BspMap bspMap)
{
const int LIGHTMAP_SIZE = 128*128;
int cant_lmaps = bspMap.Data.lightBytes.Length / (LIGHTMAP_SIZE * 3);
lightMaps = new TgcTexture[cant_lmaps];
int[] lightInfo = new int[LIGHTMAP_SIZE];
for (int i = 0; i < cant_lmaps; i++)
{
//transformo de RGB a XRGB agregandole un canal mas
for (int j = 0; j < LIGHTMAP_SIZE; j++)
{
int offset = (i*LIGHTMAP_SIZE +j)*3;
lightInfo[j] = changeGamma(bspMap.Data.lightBytes[offset + 0], bspMap.Data.lightBytes[offset + 1],
bspMap.Data.lightBytes[offset + 2]);
}
Texture tex = new Texture(GuiController.Instance.D3dDevice, 128, 128, 0, Usage.None,
Format.X8R8G8B8, Pool.Managed);
GraphicsStream graphicsStream = tex.LockRectangle(0, LockFlags.None);
graphicsStream.Write(lightInfo);
tex.UnlockRectangle(0);
string filename = "qlight" + i + ".jpg";
TextureLoader.Save(filename, ImageFileFormat.Jpg, tex);
lightMaps[i] = new TgcTexture(filename, filename, tex, false);
}
}