5 changed files with 130 additions and 14 deletions
@ -0,0 +1,62 @@ |
|||||
|
// Copyright 2022 Simon Boyé
|
||||
|
|
||||
|
#include <vk/ImageView.h> |
||||
|
#include <vk/Context.h> |
||||
|
|
||||
|
#include <cassert> |
||||
|
|
||||
|
|
||||
|
namespace vk { |
||||
|
|
||||
|
|
||||
|
ImageView::ImageView() noexcept { |
||||
|
} |
||||
|
|
||||
|
ImageView::ImageView(Context& context, const VkImageViewCreateInfo& create_info) |
||||
|
: m_context(&context) |
||||
|
{ |
||||
|
assert(m_context); |
||||
|
|
||||
|
if(vkCreateImageView( |
||||
|
context.device(), |
||||
|
&create_info, |
||||
|
nullptr, |
||||
|
&m_image_view |
||||
|
) != VK_SUCCESS) |
||||
|
throw std::runtime_error("failed to create image view"); |
||||
|
} |
||||
|
|
||||
|
ImageView::ImageView(ImageView&& other) noexcept |
||||
|
{ |
||||
|
swap(*this, other); |
||||
|
} |
||||
|
|
||||
|
ImageView::~ImageView() noexcept { |
||||
|
if(!is_null()) |
||||
|
destroy(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
ImageView& ImageView::operator=(ImageView&& other) noexcept { |
||||
|
swap(*this, other); |
||||
|
if(other) |
||||
|
other.destroy(); |
||||
|
return *this; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void ImageView::destroy() noexcept { |
||||
|
assert(!is_null()); |
||||
|
assert(m_context); |
||||
|
|
||||
|
vkDestroyImageView( |
||||
|
m_context->device(), |
||||
|
m_image_view, |
||||
|
nullptr |
||||
|
); |
||||
|
|
||||
|
m_image_view = nullptr; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,61 @@ |
|||||
|
// Copyright 2022 Simon Boyé
|
||||
|
#pragma once |
||||
|
|
||||
|
#include <vk/forward.h> |
||||
|
|
||||
|
#include <vulkan/vulkan.h> |
||||
|
|
||||
|
|
||||
|
namespace vk { |
||||
|
|
||||
|
|
||||
|
class ImageView { |
||||
|
public: |
||||
|
ImageView() noexcept; |
||||
|
ImageView(Context& context, const VkImageViewCreateInfo& create_info); |
||||
|
ImageView(const ImageView&) = delete; |
||||
|
ImageView(ImageView&& other) noexcept; |
||||
|
~ImageView() noexcept; |
||||
|
|
||||
|
ImageView& operator=(const ImageView&) = delete; |
||||
|
ImageView& operator=(ImageView&& other) noexcept; |
||||
|
|
||||
|
explicit inline operator bool() const noexcept { |
||||
|
return !is_null(); |
||||
|
} |
||||
|
|
||||
|
inline bool is_null() const noexcept { |
||||
|
return m_image_view == VK_NULL_HANDLE; |
||||
|
} |
||||
|
|
||||
|
inline const Context* context() const noexcept { |
||||
|
return m_context; |
||||
|
} |
||||
|
|
||||
|
inline Context* context() noexcept { |
||||
|
return m_context; |
||||
|
} |
||||
|
|
||||
|
inline operator VkImageView() noexcept { |
||||
|
return m_image_view; |
||||
|
} |
||||
|
|
||||
|
inline VkImageView image_view() noexcept { |
||||
|
return m_image_view; |
||||
|
} |
||||
|
|
||||
|
friend inline void swap(ImageView& image_view_0, ImageView& image_view_1) noexcept { |
||||
|
using std::swap; |
||||
|
swap(image_view_0.m_context, image_view_1.m_context); |
||||
|
swap(image_view_0.m_image_view, image_view_1.m_image_view); |
||||
|
} |
||||
|
|
||||
|
void destroy() noexcept; |
||||
|
|
||||
|
private: |
||||
|
Context* m_context = nullptr; |
||||
|
VkImageView m_image_view = VK_NULL_HANDLE; |
||||
|
}; |
||||
|
|
||||
|
|
||||
|
} |
||||
Loading…
Reference in new issue