NVidia.nvDXT module
BlitzMax Forums/BlitzMax Programming/NVidia.nvDXT module
| ||
I thought it would be neat to compile a module of NVidia's nvDXT library. This library compresses image data to make .dds textures. The library is pretty simple, but I need help getting it started. I tried importing one of the .lib files and externing functions, but they aren't found. I packaged up my code, all .libs (there are a lot of versions) and the help docs here: http://www.leadwerks.com/post/nvDXT.zip If anyone can help with this, I would appreciate it. |
| ||
That would be because you can't import .lib files. You have to convert them to .a by some means. |
| ||
Yes you can. I import a .lib file in my Newton module. |
| ||
If it's C++ compiled with MSVC you'll not get very far without lots of wrapping code :-) |
| ||
What are the libs with "DLL" in the name, like "nvDXTlibMTDLL.vc8.lib"? Is that for compiling a dll? I found something called nvDXT_DLL in the Photoshop plugin folder. I zipped it up and posted it here: http://www.leadwerks.com/post/dxtlib_dll.zip Is this straight source for compiling a dll? |
| ||
Typically, if a library has "DLL" in its name, then it's providing an interface to a DLL in a way that is the same as if you were to statically link the library. In this case, that would be for the nvDXTlib multi-threaded DLL compiled with Visual Studio 2005. You cannot use them with MinGW (since you seem to not know these things, that's the set of tools BlitzMax uses for importing other things, like C++ code, libraries, and other such things), last I checked. I believe the only version of Visual C++ that produces libraries that MinGW can handle is VC6. To answer the question about the "straight source" or whatever: no. Did you even look at it? |
| ||
Okay. NVidia Texture Tools 2 has a dll that it looks like contains all the same functionality...nvtt.dll. I can't find any documentation on it, but here's a dump of the dll functions:================================================== Function Name : ??0CompressionOptions@nvtt@@QAE@XZ Address : 0x10001b90 Relative Address : 0x00001b90 Ordinal : 1 (0x1) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ??0InputOptions@nvtt@@QAE@XZ Address : 0x100059a0 Relative Address : 0x000059a0 Ordinal : 2 (0x2) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ??1CompressionOptions@nvtt@@QAE@XZ Address : 0x10001c60 Relative Address : 0x00001c60 Ordinal : 3 (0x3) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ??1InputOptions@nvtt@@QAE@XZ Address : 0x100059e0 Relative Address : 0x000059e0 Ordinal : 4 (0x4) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ?compress@nvtt@@YA_NABUInputOptions@1@ABUOutputOptions@1@ABVCompressionOptions@1@@Z Address : 0x100032d0 Relative Address : 0x000032d0 Ordinal : 5 (0x5) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ?enableHardwareCompression@CompressionOptions@nvtt@@QAEX_N@Z Address : 0x10001d80 Relative Address : 0x00001d80 Ordinal : 6 (0x6) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ?errorString@nvtt@@YAPBDW4Error@1@@Z Address : 0x10003780 Relative Address : 0x00003780 Ordinal : 7 (0x7) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ?estimateSize@nvtt@@YAHABUInputOptions@1@ABVCompressionOptions@1@@Z Address : 0x10003640 Relative Address : 0x00003640 Ordinal : 8 (0x8) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ?reset@CompressionOptions@nvtt@@QAEXXZ Address : 0x10001cb0 Relative Address : 0x00001cb0 Ordinal : 9 (0x9) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ?reset@InputOptions@nvtt@@QAEXXZ Address : 0x10005a40 Relative Address : 0x00005a40 Ordinal : 10 (0xa) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ?reset@OutputOptions@nvtt@@QAEXXZ Address : 0x10006110 Relative Address : 0x00006110 Ordinal : 11 (0xb) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ?resetTextureLayout@InputOptions@nvtt@@QAEXXZ Address : 0x10005e10 Relative Address : 0x00005e10 Ordinal : 12 (0xc) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ?setColorWeights@CompressionOptions@nvtt@@QAEXMMM@Z Address : 0x10001d30 Relative Address : 0x00001d30 Ordinal : 13 (0xd) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ?setConvertToNormalMap@InputOptions@nvtt@@QAEX_N@Z Address : 0x10006040 Relative Address : 0x00006040 Ordinal : 14 (0xe) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ?setExternalCompressor@CompressionOptions@nvtt@@QAEXPBD@Z Address : 0x10001dc0 Relative Address : 0x00001dc0 Ordinal : 15 (0xf) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ?setFormat@CompressionOptions@nvtt@@QAEXW4Format@2@@Z Address : 0x10001d00 Relative Address : 0x00001d00 Ordinal : 16 (0x10) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ?setFormat@InputOptions@nvtt@@QAEXW4InputFormat@2@_N@Z Address : 0x10005fa0 Relative Address : 0x00005fa0 Ordinal : 17 (0x11) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ?setGamma@InputOptions@nvtt@@QAEXMM@Z Address : 0x10005fc0 Relative Address : 0x00005fc0 Ordinal : 18 (0x12) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ?setHeightEvaluation@InputOptions@nvtt@@QAEXMMMM@Z Address : 0x10006050 Relative Address : 0x00006050 Ordinal : 19 (0x13) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ?setMipmapData@InputOptions@nvtt@@QAE_NPBXHHHHH@Z Address : 0x10005e60 Relative Address : 0x00005e60 Ordinal : 20 (0x14) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ?setMipmapping@InputOptions@nvtt@@QAEX_NW4MipmapFilter@2@H@Z Address : 0x10005fe0 Relative Address : 0x00005fe0 Ordinal : 21 (0x15) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ?setNormalFilter@InputOptions@nvtt@@QAEXMMMM@Z Address : 0x10006080 Relative Address : 0x00006080 Ordinal : 22 (0x16) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ?setNormalizeMipmaps@InputOptions@nvtt@@QAEX_N@Z Address : 0x10006100 Relative Address : 0x00006100 Ordinal : 24 (0x18) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ?setNormalMap@InputOptions@nvtt@@QAEX_N@Z Address : 0x10006030 Relative Address : 0x00006030 Ordinal : 23 (0x17) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ?setPixelFormat@CompressionOptions@nvtt@@QAEXIIIII@Z Address : 0x10001d90 Relative Address : 0x00001d90 Ordinal : 25 (0x19) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ?setQuality@CompressionOptions@nvtt@@QAEXW4Quality@2@M@Z Address : 0x10001d10 Relative Address : 0x00001d10 Ordinal : 26 (0x1a) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ?setQuantization@InputOptions@nvtt@@QAEX_N00H@Z Address : 0x10006000 Relative Address : 0x00006000 Ordinal : 27 (0x1b) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ?setTextureLayout@InputOptions@nvtt@@QAEXW4TextureType@2@HHH@Z Address : 0x10005ae0 Relative Address : 0x00005ae0 Ordinal : 28 (0x1c) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== ================================================== Function Name : ?setWrapMode@InputOptions@nvtt@@QAEXW4WrapMode@2@@Z Address : 0x10001d00 Relative Address : 0x00001d00 Ordinal : 29 (0x1d) Filename : nvtt.dll Full Path : C:\Program Files\NVIDIA Corporation\NVIDIA Texture Tools 2\bin\nvtt.dll ================================================== |
| ||
You have the header file and you have the DLL. What more documentation do you need for it? :-) The DLL works the same as the library, just that you will have to put the dll into your apps directory in the end instead of raising the size of your app |
| ||
Well, I think this is the right header file, but it's a long shot from making sense. I guess the tricky part would be the structures...it looks like they have a few structures that have to be passed to the dll for options and something else: // Copyright NVIDIA Corporation 2007 -- Ignacio Castano <icastano@...; // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation // files (the "Software"), to deal in the Software without // restriction, including without limitation the rights to use, // copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following // conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. #ifndef NV_TT_H #define NV_TT_H #include <nvcore/nvcore.h> //#define HAVE_S3QUANT //#define HAVE_ATITC // Function linkage #if NVTT_SHARED #ifdef NVTT_EXPORTS #define NVTT_API DLL_EXPORT #define NVTT_CLASS DLL_EXPORT_CLASS #else #define NVTT_API DLL_IMPORT #define NVTT_CLASS DLL_IMPORT #endif #else #define NVTT_API #define NVTT_CLASS #endif // Public interface. namespace nvtt { /// Supported compression formats. enum Format { // No compression. Format_RGB, Format_RGBA = Format_RGB, // DX9 formats. Format_DXT1, // Format_DXT1a, // DXT1 with binary alpha. Format_DXT3, Format_DXT5, Format_DXT5n, // Compressed HILO: R=0, G=x, B=0, A=y // DX10 formats. Format_BC1 = Format_DXT1, Format_BC2 = Format_DXT3, Format_BC3 = Format_DXT5, Format_BC3n = Format_DXT5n, Format_BC4, // ATI1 Format_BC5, // 3DC, ATI2 // OpenGL formats. Format_LATC = Format_BC5, }; /// Quality modes. enum Quality { Quality_Fastest, Quality_Normal, Quality_Production, Quality_Highest, }; /// Compression options. This class describes the desired compression format and other compression settings. class CompressionOptions { public: NVTT_API CompressionOptions(); NVTT_API ~CompressionOptions(); NVTT_API void reset(); NVTT_API void setFormat(Format format); NVTT_API void setQuality(Quality quality, float errorThreshold = 0.5f); NVTT_API void setColorWeights(float red, float green, float blue); NVTT_API void enableHardwareCompression(bool enable); NVTT_API void setExternalCompressor(const char * name); // Set color mask to describe the RGB/RGBA format. NVTT_API void setPixelFormat(uint bitcount, uint rmask, uint gmask, uint bmask, uint amask); //private: struct Private; Private & m; }; /// Wrap modes. // This matches FloatImage::WrapMode. enum WrapMode { WrapMode_Clamp, WrapMode_Repeat, WrapMode_Mirror, }; /// Texture types. enum TextureType { TextureType_2D, TextureType_Cube, // TextureType_3D, }; /// Input formats. enum InputFormat { InputFormat_BGRA_8UB, // InputFormat_RGBE_8UB, // InputFormat_BGRA_32F, }; /// Mipmap downsampling filters. enum MipmapFilter { MipmapFilter_Box, ///< Box filter is quite good and very fast. MipmapFilter_Triangle, ///< Triangle filter blurs the results too much, but that might be what you want. MipmapFilter_Kaiser, ///< Kaiser-windowed Sinc filter is the best downsampling filter. }; /// Input options. Specify format and layout of the input texture. struct InputOptions { NVTT_API InputOptions(); NVTT_API ~InputOptions(); // Set default options. NVTT_API void reset(); // Setup input layout. NVTT_API void setTextureLayout(TextureType type, int w, int h, int d = 1); NVTT_API void resetTextureLayout(); // Set mipmap data. Copies the data. NVTT_API bool setMipmapData(const void * data, int w, int h, int d = 1, int face = 0, int mipmap = 0); // Describe the format of the input. NVTT_API void setFormat(InputFormat fmt, bool alphaTransparency); // Set gamma settings. NVTT_API void setGamma(float inputGamma, float outputGamma); // Set texture wrappign mode. NVTT_API void setWrapMode(WrapMode mode); // Set mipmapping options. NVTT_API void setMipmapping(bool generateMipmaps, MipmapFilter filter = MipmapFilter_Kaiser, int maxLevel = -1); // Set quantization options. NVTT_API void setQuantization(bool colorDithering, bool alphaDithering, bool binaryAlpha, int alphaThreshold = 127); // Set normal map options. NVTT_API void setNormalMap(bool b); NVTT_API void setConvertToNormalMap(bool convert); NVTT_API void setHeightEvaluation(float redScale, float greenScale, float blueScale, float alphaScale); NVTT_API void setNormalFilter(float small, float medium, float big, float large); NVTT_API void setNormalizeMipmaps(bool b); //private: struct Private; Private & m; }; /// Output handler. struct OutputHandler { virtual ~OutputHandler() {} /// Indicate the start of a new compressed image that's part of the final texture. virtual void mipmap(int size, int width, int height, int depth, int face, int miplevel) = 0; /// Output data. Compressed data is output as soon as it's generated to minimize memory allocations. virtual void writeData(const void * data, int size) = 0; }; /// Error codes. enum Error { Error_InvalidInput, Error_UserInterruption, Error_UnsupportedFeature, Error_CudaError, Error_Unknown, }; /// Error handler. struct ErrorHandler { virtual ~ErrorHandler() {} // Signal error. virtual void error(Error e) = 0; }; /// Output Options. This class holds pointers to the interfaces that are used to report the output of /// the compressor to the user. struct OutputOptions { OutputOptions() : outputHandler(NULL), outputHeader(true) { reset(); } OutputOptions(OutputHandler * oh, ErrorHandler * eh) : outputHandler(oh), errorHandler(eh), outputHeader(true) { reset(); } // Set default options. NVTT_API void reset(); OutputHandler * outputHandler; ErrorHandler * errorHandler; bool outputHeader; }; // Main entrypoint of the compression library. NVTT_API bool compress(const InputOptions & inputOptions, const OutputOptions & outputOptions, const CompressionOptions & compressionOptions); // Estimate the size of compressing the input with the given options. NVTT_API int estimateSize(const InputOptions & inputOptions, const CompressionOptions & compressionOptions); // Return string for the given error. NVTT_API const char * errorString(Error e); } // nvtt namespace #endif // NV_TT_H |
| ||
I believe the only version of Visual C++ that produces libraries that MinGW can handle is VC6. Not my version of it. Any non "C" extern functions are mangled in a non-MinGW compatible way. Therefore, any API exposed thru the DLL or lib must be extern "C"'d to work. If the API is exposed without extern "C", then the only option I can see is to either : 1) wrap the functions using extern "C", and create your own version of the DLL using MSVC. This is known to work. 2) try and compile the code in MinGW. Seeing as the latest Texture tools are cross-platform, you may be able to compile it with GCC on Win32. |
| ||
Isn't that exactly the point of Extern "Win32" instead of Extern "C" to be able to use mangled DLLs at least? |
| ||
If you can get MSVC++ mangled names to work with MinGW you will become the messiah of a large group of developers working on Win32 ;-) I was of the assumption that Extern "Win32" simply worked around the @8 etc naming convention ? btw, my comments regarding 'extern "C"' in my previous post is specifically concerning C++ code, not Max. ie extern "C" { ... } Anyhoo.... if it's not C++ then there's nothing to worry about :-) |
| ||
Well, this is beyond the scope of my expertise. If anyone makes any progress with it, give me an email. |
| ||
Let's see how long this takes me. |
| ||
If you are able to get this working, I would like to make a new build of my "TGATool" app. This lets you calculate or load an alpha channel for any texture, calculate a bumpmap, etc. I think I would call it "Texture Tool" now. But if I can't save .dds files directly it's not worth it. |
| ||
The lead developer of the texture tools at NVidia has emailed me to point out that extensive documentation is available here: http://code.google.com/p/nvidia-texture-tools/wiki/ApiDocumentation He's also offered to assist with the creation of a wrapper. Hopefully he'll appear here soon. |
| ||
I've got a bunch of it done, just haven't had a chance to test it, nor do I have a whole lot of time between classes right now. |
| ||
Classes Noel? I thought you knew everything? ;-) |
| ||
Remind me why I'm bothering to help anyone again? |
| ||
Because this would benefit many people and allow some cool new apps to be made. |
| ||
Hi, I'm the lead programmer of the NVIDIA Texture Tools. As simonh pointed out, there's extensive documentation available at: http://code.google.com/p/nvidia-texture-tools/wiki/ApiDocumentation The documentation is not complete yet, but already provides a good overview of all the functionality. The full source code is available at the google code project under the MIT license, so you can also look at it if the documentation is not clear enough. We also have a google discussion group, where you can ask questions or send feedback: http://groups.google.com/group/nvidia-texture-tools Feel free to file bugs if you have specific requests: http://code.google.com/p/nvidia-texture-tools/issues/list As Leadwerks pointed out, all the public functions are in the nvtt.h header file. I think it should be relatively easy to create a C wrapper for the C++ API, it shouldn't have more than ~30 functions. I know it's a bit tedious... I'd be happy to start the wrapper, and add the basic functions to it, if somebody agrees to complete and maintain it. I'd also appreciate your feedback regarding the API and what could be done in the future to interface it more easily with other languages. Thanks! |
| ||
Opportunity is knocking for someone with more time than me. BlitzMax will only have problems with the C++ structures. All other variables and pointers will work fine. I may be biased because of the above, but I think that object-oriented programming is good for your own programming, but not so good for the final end user's API. I've learned to just use my wonderful class structures for my own internal coding, and then give my users a simple procedural interface to work with. |
| ||
but not so good for the final end user's API. Can't say I've had any complaints. Although I guess it's all to do with where you are coming from. If you are used to OOP, then it's completely natural to use an class type hierarchical structure to access an API. It also separates functionality into smaller, related chunks. Of course, 30 functions is not much as far as wrappers go :-) |
| ||
Well, since one of the people actually working on the library is here, I'll let him start on the wrapper and see how he handles it. Plus it gives my fingers a break, since I didn't bother to write a script for this. Of course, 30 functions is not much as far as wrappers go :-) Testing, on the other hand, is a real pain. |
| ||
You probably don't need to do that much testing for something like this. It's just a wrapper, so as long as the syntax is followed everything will be fine. |
| ||
An initial version of the wrapper is available here: http://nvidia-texture-tools.googlecode.com/svn/trunk/src/nvtt/nvtt_wrapper.h http://nvidia-texture-tools.googlecode.com/svn/trunk/src/nvtt/nvtt_wrapper.cpp It's not functional yet, but I'll try to make it have it working and write an example during the weekend. |
| ||
Do the Texture Tools 2 handle cubemap generation like nvdxt.exe does? I can't help with the library, but I would like to make a GUI front-end for some of the command-line tools. |
| ||
The nvtt library supports compression and generation of cube maps. The nvcompress command line tool does not allow you to provide separate images for each of the cube map faces, but allows you to provide cube maps as DDS files. The nvassemble command line tool allows you to assemble a cube map from different images, so you can generate a cube map in two steps. First assemble it with nvassemble, that produces a DDS file that you can then compress with nvcompress. |
| ||
Any news on this module? |
| ||
Did this ever come to anything? |