Handle game view resize
authorunC0Rr
Sun, 19 May 2024 15:55:26 +0200
changeset 16015 0e90bdfc2642
parent 16014 e66feb918d71
child 16016 4933920eba89
Handle game view resize
qmlfrontend/game_view.cpp
--- a/qmlfrontend/game_view.cpp	Thu May 16 14:11:16 2024 +0200
+++ b/qmlfrontend/game_view.cpp	Sun May 19 15:55:26 2024 +0200
@@ -23,7 +23,8 @@
 
   QPointer<GameView> m_gameView;
   QPointer<QQuickWindow> m_window;
-  bool m_inited{false};
+  bool m_dirty{true};
+  QSizeF m_gameViewSize;
 };
 
 void GameViewRenderer::render() {
@@ -33,8 +34,8 @@
     return;
   }
 
-  if (!m_inited) {
-    m_inited = true;
+  if (m_dirty) {
+    m_dirty = false;
     engine->setOpenGLContext(QOpenGLContext::currentContext());
   }
 
@@ -57,6 +58,12 @@
     m_gameView = qobject_cast<GameView*>(fbo);
     m_window = fbo->window();
   }
+
+  if (const auto currentSize = m_gameView->size();
+      currentSize != m_gameViewSize) {
+    m_gameViewSize = currentSize;
+    m_dirty = true;
+  }
 }
 
 GameView::GameView(QQuickItem* parent)