Introduced CMake option OSG_PROVIDE_READFILE option that defaults to ON, but when switched to OFF disables the building of the osgDB::read*File() methods,

forcing users to use osgDB::readRef*File() methods.  The later is preferable as it closes a potential threading bug when using paging databases in conjunction
with the osgDB::Registry Object Cache.  This threading bug occurs when one thread gets an object from the Cache via an osgDB::read*File() call where only
a pointer to the object is passed back, so taking a reference to the object is delayed till it gets reassigned to a ref_ptr<>, but at the same time another
thread calls a flush of the Object Cache deleting this object as it's referenceCount is now zero.  Using osgDB::readREf*File() makes sure the a ref_ptr<> is
passed back and the referenceCount never goes to zero.

To ensure the OSG builds when OSG_PROVIDE_READFILE is to OFF the many cases of osgDB::read*File() usage had to be replaced with a ref_ptr<> osgDB::readRef*File()
usage.  The avoid this change causing lots of other client code to be rewritten to handle the use of ref_ptr<> in place of C pointer I introduced a serious of
templte methods in various class to adapt ref_ptr<> to the underly C pointer to be passed to old OSG API's, example of this is found in include/osg/Group:

    bool addChild(Node* child); // old method which can only be used with a Node*

    tempalte<class T> bool addChild(const osg::ref_ptr<T>& child) { return addChild(child.get()); } // adapter template method

These changes together cover 149 modified files, so it's a large submission. This extent of changes are warrent to make use of the Object Cache
and multi-threaded loaded more robust.



git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/branches/OpenSceneGraph-3.4@15165 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
Robert Osfield
2015-10-22 14:14:53 +00:00
parent 74f1838960
commit 6a67be2e32
281 changed files with 2443 additions and 2050 deletions

View File

@@ -43,17 +43,17 @@ public:
_count(0)
{
}
virtual void apply(osg::Node& node)
{
std::ostringstream os;
os << node.className() << "_"<<_count++;
node.setName(os.str());
traverse(node);
}
}
unsigned int _count;
};
@@ -64,7 +64,7 @@ public:
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
{
}
virtual void apply(osg::PagedLOD& plod)
{
std::cout<<"PagedLOD "<<plod.getName()<<" numRanges = "<< plod.getNumRanges()<<" numFiles = "<<plod.getNumFileNames()<<std::endl;
@@ -72,7 +72,7 @@ public:
{
std::cout<<" files = '"<<plod.getFileName(i)<<"'"<<std::endl;
}
}
}
};
@@ -83,7 +83,7 @@ public:
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
{
}
virtual void apply(osg::PagedLOD& plod)
{
@@ -98,9 +98,9 @@ public:
osgDB::writeNodeFile(*child,filename);
}
}
traverse(plod);
}
}
};
class ConvertToPageLODVistor : public osg::NodeVisitor
@@ -113,7 +113,7 @@ public:
_makeAllChildrenPaged(makeAllChildrenPaged)
{
}
virtual ~ConvertToPageLODVistor()
{
}
@@ -121,9 +121,9 @@ public:
virtual void apply(osg::LOD& lod)
{
_lodSet.insert(&lod);
traverse(lod);
}
}
virtual void apply(osg::PagedLOD& plod)
{
@@ -139,7 +139,7 @@ public:
++itr, ++lodNum)
{
osg::ref_ptr<osg::LOD> lod = const_cast<osg::LOD*>(itr->get());
if (lod->getNumParents()==0)
{
osg::notify(osg::NOTICE)<<"Warning can't operator on root node."<<std::endl;
@@ -153,9 +153,9 @@ public:
}
osg::notify(osg::NOTICE)<<"Converting LOD to PagedLOD."<<std::endl;
osg::PagedLOD* plod = new osg::PagedLOD;
const osg::LOD::RangeList& originalRangeList = lod->getRangeList();
typedef std::multimap< osg::LOD::MinMaxPair , unsigned int > MinMaxPairMap;
MinMaxPairMap rangeMap;
@@ -166,7 +166,7 @@ public:
{
rangeMap.insert(std::multimap< osg::LOD::MinMaxPair , unsigned int >::value_type(*ritr, pos));
}
pos = 0;
for(MinMaxPairMap::reverse_iterator mitr = rangeMap.rbegin();
mitr != rangeMap.rend();
@@ -181,11 +181,11 @@ public:
std::string filename = _basename;
std::ostringstream os;
os << _basename << "_"<<lodNum<<"_"<<pos<<_extension;
plod->addChild(lod->getChild(mitr->second), mitr->first.first, mitr->first.second, os.str());
}
}
osg::Node::ParentList parents = lod->getParents();
for(osg::Node::ParentList::iterator pitr=parents.begin();
pitr!=parents.end();
@@ -195,12 +195,12 @@ public:
}
plod->setCenter(plod->getBound().center());
}
}
typedef std::set< osg::ref_ptr<osg::LOD> > LODSet;
LODSet _lodSet;
std::string _basename;
@@ -214,7 +214,7 @@ int main( int argc, char **argv )
// use an ArgumentParser object to manage the program arguments.
osg::ArgumentParser arguments(&argc,argv);
// set up the usage document, in case we need to print out how to use this program.
arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" creates a hierarchy of files for paging which can be later loaded by viewers.");
@@ -232,8 +232,8 @@ int main( int argc, char **argv )
std::string outputfile("output.ive");
while (arguments.read("-o",outputfile)) {}
bool makeAllChildrenPaged = false;
while (arguments.read("--makeAllChildrenPaged")) { makeAllChildrenPaged = true; }
@@ -246,7 +246,7 @@ int main( int argc, char **argv )
arguments.writeErrorMessages(std::cout);
return 1;
}
// if (arguments.argc()<=1)
// {
// arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
@@ -254,21 +254,21 @@ int main( int argc, char **argv )
// }
osg::ref_ptr<osg::Node> model = osgDB::readNodeFiles(arguments);
osg::ref_ptr<osg::Node> model = osgDB::readRefNodeFiles(arguments);
if (!model)
{
osg::notify(osg::NOTICE)<<"No model loaded."<<std::endl;
return 1;
}
std::string basename( osgDB::getNameLessExtension(outputfile) );
std::string ext = '.'+ osgDB::getFileExtension(outputfile);
ConvertToPageLODVistor converter(basename,ext, makeAllChildrenPaged);
model->accept(converter);
converter.convert();
NameVistor nameNodes;
model->accept(nameNodes);
@@ -278,7 +278,7 @@ int main( int argc, char **argv )
if (model.valid())
{
osgDB::writeNodeFile(*model,outputfile);
WriteOutPagedLODSubgraphsVistor woplsv;
model->accept(woplsv);
}