Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Graphics::beginRenderLoop(
- std::vector<Pass *> &graphicsPasses,
- std::vector<Pass *> &computePasses,
- std::function<void(double time, double deltaTime)> updateFn)
- {
- Global::g_gui_thread = std::thread([&]() {
- while (!glfwWindowShouldClose(Global::g_window)) {
- if (Global::g_swapchain_dirty)
- recreateSwapchain(graphicsPasses);
- uint32_t frame;
- auto r = acquireSwapchainImage(&frame);
- if (r == VK_ERROR_OUT_OF_DATE_KHR) {
- //vkQueueWaitIdle(Global::g_queue);
- recreateSwapchain(graphicsPasses);
- continue;
- }
- render(frame, graphicsPasses, computePasses);
- r = presentImage(frame);
- if (r == VK_ERROR_OUT_OF_DATE_KHR || r == VK_SUBOPTIMAL_KHR)
- recreateSwapchain(graphicsPasses);
- }
- Global::g_window_running = false;
- });
- uint64_t frame = 0;
- double t = 0.0;
- double dt = 1000 / 60.0;
- auto currTime = std::chrono::steady_clock::now();
- double accumulator = 0.0;
- // Main loop
- while (1) {
- if (!Global::g_window_running)
- break;
- auto newTime = std::chrono::steady_clock::now();
- auto frameTime = std::chrono::duration<double, std::milli>(newTime - currTime).count();
- currTime = newTime;
- accumulator += frameTime;
- while (accumulator >= dt) {
- //processing
- updateFn(t, dt);
- accumulator -= dt;
- t += dt;
- }
- frame++;
- glfwPollEvents();
- std::this_thread::sleep_for(std::chrono::duration<double, std::milli>(dt));
- }
- Global::g_gui_thread.join();
- }
Advertisement
Add Comment
Please, Sign In to add comment