Merge pull request #236 from mpersano/master
Add support for compressing texture arrays.
This commit is contained in:
@ -135,7 +135,7 @@ int Compressor::estimateSize(const InputOptions & inputOptions, const Compressio
|
||||
// Surface API.
|
||||
bool Compressor::outputHeader(const Surface & tex, int mipmapCount, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const
|
||||
{
|
||||
return m.outputHeader(tex.type(), tex.width(), tex.height(), tex.depth(), mipmapCount, tex.isNormalMap(), compressionOptions.m, outputOptions.m);
|
||||
return m.outputHeader(tex.type(), tex.width(), tex.height(), tex.depth(), 1, mipmapCount, tex.isNormalMap(), compressionOptions.m, outputOptions.m);
|
||||
}
|
||||
|
||||
bool Compressor::compress(const Surface & tex, int face, int mipmap, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const
|
||||
@ -154,7 +154,7 @@ int Compressor::estimateSize(const Surface & tex, int mipmapCount, const Compres
|
||||
|
||||
bool Compressor::outputHeader(const CubeSurface & cube, int mipmapCount, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const
|
||||
{
|
||||
return m.outputHeader(TextureType_Cube, cube.edgeLength(), cube.edgeLength(), 1, mipmapCount, false, compressionOptions.m, outputOptions.m);
|
||||
return m.outputHeader(TextureType_Cube, cube.edgeLength(), cube.edgeLength(), 1, 1, mipmapCount, false, compressionOptions.m, outputOptions.m);
|
||||
}
|
||||
|
||||
bool Compressor::compress(const CubeSurface & cube, int mipmap, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const
|
||||
@ -174,9 +174,9 @@ int Compressor::estimateSize(const CubeSurface & cube, int mipmapCount, const Co
|
||||
|
||||
|
||||
// Raw API.
|
||||
bool Compressor::outputHeader(TextureType type, int w, int h, int d, int mipmapCount, bool isNormalMap, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const
|
||||
bool Compressor::outputHeader(TextureType type, int w, int h, int d, int arraySize, int mipmapCount, bool isNormalMap, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const
|
||||
{
|
||||
return m.outputHeader(type, w, h, d, mipmapCount, isNormalMap, compressionOptions.m, outputOptions.m);
|
||||
return m.outputHeader(type, w, h, d, arraySize, mipmapCount, isNormalMap, compressionOptions.m, outputOptions.m);
|
||||
}
|
||||
|
||||
bool Compressor::compress(int w, int h, int d, int face, int mipmap, const float * rgba, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const
|
||||
@ -231,6 +231,7 @@ bool Compressor::Private::compress(const InputOptions::Private & inputOptions, c
|
||||
int width = inputOptions.width;
|
||||
int height = inputOptions.height;
|
||||
int depth = inputOptions.depth;
|
||||
int arraySize = inputOptions.textureType == TextureType_Array ? faceCount : 1;
|
||||
|
||||
nv::getTargetExtent(&width, &height, &depth, inputOptions.maxExtent, inputOptions.roundMode, inputOptions.textureType);
|
||||
|
||||
@ -243,7 +244,7 @@ bool Compressor::Private::compress(const InputOptions::Private & inputOptions, c
|
||||
if (inputOptions.maxLevel > 0) mipmapCount = min(mipmapCount, inputOptions.maxLevel);
|
||||
}
|
||||
|
||||
if (!outputHeader(inputOptions.textureType, width, height, depth, mipmapCount, img.isNormalMap(), compressionOptions, outputOptions)) {
|
||||
if (!outputHeader(inputOptions.textureType, width, height, depth, arraySize, mipmapCount, img.isNormalMap(), compressionOptions, outputOptions)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -403,10 +404,9 @@ void Compressor::Private::quantize(Surface & img, const CompressionOptions::Priv
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Compressor::Private::outputHeader(nvtt::TextureType textureType, int w, int h, int d, int mipmapCount, bool isNormalMap, const CompressionOptions::Private & compressionOptions, const OutputOptions::Private & outputOptions) const
|
||||
bool Compressor::Private::outputHeader(nvtt::TextureType textureType, int w, int h, int d, int arraySize, int mipmapCount, bool isNormalMap, const CompressionOptions::Private & compressionOptions, const OutputOptions::Private & outputOptions) const
|
||||
{
|
||||
if (w <= 0 || h <= 0 || d <= 0 || mipmapCount <= 0)
|
||||
if (w <= 0 || h <= 0 || d <= 0 || arraySize <= 0 || mipmapCount <= 0)
|
||||
{
|
||||
outputOptions.error(Error_InvalidInput);
|
||||
return false;
|
||||
@ -425,15 +425,21 @@ bool Compressor::Private::outputHeader(nvtt::TextureType textureType, int w, int
|
||||
header.setUserVersion(outputOptions.version);
|
||||
|
||||
if (textureType == TextureType_2D) {
|
||||
nvCheck(arraySize == 1);
|
||||
header.setTexture2D();
|
||||
}
|
||||
else if (textureType == TextureType_Cube) {
|
||||
nvCheck(arraySize == 1);
|
||||
header.setTextureCube();
|
||||
}
|
||||
else if (textureType == TextureType_3D) {
|
||||
nvCheck(arraySize == 1);
|
||||
header.setTexture3D();
|
||||
header.setDepth(d);
|
||||
}
|
||||
else if (textureType == TextureType_Array) {
|
||||
header.setTextureArray(arraySize);
|
||||
}
|
||||
|
||||
header.setWidth(w);
|
||||
header.setHeight(h);
|
||||
@ -459,25 +465,22 @@ bool Compressor::Private::outputHeader(nvtt::TextureType textureType, int w, int
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (bitcount == 16) {
|
||||
if (compressionOptions.rsize == 16) {
|
||||
header.setDX10Format(DXGI_FORMAT_R16_UNORM);
|
||||
}
|
||||
else {
|
||||
// B5G6R5_UNORM
|
||||
// B5G5R5A1_UNORM
|
||||
supported = false;
|
||||
}
|
||||
}
|
||||
else if (bitcount == 32) {
|
||||
// B8G8R8A8_UNORM
|
||||
// B8G8R8X8_UNORM
|
||||
// R8G8B8A8_UNORM
|
||||
// R10G10B10A2_UNORM
|
||||
supported = false;
|
||||
if (bitcount == 16 && compressionOptions.rsize == 16) {
|
||||
header.setDX10Format(DXGI_FORMAT_R16_UNORM);
|
||||
}
|
||||
else {
|
||||
supported = false;
|
||||
uint format = findDXGIFormat(compressionOptions.bitcount,
|
||||
compressionOptions.rmask,
|
||||
compressionOptions.gmask,
|
||||
compressionOptions.bmask,
|
||||
compressionOptions.amask);
|
||||
|
||||
if (format != DXGI_FORMAT_UNKNOWN) {
|
||||
header.setDX10Format(format);
|
||||
}
|
||||
else {
|
||||
supported = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ namespace nvtt
|
||||
|
||||
void quantize(Surface & tex, const CompressionOptions::Private & compressionOptions) const;
|
||||
|
||||
bool outputHeader(nvtt::TextureType textureType, int w, int h, int d, int mipmapCount, bool isNormalMap, const CompressionOptions::Private & compressionOptions, const OutputOptions::Private & outputOptions) const;
|
||||
bool outputHeader(nvtt::TextureType textureType, int w, int h, int d, int faceCount, int mipmapCount, bool isNormalMap, const CompressionOptions::Private & compressionOptions, const OutputOptions::Private & outputOptions) const;
|
||||
|
||||
nv::CompressorInterface * chooseCpuCompressor(const CompressionOptions::Private & compressionOptions) const;
|
||||
nv::CompressorInterface * chooseGpuCompressor(const CompressionOptions::Private & compressionOptions) const;
|
||||
|
@ -124,17 +124,19 @@ void InputOptions::reset()
|
||||
|
||||
|
||||
// Setup the input image.
|
||||
void InputOptions::setTextureLayout(TextureType type, int width, int height, int depth /*= 1*/)
|
||||
void InputOptions::setTextureLayout(TextureType type, int width, int height, int depth /*= 1*/, int arraySize /*= 1*/)
|
||||
{
|
||||
// Validate arguments.
|
||||
nvCheck(width >= 0);
|
||||
nvCheck(height >= 0);
|
||||
nvCheck(depth >= 0);
|
||||
nvCheck(arraySize >= 0);
|
||||
|
||||
// Correct arguments.
|
||||
if (width == 0) width = 1;
|
||||
if (height == 0) height = 1;
|
||||
if (depth == 0) depth = 1;
|
||||
if (arraySize == 0) arraySize = 1;
|
||||
|
||||
// Delete previous images.
|
||||
resetTextureLayout();
|
||||
@ -145,7 +147,16 @@ void InputOptions::setTextureLayout(TextureType type, int width, int height, int
|
||||
m.depth = depth;
|
||||
|
||||
// Allocate images.
|
||||
m.faceCount = (type == TextureType_Cube) ? 6 : 1;
|
||||
if (type == TextureType_Cube) {
|
||||
nvCheck(arraySize == 1);
|
||||
m.faceCount = 6;
|
||||
}
|
||||
else if (type == TextureType_Array) {
|
||||
m.faceCount = arraySize;
|
||||
} else {
|
||||
nvCheck(arraySize == 1);
|
||||
m.faceCount = 1;
|
||||
}
|
||||
m.mipmapCount = countMipmaps(width, height, depth);
|
||||
m.imageCount = m.mipmapCount * m.faceCount;
|
||||
m.images = new void *[m.imageCount];
|
||||
|
@ -205,6 +205,7 @@ namespace nvtt
|
||||
TextureType_2D,
|
||||
TextureType_Cube,
|
||||
TextureType_3D,
|
||||
TextureType_Array,
|
||||
};
|
||||
|
||||
// Input formats.
|
||||
@ -266,7 +267,7 @@ namespace nvtt
|
||||
NVTT_API void reset();
|
||||
|
||||
// Setup input layout.
|
||||
NVTT_API void setTextureLayout(TextureType type, int w, int h, int d = 1);
|
||||
NVTT_API void setTextureLayout(TextureType type, int w, int h, int d = 1, int arraySize = 1);
|
||||
NVTT_API void resetTextureLayout();
|
||||
|
||||
// Set mipmap data. Copies the data.
|
||||
@ -412,7 +413,7 @@ namespace nvtt
|
||||
NVTT_API int estimateSize(const CubeSurface & cube, int mipmapCount, const CompressionOptions & compressionOptions) const;
|
||||
|
||||
// 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 outputHeader(TextureType type, int w, int h, int d, int arraySize, 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;
|
||||
};
|
||||
|
@ -76,7 +76,7 @@ int main(int argc, char *argv[])
|
||||
float topPower = 64;
|
||||
|
||||
// Output header.
|
||||
context.outputHeader(nvtt::TextureType_Cube, topSize >> firstMipmap, topSize >> firstMipmap, 1, mipmapCount-firstMipmap, false, compressionOptions, outputOptions);
|
||||
context.outputHeader(nvtt::TextureType_Cube, topSize >> firstMipmap, topSize >> firstMipmap, 1, 1, mipmapCount-firstMipmap, false, compressionOptions, outputOptions);
|
||||
|
||||
nv::Timer timer;
|
||||
timer.start();
|
||||
|
@ -59,13 +59,13 @@ int main(int argc, char *argv[])
|
||||
assembleVolume = false;
|
||||
assembleTextureArray = false;
|
||||
}
|
||||
if (strcmp("-volume", argv[i]) == 0)
|
||||
else if (strcmp("-volume", argv[i]) == 0)
|
||||
{
|
||||
assembleCubeMap = false;
|
||||
assembleVolume = true;
|
||||
assembleTextureArray = false;
|
||||
}
|
||||
if (strcmp("-array", argv[i]) == 0)
|
||||
else if (strcmp("-array", argv[i]) == 0)
|
||||
{
|
||||
assembleCubeMap = false;
|
||||
assembleVolume = false;
|
||||
|
@ -487,11 +487,14 @@ int main(int argc, char *argv[])
|
||||
|
||||
nvDebugBreak();
|
||||
}
|
||||
else
|
||||
{
|
||||
nvDebugCheck(dds.isTextureCube());
|
||||
else if (dds.isTextureCube()) {
|
||||
inputOptions.setTextureLayout(nvtt::TextureType_Cube, dds.width(), dds.height());
|
||||
faceCount = 6;
|
||||
} else {
|
||||
nvDebugCheck(dds.isTextureArray());
|
||||
inputOptions.setTextureLayout(nvtt::TextureType_Array, dds.width(), dds.height(), 1, dds.arraySize());
|
||||
faceCount = dds.arraySize();
|
||||
dds10 = true;
|
||||
}
|
||||
|
||||
uint mipmapCount = dds.mipmapCount();
|
||||
|
Reference in New Issue
Block a user