|
Crimson Engine 1.0.0
A high-performance C++20 game engine prototype showcasing a custom ECS, Vulkan renderer, and ImGui editor.
|
Manages loading, caching, and GPU memory uploads for textures and glTF model meshes. More...
#include <ResourceManager.hpp>
Public Member Functions | |
| ResourceManager ()=default | |
| Construct a new Resource Manager object. | |
| ~ResourceManager ()=default | |
| Destroy the Resource Manager object. | |
| Texture * | loadTexture (const std::string &path, VulkanRenderer &renderer, TextureFilterMode filterMode=TextureFilterMode::Bilinear) |
| Loads a texture from file, uploading it to the GPU and caching the resource. | |
| Mesh | loadMesh (const std::string &path, VulkanRenderer &renderer, int primitiveIndex=-1) |
| Loads a glTF mesh from file, uploading geometry buffers to the GPU and caching it. | |
| void | clearMeshCache (const std::string &path) |
| Clears the cached mesh for a specific path to force a re-import. | |
| int | getMeshPrimitiveCount (const std::string &path) |
| Scans a glTF file and returns the count of primitive submesh parts. | |
| bool | loadSkeletonAndAnimations (const std::string &path, SkeletonComponent &skeleton, AnimatorComponent &animator, bool append=false) |
| Loads skeletal skin and animations from a glTF file. | |
| bool | loadBinarySkeletonAndAnimations (const std::string &path, SkeletonComponent &skeleton, AnimatorComponent &animator, bool append=false) |
| Loads skeletal skin and animations from a custom binary animation file (.anim). | |
| bool | saveBinarySkeletonAndAnimations (const std::string &path, const SkeletonComponent &skeleton, const AnimatorComponent &animator) |
| Saves skeletal skin and animations to a custom binary animation file (.anim). | |
| void | updateTextureFilterMode (const std::string &path, VulkanRenderer &renderer, TextureFilterMode filterMode) |
| Updates an already loaded texture's filter settings live and recreates its Vulkan sampler. | |
| void | createDefaultTextures (VulkanRenderer &renderer) |
| Initializes default 1x1 textures (white, normal, metallic) for fallbacks. | |
| Texture * | getDefaultWhiteTexture () |
| Retrieves the default fallback white texture pointer. | |
| Texture * | getDefaultNormalTexture () |
| Texture * | getDefaultMetallicTexture () |
| void | updateMaterialDescriptorSet (Material &mat, VulkanRenderer &renderer) |
| Dynamically updates or allocates a descriptor set for a Material, binding its diffuse, normal, and metallic maps. | |
| Texture * | createTextureFromPixels (const std::string &cacheKey, const uint8_t *pixels, int width, int height, VulkanRenderer &renderer, TextureFilterMode filterMode=TextureFilterMode::Nearest) |
| Creates and caches a Vulkan texture directly from raw RGBA pixel data. Used by TilesetAsset::buildAtlas() to upload the packed tile atlas. | |
| void | evictTexture (const std::string &cacheKey, VkDevice device) |
| Removes a texture from the cache and frees its GPU memory. | |
| void | cleanup (VkDevice device) |
| Safely frees all cached textures and meshes from GPU memory. | |
| uint32_t | findMemoryType (VkPhysicalDevice physicalDevice, uint32_t typeFilter, VkMemoryPropertyFlags properties) |
| Finds a memory type matching properties in the physical GPU. | |
Private Member Functions | |
| void | createTextureImage (const std::string &path, VulkanRenderer &renderer, Texture &texture) |
| Helper to load pixel data, create a VkImage, and copy staging data onto the GPU. | |
| void | createTextureImageView (VkDevice device, Texture &texture) |
| Helper to create standard 2D image views. | |
| void | createTextureSampler (VkDevice device, Texture &texture, TextureFilterMode filterMode) |
| Helper to configure texture samplers with the specified filter mode. | |
Private Attributes | |
| std::unordered_map< std::string, std::unique_ptr< Texture > > | textureCache |
| Cache of loaded textures mapped by file path. | |
| std::unordered_map< std::string, Mesh > | meshCache |
| Cache of loaded meshes mapped by file path. | |
| Texture | defaultWhiteTexture |
| Fallback default 1x1 texture. | |
| Texture | defaultNormalTexture |
| Texture | defaultMetallicTexture |
Manages loading, caching, and GPU memory uploads for textures and glTF model meshes.
|
default |
Construct a new Resource Manager object.
|
default |
Destroy the Resource Manager object.
| void ResourceManager::cleanup | ( | VkDevice | device | ) |
Safely frees all cached textures and meshes from GPU memory.
| device | Vulkan logical device context. |
| void ResourceManager::clearMeshCache | ( | const std::string & | path | ) |
Clears the cached mesh for a specific path to force a re-import.
| path | The file path. |
| void ResourceManager::createDefaultTextures | ( | VulkanRenderer & | renderer | ) |
Initializes default 1x1 textures (white, normal, metallic) for fallbacks.
| renderer | Reference to active VulkanRenderer. |
| Texture * ResourceManager::createTextureFromPixels | ( | const std::string & | cacheKey, |
| const uint8_t * | pixels, | ||
| int | width, | ||
| int | height, | ||
| VulkanRenderer & | renderer, | ||
| TextureFilterMode | filterMode = TextureFilterMode::Nearest ) |
Creates and caches a Vulkan texture directly from raw RGBA pixel data. Used by TilesetAsset::buildAtlas() to upload the packed tile atlas.
| cacheKey | Unique string key used for the texture cache (e.g. "tileset:forest"). |
| pixels | Pointer to RGBA8 pixel data (4 bytes per pixel, row-major). |
| width | Width in pixels. |
| height | Height in pixels. |
| renderer | Active VulkanRenderer. |
| filterMode | Desired sampler filter mode. |
|
private |
Helper to load pixel data, create a VkImage, and copy staging data onto the GPU.
|
private |
Helper to create standard 2D image views.
|
private |
Helper to configure texture samplers with the specified filter mode.
| void ResourceManager::evictTexture | ( | const std::string & | cacheKey, |
| VkDevice | device ) |
Removes a texture from the cache and frees its GPU memory.
| cacheKey | The key used when the texture was created. |
| device | Vulkan logical device. |
| uint32_t ResourceManager::findMemoryType | ( | VkPhysicalDevice | physicalDevice, |
| uint32_t | typeFilter, | ||
| VkMemoryPropertyFlags | properties ) |
Finds a memory type matching properties in the physical GPU.
|
inline |
|
inline |
|
inline |
Retrieves the default fallback white texture pointer.
| int ResourceManager::getMeshPrimitiveCount | ( | const std::string & | path | ) |
Scans a glTF file and returns the count of primitive submesh parts.
| path | The glTF file path. |
| bool ResourceManager::loadBinarySkeletonAndAnimations | ( | const std::string & | path, |
| SkeletonComponent & | skeleton, | ||
| AnimatorComponent & | animator, | ||
| bool | append = false ) |
Loads skeletal skin and animations from a custom binary animation file (.anim).
| path | File path of the binary animation. |
| skeleton | Target SkeletonComponent to populate. |
| animator | Target AnimatorComponent to populate. |
| append | If true, animation clips are appended instead of clearing the animator's cache. |
| Mesh ResourceManager::loadMesh | ( | const std::string & | path, |
| VulkanRenderer & | renderer, | ||
| int | primitiveIndex = -1 ) |
Loads a glTF mesh from file, uploading geometry buffers to the GPU and caching it.
| path | The glTF/glb file path. |
| renderer | Reference to active VulkanRenderer. |
| bool ResourceManager::loadSkeletonAndAnimations | ( | const std::string & | path, |
| SkeletonComponent & | skeleton, | ||
| AnimatorComponent & | animator, | ||
| bool | append = false ) |
Loads skeletal skin and animations from a glTF file.
| path | The glTF/glb file path. |
| skeleton | Target SkeletonComponent to populate. |
| animator | Target AnimatorComponent to populate. |
| Texture * ResourceManager::loadTexture | ( | const std::string & | path, |
| VulkanRenderer & | renderer, | ||
| TextureFilterMode | filterMode = TextureFilterMode::Bilinear ) |
Loads a texture from file, uploading it to the GPU and caching the resource.
| path | The texture file path. |
| renderer | Reference to active VulkanRenderer. |
| filterMode | Desired filtering mode (will be overridden by .meta if exists). |
| bool ResourceManager::saveBinarySkeletonAndAnimations | ( | const std::string & | path, |
| const SkeletonComponent & | skeleton, | ||
| const AnimatorComponent & | animator ) |
Saves skeletal skin and animations to a custom binary animation file (.anim).
| path | File path to save the binary animation. |
| skeleton | Source SkeletonComponent. |
| animator | Source AnimatorComponent. |
| void ResourceManager::updateMaterialDescriptorSet | ( | Material & | mat, |
| VulkanRenderer & | renderer ) |
Dynamically updates or allocates a descriptor set for a Material, binding its diffuse, normal, and metallic maps.
| void ResourceManager::updateTextureFilterMode | ( | const std::string & | path, |
| VulkanRenderer & | renderer, | ||
| TextureFilterMode | filterMode ) |
Updates an already loaded texture's filter settings live and recreates its Vulkan sampler.
| path | The texture file path. |
| renderer | Reference to VulkanRenderer. |
| filterMode | The new texture filter mode to apply. |
|
private |
|
private |
|
private |
Fallback default 1x1 texture.
|
private |
Cache of loaded meshes mapped by file path.
|
private |
Cache of loaded textures mapped by file path.