Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
Loading...
Searching...
No Matches
WorldUiRenderer.h
1#pragma once
2
3#include "Engine/Texture/RuntimeTextureDescriptorLease.h"
4
5#include <cstdint>
6#include <unordered_map>
7#include <vector>
8#include <vk_mem_alloc.h>
9#include <vulkan/vulkan.h>
10
11struct ImGuiContext;
12
13namespace Engine::Components
14{
15 class WidgetComponent;
16} // namespace Engine::Components
17
18namespace Engine::Core
19{
21 class AssetManager;
22} // namespace Engine::Core
23
24namespace Engine::Rendering
25{
26 class RenderProcess;
27
32 {
33 public:
37 WorldUiRenderer() = default;
38 WorldUiRenderer(Core::ApplicationContext * context, uint32_t framesInFlight);
39
44
48 WorldUiRenderer( const WorldUiRenderer & ) = delete;
49
54
55
59 [[nodiscard]] uint32_t registerWidget(
61 );
62
67
72 VkCommandBuffer commandBuffer,
73 uint32_t frameIndex,
74 RenderProcess &renderProcess
75 );
76
77 private:
81 void cleanup();
82
84 {
85 VkImage image = VK_NULL_HANDLE;
86 VmaAllocation allocation = VK_NULL_HANDLE;
87 VkImageView imageView = VK_NULL_HANDLE;
88 VkImageLayout currentLayout = VK_IMAGE_LAYOUT_UNDEFINED;
89 };
90
91 struct Target
92 {
95 uint32_t width = 0;
96 uint32_t height = 0;
97 std::vector<TargetFrame> frames;
99 };
100
102 {
104 uint32_t framesRemaining = 0;
105 };
106
108 {
109 VkDescriptorSet descriptor = VK_NULL_HANDLE;
110 VkImageView imageView = VK_NULL_HANDLE;
111 VkSampler sampler = VK_NULL_HANDLE;
112 };
113
115 void createTargetImages( Target & target ) const;
116 void destroyTarget( Target & target ) const;
117 void retireTarget( Target && target );
119 void transitionTargetsToColorAttachment( VkCommandBuffer commandBuffer, uint32_t frameIndex );
120 void transitionTargetsToShaderRead( VkCommandBuffer commandBuffer, uint32_t frameIndex );
121 void renderTarget(VkCommandBuffer commandBuffer, Target &target, uint32_t frameIndex);
123
125 ImGuiContext * imguiContext_ = nullptr;
126 VkDescriptorPool descriptorPool_ = VK_NULL_HANDLE;
127 VkSampler sampler_ = VK_NULL_HANDLE;
128 VkFormat format_ = VK_FORMAT_R8G8B8A8_UNORM;
129 uint32_t framesInFlight_ = 0;
130 bool initialized_ = false;
131
132 std::unordered_map<Components::WidgetComponent *, Target> targets_;
133 std::unordered_map<uint32_t, ImGuiTexture> imguiTextures_;
134 std::vector<RetiredTarget> retiredTargets_;
135 };
136} // namespace Engine::Rendering
Move-only ownership of one runtime texture descriptor slot.
Runtime ImGui widget that can be rendered into a world-space UI texture.
The application context is the core class which stores the basic openxr and vulkan objects.
Coordinates engine asset loading pipelines and runtime texture descriptor ownership.
WorldUiRenderer(Core::ApplicationContext *context, uint32_t framesInFlight)
std::unordered_map< Components::WidgetComponent *, Target > targets_
Core::ApplicationContext * context_
std::unordered_map< uint32_t, ImGuiTexture > imguiTextures_
void retireTarget(Target &&target)
void renderTarget(VkCommandBuffer commandBuffer, Target &target, uint32_t frameIndex)
Target & ensureTarget(Components::WidgetComponent &widget)
WorldUiRenderer()=default
Creates an uninitialized world UI renderer.
void prepareWidgetTextures(Components::WidgetComponent &widget)
uint32_t registerWidget(Components::WidgetComponent &widget)
Ensures a widget has a render target texture and returns its descriptor index.
void unregisterWidget(Components::WidgetComponent &widget)
Retires the render target owned by a widget component.
void renderWidgets(VkCommandBuffer commandBuffer, uint32_t frameIndex, RenderProcess &renderProcess)
Renders all active widget components for the current frame.
void destroyTarget(Target &target) const
void createTargetImages(Target &target) const
WorldUiRenderer & operator=(const WorldUiRenderer &)=delete
World UI renderers own Vulkan resources and cannot be copy-assigned.
void transitionTargetsToShaderRead(VkCommandBuffer commandBuffer, uint32_t frameIndex)
void transitionTargetsToColorAttachment(VkCommandBuffer commandBuffer, uint32_t frameIndex)
void cleanup()
Destroys active and retired widget render targets and renderer resources.
~WorldUiRenderer()
Releases renderer-owned Vulkan and ImGui resources.
WorldUiRenderer(const WorldUiRenderer &)=delete
World UI renderers own Vulkan resources and cannot be copied.
std::vector< RetiredTarget > retiredTargets_
Components::WidgetComponent * widget
Assets::RuntimeTextureDescriptorLease descriptor