Some progress with .net bindings.
This commit is contained in:
parent
92c3dd3f75
commit
32d694798a
193
src/nvtt/nvtt.cs
193
src/nvtt/nvtt.cs
@ -1,10 +1,15 @@
|
|||||||
|
|
||||||
|
using System;
|
||||||
namespace nvtt
|
using System.Runtime.InteropServices;
|
||||||
{
|
|
||||||
|
namespace Nvidia.TextureTools
|
||||||
|
{
|
||||||
#region Enums
|
#region Enums
|
||||||
|
|
||||||
#region enum Format
|
#region enum Format
|
||||||
|
/// <summary>
|
||||||
|
/// Compression format.
|
||||||
|
/// </summary>
|
||||||
enum Format
|
enum Format
|
||||||
{
|
{
|
||||||
// No compression.
|
// No compression.
|
||||||
@ -29,8 +34,10 @@ namespace nvtt
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region enum Quality
|
#region enum Quality
|
||||||
/// Quality modes.
|
/// <summary>
|
||||||
|
/// Quality modes.
|
||||||
|
/// </summary>
|
||||||
enum Quality
|
enum Quality
|
||||||
{
|
{
|
||||||
Fastest,
|
Fastest,
|
||||||
@ -41,7 +48,9 @@ namespace nvtt
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region enum TextureType
|
#region enum TextureType
|
||||||
/// Texture types.
|
/// <summary>
|
||||||
|
/// Texture types.
|
||||||
|
/// </summary>
|
||||||
enum TextureType
|
enum TextureType
|
||||||
{
|
{
|
||||||
Texture2D,
|
Texture2D,
|
||||||
@ -51,136 +60,164 @@ namespace nvtt
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region private static class Bindings
|
|
||||||
private static class Bindings
|
|
||||||
{
|
|
||||||
// Input Options
|
|
||||||
//NVTT_API NvttInputOptions nvttCreateInputOptions();
|
|
||||||
//NVTT_API void nvttDestroyInputOptions(NvttInputOptions inputOptions);
|
|
||||||
|
|
||||||
//NVTT_API void nvttSetInputOptionsTextureLayout(NvttInputOptions inputOptions, NvttTextureType type, int w, int h, int d);
|
#region public class InputOptions
|
||||||
//NVTT_API void nvttResetInputOptionsTextureLayout(NvttInputOptions inputOptions);
|
/// <summary>
|
||||||
//NVTT_API NvttBoolean nvttSetInputOptionsMipmapData(NvttInputOptions inputOptions, const void * data, int w, int h, int d, int face, int mipmap);
|
/// Input options.
|
||||||
|
/// </summary>
|
||||||
|
|
||||||
// Compression Options
|
|
||||||
//NVTT_API NvttCompressionOptions nvttCreateCompressionOptions();
|
|
||||||
//NVTT_API void nvttDestroyCompressionOptions(NvttCompressionOptions compressionOptions);
|
|
||||||
|
|
||||||
//NVTT_API void nvttSetCompressionOptionsFormat(NvttCompressionOptions compressionOptions, NvttFormat format);
|
|
||||||
//NVTT_API void nvttSetCompressionOptionsQuality(NvttCompressionOptions compressionOptions, NvttQuality quality);
|
|
||||||
//NVTT_API void nvttSetCompressionOptionsPixelFormat(NvttCompressionOptions compressionOptions, unsigned int bitcount, unsigned int rmask, unsigned int gmask, unsigned int bmask, unsigned int amask);
|
|
||||||
|
|
||||||
|
|
||||||
// Output Options
|
|
||||||
//NVTT_API NvttOutputOptions nvttCreateOutputOptions();
|
|
||||||
//NVTT_API void nvttDestroyOutputOptions(NvttOutputOptions outputOptions);
|
|
||||||
|
|
||||||
//NVTT_API void nvttSetOutputOptionsFileName(NvttOutputOptions outputOptions, const char * fileName);
|
|
||||||
|
|
||||||
|
|
||||||
// Main entrypoint of the compression library.
|
|
||||||
//NVTT_API NvttBoolean nvttCompress(NvttInputOptions inputOptions, NvttOutputOptions outputOptions, NvttCompressionOptions compressionOptions);
|
|
||||||
|
|
||||||
// Estimate the size of compressing the input with the given options.
|
|
||||||
//NVTT_API int nvttEstimateSize(NvttInputOptions inputOptions, NvttCompressionOptions compressionOptions);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public class InputOptions
|
|
||||||
public class InputOptions
|
public class InputOptions
|
||||||
{
|
{
|
||||||
|
#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;
|
||||||
|
|
||||||
public InputOptions()
|
public InputOptions()
|
||||||
{
|
{
|
||||||
options = Bindings.CreateInputOptions();
|
options = nvttCreateInputOptions();
|
||||||
}
|
}
|
||||||
public ~InputOptions()
|
public ~InputOptions()
|
||||||
{
|
{
|
||||||
Bindings.DestroyInputOptions(options);
|
nvttDestroyInputOptions(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTextureLayout(TextureType type, int w, int h, int d)
|
public void SetTextureLayout(TextureType type, int w, int h, int d)
|
||||||
{
|
{
|
||||||
Bindings.InputOptions_SetTextureLayout(options, type, w, h, d);
|
nvttSetInputOptionsTextureLayout(options, type, w, h, d);
|
||||||
}
|
}
|
||||||
public void ResetTextureLayout()
|
public void ResetTextureLayout()
|
||||||
{
|
{
|
||||||
Bindings.InputOptions_ResetTextureLayout(options);
|
nvttResetInputOptionsTextureLayout(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetMipmapData(Image img, int face, int mipmap)
|
public void SetMipmapData(IntPtr data, int width, int height, int depth, int face, int mipmap)
|
||||||
{
|
{
|
||||||
// TODO
|
nvttSetInputOptionsMipmapData(options, data, width, height, depth, face, mipmap);
|
||||||
//Bindings.InputOptions_SetMipmapData(options, img.Data, img.Width, img.Height, 1, face, mipmap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private IntPtr options;
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region public class CompressionOptions
|
#region public class CompressionOptions
|
||||||
|
/// <summary>
|
||||||
|
/// Compression options.
|
||||||
|
/// </summary>
|
||||||
public class CompressionOptions
|
public class CompressionOptions
|
||||||
{
|
{
|
||||||
|
#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;
|
||||||
|
|
||||||
public CompressionOptions()
|
public CompressionOptions()
|
||||||
{
|
{
|
||||||
options = Bindings.CreateCompressionOptions();
|
options = nvttCreateCompressionOptions();
|
||||||
}
|
}
|
||||||
public ~CompressionOptions()
|
public ~CompressionOptions()
|
||||||
{
|
{
|
||||||
Bindings.DestroyCompressionOptions(options);
|
nvttDestroyCompressionOptions(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetFormat(Format format)
|
public void SetFormat(Format format)
|
||||||
{
|
{
|
||||||
Bindings.CompressionOptions_SetFormat(format);
|
nvttSetCompressionOptionsFormat(options, format);
|
||||||
}
|
}
|
||||||
public void SetQuality(Quality quality)
|
public void SetQuality(Quality quality)
|
||||||
{
|
{
|
||||||
Bindings.CompressionOptions_SetQuality(quality);
|
nvttSetCompressionOptionsQuality(options, quality);
|
||||||
}
|
}
|
||||||
public void SetPixelFormat(uint bitcount, uint rmask, uint gmask, uint bmask, uint amask)
|
public void SetPixelFormat(uint bitcount, uint rmask, uint gmask, uint bmask, uint amask)
|
||||||
{
|
{
|
||||||
Bindings.CompressionOptions_SetPixelFormat(bitcount, rmask, gmask, bmask, amask);
|
nvttSetCompressionOptionsPixelFormat(options, bitcount, rmask, gmask, bmask, amask);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IntPtr options;
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region public class OutputOptions
|
#region public class OutputOptions
|
||||||
|
/// <summary>
|
||||||
|
/// Output options.
|
||||||
|
/// </summary>
|
||||||
public class OutputOptions
|
public class OutputOptions
|
||||||
{
|
{
|
||||||
|
#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;
|
||||||
|
|
||||||
public OutputOptions()
|
public OutputOptions()
|
||||||
{
|
{
|
||||||
options = Bindings.CreateOutputOptions();
|
options = nvttCreateOutputOptions();
|
||||||
}
|
}
|
||||||
public ~OutputOptions()
|
public ~OutputOptions()
|
||||||
{
|
{
|
||||||
Bindings.DestroyOutputOptions(options);
|
nvttDestroyOutputOptions(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetFileName(string fileName)
|
public void SetFileName(string fileName)
|
||||||
{
|
{
|
||||||
// TODO
|
nvttSetOutputOptionsFileName(options, fileName);
|
||||||
//Bindings.OutputOptions_SetFileName(fileName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private IntPtr options;
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region public static class Compressor
|
#region public static class Compressor
|
||||||
public static class Compressor
|
public static class Compressor
|
||||||
{
|
{
|
||||||
|
#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
|
||||||
|
|
||||||
public bool Compress(InputOptions inputOptions, CompressionOptions compressionOptions, OutputOptions outputOptions)
|
public bool Compress(InputOptions inputOptions, CompressionOptions compressionOptions, OutputOptions outputOptions)
|
||||||
{
|
{
|
||||||
Bindings.Compress(inputOptions.options, compressionOptions.options, outputOptions.options);
|
nvttCompress(inputOptions.options, compressionOptions.options, outputOptions.options);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool EstimateSize(InputOptions inputOptions, CompressionOptions compressionOptions)
|
public bool EstimateSize(InputOptions inputOptions, CompressionOptions compressionOptions)
|
||||||
{
|
{
|
||||||
Bindings.EstimateSize(inputOptions.options, compressionOptions.options);
|
nvttEstimateSize(inputOptions.options, compressionOptions.options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
|
||||||
|
} // Nvidia.TextureTools namespace
|
Loading…
Reference in New Issue
Block a user