// ============================================= // Aster: image.h // Copyright (c) 2020-2024 Anish Bhobe // ============================================= #pragma once #include "global.h" struct Device; struct Image { vk::Image m_Image = nullptr; vk::ImageView m_View = nullptr; VmaAllocation m_Allocation = nullptr; vk::Extent3D m_Extent; // Image.m_MipLevels_ is used for bookkeeping // If the image is Invalid, the remaining data in Image is used intrusively by `GpuResourceManager`. u32 m_MipLevels_; [[nodiscard]] bool IsValid() const; [[nodiscard]] bool IsOwned() const; [[nodiscard]] u32 GetMipLevels() const; void Destroy(const Device *device); constexpr static u32 VALID_BIT = 1u << 31; constexpr static u32 OWNED_BIT = 1u << 30; constexpr static u32 MIP_MASK = ~(VALID_BIT | OWNED_BIT); }; struct Texture : Image { void Init(const Device *device, vk::Extent2D extent, vk::Format imageFormat, bool isMipmapped, cstr name = nullptr); }; struct DepthImage : Image { void Init(const Device *device, vk::Extent2D extent, cstr name = nullptr); }; inline bool Image::IsValid() const { return m_MipLevels_ & VALID_BIT; } inline bool Image::IsOwned() const { return m_MipLevels_ & OWNED_BIT; } inline u32 Image::GetMipLevels() const { return m_MipLevels_ & MIP_MASK; }