Moved compile setup from osgViewer::ViewerBase into osgViewer::Renderer to

avoid threading issues associated with compile running in a parallel with 
update/cull on the first frame.

Also added automatic recompile when a new SceneData is applied to a View.
This commit is contained in:
Robert Osfield
2008-05-10 17:04:02 +00:00
parent 0dfba5dbe5
commit 4d7b2edd4c
4 changed files with 43 additions and 7 deletions

View File

@@ -167,7 +167,8 @@ Renderer::Renderer(osg::Camera* camera):
_conservativeTimeRatio(0.5),
_camera(camera),
_done(false),
_graphicsThreadDoesCull(true)
_graphicsThreadDoesCull(true),
_compileOnNextDraw(true)
{
DEBUG_MESSAGE<<"Render::Render() "<<this<<std::endl;
@@ -251,6 +252,22 @@ void Renderer::updateSceneView(osgUtil::SceneView* sceneView)
if (view) _startTick = view->getStartTick();
}
void Renderer::compile()
{
DEBUG_MESSAGE<<"Renderer::compile()"<<std::endl;
_compileOnNextDraw = false;
osgUtil::SceneView* sceneView = _sceneView[0].get();
if (!sceneView || _done) return;
if (sceneView->getSceneData())
{
osgUtil::GLObjectsVisitor glov;
glov.setState(sceneView->getState());
sceneView->getSceneData()->accept(glov);
}
}
void Renderer::cull()
{
@@ -322,8 +339,13 @@ void Renderer::draw()
osg::GraphicsContext* compileContext = sceneView ? osg::GraphicsContext::getCompileContext(sceneView->getState()->getContextID()) : 0;
osg::GraphicsThread* compileThread = compileContext ? compileContext->getGraphicsThread() : 0;
if (sceneView || _done)
if (sceneView && !_done)
{
if (_compileOnNextDraw)
{
compile();
}
osgViewer::View* view = dynamic_cast<osgViewer::View*>(_camera->getView());
osgDB::DatabasePager* databasePager = view ? view->getDatabasePager() : 0;
@@ -431,6 +453,11 @@ void Renderer::cull_draw()
osgUtil::SceneView* sceneView = _sceneView[0].get();
if (!sceneView || _done) return;
if (_compileOnNextDraw)
{
compile();
}
updateSceneView(sceneView);
osgViewer::View* view = dynamic_cast<osgViewer::View*>(_camera->getView());