Преглед на файлове

Examples: Vulkan: Reduced duplicate code by skipping present on the first frame. Amend 201d589714c6ef7ff40c87140818a2208b8686b7 by @ParticlePeter

omar преди 7 години
родител
ревизия
7b968b098e
променени са 2 файла, в които са добавени 19 реда и са изтрити 22 реда
  1. 10 11
      examples/sdl_vulkan_example/main.cpp
  2. 9 11
      examples/vulkan_example/main.cpp

+ 10 - 11
examples/sdl_vulkan_example/main.cpp

@@ -625,17 +625,7 @@ int main(int, char**)
     bool show_another_window = false;
     ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
 
-    // When IMGUI_UNLIMITED_FRAME_RATE is defined we render into latest image acquired from the swapchain but we display the image which was rendered before.
-    // Hence we must render once and increase the g_FrameIndex without presenting, which we do before entering the render loop.
-    // This is also the reason why frame_end() is split into frame_end() and frame_present(), the later one not being called here.
-#ifdef IMGUI_UNLIMITED_FRAME_RATE
-    ImGui_ImplVulkan_NewFrame();
-    ImGui_ImplSDL2_NewFrame(window);
-    frame_begin();
-    ImGui_ImplVulkan_Render(g_Frames[g_FrameIndex].CommandBuffer);
-    frame_end();
-    g_FrameIndex = (g_FrameIndex + 1) % IMGUI_VK_QUEUED_FRAMES;
-#endif // IMGUI_UNLIMITED_FRAME_RATE
+    bool swap_chain_has_at_least_one_image = false;
 
     // Main loop
     bool done = false;
@@ -699,7 +689,16 @@ int main(int, char**)
         frame_begin();
         ImGui_ImplVulkan_Render(g_Frames[g_FrameIndex].CommandBuffer);
         frame_end();
+
+        // When IMGUI_UNLIMITED_FRAME_RATE is defined we render into latest image acquired from the swapchain but we display the image which was rendered before.
+        // Hence we must render once and increase the g_FrameIndex without presenting, which we do before entering the render loop.
+#ifdef IMGUI_UNLIMITED_FRAME_RATE
+        if (swap_chain_has_at_least_one_image)
+            frame_present();
+#else
         frame_present();
+#endif
+        swap_chain_has_at_least_one_image = true;
     }
 
     // Cleanup

+ 9 - 11
examples/vulkan_example/main.cpp

@@ -635,17 +635,7 @@ int main(int, char**)
     bool show_another_window = false;
     ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
 
-    // When IMGUI_UNLIMITED_FRAME_RATE is defined we render into latest image acquired from the swapchain but we display the image which was rendered before.
-    // Hence we must render once and increase the g_FrameIndex without presenting, which we do before entering the render loop.
-    // This is also the reason why frame_end() is split into frame_end() and frame_present(), the later one not being called here.
-#ifdef IMGUI_UNLIMITED_FRAME_RATE
-    ImGui_ImplVulkan_NewFrame();
-    ImGui_ImplGlfw_NewFrame();
-    frame_begin();
-    ImGui_ImplVulkan_Render(g_Frames[g_FrameIndex].CommandBuffer);
-    frame_end();
-    g_FrameIndex = (g_FrameIndex + 1) % IMGUI_VK_QUEUED_FRAMES;
-#endif // IMGUI_UNLIMITED_FRAME_RATE
+    bool swap_chain_has_at_least_one_image = false;
 
     // Main loop
     while (!glfwWindowShouldClose(window))
@@ -700,7 +690,15 @@ int main(int, char**)
         frame_begin();
         ImGui_ImplVulkan_Render(g_Frames[g_FrameIndex].CommandBuffer);
         frame_end();
+
+        // When IMGUI_UNLIMITED_FRAME_RATE is defined we render into latest image acquired from the swapchain but we display the image which was rendered before.
+        // Hence we must render once and increase the g_FrameIndex without presenting, which we do before entering the render loop.
+#ifdef IMGUI_UNLIMITED_FRAME_RATE
+        if (swap_chain_has_at_least_one_image)
+            frame_present();
+#else
         frame_present();
+#endif
 
         ImGui::UpdatePlatformWindows();
         ImGui::RenderPlatformWindows();