1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

LP-29 simplify viewport resizing handling and other cleanups

This commit is contained in:
Philippe Renon 2016-02-21 20:02:37 +01:00
parent 9c42319e36
commit 6c6f184d28

View File

@ -48,6 +48,7 @@
#include <QOpenGLContext>
#include <QQuickWindow>
#include <QQuickFramebufferObject>
#include <QOpenGLFramebufferObject>
#include <QSGSimpleTextureNode>
#include <QOpenGLFunctions>
@ -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<osgViewer::CompositeViewer> viewer;
osg::ref_ptr<osgViewer::View> view;
static osg::ref_ptr<osg::GraphicsContext> dummy;
osg::ref_ptr<osgViewer::CompositeViewer> viewer;
osg::ref_ptr<osgViewer::View> 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<osg::GraphicsContext> 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);
}