TGUI 1.14-dev
Loading...
Searching...
No Matches
BackendRenderTargetVulkan.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_BACKEND_RENDER_TARGET_VULKAN_HPP
26#define TGUI_BACKEND_RENDER_TARGET_VULKAN_HPP
27
28#include <TGUI/Backend/Renderer/BackendRenderTarget.hpp>
29#include <TGUI/Backend/Renderer/Vulkan/BackendTextureVulkan.hpp>
30
31#include <vulkan/vulkan.h>
32
34
35namespace tgui
36{
38
45 class TGUI_API BackendRenderTargetVulkan : public BackendRenderTarget
46 {
47 public:
53 BackendRenderTargetVulkan(std::shared_ptr<BackendRendererVulkan> renderer);
54
61
65 void setClearColor(const Color& color) override;
66
70 void clearScreen() override;
71
79 void setView(FloatRect view, FloatRect viewport, Vector2f targetSize) override;
80
84 void drawGui(const std::shared_ptr<RootContainer>&) override
85 {
86 TGUI_ASSERT(false, "The Vulkan backend requires that you pass a VkCommandBuffer to the draw function");
87 throw Exception("The Vulkan backend requires that you pass a VkCommandBuffer to the draw function");
88 }
89
108 void setRenderPass(VkRenderPass renderPass,
109 VkFormat colorFormat,
110 std::uint32_t maxFramesInFlight,
111 std::uint32_t subpass = 0,
112 VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT);
113
134 void setDynamicRenderingFormats(VkFormat colorFormat,
135 std::uint32_t maxFramesInFlight,
136 VkFormat depthFormat = VK_FORMAT_UNDEFINED,
137 VkFormat stencilFormat = VK_FORMAT_UNDEFINED,
138 VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT);
139
156 bool drawGui(const std::shared_ptr<RootContainer>& root, VkCommandBuffer cmdBuffer);
157
168 void drawVertexArray(const RenderStates& states,
169 const Vertex* vertices,
170 std::size_t vertexCount,
171 const unsigned int* indices,
172 std::size_t indexCount,
173 const std::shared_ptr<BackendTexture>& texture) override;
174
176
177 protected:
186 void updateClipping(FloatRect clipRect, FloatRect clipViewport) override;
187
189 // Removes the current pipeline. It is only destroyed once the frames that might still be using it have finished.
191 void retirePipeline();
192
194 // Changes the amount of frame resources. Waits until the queue is idle when the amount changes.
196 void setMaxFramesInFlight(std::uint32_t maxFramesInFlight);
197
199 // Destroys the buffers and retired pipelines of all frames
201 void destroyFrameResources();
202
204
205 protected:
207 {
208 std::size_t indexCount;
209 std::shared_ptr<BackendTextureVulkan::ImageResources> imageResources;
210 bool smooth;
211 VkRect2D clipRect;
212 };
213
214 // Resources that can only be reused once the GPU has finished executing the frame
216 {
217 VkBuffer buffer = VK_NULL_HANDLE;
218 VkDeviceMemory memory = VK_NULL_HANDLE;
219 VkDeviceSize bufferSize = 0;
220 void* mappedMemory = nullptr;
221 std::vector<DrawCommand> drawCommands; // Keeps the used images alive until the frame is no longer in flight
222 std::vector<VkPipeline> retiredPipelines;
223 };
224
225 std::shared_ptr<BackendRendererVulkan> m_renderer;
226 std::unique_ptr<BackendTextureVulkan> m_emptyTexture;
227
228 Transform m_projectionTransform;
229
230 VkPipeline m_pipeline = VK_NULL_HANDLE;
231 VkRenderPass m_renderPass = VK_NULL_HANDLE;
232 std::uint32_t m_subpass = 0;
233 VkFormat m_colorFormat = VK_FORMAT_UNDEFINED;
234 VkFormat m_depthFormat = VK_FORMAT_UNDEFINED;
235 VkFormat m_stencilFormat = VK_FORMAT_UNDEFINED;
236 VkSampleCountFlagBits m_samples = VK_SAMPLE_COUNT_1_BIT;
237
238 std::vector<FrameResources> m_frames;
239 std::size_t m_currentFrame = 0;
240
241 // Used while drawGui is being executed
242 std::vector<Vertex> m_vertices;
243 std::vector<unsigned int> m_indices;
244 VkRect2D m_clipRect = {};
245 };
246} // namespace tgui
247
248#endif // TGUI_BACKEND_RENDER_TARGET_VULKAN_HPP
void drawGui(const std::shared_ptr< RootContainer > &) override
This function is not used by this backend, use drawGui(root, VkCommandBuffer) instead.
Definition BackendRenderTargetVulkan.hpp:84
BackendRenderTargetVulkan(std::shared_ptr< BackendRendererVulkan > renderer)
Constructor.
void setRenderPass(VkRenderPass renderPass, VkFormat colorFormat, std::uint32_t maxFramesInFlight, std::uint32_t subpass=0, VkSampleCountFlagBits samples=VK_SAMPLE_COUNT_1_BIT)
Informs the render target about the render pass in which the gui will be drawn.
void setView(FloatRect view, FloatRect viewport, Vector2f targetSize) override
Informs the render target about which part of the window is used for rendering.
void drawVertexArray(const RenderStates &states, const Vertex *vertices, std::size_t vertexCount, const unsigned int *indices, std::size_t indexCount, const std::shared_ptr< BackendTexture > &texture) override
Draws a vertex array. This is called by the other draw functions.
~BackendRenderTargetVulkan() override
Destructor.
void updateClipping(FloatRect clipRect, FloatRect clipViewport) override
Called from addClippingLayer and removeClippingLayer to apply the clipping.
void setDynamicRenderingFormats(VkFormat colorFormat, std::uint32_t maxFramesInFlight, VkFormat depthFormat=VK_FORMAT_UNDEFINED, VkFormat stencilFormat=VK_FORMAT_UNDEFINED, VkSampleCountFlagBits samples=VK_SAMPLE_COUNT_1_BIT)
Informs the render target that the gui will be drawn with dynamic rendering (vkCmdBeginRendering).
void clearScreen() override
This function isn't used by this backend.
void setClearColor(const Color &color) override
This function isn't used by this backend.
bool drawGui(const std::shared_ptr< RootContainer > &root, VkCommandBuffer cmdBuffer)
Draws the gui and all of its widgets.
Backend renderer that uses Vulkan.
Definition BackendRendererVulkan.hpp:72
Wrapper for colors.
Definition Color.hpp:63
Definition Exception.hpp:46
Defines a transform matrix.
Definition Transform.hpp:45
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:37
Definition BackendRenderTargetVulkan.hpp:207
Definition BackendRenderTargetVulkan.hpp:216
States used for drawing.
Definition RenderStates.hpp:38
Definition Vertex.hpp:37