From 89e714a07774f1e79548729155d33e6348ce019d Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Tue, 6 Jun 2023 23:30:50 -0600 Subject: [PATCH] lightpreview: don't render frames when not interacting --- lightpreview/glview.cpp | 24 +++++++++++++++++++++++- lightpreview/glview.h | 2 ++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lightpreview/glview.cpp b/lightpreview/glview.cpp index 7d33bffc..cccd8386 100644 --- a/lightpreview/glview.cpp +++ b/lightpreview/glview.cpp @@ -252,6 +252,17 @@ void main() { } )"; +bool GLView::shouldLiveUpdate() const +{ + if (m_keysPressed) + return true; + + if (QApplication::mouseButtons()) + return true; + + return false; +} + void GLView::handleLoggedMessage(const QOpenGLDebugMessage &debugMessage) { if (debugMessage.type() == QOpenGLDebugMessage::ErrorType) @@ -453,7 +464,13 @@ void GLView::paintGL() m_program->release(); - update(); // schedule the next frame + if (shouldLiveUpdate()) { + update(); // schedule the next frame + } else { + qDebug() << "pausing anims.."; + m_lastFrame = std::nullopt; + m_lastMouseDownPos = std::nullopt; + } } void GLView::setCamera(const qvec3d &origin, const qvec3d &fwd) @@ -968,6 +985,11 @@ void GLView::wheelEvent(QWheelEvent *event) m_moveSpeed = clamp(m_moveSpeed, 10.0f, 5000.0f); } +void GLView::mousePressEvent(QMouseEvent *event) +{ + update(); +} + void GLView::applyFlyMovement(float duration_seconds) { // qDebug() << "timer event: duration: " << duration_seconds; diff --git a/lightpreview/glview.h b/lightpreview/glview.h index 90870468..31e410c5 100644 --- a/lightpreview/glview.h +++ b/lightpreview/glview.h @@ -165,12 +165,14 @@ protected: void resizeGL(int width, int height) override; private: + bool shouldLiveUpdate() const; void handleLoggedMessage(const QOpenGLDebugMessage &debugMessage); protected: void keyPressEvent(QKeyEvent *event) override; void keyReleaseEvent(QKeyEvent *event) override; void wheelEvent(QWheelEvent *event) override; + void mousePressEvent(QMouseEvent *event) override; private: void applyMouseMotion();