TGUI 1.14-dev
Loading...
Searching...
No Matches

Render target implementation that uses Vulkan. More...

#include <TGUI/Backend/Renderer/Vulkan/BackendRenderTargetVulkan.hpp>

Inheritance diagram for tgui::BackendRenderTargetVulkan:
tgui::BackendRenderTarget

Classes

struct  DrawCommand
struct  FrameResources

Public Member Functions

 BackendRenderTargetVulkan (std::shared_ptr< BackendRendererVulkan > renderer)
 Constructor.
 ~BackendRenderTargetVulkan () override
 Destructor.
void setClearColor (const Color &color) override
 This function isn't used by this backend.
void clearScreen () override
 This function isn't used by this backend.
void setView (FloatRect view, FloatRect viewport, Vector2f targetSize) override
 Informs the render target about which part of the window is used for rendering.
void drawGui (const std::shared_ptr< RootContainer > &) override
 This function is not used by this backend, use drawGui(root, VkCommandBuffer) instead.
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 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).
bool drawGui (const std::shared_ptr< RootContainer > &root, VkCommandBuffer cmdBuffer)
 Draws 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.
Public Member Functions inherited from tgui::BackendRenderTarget
 BackendRenderTarget (const BackendRenderTarget &)=delete
 BackendRenderTarget (BackendRenderTarget &&)=delete
BackendRenderTarget & operator= (const BackendRenderTarget &)=delete
BackendRenderTarget & operator= (BackendRenderTarget &&)=delete
 BackendRenderTarget ()=default
 Default constructor.
virtual ~BackendRenderTarget ()=default
 Virtual destructor.
virtual void drawWidget (const RenderStates &states, const std::shared_ptr< Widget > &widget)
 Draws a widget, if the widget is visible.
virtual void addClippingLayer (const RenderStates &states, FloatRect rect)
 Adds another clipping region.
virtual void removeClippingLayer ()
 Removes the last added clipping region.
virtual void drawBorders (const RenderStates &states, const Borders &borders, Vector2f size, Color color)
 Draws borders inside a provided rectangle.
virtual void drawFilledRect (const RenderStates &states, Vector2f size, Color color)
 Draws a colored rectangle.
virtual void drawSprite (const RenderStates &states, const Sprite &sprite)
 Draws a texture.
virtual void drawText (const RenderStates &states, const Text &text)
 Draws some text.
virtual void drawTextOutline (const RenderStates &states, const Text &text)
 Draws only the outline of some text.
virtual void drawTextWithoutOutline (const RenderStates &states, const Text &text)
 Draws some text, but without rendering its outline.
virtual void drawTriangle (const RenderStates &states, const Vertex &point1, const Vertex &point2, const Vertex &point3)
 Draws a single triangles (using the color that is specified in the vertices).
virtual void drawCircle (const RenderStates &states, float size, const Color &backgroundColor, float borderThickness=0, const Color &borderColor={})
 Draws a circle.
virtual void drawRoundedRectangle (const RenderStates &states, const Vector2f &size, const Color &backgroundColor, float radius, const Borders &borders={0}, const Color &borderColor=Color::Black)
 Draws a rounded rectangle.
Vector2f getPixelsPerPoint () const
 Returns the current mapping between the screen pixels and the points in the current view.

Protected Member Functions

void updateClipping (FloatRect clipRect, FloatRect clipViewport) override
 Called from addClippingLayer and removeClippingLayer to apply the clipping.
void retirePipeline ()
void setMaxFramesInFlight (std::uint32_t maxFramesInFlight)
void destroyFrameResources ()

Protected Attributes

std::shared_ptr< BackendRendererVulkan > m_renderer
std::unique_ptr< BackendTextureVulkan > m_emptyTexture
Transform m_projectionTransform
VkPipeline m_pipeline = VK_NULL_HANDLE
VkRenderPass m_renderPass = VK_NULL_HANDLE
std::uint32_t m_subpass = 0
VkFormat m_colorFormat = VK_FORMAT_UNDEFINED
VkFormat m_depthFormat = VK_FORMAT_UNDEFINED
VkFormat m_stencilFormat = VK_FORMAT_UNDEFINED
VkSampleCountFlagBits m_samples = VK_SAMPLE_COUNT_1_BIT
std::vector< FrameResources > m_frames
std::size_t m_currentFrame = 0
std::vector< Vertex > m_vertices
std::vector< unsigned int > m_indices
VkRect2D m_clipRect = {}
Protected Attributes inherited from tgui::BackendRenderTarget
FloatRect m_viewRect
FloatRect m_viewport
Vector2f m_targetSize
std::vector< std::pair< FloatRect, FloatRect > > m_clipLayers
Vector2f m_pixelsPerPoint = {1, 1}

Detailed Description

Render target implementation that uses Vulkan.

Before the gui can be drawn, either setRenderPass or setDynamicRenderingFormats has to be called to specify where the gui will be rendered to.

Constructor & Destructor Documentation

◆ BackendRenderTargetVulkan()

tgui::BackendRenderTargetVulkan::BackendRenderTargetVulkan ( std::shared_ptr< BackendRendererVulkan > renderer)

Constructor.

Parameters
rendererRenderer that holds the Vulkan device

◆ ~BackendRenderTargetVulkan()

