diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index d0f8976a3a..247dab4795 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -1328,6 +1328,11 @@ void TextureCacheDX9::BuildTexture(TexCacheEntry *const entry, bool replaceImage int h = gstate.getTextureHeight(0); ReplacedTexture &replaced = replacer.FindReplacement(cachekey, entry->fullhash, w, h); if (replaced.GetSize(0, w, h)) { + if (replaceImages) { + // Since we're replacing the texture, we can't replace the image inside. + ReleaseTexture(entry); + replaceImages = false; + } // We're replacing, so we won't scale. scaleFactor = 1; entry->status |= TexCacheEntry::STATUS_IS_SCALED; diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index cb39a2a7ed..28c28abf31 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -1389,9 +1389,6 @@ void TextureCache::BuildTexture(TexCacheEntry *const entry, bool replaceImages) return; } - glBindTexture(GL_TEXTURE_2D, entry->textureName); - lastBoundTexture = entry->textureName; - // Adjust maxLevel to actually present levels.. bool badMipSizes = false; int maxLevel = entry->maxLevel; @@ -1434,6 +1431,13 @@ void TextureCache::BuildTexture(TexCacheEntry *const entry, bool replaceImages) int h = gstate.getTextureHeight(0); ReplacedTexture &replaced = replacer.FindReplacement(cachekey, entry->fullhash, w, h); if (replaced.GetSize(0, w, h)) { + if (replaceImages) { + // Since we're replacing the texture, we can't replace the image inside. + glDeleteTextures(1, &entry->textureName); + entry->textureName = AllocTextureName(); + replaceImages = false; + } + // We're replacing, so we won't scale. scaleFactor = 1; entry->status |= TexCacheEntry::STATUS_IS_SCALED; @@ -1463,6 +1467,9 @@ void TextureCache::BuildTexture(TexCacheEntry *const entry, bool replaceImages) } } + glBindTexture(GL_TEXTURE_2D, entry->textureName); + lastBoundTexture = entry->textureName; + // Disabled this due to issue #6075: https://github.com/hrydgard/ppsspp/issues/6075 // This breaks Dangan Ronpa 2 with mipmapping enabled. Why? No idea, it shouldn't. // glTexStorage2D probably has few benefits for us anyway.