30 VkInstance instance, VkSurfaceKHR surface)
38 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
39 VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
40 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
false,
false,
true);
45 ImGui::CreateContext();
46 ImGuiIO& io = ImGui::GetIO();
48 io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
49 io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
51 io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
52 LOG(3,
"Viewports enabled")
54 ImGui::StyleColorsDark();
56 std::array<VkDescriptorPoolSize, 1> poolSizes {};
57 poolSizes[0].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
60 VkDescriptorPoolSize pool_sizes[]
61 = { { VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 100 } };
62 VkDescriptorPoolCreateInfo pool_info = {};
63 pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
64 pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
65 pool_info.maxSets = 100;
66 pool_info.poolSizeCount = (uint32_t)IM_ARRAYSIZE(pool_sizes);
67 pool_info.pPoolSizes = pool_sizes;
68 vkCreateDescriptorPool(
71 ImGui_ImplGlfw_InitForVulkan(
window,
true);
72 ImGui_ImplVulkan_InitInfo init_info = {};
73 init_info.Instance = instance;
80 init_info.PipelineCache = VK_NULL_HANDLE;
83 init_info.Allocator =
nullptr;
86 init_info.MSAASamples = VK_SAMPLE_COUNT_1_BIT;
87 init_info.CheckVkResultFn =
nullptr;
88 ImGui_ImplVulkan_Init(&init_info);
90 VkCommandPoolCreateInfo commandPoolCreateInfo = {};
91 commandPoolCreateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
92 commandPoolCreateInfo.queueFamilyIndex
95 commandPoolCreateInfo.flags
96 = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
98 if (vkCreateCommandPool(
101 LOG(1,
"Could not create graphics command pool")
102 throw std::runtime_error(
"Could not create graphics command pool");
105 VkCommandBuffer command_buffer
107 ImGui_ImplVulkan_CreateFontsTexture();
112 VkCommandBufferAllocateInfo allocInfo {};
113 allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
115 allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
116 allocInfo.commandBufferCount =
static_cast<uint32_t
>(
commandBuffers.size());
117 if (vkAllocateCommandBuffers(
120 LOG(1,
"failed to allocate command buffers!")
121 throw std::runtime_error(
"failed to allocate command buffers!");
123 LOG(3,
"EditorRenderer initialized")
128 ImGui_ImplVulkan_Shutdown();
129 vkDestroyRenderPass(device->device, renderPass,
nullptr);
130 for (
auto framebuffer : framebuffers)
131 vkDestroyFramebuffer(device->device, framebuffer,
nullptr);
132 vkDestroyCommandPool(device->device, commandPool,
nullptr);
133 vkDestroyDescriptorPool(device->device, descriptorPool,
nullptr);
134 LOG(3,
"EditorRenderer destroyed")
148 uint32_t currentFrame, uint32_t imageIndex,
float bgColor[3])
150 vkResetCommandBuffer(commandBuffers[currentFrame], 0);
151 VkCommandBufferBeginInfo beginInfo {};
152 beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
153 VkClearValue clearColor
154 = { { { bgColor[0], bgColor[1], bgColor[2], 1.0f } } };
155 vkBeginCommandBuffer(commandBuffers[currentFrame], &beginInfo);
156 VkRenderPassBeginInfo info = {};
157 info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
158 info.renderPass = renderPass;
159 info.framebuffer = framebuffers[imageIndex];
160 info.renderArea.extent = swapChain->swapChainExtent;
161 info.clearValueCount = 1;
162 info.pClearValues = &clearColor;
163 vkCmdBeginRenderPass(
164 commandBuffers[currentFrame], &info, VK_SUBPASS_CONTENTS_INLINE);
165 ImGui_ImplVulkan_RenderDrawData(
166 ImGui::GetDrawData(), commandBuffers[currentFrame]);
167 vkCmdEndRenderPass(commandBuffers[currentFrame]);
168 vkEndCommandBuffer(commandBuffers[currentFrame]);
169 LOG(4,
"EditorRenderer rendered")
std::vector< VkFramebuffer > createFramebuffer(Chronos::Engine::Device device, Chronos::Engine::SwapChain swapChain, VkRenderPass renderPass, bool msaa)
Creates a set of framebuffers for use.
void endSingleTimeCommands(VkCommandBuffer *commandBuffer, Chronos::Engine::Device device, VkCommandPool commandPool)
Ends recording of single time command buffer and destroys it.
VkRenderPass createRenderPass(Chronos::Engine::Device device, Chronos::Engine::SwapChain swapChain, VkImageLayout initalLayout, VkImageLayout finalLayout, VkImageLayout msaaFinalLayout, bool msaa, bool clearFramebuffer, bool dependency)
Creates a render pass.