Changeset 8b823e7 in opengl-game for sdl-game.cpp
- Timestamp:
- Jan 24, 2021, 11:38:43 PM (4 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- d8cf709
- Parents:
- ce9dc9f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sdl-game.cpp
rce9dc9f r8b823e7 6 6 #include <stdexcept> 7 7 8 #include <stdlib.h> // abort (only used in check_vk_result)9 10 8 #include <SDL2/SDL_vulkan.h> 11 9 … … 20 18 static bool g_SwapChainRebuild = false; 21 19 22 static void check_ vk_result(VkResult err) {23 if ( err == 0) {20 static void check_imgui_vk_result(VkResult res) { 21 if (res == VK_SUCCESS) { 24 22 return; 25 23 } 26 fprintf(stderr, "[vulkan] Error: VkResult = %d\n", err); 27 if (err < 0) { 28 abort(); 24 25 ostringstream oss; 26 oss << "[imgui] Vulkan error! VkResult is \"" << VulkanUtils::resultString(res) << "\"" << __LINE__; 27 if (res < 0) { 28 throw runtime_error("Fatal: " + oss.str()); 29 } else { 30 cerr << oss.str(); 29 31 } 30 32 } … … 37 39 g_SwapChainRebuild = true; 38 40 return; 39 } else if (result != VK_SUCCESS) { 40 throw runtime_error("failed to acquire swap chain image!"); 41 } 42 43 if (vkWaitForFences(device, 1, &inFlightFences[imageIndex], VK_TRUE, numeric_limits<uint64_t>::max()) != VK_SUCCESS) { 44 throw runtime_error("failed waiting for fence!"); 45 } 46 if (vkResetFences(device, 1, &inFlightFences[imageIndex]) != VK_SUCCESS) { 47 throw runtime_error("failed to reset fence!"); 48 } 41 } else { 42 VKUTIL_CHECK_RESULT(result, "failed to acquire swap chain image!"); 43 } 44 45 VKUTIL_CHECK_RESULT(vkWaitForFences(device, 1, &inFlightFences[imageIndex], VK_TRUE, numeric_limits<uint64_t>::max()), 46 "failed waiting for fence!"); 47 48 VKUTIL_CHECK_RESULT(vkResetFences(device, 1, &inFlightFences[imageIndex]), 49 "failed to reset fence!"); 49 50 50 51 // START OF NEW CODE … … 52 53 // before the render loop ever starts. I should change this 53 54 54 result = vkResetCommandPool(device, commandPools[imageIndex], 0); 55 check_vk_result(result); 55 VKUTIL_CHECK_RESULT(vkResetCommandPool(device, commandPools[imageIndex], 0), 56 "failed to reset command pool!"); 57 56 58 VkCommandBufferBeginInfo info = {}; 57 59 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; 58 60 info.flags |= VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; 59 result = vkBeginCommandBuffer(commandBuffers[imageIndex], &info); 60 check_vk_result(result); 61 62 VKUTIL_CHECK_RESULT(vkBeginCommandBuffer(commandBuffers[imageIndex], &info), 63 "failed to begin recording command buffer!"); 61 64 62 65 VkRenderPassBeginInfo renderPassInfo = {}; … … 81 84 vkCmdEndRenderPass(commandBuffers[imageIndex]); 82 85 83 if (vkEndCommandBuffer(commandBuffers[imageIndex]) != VK_SUCCESS) { 84 throw runtime_error("failed to record command buffer!"); 85 } 86 VKUTIL_CHECK_RESULT(vkEndCommandBuffer(commandBuffers[imageIndex]), 87 "failed to record command buffer!"); 86 88 87 89 // END OF NEW CODE … … 101 103 submitInfo.pSignalSemaphores = signalSemaphores; 102 104 103 if (vkQueueSubmit(graphicsQueue, 1, &submitInfo, inFlightFences[imageIndex]) != VK_SUCCESS) { 104 throw runtime_error("failed to submit draw command buffer!"); 105 } 105 VKUTIL_CHECK_RESULT(vkQueueSubmit(graphicsQueue, 1, &submitInfo, inFlightFences[imageIndex]), 106 "failed to submit draw command buffer!"); 106 107 } 107 108 … … 196 197 pool_info.poolSizeCount = (uint32_t)IM_ARRAYSIZE(pool_sizes); 197 198 pool_info.pPoolSizes = pool_sizes; 198 check_vk_result(vkCreateDescriptorPool(device, &pool_info, nullptr, &descriptorPool)); 199 200 VKUTIL_CHECK_RESULT(vkCreateDescriptorPool(device, &pool_info, nullptr, &descriptorPool), 201 "failed to create descriptor pool"); 199 202 } 200 203 … … 225 228 init_info.MinImageCount = swapChainMinImageCount; 226 229 init_info.ImageCount = swapChainImageCount; 227 init_info.CheckVkResultFn = check_ vk_result;230 init_info.CheckVkResultFn = check_imgui_vk_result; 228 231 ImGui_ImplVulkan_Init(&init_info, renderPass); 229 232
Note:
See TracChangeset
for help on using the changeset viewer.