Changeset 880cfc2 in opengl-game
- Timestamp:
- Feb 14, 2021, 3:15:39 PM (4 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- 7734042
- Parents:
- ea2b4dc
- git-author:
- Dmitry Portnoy <dportnoy@…> (02/14/21 15:09:48)
- git-committer:
- Dmitry Portnoy <dportnoy@…> (02/14/21 15:15:39)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sdl-game.cpp
rea2b4dc r880cfc2 152 152 } 153 153 154 // Our state155 bool show_demo_window = true;156 bool show_another_window = false;157 158 154 done = false; 159 155 while (!done) { … … 172 168 } 173 169 174 // Resize swap chain?175 170 if (shouldRecreateSwapChain) { 176 171 int width, height; … … 194 189 ImGui::NewFrame(); 195 190 196 // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).197 if (show_demo_window)198 ImGui::ShowDemoWindow(&show_demo_window);199 200 191 // 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window. 201 192 { … … 205 196 206 197 ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too) 207 ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state208 ImGui::Checkbox("Another Window", &show_another_window);209 198 210 199 if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated) … … 217 206 } 218 207 219 // 3. Show another simple window.220 if (show_another_window)221 {222 ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)223 ImGui::Text("Hello from another window!");224 if (ImGui::Button("Close Me"))225 show_another_window = false;226 ImGui::End();227 }228 229 // Rendering230 208 ImGui::Render(); 231 209 ImDrawData* draw_data = ImGui::GetDrawData(); … … 329 307 // FIXME: We could wait on the Queue if we had the queue in wd-> (otherwise VulkanH functions can't use globals) 330 308 //vkQueueWaitIdle(g_Queue); 331 if (vkDeviceWaitIdle(device) != VK_SUCCESS) { 332 throw runtime_error("failed to wait for device!"); 333 } 309 VKUTIL_CHECK_RESULT(vkDeviceWaitIdle(device), "failed to wait for device!"); 334 310 335 311 ImGui_ImplVulkan_Shutdown(); … … 745 721 poolInfo.queueFamilyIndex = indices.graphicsFamily.value(); 746 722 poolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; 723 747 724 if (vkCreateCommandPool(device, &poolInfo, nullptr, &commandPools[i]) != VK_SUCCESS) { 748 725 throw runtime_error("failed to create graphics command pool!"); … … 787 764 788 765 if (vkAllocateCommandBuffers(device, &allocInfo, &commandBuffers[i]) != VK_SUCCESS) { 789 throw runtime_error("failed to allocate command buffer s!");766 throw runtime_error("failed to allocate command buffer!"); 790 767 } 791 768 } … … 823 800 imageAcquiredSemaphores[currentFrame], VK_NULL_HANDLE, &imageIndex); 824 801 825 if (result == VK_ERROR_OUT_OF_DATE_KHR) { 802 if (result == VK_SUBOPTIMAL_KHR) { 803 shouldRecreateSwapChain = true; 804 } else if (result == VK_ERROR_OUT_OF_DATE_KHR) { 826 805 shouldRecreateSwapChain = true; 827 806 return; … … 830 809 } 831 810 832 VKUTIL_CHECK_RESULT(vkWaitForFences(device, 1, &inFlightFences[imageIndex], VK_TRUE, numeric_limits<uint64_t>::max()), 811 VKUTIL_CHECK_RESULT( 812 vkWaitForFences(device, 1, &inFlightFences[imageIndex], VK_TRUE, numeric_limits<uint64_t>::max()), 833 813 "failed waiting for fence!"); 834 814 … … 836 816 "failed to reset fence!"); 837 817 838 // START OF NEW CODE839 // I don't have analogous code in vulkan-game right now because I record command buffers once840 // before the render loop ever starts. I should change this841 842 818 VKUTIL_CHECK_RESULT(vkResetCommandPool(device, commandPools[imageIndex], 0), 843 819 "failed to reset command pool!"); 844 820 845 VkCommandBufferBeginInfo info = {};846 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;847 info.flags |= VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;848 849 VKUTIL_CHECK_RESULT(vkBeginCommandBuffer(commandBuffers[imageIndex], & info),821 VkCommandBufferBeginInfo beginInfo = {}; 822 beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; 823 beginInfo.flags |= VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; 824 825 VKUTIL_CHECK_RESULT(vkBeginCommandBuffer(commandBuffers[imageIndex], &beginInfo), 850 826 "failed to begin recording command buffer!"); 851 827 … … 865 841 vkCmdBeginRenderPass(commandBuffers[imageIndex], &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE); 866 842 867 // Record dear imgui primitives into command buffer868 843 ImGui_ImplVulkan_RenderDrawData(draw_data, commandBuffers[imageIndex]); 869 844 870 // Submit command buffer871 845 vkCmdEndRenderPass(commandBuffers[imageIndex]); 872 846 … … 874 848 "failed to record command buffer!"); 875 849 876 // END OF NEW CODE877 878 850 VkSemaphore waitSemaphores[] = { imageAcquiredSemaphores[currentFrame] }; 879 VkPipelineStageFlags wait _stage = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;851 VkPipelineStageFlags waitStages[] = { VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT }; 880 852 VkSemaphore signalSemaphores[] = { renderCompleteSemaphores[currentFrame] }; 881 853 … … 884 856 submitInfo.waitSemaphoreCount = 1; 885 857 submitInfo.pWaitSemaphores = waitSemaphores; 886 submitInfo.pWaitDstStageMask = &wait_stage;858 submitInfo.pWaitDstStageMask = waitStages; 887 859 submitInfo.commandBufferCount = 1; 888 860 submitInfo.pCommandBuffers = &commandBuffers[imageIndex]; … … 895 867 896 868 void VulkanGame::presentFrame() { 897 if (shouldRecreateSwapChain) {898 return;899 }900 901 869 VkSemaphore signalSemaphores[] = { renderCompleteSemaphores[currentFrame] }; 902 870 … … 912 880 VkResult result = vkQueuePresentKHR(presentQueue, &presentInfo); 913 881 914 // In vulkan-game, I also handle VK_SUBOPTIMAL_KHR and framebufferResized. g_SwapChainRebuild is kind of similar915 // to framebufferResized, but not quite the same916 if (result == VK_ERROR_OUT_OF_DATE_KHR) {882 if (result == VK_SUBOPTIMAL_KHR) { 883 shouldRecreateSwapChain = true; 884 } else if (result == VK_ERROR_OUT_OF_DATE_KHR) { 917 885 shouldRecreateSwapChain = true; 918 886 return; 919 } else if (result != VK_SUCCESS){920 throw runtime_error("failed to present swap chain image!");887 } else { 888 VKUTIL_CHECK_RESULT(result, "failed to present swap chain image!"); 921 889 } 922 890
Note:
See TracChangeset
for help on using the changeset viewer.