Merge changes from The Witness.

This commit is contained in:
Ignacio
2015-10-28 23:53:08 -07:00
parent a382ea5b21
commit c0ad0f4d31
43 changed files with 890 additions and 136 deletions

View File

@ -52,12 +52,12 @@ using namespace nvtt;
namespace
{
// 1 -> 1, 2 -> 2, 3 -> 2, 4 -> 4, 5 -> 4, ...
static uint previousPowerOfTwo(const uint v)
static inline uint previousPowerOfTwo(uint v)
{
return nextPowerOfTwo(v + 1) / 2;
}
static uint nearestPowerOfTwo(const uint v)
static inline uint nearestPowerOfTwo(uint v)
{
const uint np2 = nextPowerOfTwo(v);
const uint pp2 = previousPowerOfTwo(v);
@ -72,6 +72,31 @@ namespace
}
}
static inline uint nextMultipleOfFour(uint v)
{
return (v + 3) & ~3;
}
static inline uint previousMultipleOfFour(uint v)
{
return v & ~3;
}
static inline uint nearestMultipleOfFour(uint v)
{
const uint nm4 = nextMultipleOfFour(v);
const uint pm4 = previousMultipleOfFour(v);
if (nm4 - v <= v - pm4)
{
return nm4;
}
else
{
return pm4;
}
}
static int blockSize(Format format)
{
if (format == Format_DXT1 || format == Format_DXT1a || format == Format_DXT1n) {
@ -225,6 +250,24 @@ void nv::getTargetExtent(int * width, int * height, int * depth, int maxExtent,
h = previousPowerOfTwo(h);
d = previousPowerOfTwo(d);
}
else if (roundMode == RoundMode_ToNextMultipleOfFour)
{
w = nextMultipleOfFour(w);
h = nextMultipleOfFour(h);
d = nextMultipleOfFour(d);
}
else if (roundMode == RoundMode_ToNextMultipleOfFour)
{
w = nearestMultipleOfFour(w);
h = nearestMultipleOfFour(h);
d = nearestMultipleOfFour(d);
}
else if (roundMode == RoundMode_ToPreviousMultipleOfFour)
{
w = previousMultipleOfFour(w);
h = previousMultipleOfFour(h);
d = previousMultipleOfFour(d);
}
*width = w;
*height = h;