From 77622566d71b14e68635dbd92084b1780f9ee35e Mon Sep 17 00:00:00 2001 From: fallenoak Date: Mon, 20 Oct 2025 16:50:40 -0500 Subject: [PATCH] feat(gx): add TextureCalcMipCount --- src/gx/Texture.cpp | 20 ++++++++++++++++++++ src/gx/Texture.hpp | 2 ++ 2 files changed, 22 insertions(+) diff --git a/src/gx/Texture.cpp b/src/gx/Texture.cpp index 4d7cf73..35b5653 100644 --- a/src/gx/Texture.cpp +++ b/src/gx/Texture.cpp @@ -856,6 +856,26 @@ void TextureCacheNewTexture(CTexture* texture, const CImVector& color) { // TODO } +uint32_t TextureCalcMipCount(uint32_t width, uint32_t height) { + uint32_t count = 1; + + while (width > 1 || height > 1) { + width /= 2; + if (width == 0) { + width = 1; + } + + height /= 2; + if (height == 0) { + height = 1; + } + + count++; + } + + return count; +} + HTEXTURE TextureCreate(const char* fileName, CGxTexFlags texFlags, CStatus* status, int32_t createFlags) { STORM_ASSERT(fileName); STORM_ASSERT(*fileName); diff --git a/src/gx/Texture.hpp b/src/gx/Texture.hpp index cb68564..8fa25d1 100644 --- a/src/gx/Texture.hpp +++ b/src/gx/Texture.hpp @@ -55,6 +55,8 @@ void TextureCacheNewTexture(CTexture*, CGxTexFlags); void TextureCacheNewTexture(CTexture*, const CImVector&); +uint32_t TextureCalcMipCount(uint32_t width, uint32_t height); + HTEXTURE TextureCreate(const char*, CGxTexFlags, CStatus*, int32_t); HTEXTURE TextureCreate(uint32_t, uint32_t, EGxTexFormat, EGxTexFormat, CGxTexFlags, void*, void (*)(EGxTexCommand, uint32_t, uint32_t, uint32_t, uint32_t, void*, uint32_t&, const void*&), const char*, int32_t);