HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Window_vulkan.hpp
1// Copyright 2019 Pokitec
2// All rights reserved.
3
4#pragma once
5
6#include "TTauri/GUI/Window_base.hpp"
7#include <vulkan/vulkan.hpp>
8#include <vma/vk_mem_alloc.h>
9#include <optional>
10
11namespace tt {
12
13namespace PipelineImage {
14class PipelineImage;
15}
16namespace PipelineFlat {
17class PipelineFlat;
18}
19namespace PipelineBox {
20class PipelineBox;
21}
22namespace PipelineSDF {
23class PipelineSDF;
24}
25namespace PipelineToneMapper {
26class PipelineToneMapper;
27}
28
29class Window_vulkan : public Window_base {
30public:
31 vk::SurfaceKHR intrinsic;
32
33 vk::SwapchainKHR swapchain;
34
35 int nrSwapchainImages;
36 vk::Extent2D swapchainImageExtent;
37 vk::SurfaceFormatKHR swapchainImageFormat;
38 std::vector<vk::Image> swapchainImages;
39 std::vector<vk::ImageView> swapchainImageViews;
40 std::vector<vk::Framebuffer> swapchainFramebuffers;
41
42 static const vk::Format depthImageFormat = vk::Format::eD32Sfloat;
43 VmaAllocation depthImageAllocation;
44 vk::Image depthImage;
45 vk::ImageView depthImageView;
46
47 static const vk::Format colorImageFormat = vk::Format::eR16G16B16A16Sfloat;
48 VmaAllocation colorImageAllocation;
49 vk::Image colorImage;
50 vk::ImageView colorImageView;
51 vk::DescriptorImageInfo colorDescriptorImageInfo;
52
53 vk::RenderPass renderPass;
54
55 vk::CommandBuffer commandBuffer;
56
57 vk::Semaphore imageAvailableSemaphore;
58 vk::Semaphore renderFinishedSemaphore;
59 vk::Fence renderFinishedFence;
60
66
67 Window_vulkan(std::shared_ptr<WindowDelegate> const &delegate, Label &&title);
69
70 Window_vulkan(const Window_vulkan &) = delete;
71 Window_vulkan &operator=(const Window_vulkan &) = delete;
72 Window_vulkan(Window_vulkan &&) = delete;
73 Window_vulkan &operator=(Window_vulkan &&) = delete;
74
75 void initialize() override;
76 void render(hires_utc_clock::time_point displayTimePoint) override;
77
78protected:
79 void teardown() override;
80 void build() override;
81
84 virtual vk::SurfaceKHR getSurface() const = 0;
85
86private:
87 std::optional<uint32_t> acquireNextImageFromSwapchain();
88 void presentImageToQueue(uint32_t frameBufferIndex, vk::Semaphore renderFinishedSemaphore);
89
90 void fillCommandBuffer(vk::Framebuffer frameBuffer);
91 void submitCommandBuffer();
92
93 bool readSurfaceExtent();
94 bool checkSurfaceExtent();
95
96 void buildDevice();
97 void buildSemaphores();
98 void teardownSemaphores();
99 State buildSwapchain();
100 void teardownSwapchain();
101 void buildCommandBuffers();
102 void teardownCommandBuffers();
103 void buildRenderPasses();
104 void teardownRenderPasses();
105 void buildFramebuffers();
106 void teardownFramebuffers();
107 void buildPipelines();
108 void teardownPipelines();
109 bool buildSurface();
110 void teardownSurface();
111 void teardownDevice();
112
113 void waitIdle();
114 std::tuple<uint32_t, vk::Extent2D> getImageCountAndExtent();
115};
116
117}
Definition Label.hpp:12
Definition Window_base.hpp:37
State
Definition Window_base.hpp:39
Definition Window_vulkan.hpp:29
void render(hires_utc_clock::time_point displayTimePoint) override