29 template<
typename Factory, std::derived_from<RHIObject> T>
40 template<
typename Factory,
typename T>
class RHIHandle {
51 CHECK(
IsValid() &&
"RHIHandle::Get called on an invalid handle");
54 return static_cast<U*
>(
ptr);
162 throw std::out_of_range(
"invalid handle");
163 return static_cast<U*
>(
mObjects.At(handle));
176 class RHIApplication;
#define CHECK(expr)
Definition Logging.hpp:26
General Purpose Allocator (GPA) interface.
Definition Allocator.hpp:24
Definition Device.hpp:131
Handle type for RHI Objects.
Definition Details.hpp:40
bool IsValid() const
Check if the handle is valid (i.e. associated with a Factory and not kInvalidHandle)
Definition Details.hpp:69
constexpr Handle operator()() const
Definition Details.hpp:60
bool operator==(const RHIHandle &other) const
Definition Details.hpp:62
U * Get() const
Retrieves the underlying RHIObject pointer. It is undefined behavior to use the returned pointer afte...
Definition Details.hpp:50
T * operator->() const
Definition Details.hpp:56
void Invalidate()
Resets the handle to an invalid state. After calling this, the handle is no longer associated with an...
Definition Details.hpp:74
Handle mHandle
Definition Details.hpp:44
Factory * mFactory
Definition Details.hpp:43
Storage/Object dereference facility for RHI Objects.
Definition Details.hpp:135
RHIObjectPool(Core::Allocator *allocator)
Definition Details.hpp:139
Core::Pool< Handle, Base > mObjects
Definition Details.hpp:137
U * GetObjectPtr(Handle handle) const
Retrieves the raw pointer to the object within the storage.
Definition Details.hpp:160
Core::Allocator * mAllocator
Definition Details.hpp:136
Handle CreateObject(Args &&... args)
Creates specified RHIObject of derived type T and retrieves its handle.
Definition Details.hpp:146
void DestroyObject(Handle handle)
Destroys the object associated with the given handle, and frees the handle for reuse.
Definition Details.hpp:168
Base class for all RHI objects.
Definition Details.hpp:16
RHIObject & operator=(const RHIObject &)=delete
RHIObject(RHIObject const &)=delete
virtual ~RHIObject()=default
RHIObject & operator=(RHIObject &&)=delete
RHIObject(RHIObject &&)=delete
Scoped move-only RAII handle wrapper for RHI Objects.
Definition Details.hpp:79
RHIScopedHandle & operator=(RHIScopedHandle &&other) noexcept
Definition Details.hpp:93
RHIScopedHandle(const RHIScopedHandle &)=delete
RHIScopedHandle(RHIScopedHandle &&other) noexcept
Definition Details.hpp:89
void Reset()
Destructs the underlying RHIObject, and invalidates the scoped handle.
Definition Details.hpp:119
RHIScopedHandle(Factory *factory, Handle handle)
Definition Details.hpp:88
~RHIScopedHandle()
Definition Details.hpp:127
RHIScopedHandle & operator=(const RHIScopedHandle &)=delete
RHIHandle< Factory, T > Release()
Releases the underlying RHIHandle, invalidating the scoped handle. NOTE: This may leak the resource i...
Definition Details.hpp:111
RHIScopedHandle()=default
RHIHandle< Factory, T > View() const
Returns a non-owning view of the underlying RHIHandle.
Definition Details.hpp:104
std::unique_ptr< T, StlDeleter< T > > UniquePtr
std::unique_ptr with custom deleter that uses a Foundation::Core::Allocator to deallocate memory.
Definition Allocator.hpp:161
Low-level Rendering Hardware Interface (RHI) abstractions.
Definition Application.hpp:5
uint64_t Handle
Definition Details.hpp:9
RHIScopedHandle< RHIApplication, T > RHIApplicationScopedObjectHandle
Definition Details.hpp:177
RHIScopedHandle< RHIDevice, T > RHIDeviceScopedObjectHandle
Definition Details.hpp:181
static constexpr Handle kInvalidHandle
Definition Details.hpp:10
Provides type traits for types derived from RHIObject.
Definition Details.hpp:30