Added a manualUnloadAll function to TextureResource.

Also converted some variables to static inline and cleand up some code.
This commit is contained in:
Leon Styhre 2022-08-14 21:31:02 +02:00
parent b69706fc35
commit 899ace3eb6
2 changed files with 5 additions and 9 deletions

View file

@ -11,11 +11,6 @@
#include "utils/FileSystemUtil.h"
#include "utils/StringUtil.h"
TextureDataManager TextureResource::sTextureDataManager;
std::map<TextureResource::TextureKeyType, std::weak_ptr<TextureResource>>
TextureResource::sTextureMap;
std::set<TextureResource*> TextureResource::sAllTextures;
TextureResource::TextureResource(
const std::string& path, bool tile, bool dynamic, bool linearMagnify, bool forceRasterization)
: mTextureData {nullptr}
@ -157,7 +152,7 @@ std::shared_ptr<TextureResource> TextureResource::get(const std::string& path,
return tex;
}
TextureKeyType key(canonicalPath, tile);
TextureKeyType key {canonicalPath, tile};
auto foundTexture = sTextureMap.find(key);
if (foundTexture != sTextureMap.cend()) {

View file

@ -35,6 +35,7 @@ public:
void initFromPixels(const unsigned char* dataRGBA, size_t width, size_t height);
virtual void initFromMemory(const char* data, size_t length);
static void manualUnload(std::string path, bool tile);
static void manualUnloadAll() { sTextureMap.clear(); }
// Returns the raw pixel values.
std::vector<unsigned char> getRawRGBAData();
@ -79,7 +80,7 @@ private:
std::shared_ptr<TextureData> mTextureData;
// The texture data manager manages loading and unloading of filesystem based textures.
static TextureDataManager sTextureDataManager;
static inline TextureDataManager sTextureDataManager;
glm::ivec2 mSize;
glm::vec2 mSourceSize;
@ -87,9 +88,9 @@ private:
using TextureKeyType = std::pair<std::string, bool>;
// Map of textures, used to prevent duplicate textures.
static std::map<TextureKeyType, std::weak_ptr<TextureResource>> sTextureMap;
static inline std::map<TextureKeyType, std::weak_ptr<TextureResource>> sTextureMap;
// Set of all textures, used for memory management.
static std::set<TextureResource*> sAllTextures;
static inline std::set<TextureResource*> sAllTextures;
};
#endif // ES_CORE_RESOURCES_TEXTURE_RESOURCE_H