From 1cd2b7506ae9584acdc23c13f1967cfaf64ea806 Mon Sep 17 00:00:00 2001 From: flashk Date: Wed, 14 Apr 2021 10:37:16 -0700 Subject: [PATCH] Apply swizzle to user supplied mipmaps --- encoder/basisu_comp.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/encoder/basisu_comp.cpp b/encoder/basisu_comp.cpp index e9c9d1a..9a4a1c0 100644 --- a/encoder/basisu_comp.cpp +++ b/encoder/basisu_comp.cpp @@ -623,7 +623,22 @@ namespace basisu // User-provided mipmaps for each layer or image in the texture array. for (uint32_t mip_index = 0; mip_index < m_params.m_source_mipmap_images[source_file_index].size(); mip_index++) { - const image& mip_img = m_params.m_source_mipmap_images[source_file_index][mip_index]; + image& mip_img = m_params.m_source_mipmap_images[source_file_index][mip_index]; + + if (m_params.m_swizzle[0] != 0 || + m_params.m_swizzle[1] != 1 || + m_params.m_swizzle[2] != 2 || + m_params.m_swizzle[3] != 3) + { + // Used for XY normal maps in RG - puts X in color, Y in alpha + for (uint32_t y = 0; y < mip_img.get_height(); y++) + for (uint32_t x = 0; x < mip_img.get_width(); x++) + { + const color_rgba &c = mip_img(x, y); + mip_img(x, y).set_noclamp_rgba(c[m_params.m_swizzle[0]], c[m_params.m_swizzle[1]], c[m_params.m_swizzle[2]], c[m_params.m_swizzle[3]]); + } + } + slices.push_back(mip_img); } }