From 225a602a7437ded2ffffa67d3412f5b816f6a384 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Tue, 16 Aug 2022 22:37:36 +0200 Subject: [PATCH] If the same raster image is used with different interpolation methods then these are now cached separately. --- es-core/src/resources/TextureResource.cpp | 27 ++++++++++++++++------- es-core/src/resources/TextureResource.h | 2 +- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/es-core/src/resources/TextureResource.cpp b/es-core/src/resources/TextureResource.cpp index 3ac592166..cdd8fbee2 100644 --- a/es-core/src/resources/TextureResource.cpp +++ b/es-core/src/resources/TextureResource.cpp @@ -89,11 +89,22 @@ void TextureResource::manualUnload(std::string path, bool tile) { const std::string canonicalPath = Utils::FileSystem::getCanonicalPath(path); - TextureKeyType key(canonicalPath, tile); - auto foundTexture = sTextureMap.find(key); + // TODO: We always attempt to unload both the linear and nearest interpolation entries + // which is a bit of a hack. Rewrite this to only unload the requested image. + { + TextureKeyType key {canonicalPath, tile, false}; + auto foundTexture = sTextureMap.find(key); - if (foundTexture != sTextureMap.cend()) { - sTextureMap.erase(foundTexture); + if (foundTexture != sTextureMap.cend()) + sTextureMap.erase(foundTexture); + } + + { + TextureKeyType key {canonicalPath, tile, true}; + auto foundTexture = sTextureMap.find(key); + + if (foundTexture != sTextureMap.cend()) + sTextureMap.erase(foundTexture); } } @@ -152,7 +163,7 @@ std::shared_ptr TextureResource::get(const std::string& path, return tex; } - TextureKeyType key {canonicalPath, tile}; + TextureKeyType key {canonicalPath, tile, linearMagnify}; auto foundTexture = sTextureMap.find(key); if (foundTexture != sTextureMap.cend()) { @@ -163,12 +174,12 @@ std::shared_ptr TextureResource::get(const std::string& path, // Need to create it. std::shared_ptr tex; tex = std::shared_ptr( - new TextureResource(key.first, tile, dynamic, linearMagnify, forceRasterization)); + new TextureResource(std::get<0>(key), tile, dynamic, linearMagnify, forceRasterization)); std::shared_ptr data = sTextureDataManager.get(tex.get()); // Is it an SVG? - if (Utils::String::toLower(key.first.substr(key.first.size() - 4, std::string::npos)) != - ".svg") { + if (Utils::String::toLower( + std::get<0>(key).substr(std::get<0>(key).size() - 4, std::string::npos)) != ".svg") { // Probably not. Add it to our map. We don't add SVGs because 2 SVGs might be // rasterized at different sizes. sTextureMap[key] = std::weak_ptr(tex); diff --git a/es-core/src/resources/TextureResource.h b/es-core/src/resources/TextureResource.h index d5760af00..cf44e2cc5 100644 --- a/es-core/src/resources/TextureResource.h +++ b/es-core/src/resources/TextureResource.h @@ -91,7 +91,7 @@ private: glm::vec2 mSourceSize; bool mForceLoad; - using TextureKeyType = std::pair; + using TextureKeyType = std::tuple; // Map of textures, used to prevent duplicate textures. static inline std::map> sTextureMap; // Set of all textures, used for memory management.