Lugdunum  0.1.0
Image.cpp
Go to the documentation of this file.
2 
3 #include <vector>
4 
7 
8 namespace lug {
9 namespace Graphics {
10 namespace Vulkan {
11 namespace API {
12 namespace Builder {
13 
14 Image::Image(const API::Device& device): _device(device) {}
15 
16 bool Image::build(API::Image& image, VkResult* returnResult) {
17  const std::vector<uint32_t> queueFamilyIndices(_queueFamilyIndices.begin(), _queueFamilyIndices.end());
18 
19  VkSharingMode sharingMode = VK_SHARING_MODE_EXCLUSIVE;
20  // If we have move than one queueFamilyIndices and exclusive was not manually set
21  if (queueFamilyIndices.size() > 1 && !_exclusive) {
22  sharingMode = VK_SHARING_MODE_CONCURRENT;
23  }
24 
26  if (imageFormat == VK_FORMAT_UNDEFINED) {
27  LUG_LOG.error("Image::build: Can't find image format");
28  return false;
29  }
30 
31  // Create the image creation information for vkCreateImage
32  const VkImageCreateInfo createInfo{
33  /* createInfo.sType */ VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
34  /* createInfo.pNext */ nullptr,
35  /* createInfo.flags */ _createFlags,
36  /* createInfo.imageType */ _imageType,
37  /* createInfo.format */ imageFormat,
38  /* createInfo.extent */ {_extent.width, _extent.height, _extent.depth},
39  /* createInfo.mipLevels */ _mipLevels,
40  /* createInfo.arrayLayers */ _arrayLayers,
41  /* createInfo.samples */ _sampleCount,
42  /* createInfo.tiling */ _tiling,
43  /* createInfo.usage */ _usage,
44  /* createInfo.sharingMode */ sharingMode,
45  /* createInfo.queueFamilyIndexCount */ static_cast<uint32_t>(queueFamilyIndices.size()),
46  /* createInfo.pQueueFamilyIndices */ queueFamilyIndices.data(), // Convert the set to raw data, // Convert the set to raw data,
47  /* createInfo.initialLayout */ _initialLayout
48  };
49 
50  // Create the image
51  VkImage vkImage{VK_NULL_HANDLE};
52  VkResult result = vkCreateImage(static_cast<VkDevice>(_device), &createInfo, nullptr, &vkImage);
53 
54  if (returnResult) {
55  *returnResult = result;
56  }
57 
58  if (result != VK_SUCCESS) {
59  return false;
60  }
61 
62  image = API::Image(vkImage, &_device, {_extent.width, _extent.height}, imageFormat, false);
63 
64  return true;
65 }
66 
67 std::unique_ptr<API::Image> Image::build(VkResult* returnResult) {
68  std::unique_ptr<API::Image> image = std::make_unique<API::Image>();
69  return build(*image, returnResult) ? std::move(image) : nullptr;
70 }
71 
72 } // Builder
73 } // API
74 } // Vulkan
75 } // Graphics
76 } // lug
std::set< VkFormat > _preferedFormats
Definition: Image.hpp:51
Image(const API::Device &device)
Definition: Image.cpp:14
std::set< uint32_t > _queueFamilyIndices
Definition: Image.hpp:60
VkFormatFeatureFlags _featureFlags
Definition: Image.hpp:52
VkSampleCountFlagBits _sampleCount
Definition: Image.hpp:56
static VkFormat findSupportedFormat(const Device &device, const std::set< VkFormat > &formats, VkImageTiling tiling, VkFormatFeatureFlags features)
Definition: Image.cpp:82
#define LUG_LOG
Definition: Logger.hpp:73
bool build(API::Image &instance, VkResult *returnResult=nullptr)
Definition: Image.cpp:16