private void CreateTextureArray(DeviceContext context, List <Texture2D> textureArray) { //Create the Icon texture Array ArrayTexture.CreateTexture2D(context, textureArray.ToArray(), "Icon's ArrayTexture", out _iconsTextureArray); // indexes into array corresponds textures with modifier +1 (Air) _iconTextureArray = new SpriteTexture(IconSize, IconSize, _iconsTextureArray, new Vector2()); }
private void CreateTextureResources(DeviceContext context, FilterFlags MIPfilterFlag) { if (CubeArrayTexture != null) { RemoveToDispose(CubeArrayTexture); CubeArrayTexture.Dispose(); } CubeArrayTexture = null; ImageLoadInformation ImageInfo = new ImageLoadInformation() { FirstMipLevel = 0, Usage = ResourceUsage.Staging, BindFlags = BindFlags.None, CpuAccessFlags = CpuAccessFlags.Write | CpuAccessFlags.Read, OptionFlags = ResourceOptionFlags.None, Format = SharpDX.DXGI.Format.R8G8B8A8_UNorm, Filter = FilterFlags.None, MipFilter = MIPfilterFlag }; List <Texture2D> cubeTextures = new List <Texture2D>(); //Get all file and create a list of stream ! foreach (string file in Directory.GetFiles(ClientSettings.TexturePack + @"Terran/", @"*.png").OrderBy(x => x)) { var meta = CubeTexturesMeta[Path.GetFileNameWithoutExtension(file)]; if (meta.isAnimated) { //Split file into small pieces and create Texture2D from it Bitmap animatedTex = new Bitmap(file); Bitmap frameTex = new Bitmap(meta.Size.Width, meta.Size.Width); Rectangle frameRect = new Rectangle(0, 0, meta.Size.Width, meta.Size.Width); using (Graphics gr = Graphics.FromImage(frameTex)) { int rows = meta.Size.Height / meta.Size.Width; Rectangle sourceRect = new Rectangle(0, 0, meta.Size.Width, meta.Size.Width); for (int row = 0; row < rows; row++) { // Copy the frame of the image. gr.DrawImage(animatedTex, frameRect, sourceRect, GraphicsUnit.Pixel); //Save into a memoryStream using (MemoryStream textureMemoryStream = new MemoryStream()) { frameTex.Save(textureMemoryStream, System.Drawing.Imaging.ImageFormat.Png); textureMemoryStream.Position = 0; Texture2D newTexture = Texture2D.FromStream <Texture2D>(_engine.Device, textureMemoryStream, (int)textureMemoryStream.Length, ImageInfo); cubeTextures.Add(newTexture); } sourceRect.Y += meta.Size.Width; } } frameTex.Dispose(); animatedTex.Dispose(); } else { Texture2D newTexture = Texture2D.FromFile <Texture2D>(_engine.Device, file, ImageInfo); cubeTextures.Add(newTexture); } } //2 Creation of the TextureArray resource ArrayTexture.CreateTexture2D(context, cubeTextures.ToArray(), "CubeTexturesArray", out CubeArrayTexture, ImageInfo.Format); //Disposing resources used to create the texture array foreach (Texture2D tex in cubeTextures) { tex.Dispose(); } ToDispose(CubeArrayTexture); }