Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
TextureHandle.h
Go to the documentation of this file.
1#pragma once
2#include "TextureType.h"
3#include <cassert>
4#include <cstdint>
5
6namespace Engine::Assets {
7
15public:
16 static constexpr uint32_t INVALID_ID = 0xFFFFFFFF;
17
18 TextureHandle() = default;
19 TextureHandle(uint32_t id, TextureType type) : id_(id), type_(type) {}
20
24 [[nodiscard]] bool isValid() const { return id_ != INVALID_ID; }
25
29 [[nodiscard]] uint32_t getId() const { return id_; }
30
34 [[nodiscard]] TextureType getType() const { return type_; }
35
36 bool operator==(const TextureHandle& other) const {
37 return id_ == other.id_ && type_ == other.type_;
38 }
39
40 bool operator!=(const TextureHandle& other) const {
41 return !(*this == other);
42 }
43
44private:
45 uint32_t id_ = INVALID_ID;
47};
48
68template <TextureType Type>
70public:
71 TypedTextureHandle() = default;
72
78 explicit TypedTextureHandle(TextureHandle base) : base_(base) {
79 assert((base.getType() == Type || !base.isValid()) &&
80 "TextureHandle type mismatch in TypedTextureHandle construction");
81 }
82
86 [[nodiscard]] bool isValid() const { return base_.isValid(); }
87
91 [[nodiscard]] TextureHandle getBase() const { return base_; }
92
96 [[nodiscard]] uint32_t getId() const { return base_.getId(); }
97
101 [[nodiscard]] static constexpr TextureType getType() { return Type; }
102
106 operator TextureHandle() const { return base_; }
107
108 bool operator==(const TypedTextureHandle& other) const {
109 return base_ == other.base_;
110 }
111
112 bool operator!=(const TypedTextureHandle& other) const {
113 return !(*this == other);
114 }
115
116private:
118};
119
120// Convenience type aliases for common texture types
126
127} // namespace EngineCore
Type-erased texture handle for runtime storage.
uint32_t getId() const
Get the registry ID for this handle.
bool operator!=(const TextureHandle &other) const
bool operator==(const TextureHandle &other) const
static constexpr uint32_t INVALID_ID
TextureHandle(uint32_t id, TextureType type)
bool isValid() const
Check if this handle points to a valid registry entry.
TextureType getType() const
Get the texture type for this handle.
Type-safe texture handle wrapper providing compile-time type safety.
bool operator==(const TypedTextureHandle &other) const
uint32_t getId() const
Get the registry ID for this handle.
TextureHandle getBase() const
Get the underlying base handle.
bool isValid() const
Check if this handle points to a valid registry entry.
static constexpr TextureType getType()
Get the texture type (compile-time constant)
TypedTextureHandle(TextureHandle base)
Construct from a base TextureHandle.
bool operator!=(const TypedTextureHandle &other) const
TypedTextureHandle< TextureType::Emissive > EmissiveTextureHandle
TypedTextureHandle< TextureType::Lightmap > LightmapTextureHandle
TypedTextureHandle< TextureType::Normal > NormalTextureHandle
TypedTextureHandle< TextureType::BaseColor > AlbedoTextureHandle
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
TypedTextureHandle< TextureType::MetallicRoughness > MetallicRoughnessTextureHandle