Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
Loading...
Searching...
No Matches
TextureIdentity.h
1#pragma once
2
3#include "Engine/Texture/TextureType.h"
4
5#include <cstddef>
6#include <filesystem>
7#include <functional>
8#include <string>
9
11{
17 inline std::string normalizeTexturePath( const std::filesystem::path & path )
18 {
19 std::string pathStr = path.generic_string();
20 if ( pathStr.size() >= 2 && pathStr[0] == '.' && pathStr[1] == '/' )
21 {
22 pathStr = pathStr.substr( 2 );
23 }
24 return pathStr;
25 }
26
31 {
32 std::string normalizedPath;
34
38 [[nodiscard]] bool empty() const
39 {
40 return normalizedPath.empty();
41 }
42
46 bool operator==( const TextureIdentityKey & other ) const
47 {
48 return normalizedPath == other.normalizedPath && type == other.type;
49 }
50 };
51
56 {
60 std::size_t operator()( const TextureIdentityKey & key ) const noexcept
61 {
62 const std::size_t pathHash = std::hash<std::string>{}( key.normalizedPath );
63 const std::size_t typeHash = std::hash<int>{}( static_cast<int>( key.type ) );
64 return pathHash ^ ( typeHash + 0x9e3779b9u + ( pathHash << 6u ) + ( pathHash >> 2u ) );
65 }
66 };
67
74 inline TextureIdentityKey makeTextureIdentityKey( const std::filesystem::path & path, TextureType type )
75 {
76 return TextureIdentityKey{ .normalizedPath = normalizeTexturePath( path ), .type = type };
77 }
78} // namespace Engine::Assets::Textures
TextureIdentityKey makeTextureIdentityKey(const std::filesystem::path &path, TextureType type)
Creates a texture identity key from a path and semantic type.
std::string normalizeTexturePath(const std::filesystem::path &path)
Converts a texture path to the registry key path form.
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
Hash functor for TextureIdentityKey.
std::size_t operator()(const TextureIdentityKey &key) const noexcept
Hashes the normalized path and semantic texture type.
Path and semantic type pair that uniquely identifies a texture handle.
TextureType type
Semantic texture type.
std::string normalizedPath
Normalized texture path.
bool operator==(const TextureIdentityKey &other) const
Compares both normalized path and semantic texture type.
bool empty() const
Returns true when the key has no path.