Changeset d2d9286 in opengl-game for vulkan-game.cpp
- Timestamp:
- Nov 7, 2019, 2:05:17 AM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- f985231
- Parents:
- 87c8f1a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
r87c8f1a rd2d9286 215 215 UIEvent e; 216 216 bool quit = false; 217 218 SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);219 217 220 218 while (!quit) { … … 266 264 267 265 void VulkanGame::renderUI() { 266 // TODO: Since I currently don't use any other render targets, 267 // I may as well set this once before the render loop 268 SDL_SetRenderTarget(renderer, uiOverlay); 269 270 SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00); 268 271 SDL_RenderClear(renderer); 269 SDL_RenderPresent(renderer); 272 273 SDL_Rect rect = {280, 220, 100, 100}; 274 SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0xFF); 275 SDL_RenderFillRect(renderer, &rect); 276 277 SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0xFF, 0xFF); 278 SDL_RenderDrawLine(renderer, 50, 5, 150, 500); 279 280 VulkanUtils::populateVulkanImageFromSDLTexture(device, physicalDevice, commandPool, uiOverlay, renderer, 281 sdlOverlayImage, graphicsQueue); 270 282 } 271 283 … … 274 286 275 287 uint32_t imageIndex; 288 289 VkResult result = vkAcquireNextImageKHR(device, swapChain, numeric_limits<uint64_t>::max(), 290 imageAvailableSemaphores[currentFrame], VK_NULL_HANDLE, &imageIndex); 291 292 if (result == VK_ERROR_OUT_OF_DATE_KHR) { 293 recreateSwapChain(); 294 return; 295 } else if (result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR) { 296 throw runtime_error("failed to acquire swap chain image!"); 297 } 298 299 VkSubmitInfo submitInfo = {}; 300 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; 301 302 VkSemaphore waitSemaphores[] = { imageAvailableSemaphores[currentFrame] }; 303 VkPipelineStageFlags waitStages[] = { VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT }; 304 305 submitInfo.waitSemaphoreCount = 1; 306 submitInfo.pWaitSemaphores = waitSemaphores; 307 submitInfo.pWaitDstStageMask = waitStages; 308 submitInfo.commandBufferCount = 1; 309 submitInfo.pCommandBuffers = &commandBuffers[imageIndex]; 310 311 VkSemaphore signalSemaphores[] = { renderFinishedSemaphores[currentFrame] }; 312 313 submitInfo.signalSemaphoreCount = 1; 314 submitInfo.pSignalSemaphores = signalSemaphores; 315 316 vkResetFences(device, 1, &inFlightFences[currentFrame]); 317 318 if (vkQueueSubmit(graphicsQueue, 1, &submitInfo, inFlightFences[currentFrame]) != VK_SUCCESS) { 319 throw runtime_error("failed to submit draw command buffer!"); 320 } 321 322 VkPresentInfoKHR presentInfo = {}; 323 presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; 324 presentInfo.waitSemaphoreCount = 1; 325 presentInfo.pWaitSemaphores = signalSemaphores; 326 327 VkSwapchainKHR swapChains[] = { swapChain }; 328 presentInfo.swapchainCount = 1; 329 presentInfo.pSwapchains = swapChains; 330 presentInfo.pImageIndices = &imageIndex; 331 presentInfo.pResults = nullptr; 332 333 result = vkQueuePresentKHR(presentQueue, &presentInfo); 334 335 if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR || framebufferResized) { 336 framebufferResized = false; 337 recreateSwapChain(); 338 } else if (result != VK_SUCCESS) { 339 throw runtime_error("failed to present swap chain image!"); 340 } 276 341 277 342 currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT; … … 774 839 vkCmdBeginRenderPass(commandBuffers[i], &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE); 775 840 776 // reateGraphicsPipelineCommands(scenePipeline, i);777 // createGraphicsPipelineCommands(overlayPipeline, i);778 841 for (GraphicsPipeline_Vulkan pipeline : graphicsPipelines) { 779 842 pipeline.createRenderCommands(commandBuffers[i], i); … … 809 872 } 810 873 874 void VulkanGame::recreateSwapChain() { 875 cout << "Recreating swap chain" << endl; 876 gui->refreshWindowSize(); 877 878 while (gui->getWindowWidth() == 0 || gui->getWindowHeight() == 0 || 879 (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED) != 0) { 880 SDL_WaitEvent(nullptr); 881 gui->refreshWindowSize(); 882 } 883 884 vkDeviceWaitIdle(device); 885 886 //cleanupSwapChain(); 887 } 888 811 889 void VulkanGame::cleanupSwapChain() { 812 890 VulkanUtils::destroyVulkanImage(device, depthImage);
Note:
See TracChangeset
for help on using the changeset viewer.