diff --git a/src/experimental/toolbox/window.cc b/src/experimental/toolbox/window.cc index 8afe5fba..67ea5568 100644 --- a/src/experimental/toolbox/window.cc +++ b/src/experimental/toolbox/window.cc @@ -130,7 +130,7 @@ std::string Window::GetDropFile() { return tmp; } -Window::Status Window::ProcessEvents() { +Window::Status Window::NewFrame() { SDL_Event event; while (SDL_PollEvent(&event)) { ImGui_ImplSDL2_ProcessEvent(&event); @@ -158,6 +158,15 @@ Window::Status Window::ProcessEvents() { return should_exit_ ? kQuitting : kRunning; } +void Window::EndFrame() { + // We use ImGui for input management in addition to GUI rendering so its + // important to call ImGui::EndFrame even if we don't call ImGui::Render. + // Note ImGui::Render internally calls ImGui::EndFrame, but so long as + // ImGui::NewFrame has been called, ImGui::EndFrame may be called multiple + // times; it will be a no-op. + ImGui::EndFrame(); +} + void Window::Present() { // Filament (with the exception of WebGL) handles the swapchain internally. if (config_ != kFilamentVulkan && config_ != kFilamentOpenGL) { diff --git a/src/experimental/toolbox/window.h b/src/experimental/toolbox/window.h index 8e78ce24..e13771e4 100644 --- a/src/experimental/toolbox/window.h +++ b/src/experimental/toolbox/window.h @@ -50,8 +50,12 @@ class Window { kQuitting, }; - // Processes all pendings window events, returning the status of the window. - Status ProcessEvents(); + // Processes all pendings window events and prepares ImGui for input handling + // and GUI rendering. Returns the status of the window. + Status NewFrame(); + + // Finalizes ImGui input handling. Must call NewFrame first. + void EndFrame(); // Swaps and presents the window buffer. void Present();