Fix cube map processing bug reported by Cedric Perthuis.
This commit is contained in:
@ -119,7 +119,8 @@ int Compressor::estimateSize(const InputOptions & inputOptions, const Compressio
|
|||||||
int w = inputOptions.m.width;
|
int w = inputOptions.m.width;
|
||||||
int h = inputOptions.m.height;
|
int h = inputOptions.m.height;
|
||||||
int d = inputOptions.m.depth;
|
int d = inputOptions.m.depth;
|
||||||
getTargetExtent(w, h, d, inputOptions.m.maxExtent, inputOptions.m.roundMode, inputOptions.m.textureType);
|
|
||||||
|
getTargetExtent(&w, &h, &d, inputOptions.m.maxExtent, inputOptions.m.roundMode, inputOptions.m.textureType);
|
||||||
|
|
||||||
int mipmapCount = 1;
|
int mipmapCount = 1;
|
||||||
if (inputOptions.m.generateMipmaps) {
|
if (inputOptions.m.generateMipmaps) {
|
||||||
@ -216,8 +217,7 @@ bool Compressor::Private::compress(const InputOptions::Private & inputOptions, c
|
|||||||
nvStaticCheck(FloatImage::WrapMode_Repeat == (FloatImage::WrapMode)WrapMode_Repeat);
|
nvStaticCheck(FloatImage::WrapMode_Repeat == (FloatImage::WrapMode)WrapMode_Repeat);
|
||||||
|
|
||||||
// Get output handler.
|
// Get output handler.
|
||||||
if (!outputOptions.hasValidOutputHandler())
|
if (!outputOptions.hasValidOutputHandler()) {
|
||||||
{
|
|
||||||
outputOptions.error(Error_FileOpen);
|
outputOptions.error(Error_FileOpen);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -228,23 +228,22 @@ bool Compressor::Private::compress(const InputOptions::Private & inputOptions, c
|
|||||||
img.setNormalMap(inputOptions.isNormalMap);
|
img.setNormalMap(inputOptions.isNormalMap);
|
||||||
|
|
||||||
const int faceCount = inputOptions.faceCount;
|
const int faceCount = inputOptions.faceCount;
|
||||||
int w = inputOptions.width;
|
int width = inputOptions.width;
|
||||||
int h = inputOptions.height;
|
int height = inputOptions.height;
|
||||||
int d = inputOptions.depth;
|
int depth = inputOptions.depth;
|
||||||
|
|
||||||
nv::getTargetExtent(w, h, d, inputOptions.maxExtent, inputOptions.roundMode, inputOptions.textureType);
|
nv::getTargetExtent(&width, &height, &depth, inputOptions.maxExtent, inputOptions.roundMode, inputOptions.textureType);
|
||||||
|
|
||||||
// If the extents have not changed, then we can use source images for all mipmaps.
|
// If the extents have not changed, then we can use source images for all mipmaps.
|
||||||
bool canUseSourceImages = (inputOptions.width == w && inputOptions.height == h && inputOptions.depth == d);
|
bool canUseSourceImages = (inputOptions.width == width && inputOptions.height == height && inputOptions.depth == depth);
|
||||||
|
|
||||||
int mipmapCount = 1;
|
int mipmapCount = 1;
|
||||||
if (inputOptions.generateMipmaps) {
|
if (inputOptions.generateMipmaps) {
|
||||||
mipmapCount = countMipmaps(w, h, d);
|
mipmapCount = countMipmaps(width, height, depth);
|
||||||
if (inputOptions.maxLevel > 0) mipmapCount = min(mipmapCount, inputOptions.maxLevel);
|
if (inputOptions.maxLevel > 0) mipmapCount = min(mipmapCount, inputOptions.maxLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!outputHeader(inputOptions.textureType, w, h, d, mipmapCount, img.isNormalMap(), compressionOptions, outputOptions))
|
if (!outputHeader(inputOptions.textureType, width, height, depth, mipmapCount, img.isNormalMap(), compressionOptions, outputOptions)) {
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,6 +251,11 @@ bool Compressor::Private::compress(const InputOptions::Private & inputOptions, c
|
|||||||
// Output images.
|
// Output images.
|
||||||
for (int f = 0; f < faceCount; f++)
|
for (int f = 0; f < faceCount; f++)
|
||||||
{
|
{
|
||||||
|
int w = width;
|
||||||
|
int h = height;
|
||||||
|
int d = depth;
|
||||||
|
bool canUseSourceImagesForThisFace = canUseSourceImages;
|
||||||
|
|
||||||
img.setImage(inputOptions.inputFormat, inputOptions.width, inputOptions.height, inputOptions.depth, inputOptions.images[f]);
|
img.setImage(inputOptions.inputFormat, inputOptions.width, inputOptions.height, inputOptions.depth, inputOptions.images[f]);
|
||||||
|
|
||||||
// To normal map.
|
// To normal map.
|
||||||
@ -284,11 +288,12 @@ bool Compressor::Private::compress(const InputOptions::Private & inputOptions, c
|
|||||||
int idx = m * faceCount + f;
|
int idx = m * faceCount + f;
|
||||||
|
|
||||||
bool useSourceImages = false;
|
bool useSourceImages = false;
|
||||||
if (canUseSourceImages) {
|
if (canUseSourceImagesForThisFace) {
|
||||||
useSourceImages = true;
|
|
||||||
if (inputOptions.images[idx] == NULL) { // One face is missing in this mipmap level.
|
if (inputOptions.images[idx] == NULL) { // One face is missing in this mipmap level.
|
||||||
useSourceImages = false;
|
canUseSourceImagesForThisFace = false; // If one level is missing, ignore the following source images.
|
||||||
canUseSourceImages = false; // If one level is missing, ignore the following source images.
|
}
|
||||||
|
else {
|
||||||
|
useSourceImages = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,10 +131,14 @@ uint nv::computeImageSize(uint w, uint h, uint d, uint bitCount, uint pitchAlign
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void nv::getTargetExtent(int & w, int & h, int & d, int maxExtent, RoundMode roundMode, TextureType textureType) {
|
void nv::getTargetExtent(int * width, int * height, int * depth, int maxExtent, RoundMode roundMode, TextureType textureType) {
|
||||||
nvDebugCheck(w > 0);
|
nvDebugCheck(width != NULL && *width > 0);
|
||||||
nvDebugCheck(h > 0);
|
nvDebugCheck(height != NULL && *height > 0);
|
||||||
nvDebugCheck(d > 0);
|
nvDebugCheck(depth != NULL && *depth > 0);
|
||||||
|
|
||||||
|
int w = *width;
|
||||||
|
int h = *height;
|
||||||
|
int d = *depth;
|
||||||
|
|
||||||
if (roundMode != RoundMode_None && maxExtent > 0)
|
if (roundMode != RoundMode_None && maxExtent > 0)
|
||||||
{
|
{
|
||||||
@ -180,6 +184,10 @@ void nv::getTargetExtent(int & w, int & h, int & d, int maxExtent, RoundMode rou
|
|||||||
h = previousPowerOfTwo(h);
|
h = previousPowerOfTwo(h);
|
||||||
d = previousPowerOfTwo(d);
|
d = previousPowerOfTwo(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*width = w;
|
||||||
|
*height = h;
|
||||||
|
*depth = d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -788,7 +796,7 @@ void Surface::resize(int maxExtent, RoundMode roundMode, ResizeFilter filter, fl
|
|||||||
int h = m->image->height();
|
int h = m->image->height();
|
||||||
int d = m->image->depth();
|
int d = m->image->depth();
|
||||||
|
|
||||||
getTargetExtent(w, h, d, maxExtent, roundMode, m->type);
|
getTargetExtent(&w, &h, &d, maxExtent, roundMode, m->type);
|
||||||
|
|
||||||
resize(w, h, d, filter, filterWidth, params);
|
resize(w, h, d, filter, filterWidth, params);
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ namespace nv {
|
|||||||
uint countMipmaps(uint w);
|
uint countMipmaps(uint w);
|
||||||
uint countMipmaps(uint w, uint h, uint d);
|
uint countMipmaps(uint w, uint h, uint d);
|
||||||
uint computeImageSize(uint w, uint h, uint d, uint bitCount, uint alignmentInBytes, nvtt::Format format);
|
uint computeImageSize(uint w, uint h, uint d, uint bitCount, uint alignmentInBytes, nvtt::Format format);
|
||||||
void getTargetExtent(int & w, int & h, int & d, int maxExtent, nvtt::RoundMode roundMode, nvtt::TextureType textureType);
|
void getTargetExtent(int * w, int * h, int * d, int maxExtent, nvtt::RoundMode roundMode, nvtt::TextureType textureType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user