Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void drawFrame()
- {
- vkWaitForFences(m_Device, 1, &m_inFlightFences[m_CurrentFrame], VK_TRUE, UINT64_MAX);
- uint32_t imageIndex;
- VkResult result = vkAcquireNextImageKHR(m_Device, m_SwapChain, UINT64_MAX, m_ImageAvailableSemaphore[m_CurrentFrame],
- VK_NULL_HANDLE, &imageIndex);
- if (result == VK_ERROR_OUT_OF_DATE_KHR)
- {
- recreateSwapChain();
- return;
- }
- else if (result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR)
- {
- throw std::runtime_error("Failed to acquire swap chain image!");
- }
- updateUniformBuffer(imageIndex);
- // Check if a previous frame is using this image (i.e. there is its fence to wait on)
- if (m_ImagesInFlight[imageIndex] != VK_NULL_HANDLE)
- {
- vkWaitForFences(m_Device, 1, &m_ImagesInFlight[imageIndex], VK_TRUE, UINT64_MAX);
- }
- // Mark the image as now being in use by this frame
- m_ImagesInFlight[imageIndex] = m_inFlightFences[m_CurrentFrame];
- VkSubmitInfo submitInfo = {};
- submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
- VkSemaphore waitSemaphores[] = { m_ImageAvailableSemaphore[m_CurrentFrame] };
- VkPipelineStageFlags waitStages[] = { VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT };
- submitInfo.waitSemaphoreCount = 1;
- submitInfo.pWaitSemaphores = waitSemaphores;
- submitInfo.pWaitDstStageMask = waitStages;
- submitInfo.commandBufferCount = 1;
- submitInfo.pCommandBuffers = &m_CommandBuffers[imageIndex];
- VkSemaphore signalSemaphores[] = { m_RenderFinishedSemaphore[m_CurrentFrame] };
- submitInfo.signalSemaphoreCount = 1;
- submitInfo.pSignalSemaphores = signalSemaphores;
- vkResetFences(m_Device, 1, &m_inFlightFences[m_CurrentFrame]);
- if (vkQueueSubmit(m_GraphicsQueue, 1, &submitInfo, m_inFlightFences[m_CurrentFrame]) != VK_SUCCESS)
- {
- throw std::runtime_error("Failed to submit draw command buffer!");
- }
- VkPresentInfoKHR presentInfo = {};
- presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
- presentInfo.waitSemaphoreCount = 1;
- presentInfo.pWaitSemaphores = signalSemaphores;
- VkSwapchainKHR swapChains[] = { m_SwapChain };
- presentInfo.swapchainCount = 1;
- presentInfo.pSwapchains = swapChains;
- presentInfo.pImageIndices = &imageIndex;
- presentInfo.pResults = nullptr; // Optional
- result = vkQueuePresentKHR(m_PresentQueue, &presentInfo);
- if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR || m_FrameBufferResized)
- {
- m_FrameBufferResized = false;
- recreateSwapChain();
- }
- else if (result != VK_SUCCESS)
- {
- throw std::runtime_error("Failed to present swap chain image!");
- }
- m_CurrentFrame = (m_CurrentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement