Fix the texture dimensions check in DynOS (#67)

This commit is contained in:
Radek Krzyśków 2024-06-12 00:47:22 +02:00 committed by GitHub
parent ed8b316270
commit eb45999791
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -451,8 +451,8 @@ void DynOS_Tex_AddCustom(const SysPath &aFilename, const char *aTexName) {
} }
} }
static inline bool IsPowerOfTwo(int n) { static inline bool IsPowerOfTwo(s32 n) {
return (ceil(log2(n)) == floor(log2(n))); return (n > 0) && ((n & (n - 1)) == 0);
} }
bool DynOS_Tex_Get(const char* aTexName, struct TextureInfo* aOutTexInfo) { bool DynOS_Tex_Get(const char* aTexName, struct TextureInfo* aOutTexInfo) {
@ -487,8 +487,7 @@ bool DynOS_Tex_Get(const char* aTexName, struct TextureInfo* aOutTexInfo) {
return false; return false;
} }
// texture width or height is NPOT // texture width or height is NPOT
if ((_Data->mRawWidth > 0 && _Data->mRawWidth & (_Data->mRawWidth - 1) == 0) || if (!IsPowerOfTwo(_Data->mRawWidth) || !IsPowerOfTwo(_Data->mRawHeight)) {
(_Data->mRawHeight > 0 && _Data->mRawHeight & (_Data->mRawHeight - 1) == 0)) {
PrintError("Tex file '%s' has non power of two width or height", aTexName); PrintError("Tex file '%s' has non power of two width or height", aTexName);
PrintConsole(CONSOLE_MESSAGE_WARNING, "Tex file '%s' has non power of two width or height", aTexName); PrintConsole(CONSOLE_MESSAGE_WARNING, "Tex file '%s' has non power of two width or height", aTexName);
return false; return false;