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 <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
32 vk::Image image;
33 vk::ImageView image_view;
34 vk::Framebuffer frame_buffer;
35 aarectangle redraw_rectangle;
36 bool layout_is_present = false;
37};
38
40public:
41 vk::SurfaceKHR intrinsic;
42
43 vk::SwapchainKHR swapchain;
44
45 static constexpr uint32_t defaultNumberOfSwapchainImages = 2;
46
47 int nrSwapchainImages;
48 vk::Extent2D swapchainImageExtent;
49 vk::SurfaceFormatKHR swapchainImageFormat;
50 std::vector<swapchain_image_info> swapchain_image_infos;
51
52 static const vk::Format depthImageFormat = vk::Format::eD32Sfloat;
53 VmaAllocation depthImageAllocation;
54 vk::Image depthImage;
55 vk::ImageView depthImageView;
56
57 static const vk::Format colorImageFormat = vk::Format::eR16G16B16A16Sfloat;
58 std::array<VmaAllocation,2> colorImageAllocations;
59 std::array<vk::Image,2> colorImages;
60 std::array<vk::ImageView,2> colorImageViews;
61 std::array<vk::DescriptorImageInfo, 2> colorDescriptorImageInfos;
62
63 vk::RenderPass renderPass;
64
65 vk::CommandBuffer commandBuffer;
66
67 vk::Semaphore imageAvailableSemaphore;
68 vk::Semaphore renderFinishedSemaphore;
69 vk::Fence renderFinishedFence;
70
76
77 gui_window_vulkan(gui_system &system, std::weak_ptr<gui_window_delegate> const &delegate, label const &title);
79
80 gui_window_vulkan(const gui_window_vulkan &) = delete;
81 gui_window_vulkan &operator=(const gui_window_vulkan &) = delete;
83 gui_window_vulkan &operator=(gui_window_vulkan &&) = delete;
84
85 void init() override;
86
87 gui_device_vulkan &vulkan_device() const noexcept;
88
89 void render(hires_utc_clock::time_point displayTimePoint) override;
90
93 virtual vk::SurfaceKHR getSurface() const = 0;
94
95protected:
96 void teardown() override;
97 void build() override;
98
99private:
100 std::optional<uint32_t> acquireNextImageFromSwapchain();
101 void presentImageToQueue(uint32_t frameBufferIndex, vk::Semaphore renderFinishedSemaphore);
102
103 void fill_command_buffer(swapchain_image_info &current_image, aarectangle scissor_rectangle);
104 void submitCommandBuffer();
105
106 bool readSurfaceExtent();
107 bool checkSurfaceExtent();
108
109 void buildDevice();
110 void buildSemaphores();
111 void teardownSemaphores();
112 gui_window_state buildSwapchain();
113 void teardownSwapchain();
114 void buildCommandBuffers();
115 void teardownCommandBuffers();
116 void buildRenderPasses();
117 void teardownRenderPasses();
118 void buildFramebuffers();
119 void teardownFramebuffers();
120 void buildPipelines();
121 void teardownPipelines();
122 bool buildSurface();
123 void teardownSurface();
124 void teardownDevice();
125
126 void waitIdle();
127 std::tuple<uint32_t, vk::Extent2D> getImageCountAndExtent();
128};
129
130}
STL namespace.
Class which represents an axis-aligned rectangle.
Definition axis_aligned_rectangle.hpp:18
Definition gui_device_vulkan.hpp:23
Vulkan gui_device controller.
Definition gui_system.hpp:24
Definition gui_window.hpp:37
Definition gui_window_vulkan.hpp:31
Definition gui_window_vulkan.hpp:39
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