![]() |
Rendering Engine 0.2.9
Modular Graphics Rendering Engine | v0.2.9
|
Manages texture loading, GPU uploading, and caching for reuse. More...
#include <texture_cache.hpp>
Inherits rendering_engine::IRendererObserver.
Public Member Functions | |
| TextureCache (IRenderer *renderer) | |
| Constructs the TextureCache with a reference to the renderer. More... | |
| ~TextureCache () | |
| void | LoadTexturesFromFolder (std::string pathToFolder) |
| Loads all supported texture files (*.jpg, *.png) from a specified folder into RAM and uploads them to the GPU. More... | |
| void | LoadTexture (std::string textureName, ImageData imageData) |
| void | LoadTexturesFromPackage () |
| Loads all textures from the packed asset archive. More... | |
| std::string | UploadTextureToRAM (std::string path) |
| Loads a single texture into RAM from the given file path. More... | |
| std::string | UploadTextureToRAM (std::string textureFileName, std::vector< uint8_t > const &fileBytes) |
| Loads a single texture into RAM from raw file bytes. More... | |
| std::string | UploadTextureToRAM (std::string textureName, ImageData imageData) |
| void | UploadTextureToGPU (std::string textureName) |
| Uploads a texture (previously loaded into RAM) to GPU. More... | |
| void | ReleaseTextureFromGPU (std::string textureName) |
| Releases a texture from GPU memory. More... | |
| void | ReleaseAllFromGPU () |
| Releases all cached textures from GPU memory. More... | |
| void | ReleaseAll () |
| Fully clears the texture cache, including both RAM and GPU resources. More... | |
| std::shared_ptr< ImageDataGpu > | GetTextureResources (std::string filename) |
| Retrieves the full texture resource wrapper from cache. More... | |
| ITextureRenderResources * | GetTextureRenderResources (std::string filename) |
| Retrieves only the GPU render resources of a cached texture. More... | |
| size_t | GetSizeInRAM () const |
| Gets the total size of all currently cached textures in RAM. More... | |
| size_t | GetSizeInGPU () const |
| Gets the total size of all textures currently uploaded to GPU. More... | |
Public Member Functions inherited from rendering_engine::IRendererObserver | |
| virtual void | OnRenderResourcesRelease ()=0 |
| Renderer callback: release all GPU resources (used during device loss/reset). More... | |
| virtual void | OnRenderResourcesRebuild ()=0 |
| Renderer callback: re-upload or recreate all GPU resources (used after device reset/rebuild). More... | |
| virtual | ~IRendererObserver ()=default |
| Virtual destructor. More... | |
Protected Member Functions | |
| void | OnRenderResourcesRelease () override |
| Renderer callback: release all GPU resources (used during device loss/reset). More... | |
| void | OnRenderResourcesRebuild () override |
| Renderer callback: re-upload or recreate all GPU resources (used after device reset/rebuild). More... | |
Protected Attributes | |
| IRenderer * | mRenderer |
| std::unordered_map< std::string, std::shared_ptr< ImageDataGpu > > | mTextures |
| size_t | mTotalSizeRAM |
| size_t | mTotalSizeGPU |
Manages texture loading, GPU uploading, and caching for reuse.
This class handles texture resource management at runtime. It supports loading image files (JPG and PNG) from a folder or path into RAM, uploading them to GPU, and provides access to the texture resources through string identifiers (filenames without extensions).
Textures are stored using shared pointers to ImageDataGpu, and memory tracking is performed for both RAM and GPU sides.
Definition at line 31 of file texture_cache.hpp.
| rendering_engine::TextureCache::TextureCache | ( | IRenderer * | renderer | ) |
Constructs the TextureCache with a reference to the renderer.
| renderer | Pointer to the active rendering backend. |
Definition at line 16 of file texture_cache.cpp.
| rendering_engine::TextureCache::~TextureCache | ( | ) |
Definition at line 26 of file texture_cache.cpp.
| size_t rendering_engine::TextureCache::GetSizeInGPU | ( | ) | const |
Gets the total size of all textures currently uploaded to GPU.
Definition at line 284 of file texture_cache.cpp.
| size_t rendering_engine::TextureCache::GetSizeInRAM | ( | ) | const |
Gets the total size of all currently cached textures in RAM.
Definition at line 279 of file texture_cache.cpp.
| ITextureRenderResources * rendering_engine::TextureCache::GetTextureRenderResources | ( | std::string | filename | ) |
Retrieves only the GPU render resources of a cached texture.
Useful when the caller only needs GPU handles and does not care about image metadata.
| filename | Base filename used during loading. |
Definition at line 269 of file texture_cache.cpp.
| std::shared_ptr< ImageDataGpu > rendering_engine::TextureCache::GetTextureResources | ( | std::string | filename | ) |
Retrieves the full texture resource wrapper from cache.
| filename | Base filename used during loading. |
Definition at line 259 of file texture_cache.cpp.
| void rendering_engine::TextureCache::LoadTexture | ( | std::string | textureName, |
| ImageData | imageData | ||
| ) |
Definition at line 63 of file texture_cache.cpp.
| void rendering_engine::TextureCache::LoadTexturesFromFolder | ( | std::string | pathToFolder | ) |
Loads all supported texture files (*.jpg, *.png) from a specified folder into RAM and uploads them to the GPU.
Each texture is registered under its base filename (without extension) for later access. Invalid paths or unsupported file types are skipped silently.
| pathToFolder | Absolute or relative path to the folder containing texture files. |
Definition at line 32 of file texture_cache.cpp.
| void rendering_engine::TextureCache::LoadTexturesFromPackage | ( | ) |
Loads all textures from the packed asset archive.
This function behaves similarly to LoadTexturesFromFolder(), but instead of scanning a filesystem directory, it iterates over virtual file entries stored inside the packed content system created by the packaging tool.
Only entries located under the virtual folder: "Textures/" are considered valid texture resources.
For each entry, the raw file bytes are retrieved via Utility::ReadPackedFile(), decoded into an ImageDataGpu instance, and stored in the RAM cache. GPU uploading must still be triggered via UploadTextureToGPU().
Definition at line 73 of file texture_cache.cpp.
|
overrideprotectedvirtual |
Renderer callback: re-upload or recreate all GPU resources (used after device reset/rebuild).
This method will be called after the device or swapchain is recreated, allowing the observer to re-upload or recreate all necessary resources for rendering.
Implements rendering_engine::IRendererObserver.
Definition at line 294 of file texture_cache.cpp.
|
overrideprotectedvirtual |
Renderer callback: release all GPU resources (used during device loss/reset).
This method will be called before any device or swapchain is destroyed, allowing the observer to safely release all handles and deallocate any GPU memory.
Implements rendering_engine::IRendererObserver.
Definition at line 289 of file texture_cache.cpp.
| void rendering_engine::TextureCache::ReleaseAll | ( | ) |
Fully clears the texture cache, including both RAM and GPU resources.
Definition at line 247 of file texture_cache.cpp.
| void rendering_engine::TextureCache::ReleaseAllFromGPU | ( | ) |
Releases all cached textures from GPU memory.
This does not affect RAM-side caching.
Definition at line 238 of file texture_cache.cpp.
| void rendering_engine::TextureCache::ReleaseTextureFromGPU | ( | std::string | textureName | ) |
Releases a texture from GPU memory.
The texture remains in RAM cache and can be uploaded again later.
| filename | Cache key of the texture to release (base filename). |
Definition at line 223 of file texture_cache.cpp.
| void rendering_engine::TextureCache::UploadTextureToGPU | ( | std::string | textureName | ) |
Uploads a texture (previously loaded into RAM) to GPU.
If the texture is not found in RAM cache, the function does nothing.
| textureName | Base texture name (no path, no extension) used as the cache key. |
Definition at line 197 of file texture_cache.cpp.
| std::string rendering_engine::TextureCache::UploadTextureToRAM | ( | std::string | path | ) |
Loads a single texture into RAM from the given file path.
The texture will not be uploaded to GPU automatically. The caller must use UploadTextureToGPU() after this call if GPU usage is needed.
| path | Full file path to the texture image (JPG/PNG). |
Definition at line 112 of file texture_cache.cpp.
| std::string rendering_engine::TextureCache::UploadTextureToRAM | ( | std::string | textureFileName, |
| std::vector< uint8_t > const & | fileBytes | ||
| ) |
Loads a single texture into RAM from raw file bytes.
This overload enables texture loading from virtual files stored in a packed asset archive or from any memory-based source rather than the OS filesystem.
The fileBytes buffer must contain the complete encoded texture data (e.g., PNG or JPEG). The data is decoded and stored inside ImageDataGpu.
| textureFileName | Cache key representing the virtual texture path (e.g., "Textures/myTexture.png" or simply "myTexture"). |
| fileBytes | Raw encoded texture file data (PNG/JPG). |
Definition at line 150 of file texture_cache.cpp.
| std::string rendering_engine::TextureCache::UploadTextureToRAM | ( | std::string | textureName, |
| ImageData | imageData | ||
| ) |
Definition at line 174 of file texture_cache.cpp.
|
protected |
Definition at line 170 of file texture_cache.hpp.
|
protected |
Definition at line 171 of file texture_cache.hpp.
|
protected |
Definition at line 174 of file texture_cache.hpp.
|
protected |
Definition at line 173 of file texture_cache.hpp.