]> git.tdb.fi Git - libs/gl.git/blob - source/backends/vulkan/windowview_backend.cpp
Align staging memory with an alignment suitable for image transfers
[libs/gl.git] / source / backends / vulkan / windowview_backend.cpp
1 #include "device.h"
2 #include "renderer.h"
3 #include "vulkan.h"
4 #include "windowview.h"
5 #include "windowview_backend.h"
6
7 namespace Msp {
8 namespace GL {
9
10 VulkanWindowView::~VulkanWindowView()
11 {
12         delete swap_chain;
13 }
14
15 void VulkanWindowView::render()
16 {
17         Device &device = static_cast<const WindowView *>(this)->device;
18
19         Semaphore *sem = semaphores+frame_index*2;
20         unsigned image_index = swap_chain->begin_frame(sem[0]);
21         current_target = &framebuffers[image_index];
22
23         if(!internal_renderer)
24                 internal_renderer = new Renderer;
25         internal_renderer->begin(sem[0]);
26         View::render(*internal_renderer);
27         internal_renderer->end(sem[1]);
28
29         swap_chain->present_frame(sem[1]);
30         frame_index = (frame_index+1)%device.get_n_frames_in_flight();
31
32         device.get_destroy_queue().tick();
33 }
34
35 void VulkanWindowView::resize_framebuffer(unsigned w, unsigned h)
36 {
37         Device &device = static_cast<const WindowView *>(this)->device;
38
39         framebuffers.clear();
40         delete swap_chain;
41
42         swap_chain = new SwapChain(w, h, device.get_n_frames_in_flight());
43
44         unsigned n_images = swap_chain->get_n_images();
45         framebuffers.reserve(n_images);
46         for(unsigned i=0; i<n_images; ++i)
47         {
48                 const SwapChainTexture &image = swap_chain->get_image(i);
49                 framebuffers.emplace_back((COLOR_ATTACHMENT, image.get_format()));
50                 framebuffers.back().attach(COLOR_ATTACHMENT, swap_chain->get_image(i));
51         }
52
53         current_target = &framebuffers.front();
54 }
55
56 } // namespace GL
57 } // namespace Msp