Skip to content

Commit b6ee8dc

Browse files
committed
Rework UI overlay initialization
1 parent 5a07711 commit b6ee8dc

3 files changed

Lines changed: 13 additions & 12 deletions

File tree

base/VulkanUIOverlay.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*
33
* UI overlay class using ImGui
44
*
5-
* Copyright (C) 2017-2025 by Sascha Willems - www.saschawillems.de
5+
* Copyright (C) 2017-2026 by Sascha Willems - www.saschawillems.de
66
*
77
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
88
*/
@@ -56,7 +56,7 @@ namespace vks
5656
}
5757

5858
/** Prepare all vulkan resources required to render the UI overlay */
59-
void UIOverlay::prepareResources()
59+
void UIOverlay::prepare()
6060
{
6161
assert(maxConcurrentFrames > 0);
6262

@@ -192,11 +192,7 @@ namespace vks
192192

193193
// Buffers per max. frames-in-flight
194194
buffers.resize(maxConcurrentFrames);
195-
}
196195

197-
/** Prepare a separate pipeline for the UI overlay rendering decoupled from the main application */
198-
void UIOverlay::preparePipeline(const VkPipelineCache pipelineCache, const VkRenderPass renderPass, const VkFormat colorFormat, const VkFormat depthFormat)
199-
{
200196
// Pipeline layout
201197
// Push constants for UI rendering parameters
202198
VkPushConstantRange pushConstantRange{ .stageFlags = VK_SHADER_STAGE_VERTEX_BIT, .size = sizeof(PushConstBlock) };
@@ -276,7 +272,7 @@ namespace vks
276272
pipelineCreateInfo.pNext = &pipelineRenderingCreateInfo;
277273
}
278274
#endif
279-
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device->logicalDevice, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipeline));
275+
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device->logicalDevice, VK_NULL_HANDLE, 1, &pipelineCreateInfo, nullptr, &pipeline));
280276
}
281277

282278
/** Update vertex and index buffer containing the imGui elements when required */

base/VulkanUIOverlay.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* UI overlay class using ImGui
33
*
4-
* Copyright (C) 2017-2025 by Sascha Willems - www.saschawillems.de
4+
* Copyright (C) 2017-2026 by Sascha Willems - www.saschawillems.de
55
*
66
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
77
*/
@@ -74,11 +74,14 @@ namespace vks
7474
bool visible{ true };
7575
float scale{ 1.0f };
7676

77+
VkRenderPass renderPass{ VK_NULL_HANDLE };
78+
VkFormat colorFormat{ VK_FORMAT_UNDEFINED };
79+
VkFormat depthFormat{ VK_FORMAT_UNDEFINED };
80+
7781
UIOverlay();
7882
~UIOverlay();
7983

80-
void preparePipeline(const VkPipelineCache pipelineCache, const VkRenderPass renderPass, const VkFormat colorFormat, const VkFormat depthFormat);
81-
void prepareResources();
84+
void prepare();
8285

8386
void update(uint32_t currentBuffer);
8487
void draw(const VkCommandBuffer commandBuffer, uint32_t currentBuffer);

base/vulkanexamplebase.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,14 @@ void VulkanExampleBase::prepare()
239239
ui.maxConcurrentFrames = maxConcurrentFrames;
240240
ui.device = vulkanDevice;
241241
ui.queue = queue;
242+
ui.renderPass = renderPass;
243+
ui.colorFormat = swapChain.colorFormat;
244+
ui.depthFormat = depthFormat;
242245
ui.shaders = {
243246
loadShader(getShadersPath() + "base/uioverlay.vert.spv", VK_SHADER_STAGE_VERTEX_BIT),
244247
loadShader(getShadersPath() + "base/uioverlay.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT),
245248
};
246-
ui.prepareResources();
247-
ui.preparePipeline(pipelineCache, renderPass, swapChain.colorFormat, depthFormat);
249+
ui.prepare();
248250
}
249251
}
250252

0 commit comments

Comments
 (0)