2008-01-19 08:52:50 +00:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
namespace Nvidia.TextureTools
|
|
|
|
{
|
2008-01-18 23:47:05 +00:00
|
|
|
#region Enums
|
|
|
|
|
2008-01-19 08:52:50 +00:00
|
|
|
#region enum Format
|
|
|
|
/// <summary>
|
|
|
|
/// Compression format.
|
|
|
|
/// </summary>
|
2008-01-18 23:47:05 +00:00
|
|
|
enum Format
|
|
|
|
{
|
|
|
|
// No compression.
|
|
|
|
RGB,
|
|
|
|
RGBA = RGB,
|
|
|
|
|
|
|
|
// DX9 formats.
|
|
|
|
DXT1,
|
|
|
|
DXT1a,
|
|
|
|
DXT3,
|
|
|
|
DXT5,
|
|
|
|
DXT5n,
|
|
|
|
|
|
|
|
// DX10 formats.
|
|
|
|
BC1 = DXT1,
|
|
|
|
BC1a = DXT1a,
|
|
|
|
BC2 = DXT3,
|
|
|
|
BC3 = DXT5,
|
|
|
|
BC3n = DXT5n,
|
|
|
|
BC4,
|
|
|
|
BC5,
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
2008-01-19 08:52:50 +00:00
|
|
|
#region enum Quality
|
|
|
|
/// <summary>
|
|
|
|
/// Quality modes.
|
|
|
|
/// </summary>
|
2008-01-18 23:47:05 +00:00
|
|
|
enum Quality
|
|
|
|
{
|
|
|
|
Fastest,
|
|
|
|
Normal,
|
|
|
|
Production,
|
|
|
|
Highest,
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region enum TextureType
|
2008-01-19 08:52:50 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Texture types.
|
|
|
|
/// </summary>
|
2008-01-18 23:47:05 +00:00
|
|
|
enum TextureType
|
|
|
|
{
|
|
|
|
Texture2D,
|
|
|
|
TextureCube,
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
2008-01-19 08:52:50 +00:00
|
|
|
#region public class InputOptions
|
|
|
|
/// <summary>
|
|
|
|
/// Input options.
|
|
|
|
/// </summary>
|
2008-01-18 23:47:05 +00:00
|
|
|
public class InputOptions
|
2008-01-19 08:52:50 +00:00
|
|
|
{
|
|
|
|
#region Bindings
|
|
|
|
[DllImport("nvtt")]
|
|
|
|
private extern static IntPtr nvttCreateInputOptions();
|
|
|
|
|
|
|
|
[DllImport("nvtt")]
|
|
|
|
private extern static void nvttDestroyInputOptions(IntPtr inputOptions);
|
|
|
|
|
|
|
|
[DllImport("nvtt")]
|
|
|
|
private extern static void nvttSetInputOptionsTextureLayout(IntPtr inputOptions, TextureType type, int w, int h, int d);
|
|
|
|
|
|
|
|
[DllImport("nvtt")]
|
|
|
|
private extern static void nvttResetInputOptionsTextureLayout(IntPtr inputOptions);
|
|
|
|
|
|
|
|
[DllImport("nvtt")]
|
|
|
|
private extern static bool nvttSetInputOptionsMipmapData(IntPtr inputOptions, IntPtr data, int w, int h, int d, int face, int mipmap);
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
internal IntPtr options;
|
|
|
|
|
2008-01-18 23:47:05 +00:00
|
|
|
public InputOptions()
|
|
|
|
{
|
2008-01-19 08:52:50 +00:00
|
|
|
options = nvttCreateInputOptions();
|
2008-01-18 23:47:05 +00:00
|
|
|
}
|
|
|
|
public ~InputOptions()
|
2008-01-19 08:52:50 +00:00
|
|
|
{
|
|
|
|
nvttDestroyInputOptions(options);
|
2008-01-18 23:47:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetTextureLayout(TextureType type, int w, int h, int d)
|
|
|
|
{
|
2008-01-19 08:52:50 +00:00
|
|
|
nvttSetInputOptionsTextureLayout(options, type, w, h, d);
|
2008-01-18 23:47:05 +00:00
|
|
|
}
|
|
|
|
public void ResetTextureLayout()
|
|
|
|
{
|
2008-01-19 08:52:50 +00:00
|
|
|
nvttResetInputOptionsTextureLayout(options);
|
2008-01-18 23:47:05 +00:00
|
|
|
}
|
|
|
|
|
2008-01-19 08:52:50 +00:00
|
|
|
public void SetMipmapData(IntPtr data, int width, int height, int depth, int face, int mipmap)
|
2008-01-18 23:47:05 +00:00
|
|
|
{
|
2008-01-19 08:52:50 +00:00
|
|
|
nvttSetInputOptionsMipmapData(options, data, width, height, depth, face, mipmap);
|
2008-01-18 23:47:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
2008-01-19 08:52:50 +00:00
|
|
|
#region public class CompressionOptions
|
|
|
|
/// <summary>
|
|
|
|
/// Compression options.
|
|
|
|
/// </summary>
|
2008-01-18 23:47:05 +00:00
|
|
|
public class CompressionOptions
|
2008-01-19 08:52:50 +00:00
|
|
|
{
|
|
|
|
#region Bindings
|
|
|
|
[DllImport("nvtt")]
|
|
|
|
private extern static IntPtr nvttCreateCompressionOptions();
|
|
|
|
|
|
|
|
[DllImport("nvtt")]
|
|
|
|
private extern static void nvttDestroyCompressionOptions(IntPtr compressionOptions);
|
|
|
|
|
|
|
|
[DllImport("nvtt")]
|
|
|
|
private extern static void nvttSetCompressionOptionsFormat(IntPtr compressionOptions, Format format);
|
|
|
|
|
|
|
|
[DllImport("nvtt")]
|
|
|
|
private extern static void nvttSetCompressionOptionsQuality(IntPtr compressionOptions, Quality quality);
|
|
|
|
|
|
|
|
[DllImport("nvtt")]
|
|
|
|
private extern static void nvttSetCompressionOptionsPixelFormat(IntPtr compressionOptions, uint bitcount, uint rmask, uint gmask, uint bmask, uint amask);
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
internal IntPtr options;
|
|
|
|
|
2008-01-18 23:47:05 +00:00
|
|
|
public CompressionOptions()
|
|
|
|
{
|
2008-01-19 08:52:50 +00:00
|
|
|
options = nvttCreateCompressionOptions();
|
2008-01-18 23:47:05 +00:00
|
|
|
}
|
|
|
|
public ~CompressionOptions()
|
|
|
|
{
|
2008-01-19 08:52:50 +00:00
|
|
|
nvttDestroyCompressionOptions(options);
|
2008-01-18 23:47:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetFormat(Format format)
|
|
|
|
{
|
2008-01-19 08:52:50 +00:00
|
|
|
nvttSetCompressionOptionsFormat(options, format);
|
2008-01-18 23:47:05 +00:00
|
|
|
}
|
|
|
|
public void SetQuality(Quality quality)
|
|
|
|
{
|
2008-01-19 08:52:50 +00:00
|
|
|
nvttSetCompressionOptionsQuality(options, quality);
|
2008-01-18 23:47:05 +00:00
|
|
|
}
|
|
|
|
public void SetPixelFormat(uint bitcount, uint rmask, uint gmask, uint bmask, uint amask)
|
|
|
|
{
|
2008-01-19 08:52:50 +00:00
|
|
|
nvttSetCompressionOptionsPixelFormat(options, bitcount, rmask, gmask, bmask, amask);
|
2008-01-18 23:47:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
2008-01-19 08:52:50 +00:00
|
|
|
#region public class OutputOptions
|
|
|
|
/// <summary>
|
|
|
|
/// Output options.
|
|
|
|
/// </summary>
|
2008-01-18 23:47:05 +00:00
|
|
|
public class OutputOptions
|
2008-01-19 08:52:50 +00:00
|
|
|
{
|
|
|
|
#region Bindings
|
|
|
|
[DllImport("nvtt")]
|
|
|
|
private extern static IntPtr nvttCreateOutputOptions();
|
|
|
|
|
|
|
|
[DllImport("nvtt")]
|
|
|
|
private extern static void nvttDestroyOutputOptions(IntPtr outputOptions);
|
|
|
|
|
|
|
|
[DllImport("nvtt", CharSet = CharSet.Ansi)]
|
|
|
|
private extern static void nvttSetOutputOptionsFileName(IntPtr outputOptions, string fileName);
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
internal IntPtr options;
|
|
|
|
|
2008-01-18 23:47:05 +00:00
|
|
|
public OutputOptions()
|
|
|
|
{
|
2008-01-19 08:52:50 +00:00
|
|
|
options = nvttCreateOutputOptions();
|
2008-01-18 23:47:05 +00:00
|
|
|
}
|
|
|
|
public ~OutputOptions()
|
|
|
|
{
|
2008-01-19 08:52:50 +00:00
|
|
|
nvttDestroyOutputOptions(options);
|
2008-01-18 23:47:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetFileName(string fileName)
|
2008-01-19 08:52:50 +00:00
|
|
|
{
|
|
|
|
nvttSetOutputOptionsFileName(options, fileName);
|
2008-01-18 23:47:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region public static class Compressor
|
|
|
|
public static class Compressor
|
2008-01-19 08:52:50 +00:00
|
|
|
{
|
|
|
|
#region Bindings
|
|
|
|
[DllImport("nvtt")]
|
|
|
|
private extern static bool nvttCompress(IntPtr inputOptions, IntPtr compressionOptions, IntPtr outputOptions);
|
|
|
|
|
|
|
|
[DllImport("nvtt")]
|
|
|
|
private extern static void nvttEstimateSize(IntPtr inputOptions, IntPtr compressionOptions);
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2008-01-18 23:47:05 +00:00
|
|
|
public bool Compress(InputOptions inputOptions, CompressionOptions compressionOptions, OutputOptions outputOptions)
|
|
|
|
{
|
2008-01-19 08:52:50 +00:00
|
|
|
nvttCompress(inputOptions.options, compressionOptions.options, outputOptions.options);
|
2008-01-18 23:47:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool EstimateSize(InputOptions inputOptions, CompressionOptions compressionOptions)
|
|
|
|
{
|
2008-01-19 08:52:50 +00:00
|
|
|
nvttEstimateSize(inputOptions.options, compressionOptions.options);
|
2008-01-18 23:47:05 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-19 08:52:50 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
} // Nvidia.TextureTools namespace
|