From Wang Rui, "I've encountered a strange problem that osgviewerMFC doesn't work well

with the StatsHandler. When the 's' key is pressed, the rendering
window will be halted. I tried solving the problem by commenting a
line in CMFC_OSG_MDIView::OnKeyDown() and it seems to work now.

Another improvement here is to use a thread class derived from
OpenThreads to replace the old _beginthread(). It helps a lot in
keeping a high frame rate when you open more than one MDI child
windows. And the application using OpenThreads in my opinion will be
more compatible and portable."
This commit is contained in:
Robert Osfield
2011-09-12 10:47:59 +00:00
parent c8de3b70ca
commit 5162fcc108
4 changed files with 53 additions and 6 deletions

View File

@@ -52,6 +52,7 @@ void cOSG::InitSceneGraph(void)
// Load the Model from the model name
mModel = osgDB::readNodeFile(m_ModelName);
if (!mModel) return;
// Optimize the model
osgUtil::Optimizer optimizer;
@@ -141,7 +142,7 @@ void cOSG::PostFrameUpdate()
// Due any postframe updates in this routine
}
void cOSG::Render(void* ptr)
/*void cOSG::Render(void* ptr)
{
cOSG* osg = (cOSG*)ptr;
@@ -166,4 +167,33 @@ void cOSG::Render(void* ptr)
AfxMessageBox("Exit Rendering Thread");
_endthread();
}*/
CRenderingThread::CRenderingThread( cOSG* ptr )
: OpenThreads::Thread(), _ptr(ptr), _done(false)
{
}
CRenderingThread::~CRenderingThread()
{
_done = true;
while( isRunning() )
OpenThreads::Thread::YieldCurrentThread();
}
void CRenderingThread::run()
{
if ( !_ptr )
{
_done = true;
return;
}
osgViewer::Viewer* viewer = _ptr->getViewer();
do
{
_ptr->PreFrameUpdate();
viewer->frame();
_ptr->PostFrameUpdate();
} while ( !testCancel() && !viewer->done() && !_done );
}