ngscopeclient 0.1-dev+51fbda87c
VulkanWindow.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* ngscopeclient *
4* *
5* Copyright (c) 2012-2024 Andrew D. Zonenberg *
6* All rights reserved. *
7* *
8* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
9* following conditions are met: *
10* *
11* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
12* following disclaimer. *
13* *
14* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
15* following disclaimer in the documentation and/or other materials provided with the distribution. *
16* *
17* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
18* derived from this software without specific prior written permission. *
19* *
20* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
21* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
22* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
26* POSSIBILITY OF SUCH DAMAGE. *
27* *
28***********************************************************************************************************************/
29
35#ifndef VulkanWindow_h
36#define VulkanWindow_h
37
38class Texture;
39
44{
45public:
46 VulkanWindow(const std::string& title, std::shared_ptr<QueueHandle> queue);
47 virtual ~VulkanWindow();
48
49 GLFWwindow* GetWindow()
50 { return m_window; }
51
52 // Return a DPI 'scale' value where 1 ~= 96DPI
53 // Akin to uses of `get_pango_context()->get_resolution() / 96` in glscopeclient
54 float GetContentScale();
55
56 virtual void Render();
57
58 std::shared_ptr<QueueHandle> GetRenderQueue()
59 { return m_renderQueue; }
60
61 void AddTextureUsedThisFrame(std::shared_ptr<Texture> tex)
62 { m_texturesUsedThisFrame[m_frameIndex].emplace(tex); }
63
64 bool IsFullscreen()
65 { return m_fullscreen; }
66
67protected:
68 bool UpdateFramebuffer();
69 void SetFullscreen(bool fullscreen);
70
71 virtual void DoRender(vk::raii::CommandBuffer& cmdBuf);
72 virtual void RenderUI();
73
75 GLFWwindow* m_window;
76
78 ImGuiContext* m_context;
79
81 std::shared_ptr<vk::raii::SurfaceKHR> m_surface;
82
84 std::shared_ptr<vk::raii::DescriptorPool> m_imguiDescriptorPool;
85
87 std::shared_ptr<QueueHandle> m_renderQueue;
88
91
94
97
100
102 std::unique_ptr<vk::raii::CommandPool> m_cmdPool;
103
105 std::vector<std::unique_ptr<vk::raii::CommandBuffer> > m_cmdBuffers;
106
108 std::vector<std::unique_ptr<vk::raii::Semaphore> > m_imageAcquiredSemaphores;
109
111 std::vector<std::unique_ptr<vk::raii::Semaphore> > m_renderCompleteSemaphores;
112
115
117 uint32_t m_frameIndex;
118
121
123 std::vector<std::unique_ptr<vk::raii::Fence> > m_fences;
124
126 std::vector<std::unique_ptr<vk::raii::ImageView> > m_backBufferViews;
127
129 std::vector<std::unique_ptr<vk::raii::Framebuffer> > m_framebuffers;
130
132 std::unique_ptr<vk::raii::RenderPass> m_renderPass;
133
135 std::unique_ptr<vk::raii::SwapchainKHR> m_swapchain;
136
143 #if VK_HEADER_VERSION >= 229
144 std::vector<vk::Image> m_backBuffers;
145 #else
146 std::vector<VkImage> m_backBuffers;
147 #endif
148
151
154
157
160
163
166
169
172
174 std::vector< std::set<std::shared_ptr<Texture> > > m_texturesUsedThisFrame;
175
176};
177
178#endif
Encapsulates the various Vulkan objects we need to represent texture image memory.
Definition: TextureManager.h:46
A GLFW window containing a Vulkan surface.
Definition: VulkanWindow.h:44
std::vector< std::unique_ptr< vk::raii::Semaphore > > m_renderCompleteSemaphores
Semaphore indicating frame is complete.
Definition: VulkanWindow.h:111
std::vector< VkImage > m_backBuffers
Back buffer images.
Definition: VulkanWindow.h:146
bool m_fullscreen
Fullscreen flag.
Definition: VulkanWindow.h:159
std::shared_ptr< vk::raii::SurfaceKHR > m_surface
Surface for drawing onto.
Definition: VulkanWindow.h:81
int m_width
Current window width.
Definition: VulkanWindow.h:153
std::vector< std::unique_ptr< vk::raii::Semaphore > > m_imageAcquiredSemaphores
Semaphore indicating framebuffer is ready.
Definition: VulkanWindow.h:108
VulkanWindow(const std::string &title, std::shared_ptr< QueueHandle > queue)
Creates a new top level window with the specified title.
Definition: VulkanWindow.cpp:60
int m_pendingHeight
Requested height for software resize.
Definition: VulkanWindow.h:99
int m_windowedWidth
Saved size before we went fullscreen.
Definition: VulkanWindow.h:168
int m_windowedX
Saved position before we went fullscreen.
Definition: VulkanWindow.h:162
bool m_resizeEventPending
Set true if we have to handle a resize event.
Definition: VulkanWindow.h:90
std::shared_ptr< vk::raii::DescriptorPool > m_imguiDescriptorPool
Descriptor pool for ImGui.
Definition: VulkanWindow.h:84
int m_minImageCount
The minimum image count for the backbuffer allowed by this GPU.
Definition: VulkanWindow.h:150
bool UpdateFramebuffer()
Updates the framebuffer.
Definition: VulkanWindow.cpp:303
std::vector< std::unique_ptr< vk::raii::CommandBuffer > > m_cmdBuffers
Frame command buffers.
Definition: VulkanWindow.h:105
int m_windowedHeight
Saved size before we went fullscreen.
Definition: VulkanWindow.h:171
GLFWwindow * m_window
The underlying GLFW window object.
Definition: VulkanWindow.h:75
std::vector< std::unique_ptr< vk::raii::ImageView > > m_backBufferViews
Back buffer view.
Definition: VulkanWindow.h:126
virtual ~VulkanWindow()
Destroys a VulkanWindow.
Definition: VulkanWindow.cpp:277
uint32_t m_frameIndex
Frame number for double buffering.
Definition: VulkanWindow.h:117
int m_height
Current window height.
Definition: VulkanWindow.h:156
std::vector< std::unique_ptr< vk::raii::Framebuffer > > m_framebuffers
Framebuffer.
Definition: VulkanWindow.h:129
std::unique_ptr< vk::raii::CommandPool > m_cmdPool
Frame command pool.
Definition: VulkanWindow.h:102
std::shared_ptr< QueueHandle > m_renderQueue
Queue for rendering to.
Definition: VulkanWindow.h:87
ImGuiContext * m_context
ImGui context for GUI objects.
Definition: VulkanWindow.h:78
uint32_t m_semaphoreIndex
Frame semaphore number for double buffering.
Definition: VulkanWindow.h:114
int m_windowedY
Saved position before we went fullscreen.
Definition: VulkanWindow.h:165
int m_pendingWidth
Requested width for software resize.
Definition: VulkanWindow.h:96
uint32_t m_lastFrameIndex
Frame number for double buffering.
Definition: VulkanWindow.h:120
bool m_softwareResizeRequested
Set true if a resize was requested by software (i.e. we need to resize to m_pendingWidth / m_pendingH...
Definition: VulkanWindow.h:93
std::vector< std::unique_ptr< vk::raii::Fence > > m_fences
Frame fences.
Definition: VulkanWindow.h:123
std::vector< std::set< std::shared_ptr< Texture > > > m_texturesUsedThisFrame
Textures used this frame.
Definition: VulkanWindow.h:174
std::unique_ptr< vk::raii::SwapchainKHR > m_swapchain
Swapchain for presenting to the screen.
Definition: VulkanWindow.h:135
std::unique_ptr< vk::raii::RenderPass > m_renderPass
Render pass for drawing everything.
Definition: VulkanWindow.h:132