qmlfrontend/game_view.cpp
changeset 16044 0e90bdfc2642
parent 16039 a73b9770467a
child 16046 e8afb1bf2779
equal deleted inserted replaced
16043:e66feb918d71 16044:0e90bdfc2642
    21   QOpenGLFramebufferObject* createFramebufferObject(const QSize& size) override;
    21   QOpenGLFramebufferObject* createFramebufferObject(const QSize& size) override;
    22   void synchronize(QQuickFramebufferObject* fbo) override;
    22   void synchronize(QQuickFramebufferObject* fbo) override;
    23 
    23 
    24   QPointer<GameView> m_gameView;
    24   QPointer<GameView> m_gameView;
    25   QPointer<QQuickWindow> m_window;
    25   QPointer<QQuickWindow> m_window;
    26   bool m_inited{false};
    26   bool m_dirty{true};
       
    27   QSizeF m_gameViewSize;
    27 };
    28 };
    28 
    29 
    29 void GameViewRenderer::render() {
    30 void GameViewRenderer::render() {
    30   const auto engine = m_gameView->engineInstance();
    31   const auto engine = m_gameView->engineInstance();
    31 
    32 
    32   if (!engine) {
    33   if (!engine) {
    33     return;
    34     return;
    34   }
    35   }
    35 
    36 
    36   if (!m_inited) {
    37   if (m_dirty) {
    37     m_inited = true;
    38     m_dirty = false;
    38     engine->setOpenGLContext(QOpenGLContext::currentContext());
    39     engine->setOpenGLContext(QOpenGLContext::currentContext());
    39   }
    40   }
    40 
    41 
    41   engine->renderFrame();
    42   engine->renderFrame();
    42 
    43 
    54 
    55 
    55 void GameViewRenderer::synchronize(QQuickFramebufferObject* fbo) {
    56 void GameViewRenderer::synchronize(QQuickFramebufferObject* fbo) {
    56   if (!m_gameView) {
    57   if (!m_gameView) {
    57     m_gameView = qobject_cast<GameView*>(fbo);
    58     m_gameView = qobject_cast<GameView*>(fbo);
    58     m_window = fbo->window();
    59     m_window = fbo->window();
       
    60   }
       
    61 
       
    62   if (const auto currentSize = m_gameView->size();
       
    63       currentSize != m_gameViewSize) {
       
    64     m_gameViewSize = currentSize;
       
    65     m_dirty = true;
    59   }
    66   }
    60 }
    67 }
    61 
    68 
    62 GameView::GameView(QQuickItem* parent)
    69 GameView::GameView(QQuickItem* parent)
    63     : QQuickFramebufferObject(parent), m_delta(0) {
    70     : QQuickFramebufferObject(parent), m_delta(0) {