From 5f211e0a386a42283d9d336dd5c724ee7aa3c01f Mon Sep 17 00:00:00 2001 From: fallenoak Date: Wed, 22 Oct 2025 08:29:34 -0500 Subject: [PATCH] chore(component): clean up mip level calculation in CCharacterComponent::PasteFromSkin --- src/component/CCharacterComponent.cpp | 10 ++++++---- src/component/CCharacterComponent.hpp | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/component/CCharacterComponent.cpp b/src/component/CCharacterComponent.cpp index b887694..62335d8 100644 --- a/src/component/CCharacterComponent.cpp +++ b/src/component/CCharacterComponent.cpp @@ -135,13 +135,15 @@ void CCharacterComponent::PasteFromSkin(COMPONENT_SECTIONS section, void* srcTex srcInfo.alphaSize = 0; if (srcInfo.width >= CCharacterComponent::s_textureSize || srcInfo.height >= CCharacterComponent::s_textureSize ) { - int32_t levelDelta; + // Calculate mip level matching CCharacterComponent::s_textureSize + int32_t mipLevel = 0; int32_t srcWidth = srcInfo.width; - for (levelDelta = 0; CCharacterComponent::s_textureSize < srcWidth; levelDelta++) { - srcWidth >>= 1; + while (srcWidth > CCharacterComponent::s_textureSize) { + srcWidth /= 2; + mipLevel++; } - CCharacterComponent::Paste(srcTexture, dstMips, sectionInfo.pos, sectionInfo.pos, sectionInfo.size, srcInfo, levelDelta); + CCharacterComponent::Paste(srcTexture, dstMips, sectionInfo.pos, sectionInfo.pos, sectionInfo.size, srcInfo, mipLevel); } else { CCharacterComponent::PasteScale(srcTexture, dstMips, sectionInfo.pos, sectionInfo.pos, sectionInfo.size, srcInfo); } diff --git a/src/component/CCharacterComponent.hpp b/src/component/CCharacterComponent.hpp index 39f9df5..643f28f 100644 --- a/src/component/CCharacterComponent.hpp +++ b/src/component/CCharacterComponent.hpp @@ -87,7 +87,7 @@ class CCharacterComponent { static void RenderPrepLU(CCharacterComponent* component); static void RenderPrepTL(CCharacterComponent* component); static void RenderPrepTU(CCharacterComponent* component); - static void Paste(void* srcTexture, MipBits* dstMips, const C2iVector& a3, const C2iVector& a4, const C2iVector& a5, TCTEXTUREINFO& srcInfo, int32_t a7); + static void Paste(void* srcTexture, MipBits* dstMips, const C2iVector& a3, const C2iVector& a4, const C2iVector& a5, TCTEXTUREINFO& srcInfo, int32_t mipLevel); static void PasteFromSkin(COMPONENT_SECTIONS section, void* srcTexture, MipBits* dstMips); static void PasteScale(void* srcTexture, MipBits* dstMips, const C2iVector& a3, const C2iVector& a4, const C2iVector& a5, TCTEXTUREINFO& srcInfo); static void UpdateBaseTexture(EGxTexCommand cmd, uint32_t width, uint32_t height, uint32_t depth, uint32_t mipLevel, void* userArg, uint32_t& texelStrideInBytes, const void*& texels);