TGUI 1.9.0
Loading...
Searching...
No Matches
BackendRenderTargetSDLGPU.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2025 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_SDL_GPU_HPP
26#define TGUI_BACKEND_RENDER_TARGET_SDL_GPU_HPP
27
28#include <TGUI/Backend/Renderer/SDL_GPU/BackendTextureSDLGPU.hpp>
29
30#if !TGUI_BUILD_AS_CXX_MODULE
31 #include <TGUI/Backend/Renderer/BackendRenderTarget.hpp>
32#endif
33
35
36TGUI_MODULE_EXPORT namespace tgui
37{
41 class TGUI_API BackendRenderTargetSDLGPU : public BackendRenderTarget
42 {
43 public:
44
51 BackendRenderTargetSDLGPU(SDL_GPUDevice* device, SDL_GPUTextureFormat swapchainTextureFormat);
52
57
62 void setClearColor(const Color& color) override;
63
67 void clearScreen() override;
68
76 void setView(FloatRect view, FloatRect viewport, Vector2f targetSize) override;
77
81 void drawGui(const std::shared_ptr<RootContainer>&) override
82 {
83 TGUI_ASSERT(false, "The SDL_GPU backend requires that you pass SDL_GPUCommandBuffer and SDL_GPURenderPass pointers to the draw function");
84 throw Exception("The SDL_GPU backend requires that you pass SDL_GPUCommandBuffer and SDL_GPURenderPass pointers to the draw function");
85 }
86
99 bool prepareDrawGui(const std::shared_ptr<RootContainer>& root, SDL_GPUCommandBuffer* cmdBuffer, SDL_GPUCopyPass* copyPass = nullptr);
100
113 void drawGui(SDL_GPURenderPass* renderPass);
114
125 void drawVertexArray(const RenderStates& states, const Vertex* vertices, std::size_t vertexCount,
126 const unsigned int* indices, std::size_t indexCount, const std::shared_ptr<BackendTexture>& texture) override;
127
129 protected:
130
139 void updateClipping(FloatRect clipRect, FloatRect clipViewport) override;
140
142 protected:
143
145 {
146 std::size_t indexCount;
147 std::shared_ptr<BackendTexture> texture;
148 SDL_Rect clipRect;
149 };
150
151 SDL_GPUDevice* m_device = nullptr;
152 SDL_GPUGraphicsPipeline* m_pipeline = nullptr;
153 SDL_GPUSampler* m_samplerNearest = nullptr;
154 SDL_GPUSampler* m_samplerLinear = nullptr;
155 std::unique_ptr<BackendTextureSDLGPU> m_emptyTexture;
156
157 Transform m_projectionTransform;
158
159 // Used while prepateDrawGui is being executed
160 std::vector<Vertex> m_vertices;
161 std::vector<unsigned int> m_indices;
162 SDL_Rect m_clipRect;
163
164 // Filled duing prepateDrawGui and used during drawGui
165 std::vector<DrawCommand> m_drawCommands;
166 SDL_GPUBuffer* m_vertexBuffer = nullptr;
167 SDL_GPUBuffer* m_indexBuffer = nullptr;
168 };
169
171}
172
174
175#endif // TGUI_BACKEND_RENDER_TARGET_SDL_GPU_HPP
void setClearColor(const Color &color) override
Select the color that will be used by clearScreen.
bool prepareDrawGui(const std::shared_ptr< RootContainer > &root, SDL_GPUCommandBuffer *cmdBuffer, SDL_GPUCopyPass *copyPass=nullptr)
Prepares drawing the gui and all of its widgets.
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.
void setView(FloatRect view, FloatRect viewport, Vector2f targetSize) override
Informs the render target about which part of the window is used for rendering.
void updateClipping(FloatRect clipRect, FloatRect clipViewport) override
Called from addClippingLayer and removeClippingLayer to apply the clipping.
BackendRenderTargetSDLGPU(SDL_GPUDevice *device, SDL_GPUTextureFormat swapchainTextureFormat)
Constructor.
void clearScreen() override
Clears the screen, called at the beginning of each frame when gui.mainLoop() is called.
void drawGui(SDL_GPURenderPass *renderPass)
Draws the gui and all of its widgets.
void drawGui(const std::shared_ptr< RootContainer > &) override
This function is not used by this backend, use drawGui(SDL_GPURenderPass*) instead.
Definition BackendRenderTargetSDLGPU.hpp:81
Wrapper for colors.
Definition Color.hpp:73
Definition Exception.hpp:48
Defines a transform matrix.
Definition Transform.hpp:46
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38
Definition BackendRenderTargetSDLGPU.hpp:145
States used for drawing.
Definition RenderStates.hpp:38
Definition Vertex.hpp:39