ngscopeclient v0.3
Loading...
Searching...
No Matches
VulkanWindow.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* ngscopeclient *
4* *
5* Copyright (c) 2012-2026 Andrew D. Zonenberg and contributors *
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, bool noMaximize, bool noRestore);
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)
63
64 bool IsFullscreen()
65 { return m_fullscreen; }
66
67 void SaveWindowPositionAndSize();
68
69protected:
70 bool UpdateFramebuffer();
71 void SetFullscreen(bool fullscreen);
72 GLFWmonitor* GetCurrentMonitor();
73 bool IsPositionValid(
74 const std::string& monitorName,
75 int monitorWidth,
76 int monitorHeight,
77 int windowXPos,
78 int windowYPos);
79
80 virtual void DoRender(vk::raii::CommandBuffer& cmdBuf);
81 virtual void RenderUI();
82
85
88
90 std::shared_ptr<vk::raii::SurfaceKHR> m_surface;
91
93 std::shared_ptr<vk::raii::DescriptorPool> m_imguiDescriptorPool;
94
96 std::shared_ptr<QueueHandle> m_renderQueue;
97
100
103
106
109
111 std::unique_ptr<vk::raii::CommandPool> m_cmdPool;
112
114 std::vector<std::unique_ptr<vk::raii::CommandBuffer> > m_cmdBuffers;
115
117 std::vector<std::unique_ptr<vk::raii::Semaphore> > m_imageAcquiredSemaphores;
118
120 std::vector<std::unique_ptr<vk::raii::Semaphore> > m_renderCompleteSemaphores;
121
124
127
130
132 std::vector<std::unique_ptr<vk::raii::Fence> > m_fences;
133
135 std::vector<std::unique_ptr<vk::raii::ImageView> > m_backBufferViews;
136
138 std::vector<std::unique_ptr<vk::raii::Framebuffer> > m_framebuffers;
139
141 std::unique_ptr<vk::raii::RenderPass> m_renderPass;
142
144 std::unique_ptr<vk::raii::SwapchainKHR> m_swapchain;
145
152 #if VK_HEADER_VERSION >= 229
153 std::vector<vk::Image> m_backBuffers;
154 #else
155 std::vector<VkImage> m_backBuffers;
156 #endif
157
160
163
166
169
172
175
177 float m_forcedFontScale = 1.0f;
178
180 float m_forcedUIScale = 1.0f;
181
184
187
190
193
195 std::vector< std::set<std::shared_ptr<Texture> > > m_texturesUsedThisFrame;
196
198 std::string m_title;
199};
200
201#endif
Definition AcceleratorBuffer.h:204
Encapsulates the various Vulkan objects we need to represent texture image memory.
Definition TextureManager.h:48
A GLFW window containing a Vulkan surface.
Definition VulkanWindow.h:44
bool m_forceDPIScaling
True if user asked (via NGSCOPECLIENT_UI_SCALE or NGSCOPECLIENT_FONT_SCALE environment variable) to f...
Definition VulkanWindow.h:174
std::vector< std::unique_ptr< vk::raii::Semaphore > > m_renderCompleteSemaphores
Semaphore indicating frame is complete.
Definition VulkanWindow.h:120
std::vector< VkImage > m_backBuffers
Back buffer images.
Definition VulkanWindow.h:155
bool m_fullscreen
Fullscreen flag.
Definition VulkanWindow.h:168
std::shared_ptr< vk::raii::SurfaceKHR > m_surface
Surface for drawing onto.
Definition VulkanWindow.h:90
bool m_restore
True if user asked (via command line argument) not to restore previous window state.
Definition VulkanWindow.h:171
int m_width
Current window width.
Definition VulkanWindow.h:162
std::vector< std::unique_ptr< vk::raii::Semaphore > > m_imageAcquiredSemaphores
Semaphore indicating framebuffer is ready.
Definition VulkanWindow.h:117
int m_pendingHeight
Requested height for software resize.
Definition VulkanWindow.h:108
int m_windowedWidth
Saved size before we went fullscreen.
Definition VulkanWindow.h:189
int m_windowedX
Saved position before we went fullscreen.
Definition VulkanWindow.h:183
bool m_resizeEventPending
Set true if we have to handle a resize event.
Definition VulkanWindow.h:99
std::shared_ptr< vk::raii::DescriptorPool > m_imguiDescriptorPool
Descriptor pool for ImGui.
Definition VulkanWindow.h:93
int m_minImageCount
The minimum image count for the backbuffer allowed by this GPU.
Definition VulkanWindow.h:159
bool UpdateFramebuffer()
Updates the framebuffer.
Definition VulkanWindow.cpp:429
std::vector< std::unique_ptr< vk::raii::CommandBuffer > > m_cmdBuffers
Frame command buffers.
Definition VulkanWindow.h:114
int m_windowedHeight
Saved size before we went fullscreen.
Definition VulkanWindow.h:192
GLFWwindow * m_window
The underlying GLFW window object.
Definition VulkanWindow.h:84
std::vector< std::unique_ptr< vk::raii::ImageView > > m_backBufferViews
Back buffer view.
Definition VulkanWindow.h:135
std::string m_title
Window title.
Definition VulkanWindow.h:198
virtual ~VulkanWindow()
Destroys a VulkanWindow.
Definition VulkanWindow.cpp:401
uint32_t m_frameIndex
Frame number for double buffering.
Definition VulkanWindow.h:126
int m_height
Current window height.
Definition VulkanWindow.h:165
std::vector< std::unique_ptr< vk::raii::Framebuffer > > m_framebuffers
Framebuffer.
Definition VulkanWindow.h:138
std::unique_ptr< vk::raii::CommandPool > m_cmdPool
Frame command pool.
Definition VulkanWindow.h:111
std::shared_ptr< QueueHandle > m_renderQueue
Queue for rendering to.
Definition VulkanWindow.h:96
float m_forcedFontScale
Forced font DPI scale value.
Definition VulkanWindow.h:177
ImGuiContext * m_context
ImGui context for GUI objects.
Definition VulkanWindow.h:87
uint32_t m_semaphoreIndex
Frame semaphore number for double buffering.
Definition VulkanWindow.h:123
int m_windowedY
Saved position before we went fullscreen.
Definition VulkanWindow.h:186
float m_forcedUIScale
Forced UI DPI scale value.
Definition VulkanWindow.h:180
int m_pendingWidth
Requested width for software resize.
Definition VulkanWindow.h:105
uint32_t m_lastFrameIndex
Frame number for double buffering.
Definition VulkanWindow.h:129
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:102
std::vector< std::unique_ptr< vk::raii::Fence > > m_fences
Frame fences.
Definition VulkanWindow.h:132
std::vector< std::set< std::shared_ptr< Texture > > > m_texturesUsedThisFrame
Textures used this frame.
Definition VulkanWindow.h:195
std::unique_ptr< vk::raii::SwapchainKHR > m_swapchain
Swapchain for presenting to the screen.
Definition VulkanWindow.h:144
std::unique_ptr< vk::raii::RenderPass > m_renderPass
Render pass for drawing everything.
Definition VulkanWindow.h:141