111 lines
2.8 KiB
C++
111 lines
2.8 KiB
C++
// =============================================
|
|
// Aster: image_view.h
|
|
// Copyright (c) 2020-2025 Anish Bhobe
|
|
// =============================================
|
|
|
|
#pragma once
|
|
|
|
#include "global.h"
|
|
#include "image.h"
|
|
|
|
namespace aster
|
|
{
|
|
template <concepts::AnyImage TImage>
|
|
struct View
|
|
{
|
|
using ImageType = TImage;
|
|
|
|
Ref<Image> m_Image;
|
|
vk::ImageView m_View = nullptr;
|
|
vk::Extent3D m_Extent;
|
|
u8 m_BaseLayer = 0;
|
|
u8 m_LayerCount = 0;
|
|
u8 m_BaseMipLevel = 0;
|
|
u8 m_MipLevelCount = 0;
|
|
|
|
[[nodiscard]] vk::Image
|
|
GetImage() const
|
|
{
|
|
return m_Image->m_Image;
|
|
}
|
|
|
|
[[nodiscard]] bool
|
|
IsValid() const
|
|
{
|
|
return static_cast<bool>(m_Image);
|
|
}
|
|
|
|
View(Ref<Image> image, vk::ImageView const view, vk::Extent3D const extent, u8 const baseLayer, u8 const layerCount,
|
|
u8 const baseMipLevel, u8 const mipLevelCount)
|
|
: m_Image{std::move(image)}
|
|
, m_View{view}
|
|
, m_Extent{extent}
|
|
, m_BaseLayer{baseLayer}
|
|
, m_LayerCount{layerCount}
|
|
, m_BaseMipLevel{baseMipLevel}
|
|
, m_MipLevelCount{mipLevelCount}
|
|
{
|
|
}
|
|
|
|
View(View &&other) noexcept
|
|
: m_Image{std::move(other.m_Image)}
|
|
, m_View{Take(other.m_View)}
|
|
, m_Extent{std::move(other.m_Extent)}
|
|
, m_BaseLayer{other.m_BaseLayer}
|
|
, m_LayerCount{other.m_LayerCount}
|
|
, m_BaseMipLevel{other.m_BaseMipLevel}
|
|
, m_MipLevelCount{other.m_MipLevelCount}
|
|
{
|
|
}
|
|
|
|
View &
|
|
operator=(View &&other) noexcept
|
|
{
|
|
if (this == &other)
|
|
return *this;
|
|
using std::swap;
|
|
swap(m_Image, other.m_Image);
|
|
swap(m_View, other.m_View);
|
|
swap(m_Extent, other.m_Extent);
|
|
swap(m_BaseLayer, other.m_BaseLayer);
|
|
swap(m_LayerCount, other.m_LayerCount);
|
|
swap(m_BaseMipLevel, other.m_BaseMipLevel);
|
|
swap(m_MipLevelCount, other.m_MipLevelCount);
|
|
return *this;
|
|
}
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(View);
|
|
|
|
~View()
|
|
{
|
|
if (!IsValid())
|
|
return;
|
|
|
|
m_Image->DestroyView(Take(m_View));
|
|
}
|
|
};
|
|
|
|
using ImageView = View<Image>;
|
|
using ImageCubeView = View<ImageCube>;
|
|
using TextureView = View<Texture>;
|
|
using TextureCubeView = View<TextureCube>;
|
|
using StorageImageView = View<StorageImage>;
|
|
using StorageTextureView = View<StorageTexture>;
|
|
using StorageTextureCubeView = View<StorageTextureCube>;
|
|
|
|
namespace concepts
|
|
{
|
|
template <typename T>
|
|
concept View = std::derived_from<T, View<typename T::ImageType>>;
|
|
|
|
template <typename T, typename TTo>
|
|
concept ViewTo = View<T> and ImageInto<typename T::ImageType, TTo>;
|
|
|
|
template <typename T>
|
|
concept ViewRef = Deref<T> and View<DerefType<T>>;
|
|
|
|
template <typename T, typename TTo>
|
|
concept ViewRefTo = ViewRef<T> and ImageInto<typename DerefType<T>::ImageType, TTo>;
|
|
|
|
} // namespace concepts
|
|
} // namespace aster
|