10 std::string normalizePath(
const std::filesystem::path& path) {
12 std::string pathStr = path.generic_string();
15 if (pathStr.size() >= 2 && pathStr[0] ==
'.' && pathStr[1] ==
'/') {
16 pathStr = pathStr.substr(2);
24 std::string pathKey = normalizePath(path);
25 PLOGI <<
"TextureHandleRegistry::getOrCreateHandleImpl - normalized path: '" << pathKey <<
"' from '" << path.generic_string() <<
"'";
29 std::shared_lock<std::shared_mutex> readLock(
mutex_);
34 if (entry.
type != type) {
35 PLOGW <<
"TextureHandleRegistry: Type mismatch for path '" << pathKey
36 <<
"' - existing type=" <<
static_cast<int>(entry.
type)
37 <<
" requested type=" <<
static_cast<int>(type)
38 <<
". Using existing type.";
45 std::unique_lock<std::shared_mutex> writeLock(
mutex_);
55 uint32_t newId =
static_cast<uint32_t
>(
entries_.size());
62 entries_.push_back(std::move(newEntry));
65 PLOGD <<
"TextureHandleRegistry: Created handle " << newId
66 <<
" for path '" << pathKey <<
"' with type " <<
static_cast<int>(type);
76 std::shared_lock<std::shared_mutex> lock(
mutex_);
78 uint32_t
id = handle.
getId();
80 PLOGW <<
"TextureHandleRegistry: Invalid handle ID " <<
id
81 <<
" (entries size=" <<
entries_.size() <<
")";
93 std::shared_lock<std::shared_mutex> lock(
mutex_);
95 uint32_t
id = handle.
getId();
104 std::string pathKey = normalizePath(path);
105 PLOGI <<
"TextureHandleRegistry::getTextureTypeForPath - normalized path: '" << pathKey <<
"'";
107 std::shared_lock<std::shared_mutex> lock(
mutex_);
118 std::string pathKey = normalizePath(path);
119 PLOGI <<
"TextureHandleRegistry::onTextureLoaded - normalized path: '" << pathKey <<
"' from '" << path.generic_string() <<
"'";
121 std::unique_lock<std::shared_mutex> lock(
mutex_);
125 PLOGW <<
"TextureHandleRegistry: onTextureLoaded called for unregistered path '" << pathKey <<
"'";
133 PLOGD <<
"TextureHandleRegistry: Texture loaded for handle " << it->second
134 <<
" path='" << pathKey <<
"' descriptorIndex=" << descriptorIndex;
138 std::string pathKey = normalizePath(path);
140 std::unique_lock<std::shared_mutex> lock(
mutex_);
151 PLOGD <<
"TextureHandleRegistry: Texture unloaded for handle " << it->second
152 <<
" path='" << pathKey <<
"'";
156 std::shared_lock<std::shared_mutex> lock(
mutex_);
165 std::shared_lock<std::shared_mutex> lock(
mutex_);
167 uint32_t
id = handle.
getId();
176 std::unique_lock<std::shared_mutex> lock(
mutex_);
179 PLOGD <<
"TextureHandleRegistry: Cleared all entries";
std::filesystem::path getPathForHandle(TextureHandle handle) const
Get the path associated with a handle (for debugging/validation)
uint32_t resolveDescriptorIndex(TextureHandle handle) const
Resolve a handle to its descriptor index (O(1) operation)
TextureHandle getOrCreateHandleImpl(const std::filesystem::path &path, TextureType type)
Internal implementation of getOrCreateHandle.
void clear()
Clear all registry entries (typically called on shutdown)
void onTextureLoaded(const std::filesystem::path &path, Texture *texture, uint32_t descriptorIndex)
Called when a texture finishes loading.
void onTextureUnloaded(const std::filesystem::path &path)
Called when a texture is unloaded.
std::unordered_map< std::string, uint32_t > pathToHandleId_
TextureType getTextureTypeForPath(const std::filesystem::path &path) const
Get the texture type for a path (if registered)
size_t getHandleCount() const
Get the total number of registered texture handles.
TextureType getTextureType(TextureHandle handle) const
Get the texture type for a handle.
std::vector< Entry > entries_
Type-erased texture handle for runtime storage.
static constexpr uint32_t INVALID_ID
bool isValid() const
Check if this handle points to a valid registry entry.
uint32_t getId() const
Get the registry ID for this handle.
Log category system implementation.
TextureType
Represents the semantic type of a texture, determining its Vulkan format.
@ Unknown
Fallback type, uses SRGB as default.
Registry entry storing texture metadata.
std::filesystem::path path