private Texture2D DownScale(GraphicsDevice graphicsDevice, RenderTarget2D texture, int newsize) { Texture2D newtexture = new RenderTarget2D(graphicsDevice, newsize, newsize, true, graphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24); graphicsDevice.SetRenderTarget((RenderTarget2D)newtexture); GraphicsBasic.DrawSpriteRect(graphicsDevice, 0, 0, newsize, newsize, texture, BlendState.AlphaBlend, Microsoft.Xna.Framework.Color.White); return(newtexture); }
private void RebuildImage(GraphicsDevice graphicsDevice, ISector sector) { // combination images using (Texture2D rendered = new RenderTarget2D(graphicsDevice, 512, 512, false, graphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24)) { int highestZoom = ZCoords.GetSectorManager().GetHighestCacheZoom(); foreach (var parent in sector.GetAllParents().OrderBy(x => - x.Zoom).Where(x => x.Zoom <= highestZoom)) { List <ISector> roadSectors = parent.GetChildrenAtLevel(parent.Zoom == highestZoom - 1 ? ZCoords.GetSectorManager().GetHighestOSMZoom() : parent.Zoom + 1); Texture2D[] textures = new Texture2D[roadSectors.Count]; for (int i = 0; i < roadSectors.Count; i++) { IGraphicsBuffer buffer = null; if (File.Exists(OSMPaths.GetSectorImagePath(roadSectors[i]))) { using (var reader = File.OpenRead(OSMPaths.GetSectorImagePath(roadSectors[i]))) { buffer = new ImageTileBuffer(graphicsDevice, Texture2D.FromStream(graphicsDevice, reader), roadSectors[i]); } } else { throw new NotImplementedException(); } textures[i] = buffer.GetImage(graphicsDevice); } if (textures.Any(x => x != null)) { graphicsDevice.SetRenderTarget((RenderTarget2D)rendered); for (int i = 0; i < roadSectors.Count; i++) { int size, x, y; size = 512 >> (roadSectors[i].Zoom - parent.Zoom); x = parent.GetRelativeXOf(roadSectors[i]) * size; y = parent.GetRelativeYOf(roadSectors[i]) * size; if (textures[i] != null) { GraphicsBasic.DrawSpriteRect(graphicsDevice, x, y, size, size, textures[i], BlendState.AlphaBlend, Microsoft.Xna.Framework.Color.White); } } } for (int i = 0; i < textures.Length; i++) { if (textures[i] != null && textures[i] != GlobalContent.Error) { textures[i].Dispose(); } } SuperSave(rendered, OSMPaths.GetSectorImagePath(parent)); } } }