mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-02 10:24:11 +01:00
LP-29 improve OSGViewport rendering loop
update scene in the Renderer synchronize method
This commit is contained in:
parent
f9694acfd1
commit
7461159c69
@ -361,8 +361,9 @@ public:
|
|||||||
// add the screen capture handler
|
// add the screen capture handler
|
||||||
// view->addEventHandler(new osgViewer::ScreenCaptureHandler);
|
// view->addEventHandler(new osgViewer::ScreenCaptureHandler);
|
||||||
|
|
||||||
osg::GraphicsContext *gc = createGraphicsContext();
|
// setup graphics context and camera
|
||||||
osg::Camera *camera = view->getCamera();
|
osg::Camera *camera = view->getCamera();
|
||||||
|
osg::GraphicsContext *gc = createGraphicsContext();
|
||||||
camera->setGraphicsContext(gc);
|
camera->setGraphicsContext(gc);
|
||||||
camera->setViewport(new osg::Viewport(0, 0, gc->getTraits()->width, gc->getTraits()->height));
|
camera->setViewport(new osg::Viewport(0, 0, gc->getTraits()->width, gc->getTraits()->height));
|
||||||
|
|
||||||
@ -470,6 +471,9 @@ public:
|
|||||||
osgQtQuick::openGLContextInfo(QOpenGLContext::currentContext(), "ViewportRenderer::ViewportRenderer");
|
osgQtQuick::openGLContextInfo(QOpenGLContext::currentContext(), "ViewportRenderer::ViewportRenderer");
|
||||||
|
|
||||||
h->initializeResources();
|
h->initializeResources();
|
||||||
|
|
||||||
|
firstFrame = true;
|
||||||
|
needToDoFrame = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
~ViewportRenderer()
|
~ViewportRenderer()
|
||||||
@ -477,7 +481,6 @@ public:
|
|||||||
qDebug() << "ViewportRenderer::~ViewportRenderer";
|
qDebug() << "ViewportRenderer::~ViewportRenderer";
|
||||||
osgQtQuick::openGLContextInfo(QOpenGLContext::currentContext(), "ViewportRenderer::~ViewportRenderer");
|
osgQtQuick::openGLContextInfo(QOpenGLContext::currentContext(), "ViewportRenderer::~ViewportRenderer");
|
||||||
|
|
||||||
h->releaseResources();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function is the only place when it is safe for the renderer and the item to read and write each others members.
|
// This function is the only place when it is safe for the renderer and the item to read and write each others members.
|
||||||
@ -486,12 +489,29 @@ public:
|
|||||||
// qDebug() << "ViewportRenderer::synchronize";
|
// qDebug() << "ViewportRenderer::synchronize";
|
||||||
// osgQtQuick::openGLContextInfo(QOpenGLContext::currentContext(), "ViewportRenderer::synchronize");
|
// osgQtQuick::openGLContextInfo(QOpenGLContext::currentContext(), "ViewportRenderer::synchronize");
|
||||||
|
|
||||||
|
if (!h->viewer.valid()) {
|
||||||
|
qWarning() << "ViewportRenderer::synchronize - invalid viewer";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!h->view.valid()) {
|
if (!h->view.valid()) {
|
||||||
qWarning() << "ViewportRenderer::synchronize - invalid view";
|
qWarning() << "ViewportRenderer::synchronize - invalid view";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// need to split frame() open and do the synchronization here (calling update callbacks, etc...)
|
needToDoFrame = h->viewer->checkNeedToDoFrame();
|
||||||
|
if (needToDoFrame) {
|
||||||
|
if (firstFrame) {
|
||||||
|
h->view->init();
|
||||||
|
if (!h->viewer->isRealized()) {
|
||||||
|
h->viewer->realize();
|
||||||
|
}
|
||||||
|
firstFrame = false;
|
||||||
|
}
|
||||||
|
h->viewer->advance();
|
||||||
|
h->viewer->eventTraversal();
|
||||||
|
h->viewer->updateTraversal();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function is called when the FBO should be rendered into.
|
// This function is called when the FBO should be rendered into.
|
||||||
@ -502,16 +522,16 @@ public:
|
|||||||
// osgQtQuick::openGLContextInfo(QOpenGLContext::currentContext(), "ViewportRenderer::render");
|
// osgQtQuick::openGLContextInfo(QOpenGLContext::currentContext(), "ViewportRenderer::render");
|
||||||
|
|
||||||
if (!h->viewer.valid()) {
|
if (!h->viewer.valid()) {
|
||||||
qWarning() << "ViewportRenderer::render - invalid viewport";
|
qWarning() << "ViewportRenderer::render - invalid viewer";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// needed to properly render models without terrain (Qt bug?)
|
|
||||||
QOpenGLContext::currentContext()->functions()->glUseProgram(0);
|
|
||||||
|
|
||||||
if (h->viewer->checkNeedToDoFrame()) {
|
if (needToDoFrame) {
|
||||||
// TODO scene update should NOT be done here
|
// needed to properly render models without terrain (Qt bug?)
|
||||||
h->viewer->frame();
|
QOpenGLContext::currentContext()->functions()->glUseProgram(0);
|
||||||
|
h->viewer->renderingTraversals();
|
||||||
|
needToDoFrame = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (h->updateMode == UpdateMode::Continuous) {
|
if (h->updateMode == UpdateMode::Continuous) {
|
||||||
@ -544,6 +564,9 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
OSGViewport::Hidden *h;
|
OSGViewport::Hidden *h;
|
||||||
|
|
||||||
|
bool firstFrame;
|
||||||
|
bool needToDoFrame;
|
||||||
};
|
};
|
||||||
|
|
||||||
osg::ref_ptr<osg::GraphicsContext> OSGViewport::Hidden::dummy;
|
osg::ref_ptr<osg::GraphicsContext> OSGViewport::Hidden::dummy;
|
||||||
|
Loading…
Reference in New Issue
Block a user