private IList <TextureFragment> GetTextureFragments() { if (squares.Count == 0) { return(null); } int totalWidth = squares.Max(s => s.Bounds.X + s.Bounds.Width); int totalHeight = squares.Max(s => s.Bounds.Y + s.Bounds.Height); IList <TextureFragment> textures = new List <TextureFragment>(); int remainingWidth = totalWidth; while (remainingWidth > 0) { int x = totalWidth - remainingWidth; int w = remainingWidth; if (w > fragmentWidth) { w = fragmentWidth; } remainingWidth -= w; int remainingHeight = totalHeight; while (remainingHeight > 0) { int y = totalHeight - remainingHeight; int h = remainingHeight; if (h > fragmentHeight) { h = fragmentHeight; } remainingHeight -= h; GraphicsDevice device = GameCore.Instance.GraphicsDevice; Texture2D texture = new Texture2D(device, w, h); Vector2 rel = new Vector2(x, y); TextureFragment fragment = new TextureFragment { Texture = texture, Relative = rel }; textures.Add(fragment); foreach (Square square in squares) { Rectangle src = square.Bounds; Rectangle rect = new Rectangle(src.X - (int)rel.X, src.Y - (int)rel.Y, src.Width, src.Height); if (rect.X + rect.Width > x + w || rect.Y + rect.Height > y + h) { continue; } if (rect.X < 0 || rect.Y < 0) { continue; } Color[] data = square.GetData(); texture.SetData(0, rect, data, 0, data.Length); } } } return(textures); }
private IList<TextureFragment> GetTextureFragments() { if (squares.Count == 0) { return null; } int totalWidth = squares.Max(s => s.Bounds.X + s.Bounds.Width); int totalHeight = squares.Max(s => s.Bounds.Y + s.Bounds.Height); IList<TextureFragment> textures = new List<TextureFragment>(); int remainingWidth = totalWidth; while (remainingWidth > 0) { int x = totalWidth - remainingWidth; int w = remainingWidth; if (w > fragmentWidth) { w = fragmentWidth; } remainingWidth -= w; int remainingHeight = totalHeight; while (remainingHeight > 0) { int y = totalHeight - remainingHeight; int h = remainingHeight; if (h > fragmentHeight) { h = fragmentHeight; } remainingHeight -= h; GraphicsDevice device = GameCore.Instance.GraphicsDevice; Texture2D texture = new Texture2D(device, w, h); Vector2 rel = new Vector2(x, y); TextureFragment fragment = new TextureFragment { Texture = texture, Relative = rel }; textures.Add(fragment); foreach (Square square in squares) { Rectangle src = square.Bounds; Rectangle rect = new Rectangle(src.X - (int)rel.X, src.Y - (int)rel.Y, src.Width, src.Height); if (rect.X + rect.Width > x + w || rect.Y + rect.Height > y + h) { continue; } if (rect.X < 0 || rect.Y < 0) { continue; } Color[] data = square.GetData(); texture.SetData(0, rect, data, 0, data.Length); } } } return textures; }