From deaf61299f12168b775d7e2d448b9eca149c0e7e Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Mon, 2 Oct 2017 16:58:55 +0700 Subject: [PATCH] Decrease level of mip-map texture if texture with given size and level can't be created by OpenGL. Fixed shadows of empire: black triangles (regression!) #1612 --- src/Textures.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Textures.cpp b/src/Textures.cpp index c4036f95..36f76cb1 100644 --- a/src/Textures.cpp +++ b/src/Textures.cpp @@ -3,6 +3,7 @@ #include #include // std::this_thread::sleep_for #include // std::chrono::seconds +#include "Platform.h" #include "Textures.h" #include "GBI.h" #include "RSP.h" @@ -1147,8 +1148,16 @@ void TextureCache::_load(u32 _tile, CachedTexture *_pTexture) s32 mipLevel = 0; _pTexture->max_level = 0; - if (config.generalEmulation.enableLOD != 0 && gSP.texture.level > 1) - _pTexture->max_level = static_cast(_tile == 0 ? 0 : gSP.texture.level - 1); + if (config.generalEmulation.enableLOD != 0 && gSP.texture.level > 1) { + if (_tile == 0) { + _pTexture->max_level = 0; + } else { + _pTexture->max_level = static_cast(gSP.texture.level - 1); + const u16 dim = std::max(_pTexture->width, _pTexture->height); + while (dim < static_cast(1 << _pTexture->max_level)) + --_pTexture->max_level; + } + } ObjectHandle name; CachedTexture tmptex(name);