/// <summary> /// DirtyRect is a callback that passes us regions of an updated part /// of the texture, we pass this to the dirty texture class as /// dirty rectangles so directx updates them /// </summary> public void AddDirtyRectangle(IntPtr pTexture, Int32 pX, Int32 pY, Int32 pX1, Int32 pY1) { System.Drawing.Rectangle tRectangle = new System.Drawing.Rectangle(pX, pY, pX1 - pX, pY1 - pY); //set the rectangle to dirty if ((Int32)pTexture == 0) { _Texture1.AddDirtyRectangle(tRectangle); } else { _Texture2.AddDirtyRectangle(tRectangle); } }
/// <summary> /// DirtyRect is a callback that passes us regions of an updated part /// of the texture, we pass this to the dirty texture class as /// dirty rectangles so directx updates them /// </summary> public void AddDirtyRectangle(IntPtr pTexture, Int32 x, Int32 y, Int32 x1, Int32 y1) { System.Drawing.Rectangle tRectangle = new System.Drawing.Rectangle(x, y, x1 - x, y1 - y); //set the rectangle to dirty if ((Int32)pTexture == 0) { _Texture1.AddDirtyRectangle(tRectangle); Console.WriteLine("Texture1.AddDirtyRectangle()"); } else { _Texture2.AddDirtyRectangle(tRectangle); Console.WriteLine("Texture2.AddDirtyRectangle()"); } }
static void ApplyFilter(ref Texture tex) { if (tex == null) { return; } if (tex.LevelCount == 0) { return; } if (tex.GetLevelDescription(0).Format == Format.Dxt1) { Surface oldsuf = tex.GetSurfaceLevel(0); Texture newtex = new Texture(tex.Device, oldsuf.Description.Width, oldsuf.Description.Height, tex.LevelCount, oldsuf.Description.Usage, Format.Dxt3, oldsuf.Description.Pool); Surface newsuf = newtex.GetSurfaceLevel(0); Surface.FromSurface(newsuf, oldsuf, Filter.None, 0); newsuf.Dispose(); oldsuf.Dispose(); tex.Dispose(); tex = newtex; } switch (tex.GetLevelDescription(0).Format) { case Format.A8R8G8B8: case Format.A1R5G5B5: case Format.A4R4G4B4: case Format.A8: case Format.A8R3G3B2: case Format.A2B10G10R10: case Format.A8B8G8R8: case Format.A2R10G10B10: case Format.A16B16G16R16: case Format.A8P8: case Format.A8L8: case Format.A4L4: case Format.A2W10V10U10: case Format.A16B16G16R16F: case Format.A32B32G32R32F: case Format.A1: case Format.Dxt2: case Format.Dxt3: case Format.Dxt4: case Format.Dxt5: Surface lower = null; for (int j = 0; j < tex.LevelCount; j++) { Surface upperlevel = tex.GetSurfaceLevel(j); Surface upper = Surface.CreateOffscreenPlain(tex.Device, upperlevel.Description.Width, upperlevel.Description.Height, Format.A8R8G8B8, Pool.SystemMemory); if (j == 0) { Surface.FromSurface(upper, upperlevel, Filter.Default, 0); } DataRectangle upperrect = upper.LockRectangle(j == 0 ? LockFlags.None : LockFlags.Discard); int upperpitch = upperrect.Pitch; if (j != 0) { DataRectangle lowerrect = lower.LockRectangle(LockFlags.ReadOnly); int lowerpitch = lowerrect.Pitch; unsafe { byte *lowerptr = (byte *)lowerrect.Data.DataPointer.ToPointer(); byte *upperptr = (byte *)upperrect.Data.DataPointer.ToPointer(); for (int k = 0; k < (lower.Description.Height + 1) / 2; k++) { int mc = k == (lower.Description.Height + 1) / 2 - 1 && lower.Description.Height % 2 == 1 ? 1 : 2; for (int l = 0; l < (lower.Description.Width + 1) / 2; l++) { int nc = l == (lower.Description.Width + 1) / 2 - 1 && lower.Description.Width % 2 == 1 ? 1 : 2; int r = 0, g = 0, b = 0, a = 0; for (int m = 0; m < mc; m++) { for (int n = 0; n < nc; n++) { byte *src = lowerptr + (k * 2 + m) * lowerpitch + (l * 2 + n) * 4; r += src[0] * src[3]; g += src[1] * src[3]; b += src[2] * src[3]; a += src[3]; } } if (a == 0) { a = 1; } byte *dest = upperptr + k * upperpitch + l * 4; dest[0] = (byte)(r / a); dest[1] = (byte)(g / a); dest[2] = (byte)(b / a); dest[3] = (byte)(a / (nc * mc)); } } } lower.UnlockRectangle(); lower.Dispose(); } unsafe { byte *upperptr = (byte *)upperrect.Data.DataPointer.ToPointer(); for (int k = 0; k < upper.Description.Height; k++) { for (int l = 0; l < upper.Description.Width; l++) { if (upperptr[k * upperpitch + l * 4 + 3] > 0) { continue; } int r = 0, g = 0, b = 0, a = 0; for (int m = -1; m < 2; m++) { byte *src = upperptr + (k + m + upper.Description.Height) % upper.Description.Height * upperpitch + l * 4; r += src[0] * src[3]; g += src[1] * src[3]; b += src[2] * src[3]; a += src[3]; } for (int n = -1; n < 2; n++) { byte *src = upperptr + k * upperpitch + (l + n + upper.Description.Width) % upper.Description.Width * 4; r += src[0] * src[3]; g += src[1] * src[3]; b += src[2] * src[3]; a += src[3]; } if (a == 0) { for (int m = -1; m < 2; m += 2) { for (int n = -1; n < 2; n += 2) { byte *src = upperptr + (k + m + upper.Description.Height) % upper.Description.Height * upperpitch + (l + n + upper.Description.Width) % upper.Description.Width * 4; r += src[0] * src[3]; g += src[1] * src[3]; b += src[2] * src[3]; a += src[3]; } } } if (a == 0) { continue; } byte *dest = upperptr + k * upperpitch + l * 4; dest[0] = (byte)(r / a); dest[1] = (byte)(g / a); dest[2] = (byte)(b / a); } } } upper.UnlockRectangle(); lower = upper; Surface.FromSurface(upperlevel, upper, Filter.Default, 0); upperlevel.Dispose(); } lower.Dispose(); tex.AddDirtyRectangle(); break; } }
public Result AddDirtyRectangle() { return(_texture.AddDirtyRectangle()); }