SHARE
TWEET

Untitled

a guest Jul 11th, 2019 76 in 17 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.     FResult Renderer::draw() {
  3.    
  4.         vkWaitForFences(m_logicalDevice, 1, &m_inFlightFences[m_currFrameIndex], VK_TRUE, std::numeric_limits<uint64_t>::max());
  5.  
  6.  
  7.         uint32_t imageIndex;
  8.         VkResult res = vkAcquireNextImageKHR(m_logicalDevice, m_canvas->getSwapchain(), std::numeric_limits<uint64_t>::max(), m_imageAvailableSemaphores[m_currFrameIndex], VK_NULL_HANDLE, &imageIndex);
  9.        
  10.         // Check if swapchain is still intact
  11.         if (res == VK_ERROR_OUT_OF_DATE_KHR) {
  12.             recreateRenderTarget();
  13.             return FResult::EarlyReturn;
  14.         }
  15.         else if (res != VK_SUCCESS && res != VK_SUBOPTIMAL_KHR) {
  16.             CLOG_ERROR(LogCategory::Graphics, "Failed to acquire swapchian image");
  17.             return FResult::Error;
  18.         }
  19.  
  20.         // Submit to queue
  21.  
  22.         VkSemaphore waitSemaphores[] = { m_imageAvailableSemaphores[m_currFrameIndex] };
  23.         VkPipelineStageFlags waitStages[] = { VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT }; // Each element corresponds to the element with the same index in the waitSemaphores[] array
  24.  
  25.         VkSemaphore signalSemaphores[] = { m_renderFinishedSemaphores[m_currFrameIndex] };
  26.  
  27.         // What we're submitting
  28.         VkSubmitInfo submitInfo = {};
  29.         submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
  30.         submitInfo.waitSemaphoreCount = 1;
  31.         submitInfo.pWaitSemaphores = waitSemaphores;
  32.         submitInfo.pWaitDstStageMask = waitStages;
  33.         submitInfo.commandBufferCount = 1;
  34.         submitInfo.pCommandBuffers = &m_commandBuffers[imageIndex];
  35.         submitInfo.signalSemaphoreCount = 1;
  36.         submitInfo.pSignalSemaphores = signalSemaphores;
  37.  
  38.         vkResetFences(m_logicalDevice, 1, &m_inFlightFences[m_currFrameIndex]);
  39.  
  40.  
  41.         if (vkQueueSubmit(m_device->getGraphicsQueueHandle(), 1, &submitInfo, m_inFlightFences[m_currFrameIndex]) != VK_SUCCESS) {
  42.             CLOG_ERROR(LogCategory::Graphics, "Failed submitting to queue");
  43.             return FResult::Error;
  44.         }
  45.  
  46.         VkSwapchainKHR swapchainsUsed[] = { m_canvas->getSwapchain() };
  47.  
  48.         // Where we're submitting
  49.         VkPresentInfoKHR presentInfo = {};
  50.         presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
  51.         presentInfo.waitSemaphoreCount = 1;
  52.         presentInfo.pWaitSemaphores = signalSemaphores;
  53.         presentInfo.swapchainCount = 1;
  54.         presentInfo.pSwapchains = swapchainsUsed;
  55.         presentInfo.pImageIndices = &imageIndex;
  56.  
  57.         res = vkQueuePresentKHR(m_device->getPresentQueueHandle(), &presentInfo);
  58.        
  59.  
  60.         // Check if swapchain is still intact
  61.         if (res == VK_ERROR_OUT_OF_DATE_KHR || res == VK_SUBOPTIMAL_KHR || m_canvas->m_framebufferResized) {
  62.             m_canvas->m_framebufferResized = false;
  63.             recreateRenderTarget();
  64.             return FResult::EarlyReturn;
  65.         }
  66.         else if (res != VK_SUCCESS) {
  67.             CLOG_ERROR(LogCategory::Graphics, "Failed presenting swapchain image");
  68.             return FResult::Error;
  69.         }
  70.  
  71.  
  72.         m_currFrameIndex = (m_currFrameIndex + 1) % m_maxFramesInFlight;
  73.    
  74.         return FResult::Success;
  75.    
  76.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top