Apply patch to update C# wraper. Fixes issue 184.
This commit is contained in:
parent
f705b2eaa1
commit
ac87eefa6d
@ -422,8 +422,18 @@ namespace Nvidia.TextureTools
|
||||
{
|
||||
#region Delegates
|
||||
public delegate void ErrorHandler(Error error);
|
||||
private delegate void WriteDataDelegate(IntPtr data, int size);
|
||||
private delegate void ImageDelegate(int size, int width, int height, int depth, int face, int miplevel);
|
||||
|
||||
//[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
//public delegate void InternalErrorHandlerDelegate(Error error);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate void BeginImageDelegate(int size, int width, int height, int depth, int face, int miplevel);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate bool WriteDataDelegate(IntPtr data, int size);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate void EndImageDelegate();
|
||||
#endregion
|
||||
|
||||
#region Bindings
|
||||
@ -447,8 +457,8 @@ namespace Nvidia.TextureTools
|
||||
[DllImport("nvtt"), SuppressUnmanagedCodeSecurity]
|
||||
private extern static void nvttSetOutputOptionsOutputHeader(IntPtr outputOptions, bool b);
|
||||
|
||||
//[DllImport("nvtt"), SuppressUnmanagedCodeSecurity]
|
||||
//private extern static void nvttSetOutputOptionsOutputHandler(IntPtr outputOptions, WriteDataDelegate writeData, ImageDelegate image);
|
||||
[DllImport("nvtt", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
private extern static void nvttSetOutputOptionsOutputHandler(IntPtr outputOptions, IntPtr beginImage, IntPtr writeData, IntPtr endImage);
|
||||
|
||||
#endregion
|
||||
|
||||
@ -476,7 +486,21 @@ namespace Nvidia.TextureTools
|
||||
nvttSetOutputOptionsOutputHeader(options, b);
|
||||
}
|
||||
|
||||
// @@ Add OutputHandler interface.
|
||||
public void SetOutputHandler(BeginImageDelegate beginImage, WriteDataDelegate writeImage, EndImageDelegate endImage)
|
||||
{
|
||||
IntPtr ptrBeginImage = IntPtr.Zero;
|
||||
IntPtr ptrWriteData = IntPtr.Zero;
|
||||
IntPtr ptrEndImage = IntPtr.Zero;
|
||||
|
||||
if (beginImage != null || writeImage != null || endImage != null)
|
||||
{
|
||||
ptrBeginImage = Marshal.GetFunctionPointerForDelegate(beginImage);
|
||||
ptrWriteData = Marshal.GetFunctionPointerForDelegate(writeImage);
|
||||
ptrEndImage = Marshal.GetFunctionPointerForDelegate(endImage);
|
||||
}
|
||||
|
||||
nvttSetOutputOptionsOutputHandler(options, ptrBeginImage, ptrWriteData, ptrEndImage);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -117,6 +117,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hdrtest", "hdrtest\hdrtest.
|
||||
{4046F392-A18B-4C66-9639-3EABFFF5D531} = {4046F392-A18B-4C66-9639-3EABFFF5D531}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hlslparser", "hlslparser\hlslparser.vcproj", "{FEBA8AE3-0628-4870-B087-05A4974F0729}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bc7", "bc7\bc7.vcproj", "{F974F34B-AF02-4C88-8E1E-85475094EA78}"
|
||||
EndProject
|
||||
Global
|
||||
@ -419,6 +421,26 @@ Global
|
||||
{E493E368-A4CF-4A8D-99DD-E128CC3A27EF}.Release-CUDA|Win32.Build.0 = Release|Win32
|
||||
{E493E368-A4CF-4A8D-99DD-E128CC3A27EF}.Release-CUDA|x64.ActiveCfg = Release|x64
|
||||
{E493E368-A4CF-4A8D-99DD-E128CC3A27EF}.Release-CUDA|x64.Build.0 = Release|x64
|
||||
{FEBA8AE3-0628-4870-B087-05A4974F0729}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
|
||||
{FEBA8AE3-0628-4870-B087-05A4974F0729}.Debug|Mixed Platforms.Build.0 = Debug|Win32
|
||||
{FEBA8AE3-0628-4870-B087-05A4974F0729}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{FEBA8AE3-0628-4870-B087-05A4974F0729}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{FEBA8AE3-0628-4870-B087-05A4974F0729}.Debug|x64.ActiveCfg = Debug|Win32
|
||||
{FEBA8AE3-0628-4870-B087-05A4974F0729}.Debug-CUDA|Mixed Platforms.ActiveCfg = Debug|Win32
|
||||
{FEBA8AE3-0628-4870-B087-05A4974F0729}.Debug-CUDA|Mixed Platforms.Build.0 = Debug|Win32
|
||||
{FEBA8AE3-0628-4870-B087-05A4974F0729}.Debug-CUDA|Win32.ActiveCfg = Debug|Win32
|
||||
{FEBA8AE3-0628-4870-B087-05A4974F0729}.Debug-CUDA|Win32.Build.0 = Debug|Win32
|
||||
{FEBA8AE3-0628-4870-B087-05A4974F0729}.Debug-CUDA|x64.ActiveCfg = Debug|Win32
|
||||
{FEBA8AE3-0628-4870-B087-05A4974F0729}.Release|Mixed Platforms.ActiveCfg = Release|Win32
|
||||
{FEBA8AE3-0628-4870-B087-05A4974F0729}.Release|Mixed Platforms.Build.0 = Release|Win32
|
||||
{FEBA8AE3-0628-4870-B087-05A4974F0729}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{FEBA8AE3-0628-4870-B087-05A4974F0729}.Release|Win32.Build.0 = Release|Win32
|
||||
{FEBA8AE3-0628-4870-B087-05A4974F0729}.Release|x64.ActiveCfg = Release|Win32
|
||||
{FEBA8AE3-0628-4870-B087-05A4974F0729}.Release-CUDA|Mixed Platforms.ActiveCfg = Release|Win32
|
||||
{FEBA8AE3-0628-4870-B087-05A4974F0729}.Release-CUDA|Mixed Platforms.Build.0 = Release|Win32
|
||||
{FEBA8AE3-0628-4870-B087-05A4974F0729}.Release-CUDA|Win32.ActiveCfg = Release|Win32
|
||||
{FEBA8AE3-0628-4870-B087-05A4974F0729}.Release-CUDA|Win32.Build.0 = Release|Win32
|
||||
{FEBA8AE3-0628-4870-B087-05A4974F0729}.Release-CUDA|x64.ActiveCfg = Release|Win32
|
||||
{F974F34B-AF02-4C88-8E1E-85475094EA78}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{F974F34B-AF02-4C88-8E1E-85475094EA78}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{F974F34B-AF02-4C88-8E1E-85475094EA78}.Debug|x64.ActiveCfg = Debug|x64
|
||||
|
@ -78,6 +78,8 @@ namespace nvtt
|
||||
bool srgb;
|
||||
bool deleteOutputHandler;
|
||||
|
||||
void * wrapperProxy; // For the C/C# wrapper.
|
||||
|
||||
bool hasValidOutputHandler() const;
|
||||
|
||||
void beginImage(int size, int width, int height, int depth, int face, int miplevel) const;
|
||||
|
@ -73,8 +73,9 @@ namespace nvtt
|
||||
|
||||
// Supported compression formats.
|
||||
// @@ I wish I had distinguished between "formats" and compressors.
|
||||
// That is, 'DXT1' is a format 'DXT1a' and 'DXT1n' are DXT1 compressors.
|
||||
// That is, 'DXT3' is a format 'DXT3n' is a DXT3 compressor.
|
||||
// That is:
|
||||
// - 'DXT1' is a format 'DXT1a' and 'DXT1n' are DXT1 compressors.
|
||||
// - 'DXT3' is a format 'DXT3n' is a DXT3 compressor.
|
||||
// Having multiple enums for the same ids only creates confusion. Clean this up.
|
||||
enum Format
|
||||
{
|
||||
@ -98,13 +99,11 @@ namespace nvtt
|
||||
Format_BC4, // ATI1
|
||||
Format_BC5, // 3DC, ATI2
|
||||
|
||||
Format_DXT1n, // Not supported on CPU yet.
|
||||
Format_CTX1, // Not supported on CPU yet.
|
||||
Format_DXT1n, // Not supported.
|
||||
Format_CTX1, // Not supported.
|
||||
|
||||
Format_BC6,
|
||||
Format_BC7,
|
||||
|
||||
Format_DXT1_Luma,
|
||||
};
|
||||
|
||||
// Pixel types. These basically indicate how the output should be interpreted, but do not have any influence over the input. They are only relevant in RGBA mode.
|
||||
@ -133,7 +132,6 @@ namespace nvtt
|
||||
Decoder_D3D10,
|
||||
Decoder_D3D9,
|
||||
Decoder_NV5x,
|
||||
//Decoder_RSX, // To take advantage of DXT5 bug.
|
||||
};
|
||||
|
||||
|
||||
@ -163,7 +161,7 @@ namespace nvtt
|
||||
NVTT_API void setPitchAlignment(int pitchAlignment);
|
||||
|
||||
// @@ I wish this wasn't part of the compression options. Quantization is applied before compression. We don't have compressors with error diffusion.
|
||||
NVTT_API void setQuantization(bool colorDithering, bool alphaDithering, bool binaryAlpha, int alphaThreshold = 127);
|
||||
NVTT_API void setQuantization(bool colorDithering, bool alphaDithering, bool binaryAlpha, int alphaThreshold = 127); // (Deprecated in NVTT 2.1)
|
||||
|
||||
NVTT_API void setTargetDecoder(Decoder decoder);
|
||||
|
||||
@ -243,7 +241,7 @@ namespace nvtt
|
||||
AlphaMode_Premultiplied,
|
||||
};
|
||||
|
||||
// Input options. Specify format and layout of the input texture.
|
||||
// Input options. Specify format and layout of the input texture. (Deprecated in NVTT 2.1)
|
||||
struct InputOptions
|
||||
{
|
||||
NVTT_FORBID_COPY(InputOptions);
|
||||
@ -303,7 +301,7 @@ namespace nvtt
|
||||
// Output data. Compressed data is output as soon as it's generated to minimize memory allocations.
|
||||
virtual bool writeData(const void * data, int size) = 0;
|
||||
|
||||
// Indicate the end of a the compressed image.
|
||||
// Indicate the end of a the compressed image. (New in NVTT 2.1)
|
||||
virtual void endImage() = 0;
|
||||
};
|
||||
|
||||
@ -363,8 +361,10 @@ namespace nvtt
|
||||
NVTT_API void setSrgbFlag(bool b);
|
||||
};
|
||||
|
||||
// (New in NVTT 2.1)
|
||||
typedef void Task(void * context, int id);
|
||||
|
||||
// (New in NVTT 2.1)
|
||||
struct TaskDispatcher
|
||||
{
|
||||
virtual void dispatch(Task * task, void * context, int count) = 0;
|
||||
@ -382,23 +382,23 @@ namespace nvtt
|
||||
// Context settings.
|
||||
NVTT_API void enableCudaAcceleration(bool enable);
|
||||
NVTT_API bool isCudaAccelerationEnabled() const;
|
||||
NVTT_API void setTaskDispatcher(TaskDispatcher * disp);
|
||||
NVTT_API void setTaskDispatcher(TaskDispatcher * disp); // (New in NVTT 2.1)
|
||||
|
||||
// InputOptions API.
|
||||
NVTT_API bool process(const InputOptions & inputOptions, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const;
|
||||
NVTT_API int estimateSize(const InputOptions & inputOptions, const CompressionOptions & compressionOptions) const;
|
||||
|
||||
// Surface API.
|
||||
// Surface API. (New in NVTT 2.1)
|
||||
NVTT_API bool outputHeader(const Surface & img, int mipmapCount, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const;
|
||||
NVTT_API bool compress(const Surface & img, int face, int mipmap, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const;
|
||||
NVTT_API int estimateSize(const Surface & img, int mipmapCount, const CompressionOptions & compressionOptions) const;
|
||||
|
||||
// CubeSurface API.
|
||||
// CubeSurface API. (New in NVTT 2.1)
|
||||
NVTT_API bool outputHeader(const CubeSurface & cube, int mipmapCount, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const;
|
||||
NVTT_API bool compress(const CubeSurface & cube, int mipmap, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const;
|
||||
NVTT_API int estimateSize(const CubeSurface & cube, int mipmapCount, const CompressionOptions & compressionOptions) const;
|
||||
|
||||
// Raw API.
|
||||
// Raw API. (New in NVTT 2.1)
|
||||
NVTT_API bool outputHeader(TextureType type, int w, int h, int d, int mipmapCount, bool isNormalMap, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const;
|
||||
NVTT_API bool compress(int w, int h, int d, int face, int mipmap, const float * rgba, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const;
|
||||
NVTT_API int estimateSize(int w, int h, int d, int mipmapCount, const CompressionOptions & compressionOptions) const;
|
||||
@ -407,6 +407,7 @@ namespace nvtt
|
||||
// "Compressor" is deprecated. This should have been called "Context"
|
||||
typedef Compressor Context;
|
||||
|
||||
// (New in NVTT 2.1)
|
||||
enum NormalTransform {
|
||||
NormalTransform_Orthographic,
|
||||
NormalTransform_Stereographic,
|
||||
@ -415,6 +416,7 @@ namespace nvtt
|
||||
//NormalTransform_DualParaboloid,
|
||||
};
|
||||
|
||||
// (New in NVTT 2.1)
|
||||
enum ToneMapper {
|
||||
ToneMapper_Linear,
|
||||
ToneMapper_Reindhart,
|
||||
@ -422,15 +424,8 @@ namespace nvtt
|
||||
ToneMapper_Lightmap,
|
||||
};
|
||||
|
||||
/*enum ChannelMask {
|
||||
R = 0x70000001,
|
||||
G = 0x70000002,
|
||||
B = 0x70000004,
|
||||
A = 0x70000008,
|
||||
};*/
|
||||
|
||||
// A surface is one level of a 2D or 3D texture.
|
||||
// @@ It would be nice to add support for texture borders for correct resizing of tiled textures and constrained DXT compression.
|
||||
// A surface is one level of a 2D or 3D texture. (New in NVTT 2.1)
|
||||
struct Surface
|
||||
{
|
||||
NVTT_API Surface();
|
||||
@ -559,7 +554,7 @@ namespace nvtt
|
||||
};
|
||||
|
||||
|
||||
// Cube layout formats.
|
||||
// Cube layout formats. (New in NVTT 2.1)
|
||||
enum CubeLayout {
|
||||
CubeLayout_VerticalCross,
|
||||
CubeLayout_HorizontalCross,
|
||||
@ -568,6 +563,7 @@ namespace nvtt
|
||||
CubeLayout_LatitudeLongitude
|
||||
};
|
||||
|
||||
// (New in NVTT 2.1)
|
||||
enum EdgeFixup {
|
||||
EdgeFixup_None,
|
||||
EdgeFixup_Stretch,
|
||||
@ -575,7 +571,7 @@ namespace nvtt
|
||||
EdgeFixup_Average,
|
||||
};
|
||||
|
||||
// A CubeSurface is one level of a cube map texture.
|
||||
// A CubeSurface is one level of a cube map texture. (New in NVTT 2.1)
|
||||
struct CubeSurface
|
||||
{
|
||||
NVTT_API CubeSurface();
|
||||
@ -645,6 +641,7 @@ namespace nvtt
|
||||
// Return NVTT version.
|
||||
NVTT_API unsigned int version();
|
||||
|
||||
// Image comparison and error measurement functions. (New in NVTT 2.1)
|
||||
NVTT_API float rmsError(const Surface & reference, const Surface & img);
|
||||
NVTT_API float rmsAlphaError(const Surface & reference, const Surface & img);
|
||||
NVTT_API float cieLabError(const Surface & reference, const Surface & img);
|
||||
|
@ -25,6 +25,47 @@
|
||||
#include "nvtt.h"
|
||||
#include "nvtt_wrapper.h"
|
||||
|
||||
#include "OutputOptions.h"
|
||||
|
||||
// An OutputHandler that sets and calls function pointers, rather than
|
||||
// requiring interfaces to derive from OutputHandler itself
|
||||
struct HandlerProxy : public nvtt::OutputHandler
|
||||
{
|
||||
public:
|
||||
|
||||
HandlerProxy() {}
|
||||
|
||||
nvttBeginImageHandler beginImageHandler;
|
||||
nvttOutputHandler writeDataHandler;
|
||||
nvttEndImageHandler endImageHandler;
|
||||
|
||||
virtual void beginImage(int size, int width, int height, int depth, int face, int miplevel)
|
||||
{
|
||||
if (beginImageHandler != NULL)
|
||||
{
|
||||
beginImageHandler(size, width, height, depth, face, miplevel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
virtual bool writeData(const void * data, int size)
|
||||
{
|
||||
if (writeDataHandler != NULL)
|
||||
{
|
||||
return writeDataHandler(data, size);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void endImage()
|
||||
{
|
||||
if (endImageHandler != NULL)
|
||||
{
|
||||
endImageHandler();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// InputOptions class.
|
||||
NvttInputOptions * nvttCreateInputOptions()
|
||||
@ -151,7 +192,7 @@ void nvttSetCompressionOptionsColorWeights(NvttCompressionOptions * compressionO
|
||||
|
||||
/*void nvttEnableCompressionOptionsCudaCompression(NvttCompressionOptions * compressionOptions, NvttBoolean enable)
|
||||
{
|
||||
compressionOptions->enableCudaCompression(enable != NVTT_False);
|
||||
compressionOptions->enableCudaCompression(enable != NVTT_False);
|
||||
}*/
|
||||
|
||||
void nvttSetCompressionOptionsPixelFormat(NvttCompressionOptions * compressionOptions, unsigned int bitcount, unsigned int rmask, unsigned int gmask, unsigned int bmask, unsigned int amask)
|
||||
@ -168,11 +209,18 @@ void nvttSetCompressionOptionsQuantization(NvttCompressionOptions * compressionO
|
||||
// OutputOptions class.
|
||||
NvttOutputOptions * nvttCreateOutputOptions()
|
||||
{
|
||||
return new nvtt::OutputOptions();
|
||||
nvtt::OutputOptions * outputOptions = new nvtt::OutputOptions();
|
||||
HandlerProxy * handlerProxy = new HandlerProxy();
|
||||
|
||||
outputOptions->m.wrapperProxy = handlerProxy;
|
||||
|
||||
return outputOptions;
|
||||
}
|
||||
|
||||
void nvttDestroyOutputOptions(NvttOutputOptions * outputOptions)
|
||||
{
|
||||
HandlerProxy * handlerProxy = (HandlerProxy *)outputOptions->m.wrapperProxy;
|
||||
delete handlerProxy;
|
||||
delete outputOptions;
|
||||
}
|
||||
|
||||
@ -190,12 +238,26 @@ void nvttSetOutputOptionsErrorHandler(NvttOutputOptions * outputOptions, nvttErr
|
||||
{
|
||||
outputOptions->setErrorHandler(errorHandler);
|
||||
}
|
||||
|
||||
void nvttSetOutputOptionsOutputHandler(NvttOutputOptions * outputOptions, nvttOutputHandler outputHandler, nvttImageHandler imageHandler)
|
||||
{
|
||||
}
|
||||
*/
|
||||
|
||||
void nvttSetOutputOptionsOutputHandler(NvttOutputOptions * outputOptions, nvttBeginImageHandler beginImageHandler, nvttOutputHandler writeDataHandler, nvttEndImageHandler endImageHandler)
|
||||
{
|
||||
HandlerProxy * handler = (HandlerProxy *)outputOptions->m.wrapperProxy;
|
||||
|
||||
handler->beginImageHandler = beginImageHandler;
|
||||
handler->writeDataHandler = writeDataHandler;
|
||||
handler->endImageHandler = endImageHandler;
|
||||
|
||||
if(beginImageHandler == NULL && writeDataHandler == NULL && endImageHandler == NULL)
|
||||
{
|
||||
outputOptions->setOutputHandler(NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
outputOptions->setOutputHandler(handler);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Compressor class.
|
||||
NvttCompressor * nvttCreateCompressor()
|
||||
|
@ -166,8 +166,9 @@ extern "C" {
|
||||
|
||||
// Callbacks
|
||||
//typedef void (* nvttErrorHandler)(NvttError e);
|
||||
//typedef void (* nvttOutputHandler)(const void * data, int size);
|
||||
//typedef void (* nvttImageHandler)(int size, int width, int height, int depth, int face, int miplevel);
|
||||
typedef void (* nvttBeginImageHandler)(int size, int width, int height, int depth, int face, int miplevel);
|
||||
typedef bool (* nvttOutputHandler)(const void * data, int size);
|
||||
typedef void (* nvttEndImageHandler)();
|
||||
|
||||
|
||||
// InputOptions class.
|
||||
@ -211,7 +212,7 @@ NVTT_API void nvttDestroyOutputOptions(NvttOutputOptions * outputOptions);
|
||||
NVTT_API void nvttSetOutputOptionsFileName(NvttOutputOptions * outputOptions, const char * fileName);
|
||||
NVTT_API void nvttSetOutputOptionsOutputHeader(NvttOutputOptions * outputOptions, NvttBoolean b);
|
||||
//NVTT_API void nvttSetOutputOptionsErrorHandler(NvttOutputOptions * outputOptions, nvttErrorHandler errorHandler);
|
||||
//NVTT_API void nvttSetOutputOptionsOutputHandler(NvttOutputOptions * outputOptions, nvttOutputHandler outputHandler, nvttImageHandler imageHandler);
|
||||
NVTT_API void nvttSetOutputOptionsOutputHandler(NvttOutputOptions * outputOptions, nvttBeginImageHandler beginImageHandler, nvttOutputHandler outputHandler, nvttEndImageHandler endImageHandler);
|
||||
|
||||
|
||||
// Compressor class.
|
||||
|
Loading…
Reference in New Issue
Block a user