Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
Loading...
Searching...
No Matches
TextureHandle.h
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
21 TextureHandle() = default;
22
28 TextureHandle(uint32_t id, TextureType type) : id_(id), type_(type) {}
29
33 [[nodiscard]] bool isValid() const { return id_ != INVALID_ID; }
34
38 [[nodiscard]] uint32_t getId() const { return id_; }
39
43 [[nodiscard]] TextureType getType() const { return type_; }
44
48 bool operator==(const TextureHandle& other) const {
49 return id_ == other.id_ && type_ == other.type_;
50 }
51
55 bool operator!=(const TextureHandle& other) const {
56 return !(*this == other);
57 }
58
59private:
60 uint32_t id_ = INVALID_ID;
62};
63
83template <TextureType Type>
85public:
89 TypedTextureHandle() = default;
90
96 explicit TypedTextureHandle(TextureHandle base) : base_(base) {
97 assert((base.getType() == Type || !base.isValid()) &&
98 "TextureHandle type mismatch in TypedTextureHandle construction");
99 }
100
104 [[nodiscard]] bool isValid() const { return base_.isValid(); }
105
109 [[nodiscard]] TextureHandle getBase() const { return base_; }
110
114 [[nodiscard]] uint32_t getId() const { return base_.getId(); }
115
119 [[nodiscard]] static constexpr TextureType getType() { return Type; }
120
124 operator TextureHandle() const { return base_; }
125
129 bool operator==(const TypedTextureHandle& other) const {
130 return base_ == other.base_;
131 }
132
136 bool operator!=(const TypedTextureHandle& other) const {
137 return !(*this == other);
138 }
139
140private:
142};
143
144} // 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
Returns true when registry ID or texture type differs.
bool operator==(const TextureHandle &other) const
Compares registry ID and texture type.
static constexpr uint32_t INVALID_ID
Sentinel ID for an invalid handle.
TextureHandle(uint32_t id, TextureType type)
Creates a texture handle from a registry ID and semantic type.
bool isValid() const
Check if this handle points to a valid registry entry.
TextureHandle()=default
Creates an invalid texture handle.
TextureType getType() const
Get the texture type for this handle.
bool operator==(const TypedTextureHandle &other) const
Compares the underlying base handles.
TypedTextureHandle()=default
Creates an invalid typed texture handle.
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
Returns true when the underlying base handles differ.
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