tgui::BackendRenderTargetVulkan::~BackendRenderTargetVulkan ( )
override

Destructor.

The destructor waits until the queue is idle, to make sure the GPU no longer uses any of the resources.

Member Function Documentation

◆ clearScreen()

void tgui::BackendRenderTargetVulkan::clearScreen ( )
overridevirtual

This function isn't used by this backend.

Implements tgui::BackendRenderTarget.

◆ drawGui() [1/2]

void tgui::BackendRenderTargetVulkan::drawGui ( const std::shared_ptr< RootContainer > & )
inlineoverridevirtual

This function is not used by this backend, use drawGui(root, VkCommandBuffer) instead.

Implements tgui::BackendRenderTarget.

◆ drawGui() [2/2]

bool tgui::BackendRenderTargetVulkan::drawGui ( const std::shared_ptr< RootContainer > & root,
VkCommandBuffer cmdBuffer )

Draws the gui and all of its widgets.

Parameters
rootRoot container that holds all widgets in the gui
cmdBufferCommand buffer to record the draw commands in, which must be inside an active render pass
Returns
True if there weren't any errors, false if something went wrong (e.g. could not create a buffer)

This function should be called once per frame. Textures may still be uploaded to the GPU during this call, which happens by submitting a separate command buffer to the queue. The command buffer must be submitted to the queue that was passed to the renderer in the VulkanContext, because the texture uploads are only synchronized with work that is submitted to that same queue.

Warning
Bound pipeline, vertex buffer, index buffer and descriptor sets will be changed by this function
Viewport and scissor are changed by this function. The scissor will contain the entire target afterwards.

◆ drawVertexArray()

void tgui::BackendRenderTargetVulkan::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 )
overridevirtual

Draws a vertex array. This is called by the other draw functions.

Parameters
statesRender states to use for drawing
verticesPointer to first element in array of vertices
vertexCountAmount of elements in the vertex array
indicesPointer to first element in array of indices
indexCountAmount of elements in the indices array
textureTexture to use, or nullptr when drawing colored triangles

Implements tgui::BackendRenderTarget.

◆ setClearColor()

void tgui::BackendRenderTargetVulkan::setClearColor ( const Color & color)
overridevirtual

This function isn't used by this backend.

Implements tgui::BackendRenderTarget.

◆ setDynamicRenderingFormats()

void tgui::BackendRenderTargetVulkan::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).

Parameters
colorFormatFormat of the color attachment
maxFramesInFlightMaximum number of frames that your render loop lets the GPU execute at the same time (e.g. the amount of per-frame fences that you wait on). When drawGui is called, the frame that was drawn maxFramesInFlight frames earlier must have finished executing, otherwise TGUI can overwrite buffers that the GPU is still reading from. A value that is higher than needed only costs a bit of memory.
depthFormatFormat of the depth attachment, or VK_FORMAT_UNDEFINED if there is none
stencilFormatFormat of the stencil attachment, or VK_FORMAT_UNDEFINED if there is none
samplesAmount of samples of the attachments

Exactly one color attachment must be used. sRGB formats are supported, but alpha blending then happens in linear space, so semi-transparent parts can look slightly different than with a UNORM format. Changing maxFramesInFlight waits until the queue is idle, as the resources of all frames are recreated. It thus shouldn't be changed while a command buffer in which the gui was drawn still has to be submitted. Dynamic rendering requires Vulkan 1.3 or the VK_KHR_dynamic_rendering extension, and the dynamicRendering feature has to be enabled on the device.

◆ setRenderPass()

void tgui::BackendRenderTargetVulkan::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.

Parameters
renderPassRender pass that will be active when drawGui is called
colorFormatFormat of the color attachment of the subpass
maxFramesInFlightMaximum number of frames that your render loop lets the GPU execute at the same time (e.g. the amount of per-frame fences that you wait on). When drawGui is called, the frame that was drawn maxFramesInFlight frames earlier must have finished executing, otherwise TGUI can overwrite buffers that the GPU is still reading from. A value that is higher than needed only costs a bit of memory.
subpassIndex of the subpass that will be active when drawGui is called
samplesAmount of samples of the color attachment

The subpass must have exactly one color attachment. sRGB formats are supported, but alpha blending then happens in linear space, so semi-transparent parts can look slightly different than with a UNORM format. Changing maxFramesInFlight waits until the queue is idle, as the resources of all frames are recreated. It thus shouldn't be changed while a command buffer in which the gui was drawn still has to be submitted.

◆ setView()

void tgui::BackendRenderTargetVulkan::setView ( FloatRect view,
FloatRect viewport,
Vector2f targetSize )
overridevirtual

Informs the render target about which part of the window is used for rendering.

Parameters
viewDefines which part of the gui is being shown
viewportDefines which part of the window is being rendered to
targetSizeSize of the window

Reimplemented from tgui::BackendRenderTarget.

◆ updateClipping()

void tgui::BackendRenderTargetVulkan::updateClipping ( FloatRect clipRect,
FloatRect clipViewport )
overrideprotectedvirtual

Called from addClippingLayer and removeClippingLayer to apply the clipping.

Parameters
clipRectView rectangle to apply
clipViewportViewport to apply

Both rectangles may be empty when nothing that will be drawn is going to be visible.

Implements tgui::BackendRenderTarget.


The documentation for this class was generated from the following file: