From 6c6f184d28f4c81634636e86026a104183b390dc Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Sun, 21 Feb 2016 20:02:37 +0100 Subject: [PATCH] LP-29 simplify viewport resizing handling and other cleanups --- .../libs/osgearth/osgQtQuick/OSGViewport.cpp | 43 ++++++++----------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGViewport.cpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGViewport.cpp index 67508ac7a..caae373d0 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGViewport.cpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGViewport.cpp @@ -48,6 +48,7 @@ #include #include +#include #include #include #include @@ -157,17 +158,17 @@ public: qWarning() << "OSGViewport::attach - invalid scene!"; return false; } + // attach scene + if (!attach(view, sceneData->node())) { + qWarning() << "OSGViewport::attach - failed to attach node!"; + return false; + } // attach camera if (camera) { camera->attach(view); } else { qWarning() << "OSGViewport::attach - no camera!"; } - // attach scene - if (!attach(view, sceneData->node())) { - qWarning() << "OSGViewport::attach - failed to attach node!"; - return false; - } return true; } @@ -237,8 +238,8 @@ public: return; } view = createView(); - self->attach(view.get()); viewer->addView(view); + self->attach(view.get()); start(); } @@ -290,10 +291,8 @@ public: int frameTimer; - osg::ref_ptr viewer; - osg::ref_ptr view; - - static osg::ref_ptr dummy; + osg::ref_ptr viewer; + osg::ref_ptr view; static QtKeyboardMap keyMap; @@ -359,10 +358,11 @@ public: // view->addEventHandler(new osgViewer::ScreenCaptureHandler); // setup graphics context and camera - osg::Camera *camera = view->getCamera(); osg::GraphicsContext *gc = createGraphicsContext(); + + osg::Camera *camera = view->getCamera(); camera->setGraphicsContext(gc); - camera->setViewport(new osg::Viewport(0, 0, gc->getTraits()->width, gc->getTraits()->height)); + camera->setViewport(0, 0, gc->getTraits()->width, gc->getTraits()->height); return view; } @@ -504,6 +504,11 @@ public: } firstFrame = false; } + osg::Viewport *viewport = h->view->getCamera()->getViewport(); + if ((viewport->width() != item->width()) || (viewport->height() != item->height())) { + h->view->getCamera()->getGraphicsContext()->resized(0, 0, item->width(), item->height()); + } + h->viewer->advance(); h->viewer->eventTraversal(); h->viewer->updateTraversal(); @@ -522,7 +527,6 @@ public: return; } - if (needToDoFrame) { // needed to properly render models without terrain (Qt bug?) QOpenGLContext::currentContext()->functions()->glUseProgram(0); @@ -538,12 +542,6 @@ public: QOpenGLFramebufferObject *createFramebufferObject(const QSize &size) { - // qDebug() << "ViewportRenderer::createFramebufferObject" << size; - if (h->view.valid()) { - h->view->getCamera()->getGraphicsContext()->resized(0, 0, size.width(), size.height()); - h->view->getEventQueue()->windowResize(0, 0, size.width(), size.height()); - } - QOpenGLFramebufferObjectFormat format; format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); // format.setSamples(4); @@ -565,7 +563,6 @@ private: bool needToDoFrame; }; -osg::ref_ptr OSGViewport::Hidden::dummy; QtKeyboardMap OSGViewport::Hidden::keyMap = QtKeyboardMap(); /* class OSGViewport */ @@ -705,10 +702,8 @@ QSGNode *OSGViewport::updatePaintNode(QSGNode *node, QQuickItem::UpdatePaintNode QPointF OSGViewport::mousePoint(QMouseEvent *event) { - // qreal x = 2.0 * (event->x() - width() / 2) / width(); - // qreal y = 2.0 * (event->y() - height() / 2) / height(); - qreal x = event->x(); - qreal y = event->y(); + qreal x = 2.0 * (event->x() - width() / 2) / width(); + qreal y = 2.0 * (event->y() - height() / 2) / height(); return QPointF(x, y); }