8#include "boost/filesystem.hpp"
31 boost::filesystem::path pathToDirectory = boost::filesystem::path(pathToFolder);
32 const bool isValidFolderPath = boost::filesystem::exists(boost::filesystem::path(pathToFolder)) && boost::filesystem::is_directory(boost::filesystem::path(pathToFolder));
33 if (!isValidFolderPath)
39 for (boost::filesystem::directory_entry& x : boost::filesystem::directory_iterator(pathToDirectory))
42 if (!textureName.empty())
53 std::string folderEntry = {
"Textures/" };
54 for (
auto& entry : entries)
56 const std::string& virtualPath = entry.first;
57 if (virtualPath.rfind(folderEntry, 0) == 0)
59 std::string textureFileName = virtualPath.substr(folderEntry.size());
62 if (binaryFileData.empty())
64 std::cerr <<
"[TextureCache] Could not read packed texture: "
65 << virtualPath << std::endl;
71 if (!textureName.empty())
81 auto filePath = boost::filesystem::path(path);
82 if (!boost::filesystem::is_regular_file(filePath))
87 const std::string ext = filePath.extension().string();
88 const bool isExtensionSupported = (ext ==
".jpg") || (ext ==
".png");
89 if (!isExtensionSupported)
94 std::string filename = filePath.stem().string();
102 size_t size =
mTextures.at(filename)->GetSizeInRAM();
110 auto textureName = boost::filesystem::path(textureFileName).stem().string();
114 return std::string{};
118 size_t size =
mTextures.at(textureName)->GetSizeInRAM();
137 size_t size =
mTextures[filename]->GetSizeInGPU();
149 size_t size = texture->GetSizeInGPU();
150 texture->ReleaseFromGPU();
159 texture.second->ReleaseFromGPU();
179 return search->second;
189 return mTextures.at(filename)->GetTextureRenderResources();
211 texture.second->UploadToGPU();
212 size_t size = texture.second->GetSizeInGPU();
Defines an abstract interface for rendering backends.
Interface for backend-specific GPU texture resource management.
void OnRenderResourcesRelease() override
Renderer callback: release all GPU resources (used during device loss/reset).
std::unordered_map< std::string, std::shared_ptr< ImageDataGpu > > mTextures
void LoadTexturesFromPackage()
Loads all textures from the packed asset archive.
void ReleaseAll()
Fully clears the texture cache, including both RAM and GPU resources.
void OnRenderResourcesRebuild() override
Renderer callback: re-upload or recreate all GPU resources (used after device reset/rebuild).
std::shared_ptr< ImageDataGpu > GetTextureResources(std::string filename)
Retrieves the full texture resource wrapper from cache.
void ReleaseAllFromGPU()
Releases all cached textures from GPU memory.
std::string UploadTextureToRAM(std::string path)
Loads a single texture into RAM from the given file path.
ITextureRenderResources * GetTextureRenderResources(std::string filename)
Retrieves only the GPU render resources of a cached texture.
size_t GetSizeInRAM() const
Gets the total size of all currently cached textures in RAM.
void UploadTextureToGPU(std::string filename)
Uploads a texture (previously loaded into RAM) to GPU.
void LoadTexturesFromFolder(std::string pathToFolder)
Loads all supported texture files (*.jpg, *.png) from a specified folder into RAM and uploads them to...
TextureCache(IRenderer *renderer)
Constructs the TextureCache with a reference to the renderer.
size_t GetSizeInGPU() const
Gets the total size of all textures currently uploaded to GPU.
void ReleaseTextureFromGPU(std::string filename)
Releases a texture from GPU memory.
static const PackEntries & GetPackEntries()
Returns the manifest of packed files.
static std::vector< uint8_t > ReadPackedFile(const std::string &entryPath)
Reads raw bytes of a file stored inside Pack.bin.