diff --git a/tools/texturec/texturec.cpp b/tools/texturec/texturec.cpp index d25781f..62cd309 100644 --- a/tools/texturec/texturec.cpp +++ b/tools/texturec/texturec.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include @@ -36,6 +35,7 @@ struct Options { DBG("Options:\n" "\t maxSize: %d\n" + "\t mipSkip: %d\n" "\t edge: %f\n" "\t format: %s\n" "\t mips: %s\n" @@ -47,6 +47,7 @@ struct Options "\t equirect: %s\n" "\t strip: %s\n" , maxSize + , mipSkip , edge , bimg::getName(format) , mips ? "true" : "false" @@ -61,6 +62,7 @@ struct Options } uint32_t maxSize = UINT32_MAX; + uint32_t mipSkip = 0; float edge = 0.0f; bimg::TextureFormat::Enum format = bimg::TextureFormat::Count; bimg::Quality::Enum quality = bimg::Quality::Default; @@ -159,10 +161,21 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData const uint32_t blockHeight = outputBlockInfo.blockHeight; const uint32_t minBlockX = outputBlockInfo.minBlockX; const uint32_t minBlockY = outputBlockInfo.minBlockY; - uint32_t outputWidth = bx::uint32_max(blockWidth * minBlockX, ( (input->m_width + blockWidth - 1) / blockWidth )*blockWidth); - uint32_t outputHeight = bx::uint32_max(blockHeight * minBlockY, ( (input->m_height + blockHeight - 1) / blockHeight)*blockHeight); + uint32_t outputWidth = bx::max(blockWidth * minBlockX, ( (input->m_width + blockWidth - 1) / blockWidth )*blockWidth); + uint32_t outputHeight = bx::max(blockHeight * minBlockY, ( (input->m_height + blockHeight - 1) / blockHeight)*blockHeight); uint32_t outputDepth = input->m_depth; + if (_options.mips + && _options.mipSkip != 0) + { + for (uint32_t ii = 0; ii < _options.mipSkip; ++ii) + { + outputWidth = bx::max(blockWidth * minBlockX, ( ( (outputWidth>>1) + blockWidth - 1) / blockWidth )*blockWidth); + outputHeight = bx::max(blockHeight * minBlockY, ( ( (outputHeight>>1) + blockHeight - 1) / blockHeight)*blockHeight); + outputDepth = bx::max(outputDepth>>1, 1u); + } + } + if (_options.equirect) { if (outputDepth == 1 @@ -831,6 +844,7 @@ void help(const char* _error = NULL, bool _showHelp = true) " -t Output format type (BC1/2/3/4/5, ETC1, PVR14, etc.).\n" " -q Encoding quality (default, fastest, highest).\n" " -m, --mips Generate mip-maps.\n" + " --mipskip Skip number of mips.\n" " -n, --normalmap Input texture is normal map.\n" " --equirect Input texture is equirectangular projection of cubemap.\n" " --strip Input texture is horizontal strip of cubemap.\n" @@ -997,7 +1011,17 @@ int main(int _argc, const char* _argv[]) { if (!bx::fromString(&options.maxSize, maxSize) ) { - help("Parsing max size failed."); + help("Parsing `--max` failed."); + return bx::kExitFailure; + } + } + + const char* mipSkip = cmdLine.findOption("mipskip"); + if (NULL != mipSkip) + { + if (!bx::fromString(&options.mipSkip, mipSkip) ) + { + help("Parsing `--mipskip` failed."); return bx::kExitFailure; } }