diff --git a/xo-imgui/example/ex4a/VulkanApp.cpp b/xo-imgui/example/ex4a/VulkanApp.cpp index 52e69d4a..c3b7d59a 100644 --- a/xo-imgui/example/ex4a/VulkanApp.cpp +++ b/xo-imgui/example/ex4a/VulkanApp.cpp @@ -322,4 +322,20 @@ MinimalImGuiVulkan::create_command_pool() } } +void +MinimalImGuiVulkan::create_command_buffers() +{ + command_buffers_.resize(MAX_FRAMES_IN_FLIGHT); + + VkCommandBufferAllocateInfo alloc_info{}; + alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; + alloc_info.commandPool = command_pool_; + alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; + alloc_info.commandBufferCount = static_cast(command_buffers_.size()); + + if (vkAllocateCommandBuffers(device_, &alloc_info, command_buffers_.data()) != VK_SUCCESS) { + throw std::runtime_error("Failed to allocate command buffers!"); + } +} + /* end VulkanApp.cpp */ diff --git a/xo-imgui/example/ex4a/VulkanApp.hpp b/xo-imgui/example/ex4a/VulkanApp.hpp index e3310f54..04f13f07 100644 --- a/xo-imgui/example/ex4a/VulkanApp.hpp +++ b/xo-imgui/example/ex4a/VulkanApp.hpp @@ -72,19 +72,10 @@ private: */ void create_command_pool(); - void create_command_buffers() { - commandBuffers.resize(MAX_FRAMES_IN_FLIGHT); - - VkCommandBufferAllocateInfo allocInfo{}; - allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; - allocInfo.commandPool = command_pool_; - allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; - allocInfo.commandBufferCount = static_cast(commandBuffers.size()); - - if (vkAllocateCommandBuffers(device_, &allocInfo, commandBuffers.data()) != VK_SUCCESS) { - throw std::runtime_error("Failed to allocate command buffers!"); - } - } + /* + * populate @ref command_buffers_ + */ + void create_command_buffers(); void create_sync_objects() { imageAvailableSemaphores.resize(MAX_FRAMES_IN_FLIGHT); @@ -245,8 +236,8 @@ private: vkResetFences(device_, 1, &inFlightFences[currentFrame]); - vkResetCommandBuffer(commandBuffers[currentFrame], 0); - recordCommandBuffer(commandBuffers[currentFrame], imageIndex); + vkResetCommandBuffer(command_buffers_[currentFrame], 0); + recordCommandBuffer(command_buffers_[currentFrame], imageIndex); VkSubmitInfo submitInfo{}; submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; @@ -258,7 +249,7 @@ private: submitInfo.pWaitDstStageMask = waitStages; submitInfo.commandBufferCount = 1; - submitInfo.pCommandBuffers = &commandBuffers[currentFrame]; + submitInfo.pCommandBuffers = &command_buffers_[currentFrame]; VkSemaphore signalSemaphores[] = {renderFinishedSemaphores[currentFrame]}; submitInfo.signalSemaphoreCount = 1; @@ -453,7 +444,8 @@ private: VkCommandPool command_pool_; - std::vector commandBuffers; + std::vector command_buffers_; + std::vector imageAvailableSemaphores; std::vector renderFinishedSemaphores; std::vector inFlightFences;