TGUI
=
=
Download
Tutorials
1.x
0.9
0.8
Documentation
1.x
0.9
0.8
Examples
1.x
0.9
0.8
Community
TGUI
1.14-dev
Toggle main menu visibility
Loading...
Searching...
No Matches
include
TGUI
Backend
Renderer
Vulkan
SwapchainVulkan.hpp
1
2
//
3
// TGUI - Texus' Graphical User Interface
4
// Copyright (C) 2012-2026 Bruno Van de Velde (vdv_b@tgui.eu)
5
//
6
// This software is provided 'as-is', without any express or implied warranty.
7
// In no event will the authors be held liable for any damages arising from the use of this software.
8
//
9
// Permission is granted to anyone to use this software for any purpose,
10
// including commercial applications, and to alter it and redistribute it freely,
11
// subject to the following restrictions:
12
//
13
// 1. The origin of this software must not be misrepresented;
14
// you must not claim that you wrote the original software.
15
// If you use this software in a product, an acknowledgment
16
// in the product documentation would be appreciated but is not required.
17
//
18
// 2. Altered source versions must be plainly marked as such,
19
// and must not be misrepresented as being the original software.
20
//
21
// 3. This notice may not be removed or altered from any source distribution.
22
//
24
25
#ifndef TGUI_SWAPCHAIN_VULKAN_HPP
26
#define TGUI_SWAPCHAIN_VULKAN_HPP
27
28
#include <TGUI/Color.hpp>
29
#include <TGUI/Vector2.hpp>
30
31
#include <memory>
32
#include <vector>
33
#include <vulkan/vulkan.h>
34
36
37
namespace
tgui
38
{
39
class
BackendRendererVulkan
;
40
50
class
SwapchainVulkan
51
{
52
public
:
53
// Amount of frames that can be executing on the GPU at the same time, which has to be passed to setRenderPass.
54
// With FIFO presentation, more frames would only increase the input latency.
55
static
constexpr
std::uint32_t FramesInFlight = 2;
56
65
SwapchainVulkan
(std::shared_ptr<BackendRendererVulkan> renderer, VkSurfaceKHR surface);
66
70
~SwapchainVulkan
();
71
72
SwapchainVulkan
(
const
SwapchainVulkan
&) =
delete
;
73
SwapchainVulkan
& operator=(
const
SwapchainVulkan
&) =
delete
;
74
85
[[nodiscard]] VkCommandBuffer
beginFrame
(Vector2u framebufferSize,
Color
clearColor);
86
90
void
endFrame
();
91
97
[[nodiscard]] VkRenderPass
getRenderPass
()
const
;
98
104
[[nodiscard]] VkFormat
getColorFormat
()
const
;
105
113
[[nodiscard]]
bool
isSurfaceLost
()
const
;
114
116
117
private
:
119
// Creates the render pass, command buffers and synchronization objects
121
void
createVulkanObjects();
122
124
// Destroys the objects that were created in createVulkanObjects
126
void
destroyVulkanObjects();
127
129
// Creates the swapchain and the objects that depend on it. Returns false if the window has no size.
131
bool
recreateSwapchain(Vector2u framebufferSize);
132
134
// Destroys the image views, framebuffers and semaphores that depend on the swapchain images
136
void
destroySwapchainImageResources();
137
139
140
private
:
141
struct
FrameSync
142
{
143
VkCommandBuffer cmdBuffer = VK_NULL_HANDLE;
144
VkFence inFlightFence = VK_NULL_HANDLE;
145
VkSemaphore imageAvailableSemaphore = VK_NULL_HANDLE;
146
};
147
148
std::shared_ptr<BackendRendererVulkan> m_renderer;
149
VkDevice m_device = VK_NULL_HANDLE;
150
VkSurfaceKHR m_surface = VK_NULL_HANDLE;
151
VkSurfaceFormatKHR m_surfaceFormat = {};
152
VkSwapchainKHR m_swapchain = VK_NULL_HANDLE;
153
VkExtent2D m_extent = {};
154
Vector2u m_framebufferSize;
// Window size that was passed when the swapchain was last created
155
VkRenderPass m_renderPass = VK_NULL_HANDLE;
156
VkCommandPool m_commandPool = VK_NULL_HANDLE;
157
158
// One per swapchain image
159
std::vector<VkImageView> m_imageViews;
160
std::vector<VkFramebuffer> m_framebuffers;
161
std::vector<VkSemaphore> m_renderFinishedSemaphores;
162
163
std::vector<FrameSync> m_frames;
164
std::size_t m_currentFrame = 0;
165
std::uint32_t m_imageIndex = 0;
166
bool
m_swapchainOutdated =
false
;
167
bool
m_surfaceLost =
false
;
168
bool
m_rotatedByCompositor =
false
;
169
};
170
}
// namespace tgui
171
172
#endif
// TGUI_SWAPCHAIN_VULKAN_HPP
tgui::BackendRendererVulkan
Backend renderer that uses Vulkan.
Definition
BackendRendererVulkan.hpp:72
tgui::Color
Wrapper for colors.
Definition
Color.hpp:63
tgui::SwapchainVulkan::isSurfaceLost
bool isSurfaceLost() const
Returns whether the surface was lost and the swapchain can no longer be used.
tgui::SwapchainVulkan::endFrame
void endFrame()
Ends the render pass, submits the command buffer and presents the frame.
tgui::SwapchainVulkan::getColorFormat
VkFormat getColorFormat() const
Returns the format of the swapchain images.
tgui::SwapchainVulkan::SwapchainVulkan
SwapchainVulkan(std::shared_ptr< BackendRendererVulkan > renderer, VkSurfaceKHR surface)
Constructor.
tgui::SwapchainVulkan::getRenderPass
VkRenderPass getRenderPass() const
Returns the render pass that is started by beginFrame.
tgui::SwapchainVulkan::beginFrame
VkCommandBuffer beginFrame(Vector2u framebufferSize, Color clearColor)
Starts a new frame.
tgui::SwapchainVulkan::~SwapchainVulkan
~SwapchainVulkan()
Destructor.
tgui
Namespace that contains all TGUI functions and classes.
Definition
AbsoluteOrRelativeValue.hpp:37
Generated on
for TGUI by
1.18.0