2007-05-17 00:11:38 +00:00
|
|
|
// Copyright NVIDIA Corporation 2007 -- Ignacio Castano <icastano@nvidia.com>
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
|
|
|
// Function linkage
|
|
|
|
#if NVTT_SHARED
|
2008-01-07 19:08:17 +00:00
|
|
|
|
|
|
|
#if defined _WIN32 || defined WIN32 || defined __NT__ || defined __WIN32__ || defined __MINGW32__
|
|
|
|
# ifdef NVTT_EXPORTS
|
|
|
|
# define NVTT_API __declspec(dllexport)
|
|
|
|
# else
|
|
|
|
# define NVTT_API __declspec(dllimport)
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined __GNUC__ >= 4
|
|
|
|
# ifdef NVTT_EXPORTS
|
|
|
|
# define NVTT_API __attribute__((visibility("default")))
|
|
|
|
# endif
|
2007-05-17 00:11:38 +00:00
|
|
|
#endif
|
2008-01-07 19:08:17 +00:00
|
|
|
|
|
|
|
#endif // NVTT_SHARED
|
|
|
|
|
|
|
|
#if !defined NVTT_API
|
|
|
|
# define NVTT_API
|
2007-05-17 00:11:38 +00:00
|
|
|
#endif
|
|
|
|
|
2008-02-05 00:28:13 +00:00
|
|
|
#define NVTT_VERSION 200
|
|
|
|
|
2008-02-28 21:14:40 +00:00
|
|
|
#define NVTT_DECLARE_PIMPL(Class) \
|
|
|
|
private: \
|
|
|
|
Class(const Class &); \
|
|
|
|
void operator=(const Class &); \
|
|
|
|
public: \
|
|
|
|
struct Private; \
|
|
|
|
Private & m
|
|
|
|
|
2007-12-17 03:51:34 +00:00
|
|
|
|
2007-05-17 00:11:38 +00:00
|
|
|
// Public interface.
|
|
|
|
namespace nvtt
|
|
|
|
{
|
|
|
|
/// Supported compression formats.
|
|
|
|
enum Format
|
|
|
|
{
|
|
|
|
// No compression.
|
|
|
|
Format_RGB,
|
|
|
|
Format_RGBA = Format_RGB,
|
2007-12-17 03:51:34 +00:00
|
|
|
|
2007-05-17 00:11:38 +00:00
|
|
|
// DX9 formats.
|
|
|
|
Format_DXT1,
|
2007-11-20 22:01:09 +00:00
|
|
|
Format_DXT1a, // DXT1 with binary alpha.
|
2007-05-17 00:11:38 +00:00
|
|
|
Format_DXT3,
|
|
|
|
Format_DXT5,
|
2007-11-20 22:01:09 +00:00
|
|
|
Format_DXT5n, // Compressed HILO: R=0, G=x, B=0, A=y
|
2007-05-17 00:11:38 +00:00
|
|
|
|
|
|
|
// DX10 formats.
|
|
|
|
Format_BC1 = Format_DXT1,
|
2007-09-04 10:00:32 +00:00
|
|
|
Format_BC1a = Format_DXT1a,
|
2007-05-17 00:11:38 +00:00
|
|
|
Format_BC2 = Format_DXT3,
|
|
|
|
Format_BC3 = Format_DXT5,
|
|
|
|
Format_BC3n = Format_DXT5n,
|
2007-11-20 22:01:09 +00:00
|
|
|
Format_BC4, // ATI1
|
|
|
|
Format_BC5, // 3DC, ATI2
|
2008-02-15 08:58:02 +00:00
|
|
|
|
|
|
|
Format_DXT1n,
|
|
|
|
Format_CTX1,
|
2007-05-17 00:11:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// 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.
|
2008-01-24 04:25:24 +00:00
|
|
|
struct CompressionOptions
|
2007-05-17 00:11:38 +00:00
|
|
|
{
|
2008-02-28 21:14:40 +00:00
|
|
|
NVTT_DECLARE_PIMPL(CompressionOptions);
|
|
|
|
|
2007-05-17 00:11:38 +00:00
|
|
|
NVTT_API CompressionOptions();
|
|
|
|
NVTT_API ~CompressionOptions();
|
|
|
|
|
|
|
|
NVTT_API void reset();
|
|
|
|
|
|
|
|
NVTT_API void setFormat(Format format);
|
2008-01-18 23:50:22 +00:00
|
|
|
NVTT_API void setQuality(Quality quality);
|
2008-01-18 06:11:58 +00:00
|
|
|
NVTT_API void setColorWeights(float red, float green, float blue, float alpha = 1.0f);
|
2007-12-17 03:51:34 +00:00
|
|
|
|
2007-05-17 00:11:38 +00:00
|
|
|
NVTT_API void setExternalCompressor(const char * name);
|
|
|
|
|
|
|
|
// Set color mask to describe the RGB/RGBA format.
|
2007-12-03 23:28:03 +00:00
|
|
|
NVTT_API void setPixelFormat(unsigned int bitcount, unsigned int rmask, unsigned int gmask, unsigned int bmask, unsigned int amask);
|
2007-05-17 00:11:38 +00:00
|
|
|
|
2008-01-24 04:25:24 +00:00
|
|
|
NVTT_API void setQuantization(bool colorDithering, bool alphaDithering, bool binaryAlpha, int alphaThreshold = 127);
|
2007-05-17 00:11:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-02-03 08:24:58 +00:00
|
|
|
/// Wrap modes.
|
2007-05-17 00:11:38 +00:00
|
|
|
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
|
|
|
|
{
|
2007-11-20 22:01:09 +00:00
|
|
|
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.
|
2007-05-17 00:11:38 +00:00
|
|
|
};
|
|
|
|
|
2007-12-17 03:51:34 +00:00
|
|
|
/// Color transformation.
|
2007-11-16 11:52:29 +00:00
|
|
|
enum ColorTransform
|
|
|
|
{
|
|
|
|
ColorTransform_None,
|
2008-05-06 21:49:10 +00:00
|
|
|
ColorTransform_Linear, ///< Not implemented.
|
|
|
|
ColorTransform_Swizzle, ///< Not implemented.
|
|
|
|
ColorTransform_YCoCg, ///< Transform into r=Co, g=Cg, b=0, a=Y
|
|
|
|
ColorTransform_ScaledYCoCg, ///< Not implemented.
|
2007-12-17 03:51:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Extents rounding mode.
|
|
|
|
enum RoundMode
|
|
|
|
{
|
|
|
|
RoundMode_None,
|
|
|
|
RoundMode_ToNextPowerOfTwo,
|
2008-02-03 08:24:58 +00:00
|
|
|
RoundMode_ToNearestPowerOfTwo,
|
2007-12-17 03:51:34 +00:00
|
|
|
RoundMode_ToPreviousPowerOfTwo,
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Alpha mode.
|
|
|
|
enum AlphaMode
|
|
|
|
{
|
|
|
|
AlphaMode_None,
|
|
|
|
AlphaMode_Transparency,
|
2008-02-05 00:28:13 +00:00
|
|
|
AlphaMode_Premultiplied,
|
2007-11-16 11:52:29 +00:00
|
|
|
};
|
2007-05-17 00:11:38 +00:00
|
|
|
|
|
|
|
/// Input options. Specify format and layout of the input texture.
|
|
|
|
struct InputOptions
|
|
|
|
{
|
2008-02-28 21:14:40 +00:00
|
|
|
NVTT_DECLARE_PIMPL(InputOptions);
|
|
|
|
|
2007-05-17 00:11:38 +00:00
|
|
|
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();
|
2007-12-17 03:51:34 +00:00
|
|
|
|
2007-05-17 00:11:38 +00:00
|
|
|
// 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);
|
2007-12-17 03:51:34 +00:00
|
|
|
|
2007-05-17 00:11:38 +00:00
|
|
|
// Describe the format of the input.
|
2007-12-17 03:51:34 +00:00
|
|
|
NVTT_API void setFormat(InputFormat format);
|
|
|
|
|
2008-02-03 08:24:58 +00:00
|
|
|
// Set the way the input alpha channel is interpreted. @@ Not implemented!
|
2007-12-17 03:51:34 +00:00
|
|
|
NVTT_API void setAlphaMode(AlphaMode alphaMode);
|
|
|
|
|
2007-05-17 00:11:38 +00:00
|
|
|
// Set gamma settings.
|
|
|
|
NVTT_API void setGamma(float inputGamma, float outputGamma);
|
2007-12-17 03:51:34 +00:00
|
|
|
|
2007-05-17 00:11:38 +00:00
|
|
|
// Set texture wrappign mode.
|
|
|
|
NVTT_API void setWrapMode(WrapMode mode);
|
2007-12-17 03:51:34 +00:00
|
|
|
|
2007-05-17 00:11:38 +00:00
|
|
|
// Set mipmapping options.
|
2008-02-03 09:30:32 +00:00
|
|
|
NVTT_API void setMipmapFilter(MipmapFilter filter);
|
|
|
|
NVTT_API void setMipmapGeneration(bool enabled, int maxLevel = -1);
|
2007-12-17 03:51:34 +00:00
|
|
|
NVTT_API void setKaiserParameters(float width, float alpha, float stretch);
|
2007-11-22 01:02:01 +00:00
|
|
|
|
2007-05-17 00:11:38 +00:00
|
|
|
// Set normal map options.
|
2007-05-18 02:19:51 +00:00
|
|
|
NVTT_API void setNormalMap(bool b);
|
2007-05-17 00:11:38 +00:00
|
|
|
NVTT_API void setConvertToNormalMap(bool convert);
|
|
|
|
NVTT_API void setHeightEvaluation(float redScale, float greenScale, float blueScale, float alphaScale);
|
2008-02-01 19:49:22 +00:00
|
|
|
NVTT_API void setNormalFilter(float sm, float medium, float big, float large);
|
2007-05-17 00:11:38 +00:00
|
|
|
NVTT_API void setNormalizeMipmaps(bool b);
|
2007-12-17 03:51:34 +00:00
|
|
|
|
2008-01-17 05:44:21 +00:00
|
|
|
// Set color transforms. @@ Not implemented!
|
2007-11-16 11:52:29 +00:00
|
|
|
NVTT_API void setColorTransform(ColorTransform t);
|
2008-01-24 04:25:24 +00:00
|
|
|
NVTT_API void setLinearTransform(int channel, float w0, float w1, float w2, float w3);
|
2008-03-05 22:35:16 +00:00
|
|
|
NVTT_API void setSwizzleTransform(int x, int y, int z, int w);
|
2007-12-17 03:51:34 +00:00
|
|
|
|
2008-02-03 08:24:58 +00:00
|
|
|
// Set resizing options.
|
2007-12-17 03:51:34 +00:00
|
|
|
NVTT_API void setMaxExtents(int d);
|
|
|
|
NVTT_API void setRoundMode(RoundMode mode);
|
2008-03-07 00:41:03 +00:00
|
|
|
|
|
|
|
// Set whether or not to premultiply color by alpha
|
|
|
|
NVTT_API void setPremultiplyAlpha(bool b);
|
2007-05-17 00:11:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Output handler.
|
|
|
|
struct OutputHandler
|
|
|
|
{
|
|
|
|
virtual ~OutputHandler() {}
|
|
|
|
|
|
|
|
/// Indicate the start of a new compressed image that's part of the final texture.
|
2008-02-05 00:28:13 +00:00
|
|
|
virtual void beginImage(int size, int width, int height, int depth, int face, int miplevel) = 0;
|
2007-05-17 00:11:38 +00:00
|
|
|
|
|
|
|
/// Output data. Compressed data is output as soon as it's generated to minimize memory allocations.
|
2008-01-26 02:46:12 +00:00
|
|
|
virtual bool writeData(const void * data, int size) = 0;
|
2007-05-17 00:11:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Error codes.
|
|
|
|
enum Error
|
|
|
|
{
|
2008-01-26 02:46:12 +00:00
|
|
|
Error_Unknown,
|
2007-05-17 00:11:38 +00:00
|
|
|
Error_InvalidInput,
|
|
|
|
Error_UnsupportedFeature,
|
|
|
|
Error_CudaError,
|
2007-12-17 03:51:34 +00:00
|
|
|
Error_FileOpen,
|
|
|
|
Error_FileWrite,
|
2007-05-17 00:11:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// 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
|
|
|
|
{
|
2008-02-28 21:14:40 +00:00
|
|
|
NVTT_DECLARE_PIMPL(OutputOptions);
|
|
|
|
|
2007-12-17 03:51:34 +00:00
|
|
|
NVTT_API OutputOptions();
|
|
|
|
NVTT_API ~OutputOptions();
|
2007-05-17 00:11:38 +00:00
|
|
|
|
|
|
|
// Set default options.
|
|
|
|
NVTT_API void reset();
|
|
|
|
|
2007-12-17 03:51:34 +00:00
|
|
|
NVTT_API void setFileName(const char * fileName);
|
|
|
|
|
|
|
|
NVTT_API void setOutputHandler(OutputHandler * outputHandler);
|
|
|
|
NVTT_API void setErrorHandler(ErrorHandler * errorHandler);
|
|
|
|
NVTT_API void setOutputHeader(bool outputHeader);
|
2008-01-26 02:46:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Texture compressor.
|
|
|
|
struct Compressor
|
|
|
|
{
|
2008-02-28 21:14:40 +00:00
|
|
|
NVTT_DECLARE_PIMPL(Compressor);
|
|
|
|
|
2008-01-26 02:46:12 +00:00
|
|
|
NVTT_API Compressor();
|
|
|
|
NVTT_API ~Compressor();
|
|
|
|
|
2008-02-01 19:49:22 +00:00
|
|
|
NVTT_API void enableCudaAcceleration(bool enable);
|
|
|
|
NVTT_API bool isCudaAccelerationEnabled() const;
|
2008-01-26 02:46:12 +00:00
|
|
|
|
|
|
|
// Main entrypoint of the compression library.
|
|
|
|
NVTT_API bool process(const InputOptions & inputOptions, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const;
|
2007-12-17 03:51:34 +00:00
|
|
|
|
2008-01-26 02:46:12 +00:00
|
|
|
// Estimate the size of compressing the input with the given options.
|
|
|
|
NVTT_API int estimateSize(const InputOptions & inputOptions, const CompressionOptions & compressionOptions) const;
|
2007-05-17 00:11:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-01-26 02:46:12 +00:00
|
|
|
// Return string for the given error code.
|
2007-05-17 00:11:38 +00:00
|
|
|
NVTT_API const char * errorString(Error e);
|
|
|
|
|
2008-02-05 00:28:13 +00:00
|
|
|
// Return NVTT version.
|
|
|
|
NVTT_API unsigned int version();
|
2008-01-26 02:46:12 +00:00
|
|
|
|
2007-05-17 00:11:38 +00:00
|
|
|
} // nvtt namespace
|
|
|
|
|
|
|
|
#endif // NV_TT_H
|