public static Texture Encode(Bitmap bitmap, TextureFormat format, bool generateMipMaps) { int width = bitmap.Width; int height = bitmap.Height; if (TextureFormatUtilities.IsCompressed(format)) { width = AlignmentUtilities.AlignToNextPowerOfTwo(bitmap.Width); height = AlignmentUtilities.AlignToNextPowerOfTwo(bitmap.Height); } Texture texture; if (generateMipMaps && TextureFormatUtilities.IsCompressed(format)) { texture = new Texture(width, height, format, 1, ( int )Math.Log(Math.Max(width, height), 2) + 1); } else { texture = new Texture(width, height, format); } for (int i = 0; i < texture.MipMapCount; i++) { Encode(texture[i], bitmap); } return(texture); }
public static string GetFileName(Texture texture) { if (!TextureFormatUtilities.IsCompressed(texture.Format) || texture.IsYCbCr) { return(texture.Name + ".png"); } return(texture.Name + ".dds"); }
public static void SaveTextures(TextureSet textures, string outputDirectory) { Directory.CreateDirectory(outputDirectory); foreach (var texture in textures.Textures) { if (!TextureFormatUtilities.IsCompressed(texture.Format) || texture.IsYCbCr) { TextureDecoder.DecodeToPNG(texture, Path.Combine(outputDirectory, texture.Name + ".png")); } else { TextureDecoder.DecodeToDDS(texture, Path.Combine(outputDirectory, texture.Name + ".dds")); } } }