Lugdunum  0.1.0
View.cpp
Go to the documentation of this file.
2 
3 #include <algorithm>
4 
11 
12 namespace lug {
13 namespace Graphics {
14 namespace Vulkan {
15 namespace Render {
16 
17 View::View(Renderer& renderer, const ::lug::Graphics::Render::Target* renderTarget) : ::lug::Graphics::Render::View(renderTarget), _renderer(renderer) {}
18 
20  View::InitInfo& initInfo,
21  const API::Queue* presentQueue,
22  const std::vector<API::ImageView>& imageViews) {
24 
26  _renderTechnique = std::make_unique<Render::Technique::Forward>(_renderer, *this);
27  }
28 
29  if (_renderTechnique && !_renderTechnique->init(imageViews)) {
30  LUG_LOG.warn("View::init: Failed to init render technique");
31  return false;
32  }
33 
34  _drawCompleteSemaphores.resize(imageViews.size());
35 
36  API::Builder::Semaphore semaphoreBuilder(_renderer.getDevice());
37 
38  // Work complete semaphores
39  for (uint32_t i = 0; i < imageViews.size(); ++i) {
40  VkResult result{VK_SUCCESS};
41  if (!semaphoreBuilder.build(_drawCompleteSemaphores[i], &result)) {
42  LUG_LOG.error("View::init: Can't create semaphore: {}", result);
43  return false;
44  }
45  }
46 
47  _presentQueue = presentQueue;
48 
49  return true;
50 }
51 
52 bool View::render(const API::Semaphore& imageReadySemaphore, uint32_t currentImageIndex) {
53  if (!_camera) {
54  return true; // Not fatal, return success anyway
55  }
56 
57  _camera->update(_renderer, *this, _renderQueue);
58  return _renderTechnique->render(_renderQueue, imageReadySemaphore, _drawCompleteSemaphores[currentImageIndex], currentImageIndex);
59 }
60 
61 void View::destroy() {
62  _renderTechnique->destroy();
63 }
64 
67 
68  return true;
69 }
70 
71 VkSurfaceFormatKHR View::getFormat() const {
72  return static_cast<const Render::Window*>(_renderTarget)->getSwapchain().getFormat();
73 }
74 
75 } // Render
76 } // Vulkan
77 } // Graphics
78 } // lug
VkSurfaceFormatKHR getFormat() const
Definition: View.cpp:71
const Target * _renderTarget
Definition: View.hpp:90
bool endFrame() override final
Definition: View.cpp:65
std::vector< API::Semaphore > _drawCompleteSemaphores
Definition: View.hpp:55
void clear() override final
Definition: Queue.cpp:57
const API::Queue * _presentQueue
Definition: View.hpp:56
bool render(const API::Semaphore &imageReadySemaphore, uint32_t currentImageIndex)
Definition: View.cpp:52
bool init(View::InitInfo &initInfo, const API::Queue *presentQueue, const std::vector< API::ImageView > &imageViews)
Definition: View.cpp:19
std::unique_ptr< Technique::Technique > _renderTechnique
Definition: View.hpp:53
const InitInfo & getInfo() const
Definition: Renderer.inl:1
void init(InitInfo &initInfo)
Definition: View.cpp:43
void destroy() override final
Definition: View.cpp:61
#define LUG_LOG
Definition: Logger.hpp:73
Resource::SharedPtr< Camera::Camera > _camera
Definition: View.hpp:96
Class for graphics.
Definition: Graphics.hpp:25
View(Renderer &renderer, const ::lug::Graphics::Render::Target *renderTarget)
Definition: View.cpp:17