brutal/brutal.texture/Brutal.Texture/TextureWriter.cs
2026-10-15 14:12:02 +13:00

34 lines
1.1 KiB
C#

namespace Brutal.TextureApi;
public static partial class TextureWriter
{
/// <summary>
/// Saves an ITexture to a file.
/// </summary>
/// <param name="texture">The ITexture to save.</param>
/// <param name="filePath">The path to the file.</param>
/// <exception cref="NotSupportedException">Thrown if the extension of filePath is not supported.</exception>
public static void SaveToFile(ITexture texture, string filePath)
{
var extension = Path.GetExtension(filePath);
if (Ktx.Loader.SupportedExtensions.Contains(extension))
{
Ktx.Writer.SaveToFile(texture, filePath);
return;
}
if (Stb.Writer.SupportedExtensions.Contains(extension))
{
Stb.Writer.SaveToFile(texture, filePath);
return;
}
if (Gli.Loader.SupportedExtensions.Contains(extension))
{
Gli.Writer.SaveToFile(texture, filePath);
return;
}
throw new NotSupportedException($"No loader found that supports file {extension}");
}
}