49 vkDestroySampler(device->device, textureSampler,
nullptr);
50 vkDestroyRenderPass(device->device, renderPass,
nullptr);
51 for (
auto framebuffer : framebuffers)
52 vkDestroyFramebuffer(device->device, framebuffer,
nullptr);
53 for (
auto& objectMap : objects) {
54 objectMap.second->destroy();
58 uint32_t currentFrame, uint32_t imageIndex,
float bgColor[3])
60 VkViewport viewport {};
63 viewport.width =
static_cast<float>(swapChain->swapChainExtent.width);
64 viewport.height =
static_cast<float>(swapChain->swapChainExtent.height);
65 viewport.minDepth = 0.0f;
66 viewport.maxDepth = 1.0f;
69 scissor.offset = { 0, 0 };
70 scissor.extent = swapChain->swapChainExtent;
72 vkResetCommandBuffer(commandBuffers[currentFrame], 0);
73 VkCommandBufferBeginInfo beginInfo {};
74 beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
75 if (vkBeginCommandBuffer(commandBuffers[currentFrame], &beginInfo)
77 throw std::runtime_error(
"failed to begin recording command buffer!");
80 VkRenderPassBeginInfo renderPassInfo {};
81 renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
82 renderPassInfo.renderPass = renderPass;
83 renderPassInfo.framebuffer = framebuffers[imageIndex];
84 renderPassInfo.renderArea.offset = { 0, 0 };
85 renderPassInfo.renderArea.extent = swapChain->swapChainExtent;
86 VkClearValue clearColor
87 = { { { bgColor[0], bgColor[1], bgColor[2], 1.0f } } };
88 renderPassInfo.clearValueCount = 1;
89 renderPassInfo.pClearValues = &clearColor;
91 vkCmdBeginRenderPass(commandBuffers[currentFrame], &renderPassInfo,
92 VK_SUBPASS_CONTENTS_INLINE);
94 for (
auto&
object : this->objects) {
95 if (this->objectsToBeRemoved.count(
object.first) > 0)
97 object.second->render(currentFrame, imageIndex, bgColor, viewport,
98 scissor, commandBuffers);
101 vkCmdEndRenderPass(commandBuffers[currentFrame]);
103 if (vkEndCommandBuffer(commandBuffers[currentFrame]) != VK_SUCCESS) {
104 throw std::runtime_error(
"failed to record command buffer!");
109 vkDestroyRenderPass(device->device, renderPass,
nullptr);
112 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
113 VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
true,
true,
false);
115 for (
auto& objectMap : objects) {
116 objectMap.second->recreateGraphicsPipeline();
145 for (
auto& objectMap : objectsToBeRemoved) {
146 objectMap.second[currentFrame] =
false;
147 bool toBeRemoved =
true;
148 for (
bool flag : objectMap.second) {
155 objects[objectMap.first]->
destroy();
156 objectsToBeRemoved.erase(objectMap.first);
157 objects.erase(objectMap.first);
158 Object*
object = objects[objectMap.first];
170 throw std::runtime_error(
"Invalid object type");
174 for (
auto& objectMap : objects) {
175 if (objectsToBeRemoved.count(objectMap.first) == 0) {
176 objectMap.second->update(currentFrame);
Contains the class for creating a rectangle filled with texture.
Class for creating a text object for rendering text.
std::vector< VkFramebuffer > createFramebuffer(Chronos::Engine::Device device, Chronos::Engine::SwapChain swapChain, VkRenderPass renderPass, bool msaa)
Creates a set of framebuffers for use.
std::vector< VkCommandBuffer > createCommandBuffer(Chronos::Engine::Device device, Chronos::Engine::SwapChain swapChain, VkCommandPool commandPool)
Creates a set of command buffers for use.
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.
Contains the functions for image manipulation along with the Texture class.