Fix cube map processing bug reported by Cedric Perthuis.
This commit is contained in:
parent
086bf0343c
commit
035997bc2e
@ -119,7 +119,8 @@ int Compressor::estimateSize(const InputOptions & inputOptions, const Compressio
|
||||
int w = inputOptions.m.width;
|
||||
int h = inputOptions.m.height;
|
||||
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;
|
||||
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);
|
||||
|
||||
// Get output handler.
|
||||
if (!outputOptions.hasValidOutputHandler())
|
||||
{
|
||||
if (!outputOptions.hasValidOutputHandler()) {
|
||||
outputOptions.error(Error_FileOpen);
|
||||
return false;
|
||||
}
|
||||
@ -228,23 +228,22 @@ bool Compressor::Private::compress(const InputOptions::Private & inputOptions, c
|
||||
img.setNormalMap(inputOptions.isNormalMap);
|
||||
|
||||
const int faceCount = inputOptions.faceCount;
|
||||
int w = inputOptions.width;
|
||||
int h = inputOptions.height;
|
||||
int d = inputOptions.depth;
|
||||
int width = inputOptions.width;
|
||||
int height = inputOptions.height;
|
||||
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.
|
||||
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;
|
||||
if (inputOptions.generateMipmaps) {
|
||||
mipmapCount = countMipmaps(w, h, d);
|
||||
mipmapCount = countMipmaps(width, height, depth);
|
||||
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;
|
||||
}
|
||||
|
||||
@ -252,6 +251,11 @@ bool Compressor::Private::compress(const InputOptions::Private & inputOptions, c
|
||||
// Output images.
|
||||
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]);
|
||||
|
||||
// To normal map.
|
||||
@ -284,11 +288,12 @@ bool Compressor::Private::compress(const InputOptions::Private & inputOptions, c
|
||||
int idx = m * faceCount + f;
|
||||
|
||||
bool useSourceImages = false;
|
||||
if (canUseSourceImages) {
|
||||
useSourceImages = true;
|
||||
if (canUseSourceImagesForThisFace) {
|
||||
if (inputOptions.images[idx] == NULL) { // One face is missing in this mipmap level.
|
||||
useSourceImages = false;
|
||||
canUseSourceImages = false; // If one level is missing, ignore the following source images.
|
||||
canUseSourceImagesForThisFace = 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) {
|
||||
nvDebugCheck(w > 0);
|
||||
nvDebugCheck(h > 0);
|
||||
nvDebugCheck(d > 0);
|
||||
void nv::getTargetExtent(int * width, int * height, int * depth, int maxExtent, RoundMode roundMode, TextureType textureType) {
|
||||
nvDebugCheck(width != NULL && *width > 0);
|
||||
nvDebugCheck(height != NULL && *height > 0);
|
||||
nvDebugCheck(depth != NULL && *depth > 0);
|
||||
|
||||
int w = *width;
|
||||
int h = *height;
|
||||
int d = *depth;
|
||||
|
||||
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);
|
||||
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 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);
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ namespace nv {
|
||||
uint countMipmaps(uint w);
|
||||
uint countMipmaps(uint w, uint h, uint d);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user