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
4#include <filesystem>
5#include <shared_mutex>
6#include <unordered_map>
7#include <vector>
8
9namespace Engine::Assets
10{
11 class RuntimeTexture;
12} // namespace Engine::Assets
13
15{
16
52 {
53 public:
56
57 // Non-copyable, non-movable (contains mutex)
62
74 template <TextureType Type>
75 TypedTextureHandle<Type> getOrCreateHandle( const std::filesystem::path & path )
76 {
77 TextureHandle base = getOrCreateHandleImpl( path, Type );
78 return TypedTextureHandle<Type>( base );
79 }
80
87 [[nodiscard]] uint32_t resolveDescriptorIndex( TextureHandle handle ) const;
88
95 [[nodiscard]] TextureType getTextureType( TextureHandle handle ) const;
96
105 [[nodiscard]] TextureType getTextureTypeForPath( const std::filesystem::path & path ) const;
106
117 const std::filesystem::path & path,
118 RuntimeTexture * texture,
119 uint32_t descriptorIndex
120 );
121
129 void onTextureUnloaded( const std::filesystem::path & path );
130
134 [[nodiscard]] size_t getHandleCount() const;
135
142 [[nodiscard]] std::filesystem::path getPathForHandle( TextureHandle handle ) const;
143
147 void clear();
148
149 private:
153 TextureHandle getOrCreateHandleImpl( const std::filesystem::path & path, TextureType type );
154
165
166 std::vector<Entry> entries_;
167 std::unordered_map<std::string, uint32_t> pathToHandleId_;
168 mutable std::shared_mutex mutex_;
169 };
170
171} // namespace Engine::Assets::Textures
Type-erased texture handle for runtime storage.
static constexpr uint32_t INVALID_ID
std::unordered_map< std::string, uint32_t > pathToHandleId_
void onTextureLoaded(const std::filesystem::path &path, RuntimeTexture *texture, uint32_t descriptorIndex)
Called when a texture finishes loading.
TextureType getTextureTypeForPath(const std::filesystem::path &path) const
Get the texture type for a path (if registered)
void onTextureUnloaded(const std::filesystem::path &path)
Called when a texture is unloaded.
void clear()
Clear all registry entries (typically called on shutdown)
TextureType getTextureType(TextureHandle handle) const
Get the texture type for a handle.
TextureHandleRegistry(const TextureHandleRegistry &)=delete
TextureHandleRegistry(TextureHandleRegistry &&)=delete
TypedTextureHandle< Type > getOrCreateHandle(const std::filesystem::path &path)
Get or create a typed handle for a texture path.
TextureHandleRegistry & operator=(TextureHandleRegistry &&)=delete
size_t getHandleCount() const
Get the total number of registered texture handles.
TextureHandleRegistry & operator=(const TextureHandleRegistry &)=delete
TextureHandle getOrCreateHandleImpl(const std::filesystem::path &path, TextureType type)
Internal implementation of getOrCreateHandle.
uint32_t resolveDescriptorIndex(TextureHandle handle) const
Resolve a handle to its descriptor index (O(1) operation)
std::filesystem::path getPathForHandle(TextureHandle handle) const
Get the path associated with a handle (for debugging/validation)
Type-safe texture handle wrapper providing compile-time type safety.
TextureType
Represents the semantic type of a texture, determining its Vulkan format.
Definition TextureType.h:15
@ Unknown
Fallback type, uses SRGB as default.
Definition TextureType.h:21