Lugdunum  0.1.0
Framebuffer.cpp
Go to the documentation of this file.
2 
3 #include <algorithm>
4 
8 
9 namespace lug {
10 namespace Graphics {
11 namespace Vulkan {
12 namespace API {
13 namespace Builder {
14 
15 Framebuffer::Framebuffer(const API::Device& device) : _device{device} {}
16 
17 bool Framebuffer::build(API::Framebuffer& framebuffer, VkResult* returnResult) {
18  // Build a vector of VkImageView from the API::ImageView
19  std::vector<VkImageView> vkImageViews(_attachments.size());
20  std::transform(
21  begin(_attachments), end(_attachments), begin(vkImageViews),
22  [](const API::ImageView* imageView){ return static_cast<VkImageView>(*imageView); }
23  );
24 
25  // Create the framebuffer creation information for vkCreateFramebuffer
26  const VkFramebufferCreateInfo createInfo{
27  /* createInfo.sType */ VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
28  /* createInfo.pNext */ nullptr,
29  /* createInfo.flags */ 0,
30  /* createInfo.renderPass */ static_cast<VkRenderPass>(*_renderPass),
31  /* createInfo.attachmentCount */ static_cast<uint32_t>(vkImageViews.size()),
32  /* createInfo.pAttachments */ vkImageViews.data(),
33  /* createInfo.width */ _width,
34  /* createInfo.height */ _height,
35  /* createInfo.layers */ _layers
36  };
37 
38  // Create the framebuffer
39  VkFramebuffer vkFramebuffer{VK_NULL_HANDLE};
40  VkResult result = vkCreateFramebuffer(static_cast<VkDevice>(_device), &createInfo, nullptr, &vkFramebuffer);
41 
42  if (returnResult) {
43  *returnResult = result;
44  }
45 
46  if (result != VK_SUCCESS) {
47  return false;
48  }
49 
50  framebuffer = API::Framebuffer(vkFramebuffer, &_device, {_width, _height});
51 
52  return true;
53 }
54 
55 std::unique_ptr<API::Framebuffer> Framebuffer::build(VkResult* returnResult) {
56  std::unique_ptr<API::Framebuffer> framebuffer = std::make_unique<API::Framebuffer>();
57  return build(*framebuffer, returnResult) ? std::move(framebuffer) : nullptr;
58 }
59 
60 } // Builder
61 } // API
62 } // Vulkan
63 } // Graphics
64 } // lug
bool build(API::Framebuffer &framebuffer, VkResult *returnResult=nullptr)
Definition: Framebuffer.cpp:17
std::vector< const API::ImageView * > _attachments
Definition: Framebuffer.hpp:46