Added support into osgProducer::Viewer for flushing and compiling GL objects

via a Producer post swap callback.
This commit is contained in:
Robert Osfield
2004-01-05 13:40:36 +00:00
parent 042644df13
commit f230f5a132
3 changed files with 68 additions and 13 deletions

View File

@@ -430,6 +430,9 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced
/** Do draw traversal of draw bins generated by cull traversal.*/
virtual void draw();
/** Flush all the OpenGL objects, such as texture objects, display lists etc.*/
virtual void flushDeletedGLObjects(double& availableTime);
protected:
virtual ~SceneView();
@@ -493,6 +496,8 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced
GLenum _drawBufferValue;
bool _requiresFlush;
};
}

View File

@@ -371,9 +371,15 @@ public:
sh.drawImplementation(camera);
double availableTime = 0.0025; // 5 ms
#if 0
double availableTime = 0.0025; // 2.5 ms
// flush deleted GL objects.
sh.getSceneView()->flushDeletedGLObjects(availableTime);
// compile any GL objects that are required.
_databasePager->compileRenderingObjects(*(sh.getSceneView()->getState()),availableTime);
#endif
_databasePager->signalEndFrame();
@@ -382,6 +388,33 @@ public:
osg::ref_ptr<osgDB::DatabasePager> _databasePager;
};
class PostSwapCompileCallback : public Producer::Camera::Callback
{
public:
PostSwapCompileCallback(osgUtil::SceneView* sceneView,osgDB::DatabasePager* databasePager):
_sceneView(sceneView),
_databasePager(databasePager)
{}
virtual void operator()(const Producer::Camera&)
{
double availableTime = 0.0025; // 5 ms
// compile any GL objects that are required.
_databasePager->compileRenderingObjects(*(_sceneView->getState()),availableTime);
// flush deleted GL objects.
_sceneView->flushDeletedGLObjects(availableTime);
}
osg::ref_ptr<osgUtil::SceneView> _sceneView;
osg::ref_ptr<osgDB::DatabasePager> _databasePager;
};
bool Viewer::realize()
{
if (_realized) return _realized;
@@ -408,10 +441,20 @@ bool Viewer::realize()
// set up a draw callback to pre compile any rendering object of database has loaded,
// but not yet merged with the main scene graph.
(*p)->setDrawCallback(new DatabasePagerCompileCallback(_databasePager.get()));
// tell the database pager which graphic context the compile of rendering objexts is needed.
_databasePager->setCompileRenderingObjectsForContexID((*p)->getSceneView()->getState()->getContextID(),true);
}
// set up a post swap callback to flush deleted GL objects and compile new GL objects
for(unsigned int cameraNum=0;cameraNum<getNumberOfCameras();++cameraNum)
{
Producer::Camera* camera=getCamera(cameraNum);
camera->addPostSwapCallback(new PostSwapCompileCallback(_shvec[cameraNum]->getSceneView(),_databasePager.get()));
}
}
// force a sync before we intialize the keyswitch manipulator to home

View File

@@ -59,6 +59,7 @@ SceneView::SceneView(DisplaySettings* ds)
_drawBufferValue = GL_BACK;
_requiresFlush = true;
}
@@ -612,6 +613,17 @@ void SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& mod
}
void SceneView::flushDeletedGLObjects(double& availableTime)
{
_requiresFlush = false;
double currentTime = _state->getFrameStamp()?_state->getFrameStamp()->getReferenceTime():0.0;
osg::Texture::flushTextureObjects(_state->getContextID(),currentTime,availableTime);
osg::Drawable::flushDeletedDisplayLists(_state->getContextID(),currentTime,availableTime);
osg::Drawable::flushDeletedVertexBufferObjects(_state->getContextID(),currentTime,availableTime);
osg::VertexProgram::flushDeletedVertexProgramObjects(_state->getContextID(),currentTime,availableTime);
osg::FragmentProgram::flushDeletedFragmentProgramObjects(_state->getContextID(),currentTime,availableTime);
}
void SceneView::draw()
{
@@ -621,19 +633,14 @@ void SceneView::draw()
// context for when the object were originally created. Here we know what
// context we are in so can flush the appropriate caches.
//static osg::Timer timer;
//osg::Timer_t tstart = timer.tick();
double currentTime = _state->getFrameStamp()?_state->getFrameStamp()->getReferenceTime():0.0;
double availableTime = 0.005; // 5 ms.
osg::Drawable::flushDeletedDisplayLists(_state->getContextID(),currentTime,availableTime);
osg::Drawable::flushDeletedVertexBufferObjects(_state->getContextID(),currentTime,availableTime);
osg::VertexProgram::flushDeletedVertexProgramObjects(_state->getContextID(),currentTime,availableTime);
osg::FragmentProgram::flushDeletedFragmentProgramObjects(_state->getContextID(),currentTime,availableTime);
osg::Texture::flushTextureObjects(_state->getContextID(),currentTime,availableTime);
if (_requiresFlush)
{
double availableTime = 0.005;
flushDeletedGLObjects(availableTime);
}
//osg::Timer_t tend = timer.tick();
//std::cout<<"time to flush rendering objects"<<timer.delta_m(tstart,tend)<<std::endl;
// assume the the draw which is about to happen could generate GL objects that need flushing in the next frame.
_requiresFlush = true;
_state->setInitialViewMatrix(new osg::RefMatrix(_viewMatrix));