diff --git a/include/vsg/app/Viewer.h b/include/vsg/app/Viewer.h index 880f0ee5c..145e6e074 100644 --- a/include/vsg/app/Viewer.h +++ b/include/vsg/app/Viewer.h @@ -101,6 +101,9 @@ namespace vsg /// If still active, poll for pending events and place them in the Events list and advance to the next frame, generate updated FrameStamp to signify the advancement to a new frame and return true. virtual bool advanceToNextFrame(double simulationTime = UseTimeSinceStartPoint); + virtual bool advanceToNextFramePhaseOne(); + virtual bool advanceToNextFramePhaseTwo(double simulationTime = UseTimeSinceStartPoint); + /// pass the Events into any registered EventHandlers virtual void handleEvents(); diff --git a/include/vsg/app/Window.h b/include/vsg/app/Window.h index d1b475d25..e89f478c1 100644 --- a/include/vsg/app/Window.h +++ b/include/vsg/app/Window.h @@ -58,6 +58,8 @@ namespace vsg virtual void resize() {} + std::function resizeCallback = {}; + ref_ptr traits() { return _traits; } const ref_ptr traits() const { return _traits; } diff --git a/src/vsg/app/Viewer.cpp b/src/vsg/app/Viewer.cpp index d15ce5dba..3dceb0e23 100644 --- a/src/vsg/app/Viewer.cpp +++ b/src/vsg/app/Viewer.cpp @@ -79,6 +79,14 @@ void Viewer::addWindow(ref_ptr window) if (itr != _windows.end()) return; _windows.push_back(window); + + window->resizeCallback = [this]() { + advanceToNextFramePhaseTwo(); + handleEvents(); + update(); + recordAndSubmit(); + present(); + }; } void Viewer::removeWindow(ref_ptr window) @@ -88,6 +96,8 @@ void Viewer::removeWindow(ref_ptr window) _windows.erase(itr); + window->resizeCallback = nullptr; + // create a new list of CommandGraphs not associated with removed window CommandGraphs commandGraphs; for (const auto& task : recordAndSubmitTasks) @@ -153,6 +163,14 @@ bool Viewer::pollEvents(bool discardPreviousEvents) } bool Viewer::advanceToNextFrame(double simulationTime) +{ + if (!advanceToNextFramePhaseOne()) + return false; + + return advanceToNextFramePhaseTwo(simulationTime); +} + +bool vsg::Viewer::advanceToNextFramePhaseOne() { static constexpr SourceLocation s_frame_source_location{"Viewer advanceToNextFrame", VsgFunctionName, __FILE__, __LINE__, COLOR_VIEWER, 1}; @@ -167,6 +185,13 @@ bool Viewer::advanceToNextFrame(double simulationTime) // poll all the windows for events. pollEvents(true); + return true; +} + +bool vsg::Viewer::advanceToNextFramePhaseTwo(double simulationTime) +{ + static constexpr SourceLocation s_frame_source_location{"Viewer advanceToNextFrame", VsgFunctionName, __FILE__, __LINE__, COLOR_VIEWER, 1}; + if (!acquireNextFrame()) return false; // create FrameStamp for frame diff --git a/src/vsg/platform/win32/Win32_Window.cpp b/src/vsg/platform/win32/Win32_Window.cpp index fe1a05248..4a7081c3f 100644 --- a/src/vsg/platform/win32/Win32_Window.cpp +++ b/src/vsg/platform/win32/Win32_Window.cpp @@ -610,6 +610,8 @@ bool Win32_Window::handleWin32Messages(UINT msg, WPARAM wParam, LPARAM lParam) _windowMapped = false; return true; case WM_PAINT: + if (resizeCallback) + resizeCallback(); ValidateRect(_window, NULL); return true; case WM_MOUSEMOVE: {