From 9be4e210ff0181f03beaf00536e0f5e9ce4a7ecf Mon Sep 17 00:00:00 2001 From: richgel999 Date: Sun, 29 Sep 2019 18:41:57 -0700 Subject: [PATCH] Adding -pvrtc_clamp command line flag, so we can see what PVRTC1 textures look like when transcoded and unpacked with clamp addressing --- basisu_tool.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/basisu_tool.cpp b/basisu_tool.cpp index 3806b51..f90f398 100644 --- a/basisu_tool.cpp +++ b/basisu_tool.cpp @@ -88,6 +88,7 @@ static void print_usage() " -etc1_only: Only unpack to ETC1, skipping the other texture formats during -unpack\n" " -disable_hierarchical_endpoint_codebooks: Disable hierarchical endpoint codebook usage, slower but higher quality on some compression levels\n" " -compare_ssim: Compute and display SSIM of image comparison (slow)\n" + " -pvrtc_clamp: Use clamp addressing when transcoding and unpacking PVRTC1 textures\n" "\n" "Mipmap generation options:\n" " -mipmap: Generate mipmaps for each source image\n" @@ -216,6 +217,8 @@ static bool load_listing_file(const std::string &f, std::vector &fi class command_line_params { + BASISU_NO_EQUALS_OR_COPY_CONSTRUCT(command_line_params); + public: command_line_params() : m_mode(cDefault), @@ -225,7 +228,8 @@ public: m_no_ktx(false), m_etc1_only(false), m_fuzz_testing(false), - m_compare_ssim(false) + m_compare_ssim(false), + m_pvrtc_clamp(false) { } @@ -250,6 +254,8 @@ public: m_mode = cValidate; else if (strcasecmp(pArg, "-compare_ssim") == 0) m_compare_ssim = true; + else if (strcasecmp(pArg, "-pvrtc_clamp") == 0) + m_pvrtc_clamp = true; else if (strcasecmp(pArg, "-file") == 0) { REMAINING_ARGS_CHECK(1); @@ -578,6 +584,7 @@ public: bool m_etc1_only; bool m_fuzz_testing; bool m_compare_ssim; + bool m_pvrtc_clamp; }; static bool expand_multifile(command_line_params &opts) @@ -1009,9 +1016,11 @@ static bool unpack_and_validate_mode(command_line_params &opts, bool validate_fl // Fill the buffer with psuedo-random bytes, to help more visibly detect cases where the transcoder fails to write to part of the output. fill_buffer_with_random_bytes(gi.get_ptr(), gi.get_size_in_bytes()); + uint32_t decode_flags = (opts.m_pvrtc_clamp ? 0 : basist::basisu_transcoder::cDecodeFlagsPVRTCWrapAddressing); + tm.start(); - - if (!dec.transcode_image_level(&basis_data[0], (uint32_t)basis_data.size(), image_index, level_index, gi.get_ptr(), gi.get_total_blocks(), transcoder_tex_fmt, 0)) + + if (!dec.transcode_image_level(&basis_data[0], (uint32_t)basis_data.size(), image_index, level_index, gi.get_ptr(), gi.get_total_blocks(), transcoder_tex_fmt, decode_flags)) { error_printf("Failed transcoding image level (%u %u %u)!\n", image_index, level_index, format_iter); return false; @@ -1094,7 +1103,8 @@ static bool unpack_and_validate_mode(command_line_params &opts, bool validate_fl } image u; - if (!gi[level_index].unpack(u)) + const bool pvrtc_wrap_addressing = !opts.m_pvrtc_clamp; + if (!gi[level_index].unpack(u, pvrtc_wrap_addressing)) { printf("Warning: Failed unpacking GPU texture data (%u %u %u). Unpacking as much as possible.\n", format_iter, image_index, level_index); total_unpack_warnings++;