Changeset 880cfc2 in opengl-game


Ignore:
Timestamp:
Feb 14, 2021, 3:15:39 PM (4 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
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)
Message:

Remove some of the example windows from SDLGame and cleanup some code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sdl-game.cpp

    rea2b4dc r880cfc2  
    152152   }
    153153
    154    // Our state
    155    bool show_demo_window = true;
    156    bool show_another_window = false;
    157 
    158154   done = false;
    159155   while (!done) {
     
    172168      }
    173169
    174       // Resize swap chain?
    175170      if (shouldRecreateSwapChain) {
    176171         int width, height;
     
    194189      ImGui::NewFrame();
    195190
    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 
    200191      // 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window.
    201192      {
     
    205196
    206197         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 state
    208          ImGui::Checkbox("Another Window", &show_another_window);
    209198
    210199         if (ImGui::Button("Button"))                            // Buttons return true when clicked (most widgets return true when edited/activated)
     
    217206      }
    218207
    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       // Rendering
    230208      ImGui::Render();
    231209      ImDrawData* draw_data = ImGui::GetDrawData();
     
    329307   // FIXME: We could wait on the Queue if we had the queue in wd-> (otherwise VulkanH functions can't use globals)
    330308    //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!");
    334310
    335311   ImGui_ImplVulkan_Shutdown();
     
    745721      poolInfo.queueFamilyIndex = indices.graphicsFamily.value();
    746722      poolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
     723
    747724      if (vkCreateCommandPool(device, &poolInfo, nullptr, &commandPools[i]) != VK_SUCCESS) {
    748725         throw runtime_error("failed to create graphics command pool!");
     
    787764
    788765      if (vkAllocateCommandBuffers(device, &allocInfo, &commandBuffers[i]) != VK_SUCCESS) {
    789          throw runtime_error("failed to allocate command buffers!");
     766         throw runtime_error("failed to allocate command buffer!");
    790767      }
    791768   }
     
    823800      imageAcquiredSemaphores[currentFrame], VK_NULL_HANDLE, &imageIndex);
    824801
    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) {
    826805      shouldRecreateSwapChain = true;
    827806      return;
     
    830809   }
    831810
    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()),
    833813      "failed waiting for fence!");
    834814
     
    836816      "failed to reset fence!");
    837817
    838    // START OF NEW CODE
    839    // I don't have analogous code in vulkan-game right now because I record command buffers once
    840    // before the render loop ever starts. I should change this
    841 
    842818   VKUTIL_CHECK_RESULT(vkResetCommandPool(device, commandPools[imageIndex], 0),
    843819      "failed to reset command pool!");
    844820
    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),
    850826      "failed to begin recording command buffer!");
    851827
     
    865841   vkCmdBeginRenderPass(commandBuffers[imageIndex], &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
    866842
    867    // Record dear imgui primitives into command buffer
    868843   ImGui_ImplVulkan_RenderDrawData(draw_data, commandBuffers[imageIndex]);
    869844
    870    // Submit command buffer
    871845   vkCmdEndRenderPass(commandBuffers[imageIndex]);
    872846
     
    874848      "failed to record command buffer!");
    875849
    876    // END OF NEW CODE
    877 
    878850   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 };
    880852   VkSemaphore signalSemaphores[] = { renderCompleteSemaphores[currentFrame] };
    881853
     
    884856   submitInfo.waitSemaphoreCount = 1;
    885857   submitInfo.pWaitSemaphores = waitSemaphores;
    886    submitInfo.pWaitDstStageMask = &wait_stage;
     858   submitInfo.pWaitDstStageMask = waitStages;
    887859   submitInfo.commandBufferCount = 1;
    888860   submitInfo.pCommandBuffers = &commandBuffers[imageIndex];
     
    895867
    896868void VulkanGame::presentFrame() {
    897    if (shouldRecreateSwapChain) {
    898       return;
    899    }
    900 
    901869   VkSemaphore signalSemaphores[] = { renderCompleteSemaphores[currentFrame] };
    902870
     
    912880   VkResult result = vkQueuePresentKHR(presentQueue, &presentInfo);
    913881
    914    // In vulkan-game, I also handle VK_SUBOPTIMAL_KHR and framebufferResized. g_SwapChainRebuild is kind of similar
    915    // to framebufferResized, but not quite the same
    916    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) {
    917885      shouldRecreateSwapChain = true;
    918886      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!");
    921889   }
    922890
Note: See TracChangeset for help on using the changeset viewer.