Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
TextureHandleRegistry.h
Go to the documentation of this file.
1#pragma once
2#include "TextureHandle.h"
3#include <filesystem>
4#include <shared_mutex>
5#include <unordered_map>
6#include <vector>
7
8namespace EngineCore {
9
10class Texture;
11
50public:
53
54 // Non-copyable, non-movable (contains mutex)
59
71 template<TextureType Type>
72 TypedTextureHandle<Type> getOrCreateHandle(const std::filesystem::path& path) {
73 TextureHandle base = getOrCreateHandleImpl(path, Type);
74 return TypedTextureHandle<Type>(base);
75 }
76
83 [[nodiscard]] uint32_t resolveDescriptorIndex(TextureHandle handle) const;
84
91 [[nodiscard]] TextureType getTextureType(TextureHandle handle) const;
92
101 [[nodiscard]] TextureType getTextureTypeForPath(const std::filesystem::path& path) const;
102
112 void onTextureLoaded(const std::filesystem::path& path, Texture* texture, uint32_t descriptorIndex);
113
121 void onTextureUnloaded(const std::filesystem::path& path);
122
126 [[nodiscard]] size_t getHandleCount() const;
127
134 [[nodiscard]] std::filesystem::path getPathForHandle(TextureHandle handle) const;
135
139 void clear();
140
141private:
145 TextureHandle getOrCreateHandleImpl(const std::filesystem::path& path, TextureType type);
146
156
157 std::vector<Entry> entries_;
158 std::unordered_map<std::string, uint32_t> pathToHandleId_;
159 mutable std::shared_mutex mutex_;
160};
161
162} // namespace EngineCore
TypedTextureHandle< Type > getOrCreateHandle(const std::filesystem::path &path)
Get or create a typed handle for a texture path.
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)
TextureHandleRegistry & operator=(const TextureHandleRegistry &)=delete
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.
TextureHandleRegistry(TextureHandleRegistry &&)=delete
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.
TextureHandleRegistry(const TextureHandleRegistry &)=delete
TextureHandleRegistry & operator=(TextureHandleRegistry &&)=delete
TextureType getTextureType(TextureHandle handle) const
Get the texture type for a handle.
Type-erased texture handle for runtime storage.
static constexpr uint32_t INVALID_ID
Type-safe texture handle wrapper providing compile-time type safety.
Log category system implementation.
TextureType
Represents the semantic type of a texture, determining its Vulkan format.
Definition TextureType.h:18
@ Unknown
Fallback type, uses SRGB as default.
Definition TextureType.h:24
Registry entry storing texture metadata.