Fixed GraphcicsContext::getMaxContextID so it properly returns the current max contextID.
Fixed the osgviewer's compile context code to account for the above fix. Added compile context support into osgterrain example.
This commit is contained in:
parent
610a76b210
commit
04c1dee7a2
@ -157,7 +157,7 @@ int main(int argc, char** argv)
|
||||
int numProcessors = OpenThreads::GetNumberOfProcessors();
|
||||
int processNum = 0;
|
||||
|
||||
for(unsigned int i=0; i<osg::GraphicsContext::getMaxContextID(); ++i)
|
||||
for(unsigned int i=0; i<= osg::GraphicsContext::getMaxContextID(); ++i)
|
||||
{
|
||||
osg::GraphicsContext* gc = osg::GraphicsContext::getOrCreateCompileContext(i);
|
||||
|
||||
@ -172,6 +172,6 @@ int main(int argc, char** argv)
|
||||
}
|
||||
}
|
||||
|
||||
viewer.run();
|
||||
viewer.run();
|
||||
|
||||
}
|
||||
|
@ -29,6 +29,8 @@
|
||||
#include <osgDB/FileUtils>
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
#include <osgUtil/GLObjectsVisitor>
|
||||
|
||||
#include <osgText/FadeText>
|
||||
|
||||
#include <osgViewer/Viewer>
|
||||
@ -119,6 +121,8 @@ public:
|
||||
|
||||
virtual void operator () (osg::Object* object)
|
||||
{
|
||||
// osg::notify(osg::NOTICE)<<"void operator ()"<<std::endl;
|
||||
|
||||
Files files;
|
||||
readMasterFile(files);
|
||||
|
||||
@ -145,6 +149,8 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (newFiles.empty())
|
||||
|
||||
// first load the files.
|
||||
FilenameNodeMap nodesToAdd;
|
||||
@ -152,18 +158,29 @@ public:
|
||||
nitr != newFiles.end();
|
||||
++nitr)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"loading files "<<*nitr<<std::endl;
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile(*nitr);
|
||||
if (loadedModel.get()) nodesToAdd[*nitr] = loadedModel;
|
||||
}
|
||||
|
||||
if (loadedModel.get())
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Loadinged file "<<*nitr<<std::endl;
|
||||
|
||||
for(Files::iterator ritr = removedFiles.begin();
|
||||
ritr != removedFiles.end();
|
||||
++ritr)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Removed files "<<*ritr<<std::endl;
|
||||
}
|
||||
nodesToAdd[*nitr] = loadedModel;
|
||||
osg::ref_ptr<osgUtil::GLObjectsOperation> compileOperation = new osgUtil::GLObjectsOperation(loadedModel.get());
|
||||
|
||||
#if 1
|
||||
for(unsigned int i=0; i<= osg::GraphicsContext::getMaxContextID(); ++i)
|
||||
{
|
||||
osg::GraphicsContext* gc = osg::GraphicsContext::getCompileContext(i);
|
||||
osg::GraphicsThread* gt = gc ? gc->getGraphicsThread() : 0;
|
||||
if (gt)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Adding compile op. to compile context "<<i<<std::endl;
|
||||
gt->add( compileOperation.get() );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// swap the data.
|
||||
{
|
||||
@ -180,8 +197,6 @@ public:
|
||||
|
||||
void update(osg::Group* scene)
|
||||
{
|
||||
// osg::notify(osg::NOTICE)<<"update"<<std::endl;
|
||||
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
||||
|
||||
if (!_nodesToRemove.empty())
|
||||
@ -403,6 +418,13 @@ int main(int argc, char** argv)
|
||||
double w = 1.0;
|
||||
double h = 1.0;
|
||||
|
||||
bool createBackgroundContextForCompiling = false;
|
||||
while (arguments.read("--bc")) { createBackgroundContextForCompiling = true; }
|
||||
|
||||
bool createBackgroundThreadsForCompiling = false;
|
||||
while (arguments.read("--bt")) { createBackgroundContextForCompiling = true; createBackgroundThreadsForCompiling = true; }
|
||||
|
||||
|
||||
osg::ref_ptr<MasterOperation> masterOperation;
|
||||
std::string masterFilename;
|
||||
while(arguments.read("-m",masterFilename))
|
||||
@ -430,6 +452,27 @@ int main(int argc, char** argv)
|
||||
operationThread->add(masterOperation.get());
|
||||
}
|
||||
|
||||
if (createBackgroundContextForCompiling)
|
||||
{
|
||||
|
||||
int numProcessors = OpenThreads::GetNumberOfProcessors();
|
||||
int processNum = 0;
|
||||
|
||||
for(unsigned int i=0; i<= osg::GraphicsContext::getMaxContextID(); ++i)
|
||||
{
|
||||
osg::GraphicsContext* gc = osg::GraphicsContext::getOrCreateCompileContext(i);
|
||||
|
||||
if (gc && createBackgroundThreadsForCompiling)
|
||||
{
|
||||
gc->createGraphicsThread();
|
||||
gc->getGraphicsThread()->setProcessorAffinity(processNum % numProcessors);
|
||||
gc->getGraphicsThread()->startThread();
|
||||
|
||||
++processNum;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (!viewer.done())
|
||||
{
|
||||
viewer.advance();
|
||||
|
@ -147,8 +147,14 @@ unsigned int GraphicsContext::createNewContextID()
|
||||
unsigned int GraphicsContext::getMaxContextID()
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_contextIDMapMutex);
|
||||
|
||||
return s_contextIDMap.size();
|
||||
unsigned int maxContextID = 0;
|
||||
for(ContextIDMap::iterator itr = s_contextIDMap.begin();
|
||||
itr != s_contextIDMap.end();
|
||||
++itr)
|
||||
{
|
||||
if (itr->first > maxContextID) maxContextID = itr->first;
|
||||
}
|
||||
return maxContextID;
|
||||
}
|
||||
|
||||
|
||||
@ -260,16 +266,19 @@ GraphicsContext* GraphicsContext::getOrCreateCompileContext(unsigned int context
|
||||
traits->sharedContext = src_gc;
|
||||
traits->pbuffer = true;
|
||||
|
||||
osg::GraphicsContext* gc = osg::GraphicsContext::createGraphicsContext(traits);
|
||||
gc->realize();
|
||||
|
||||
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits);
|
||||
if (gc.valid() && gc->realize())
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_contextIDMapMutex);
|
||||
s_contextIDMap[contextID]._compileContext = gc;
|
||||
osg::notify(osg::INFO)<<" succeded GraphicsContext::createCompileContext."<<std::endl;
|
||||
return gc.release();
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
osg::notify(osg::INFO)<<" succeded GraphicsContext::createCompileContext."<<std::endl;
|
||||
return gc;
|
||||
}
|
||||
|
||||
void GraphicsContext::setCompileContext(unsigned int contextID, GraphicsContext* gc)
|
||||
@ -280,9 +289,11 @@ void GraphicsContext::setCompileContext(unsigned int contextID, GraphicsContext*
|
||||
|
||||
GraphicsContext* GraphicsContext::getCompileContext(unsigned int contextID)
|
||||
{
|
||||
//osg::notify(osg::NOTICE)<<"GraphicsContext::getCompileContext "<<contextID<<std::endl;
|
||||
// osg::notify(osg::NOTICE)<<"GraphicsContext::getCompileContext "<<contextID<<std::endl;
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_contextIDMapMutex);
|
||||
return s_contextIDMap[contextID]._compileContext.get();
|
||||
ContextIDMap::iterator itr = s_contextIDMap.find(contextID);
|
||||
if (itr != s_contextIDMap.end()) return itr->second._compileContext.get();
|
||||
else return 0;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user