HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
gui_window_vulkan.hpp
1// Copyright Take Vos 2019-2020.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "gui_window.hpp"
8#include <vulkan/vulkan.hpp>
9#include <vma/vk_mem_alloc.h>
10#include <optional>
11
12namespace tt {
13class gui_device_vulkan;
14
15namespace pipeline_image {
16class pipeline_image;
17}
18namespace pipeline_flat {
19class pipeline_flat;
20}
21namespace pipeline_box {
22class pipeline_box;
23}
24namespace pipeline_SDF {
25class pipeline_SDF;
26}
27namespace pipeline_tone_mapper {
28class pipeline_tone_mapper;
29}
30
32public:
33 vk::SurfaceKHR intrinsic;
34
35 vk::SwapchainKHR swapchain;
36
37 static constexpr uint32_t defaultNumberOfSwapchainImages = 2;
38
39 int nrSwapchainImages;
40 vk::Extent2D swapchainImageExtent;
41 vk::SurfaceFormatKHR swapchainImageFormat;
42 std::vector<vk::Image> swapchainImages;
43 std::vector<vk::ImageView> swapchainImageViews;
44 std::vector<vk::Framebuffer> swapchainFramebuffers;
45 std::vector<aarect> swapchainRedrawRectangle;
46
47 static const vk::Format depthImageFormat = vk::Format::eD32Sfloat;
48 VmaAllocation depthImageAllocation;
49 vk::Image depthImage;
50 vk::ImageView depthImageView;
51
52 static const vk::Format colorImageFormat = vk::Format::eR16G16B16A16Sfloat;
53 std::array<VmaAllocation,2> colorImageAllocations;
54 std::array<vk::Image,2> colorImages;
55 std::array<vk::ImageView,2> colorImageViews;
56 std::array<vk::DescriptorImageInfo, 2> colorDescriptorImageInfos;
57
58 vk::RenderPass renderPass;
59
60 vk::CommandBuffer commandBuffer;
61
62 vk::Semaphore imageAvailableSemaphore;
63 vk::Semaphore renderFinishedSemaphore;
64 vk::Fence renderFinishedFence;
65
71
72 gui_window_vulkan(gui_system &system, std::weak_ptr<gui_window_delegate> const &delegate, label const &title);
74
75 gui_window_vulkan(const gui_window_vulkan &) = delete;
76 gui_window_vulkan &operator=(const gui_window_vulkan &) = delete;
78 gui_window_vulkan &operator=(gui_window_vulkan &&) = delete;
79
80 void init() override;
81
82 gui_device_vulkan &vulkan_device() const noexcept;
83
84 void render(hires_utc_clock::time_point displayTimePoint) override;
85
88 virtual vk::SurfaceKHR getSurface() const = 0;
89
90protected:
91 void teardown() override;
92 void build() override;
93
94private:
95 std::optional<uint32_t> acquireNextImageFromSwapchain();
96 void presentImageToQueue(uint32_t frameBufferIndex, vk::Semaphore renderFinishedSemaphore);
97
98 void fillCommandBuffer(vk::Framebuffer frameBuffer, aarect scissor_rectangle);
99 void submitCommandBuffer();
100
101 bool readSurfaceExtent();
102 bool checkSurfaceExtent();
103
104 void buildDevice();
105 void buildSemaphores();
106 void teardownSemaphores();
107 gui_window_state buildSwapchain();
108 void teardownSwapchain();
109 void buildCommandBuffers();
110 void teardownCommandBuffers();
111 void buildRenderPasses();
112 void teardownRenderPasses();
113 void buildFramebuffers();
114 void teardownFramebuffers();
115 void buildPipelines();
116 void teardownPipelines();
117 bool buildSurface();
118 void teardownSurface();
119 void teardownDevice();
120
121 void waitIdle();
122 std::tuple<uint32_t, vk::Extent2D> getImageCountAndExtent();
123};
124
125}
STL namespace.
Definition gui_device_vulkan.hpp:23
Vulkan gui_device controller.
Definition gui_system.hpp:24
Definition gui_window.hpp:39
Definition gui_window_vulkan.hpp:31
virtual vk::SurfaceKHR getSurface() const =0
void init() override
2 phase constructor.
void render(hires_utc_clock::time_point displayTimePoint) override
Update window.
Timestamp.
Definition hires_utc_clock.hpp:16
A localized text + icon label.
Definition label.hpp:76