Lugdunum  0.1.0
ImageView.cpp
Go to the documentation of this file.
2 
5 
6 namespace lug {
7 namespace Graphics {
8 namespace Vulkan {
9 namespace API {
10 namespace Builder {
11 
12 ImageView::ImageView(const API::Device& device, const API::Image& image) : _device{device}, _image{image} {}
13 
14 bool ImageView::build(API::ImageView& imageView, VkResult* returnResult) {
15  // Create the imageView creation information for vkCreateImageView
16  const VkImageViewCreateInfo createInfo{
17  /* createInfo.sType */ VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18  /* createInfo.pNext */ nullptr,
19  /* createInfo.flags */ 0,
20  /* createInfo.image */ static_cast<VkImage>(_image),
21  /* createInfo.viewType */ _viewType,
22  /* createInfo.format */ _format,
23  /* createInfo.components */ {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
24  /* createInfo.subresourceRange */ {
25  /* createInfo.subresourceRange.aspectMask */ _aspectFlags,
26  /* createInfo.subresourceRange.baseMipLevel */ 0,
27  /* createInfo.subresourceRange.levelCount */ _levelCount,
28  /* createInfo.subresourceRange.baseArrayLayer */ 0,
29  /* createInfo.subresourceRange.layerCount */ _layerCount
30  }
31  };
32 
33  // Create the imageView
34  VkImageView vkImageView{VK_NULL_HANDLE};
35  VkResult result = vkCreateImageView(static_cast<VkDevice>(_device), &createInfo, nullptr, &vkImageView);
36 
37  if (returnResult) {
38  *returnResult = result;
39  }
40 
41  if (result != VK_SUCCESS) {
42  return false;
43  }
44 
45  imageView = API::ImageView(vkImageView, &_device, &_image);
46 
47  return true;
48 }
49 
50 std::unique_ptr<API::ImageView> ImageView::build(VkResult* returnResult) {
51  std::unique_ptr<API::ImageView> imageView = std::make_unique<API::ImageView>();
52  return build(*imageView, returnResult) ? std::move(imageView) : nullptr;
53 }
54 
55 } // Builder
56 } // API
57 } // Vulkan
58 } // Graphics
59 } // lug
bool build(API::ImageView &instance, VkResult *returnResult=nullptr)
Definition: ImageView.cpp:14
ImageView(const API::Device &device, const API::Image &image)
Definition: ImageView.cpp:12