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

@@ -31,5 +31,6 @@
#cmakedefine OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION
#cmakedefine OSG_USE_UTF8_FILENAME
#cmakedefine OSG_DISABLE_MSVC_WARNINGS
#cmakedefine OSG_PROVIDE_READFILE
#endif

View File

@@ -343,7 +343,7 @@ bool FileCache::loadDatabaseRevisionsForFile(const std::string& originalFileName
if (!cacheFileName.empty() && osgDB::fileExists(cacheFileName))
{
OSG_INFO<<" found revisions file in local cache, now loading it"<<std::endl;
osg::ref_ptr<osg::Object> object = osgDB::readObjectFile(cacheFileName);
osg::ref_ptr<osg::Object> object = osgDB::readRefObjectFile(cacheFileName);
dr_local = dynamic_cast<DatabaseRevisions*>(object.get());
if (dr_local)
{
@@ -357,7 +357,7 @@ bool FileCache::loadDatabaseRevisionsForFile(const std::string& originalFileName
}
// now load revision file from remote server
osg::ref_ptr<osg::Object> object = osgDB::readObjectFile(revisionsFileName+".curl");
osg::ref_ptr<osg::Object> object = osgDB::readRefObjectFile(revisionsFileName+".curl");
osg::ref_ptr<DatabaseRevisions> dr_remote = dynamic_cast<DatabaseRevisions*>(object.get());
if (dr_remote.valid())
@@ -463,7 +463,7 @@ FileList* FileCache::readFileList(const std::string& originalFileName) const
std::string cacheFileListName = createCacheFileName(originalFileName);
if (!cacheFileListName.empty() && osgDB::fileExists(cacheFileListName))
{
osg::ref_ptr<osg::Object> object = osgDB::readObjectFile(cacheFileListName);
osg::ref_ptr<osg::Object> object = osgDB::readRefObjectFile(cacheFileListName);
fileList = dynamic_cast<osgDB::FileList*>(object.get());
if (fileList) OSG_INFO<<" loadeded FileList from local cache "<<fileList->getName()<<std::endl;
}
@@ -471,7 +471,7 @@ FileList* FileCache::readFileList(const std::string& originalFileName) const
if (!fileList)
{
OSG_INFO<<" complete_path="<<originalFileName<<std::endl;
osg::ref_ptr<osg::Object> object = osgDB::readObjectFile(originalFileName+".curl");
osg::ref_ptr<osg::Object> object = osgDB::readRefObjectFile(originalFileName+".curl");
fileList = dynamic_cast<osgDB::FileList*>(object.get());
if (fileList)
{

View File

@@ -211,7 +211,7 @@ void ImagePager::ImageThread::run()
if (imageRequest.valid())
{
// OSG_NOTICE<<"doing readImageFile("<<imageRequest->_fileName<<") index to assign = "<<imageRequest->_attachmentIndex<<std::endl;
osg::ref_ptr<osg::Image> image = osgDB::readImageFile(imageRequest->_fileName, imageRequest->_readOptions.get());
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile(imageRequest->_fileName, imageRequest->_readOptions.get());
if (image.valid())
{
// OSG_NOTICE<<" successful readImageFile("<<imageRequest->_fileName<<") index to assign = "<<imageRequest->_attachmentIndex<<std::endl;
@@ -320,12 +320,11 @@ int ImagePager::cancel()
osg::Image* ImagePager::readImageFile(const std::string& fileName, const osg::Referenced* options)
{
osgDB::Options* readOptions = dynamic_cast<osgDB::Options*>(const_cast<osg::Referenced*>(options));
return osgDB::readImageFile(fileName, readOptions);
return osgDB::readRefImageFile(fileName, readOptions).release();
}
void ImagePager::requestImageFile(const std::string& fileName, osg::Object* attachmentPoint, int attachmentIndex, double timeToMergeBy, const osg::FrameStamp* /*framestamp*/, osg::ref_ptr<osg::Referenced>& imageRequest, const osg::Referenced* options)
{
osgDB::Options* readOptions = dynamic_cast<osgDB::Options*>(const_cast<osg::Referenced*>(options));
if (!readOptions)
{

View File

@@ -87,7 +87,7 @@ osg::Node* Input::readNode()
osg::Object* Input::readObject(const std::string& fileName)
{
return readObjectFile(fileName,_options.get());
return readRefObjectFile(fileName,_options.get()).release();
}
osg::Shader* Input::readShader()
@@ -97,17 +97,17 @@ osg::Shader* Input::readShader()
osg::Image* Input::readImage(const std::string& fileName)
{
return readImageFile(fileName,_options.get());
return readRefImageFile(fileName,_options.get()).release();
}
osg::Node* Input::readNode(const std::string& fileName)
{
return readNodeFile(fileName,_options.get());
return readRefNodeFile(fileName,_options.get()).release();
}
osg::Shader* Input::readShader(const std::string& fileName)
{
return readShaderFile(fileName,_options.get());
return readRefShaderFile(fileName,_options.get()).release();
}
bool Input::read(Parameter value1)

View File

@@ -29,6 +29,7 @@
using namespace osg;
using namespace osgDB;
#ifdef OSG_PROVIDE_READFILE
Object* osgDB::readObjectFile(const std::string& filename,const Options* options)
{
ReaderWriter::ReadResult rr = Registry::instance()->readObject(filename,options);
@@ -75,14 +76,82 @@ Node* osgDB::readNodeFile(const std::string& filename,const Options* options)
Node* osgDB::readNodeFiles(std::vector<std::string>& fileList,const Options* options)
{
typedef std::vector<osg::Node*> NodeList;
return readRefNodeFiles(fileList, options).release();
}
Node* osgDB::readNodeFiles(osg::ArgumentParser& arguments,const Options* options)
{
return readRefNodeFiles(arguments, options).release();
}
Script* osgDB::readScriptFile(const std::string& filename,const Options* options)
{
ReaderWriter::ReadResult rr = Registry::instance()->readScript(filename,options);
if (rr.validScript()) return rr.takeScript();
if (rr.error()) OSG_WARN << rr.message() << std::endl;
return NULL;
}
#endif
osg::ref_ptr<osg::Object> osgDB::readRefObjectFile(const std::string& filename,const Options* options)
{
ReaderWriter::ReadResult rr = Registry::instance()->readObject(filename,options);
if (rr.validObject()) return osg::ref_ptr<osg::Object>(rr.getObject());
if (rr.error()) OSG_WARN << rr.message() << std::endl;
return NULL;
}
osg::ref_ptr<osg::Image> osgDB::readRefImageFile(const std::string& filename,const Options* options)
{
ReaderWriter::ReadResult rr = Registry::instance()->readImage(filename,options);
if (rr.validImage()) return osg::ref_ptr<osg::Image>(rr.getImage());
if (rr.error()) OSG_WARN << rr.message() << std::endl;
return NULL;
}
osg::ref_ptr<osg::Shader> osgDB::readRefShaderFile(const std::string& filename,const Options* options)
{
ReaderWriter::ReadResult rr = Registry::instance()->readShader(filename,options);
if (rr.validShader()) return osg::ref_ptr<osg::Shader>(rr.getShader());
if (rr.error()) OSG_WARN << rr.message() << std::endl;
return NULL;
}
osg::ref_ptr<osg::HeightField> osgDB::readRefHeightFieldFile(const std::string& filename,const Options* options)
{
ReaderWriter::ReadResult rr = Registry::instance()->readHeightField(filename,options);
if (rr.validHeightField()) return osg::ref_ptr<osg::HeightField>(rr.getHeightField());
if (rr.error()) OSG_WARN << rr.message() << std::endl;
return NULL;
}
osg::ref_ptr<osg::Node> osgDB::readRefNodeFile(const std::string& filename,const Options* options)
{
ReaderWriter::ReadResult rr = Registry::instance()->readNode(filename,options);
if (rr.validNode()) return osg::ref_ptr<osg::Node>(rr.getNode());
if (rr.error()) OSG_WARN << rr.message() << std::endl;
return NULL;
}
osg::ref_ptr<osg::Script> osgDB::readRefScriptFile(const std::string& filename,const Options* options)
{
ReaderWriter::ReadResult rr = Registry::instance()->readScript(filename,options);
if (rr.validScript()) return osg::ref_ptr<osg::Script>(rr.getScript());
if (rr.error()) OSG_WARN << rr.message() << std::endl;
return NULL;
}
osg::ref_ptr<Node> osgDB::readRefNodeFiles(std::vector<std::string>& fileList,const Options* options)
{
typedef std::vector< osg::ref_ptr<osg::Node> > NodeList;
NodeList nodeList;
for(std::vector<std::string>::iterator itr=fileList.begin();
itr!=fileList.end();
++itr)
{
osg::Node *node = osgDB::readNodeFile( *itr , options );
osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFile( *itr , options );
if( node != (osg::Node *)0L )
{
@@ -103,7 +172,7 @@ Node* osgDB::readNodeFiles(std::vector<std::string>& fileList,const Options* opt
}
else // size >1
{
osg::Group* group = new osg::Group;
osg::ref_ptr<osg::Group> group = new osg::Group;
for(NodeList::iterator itr=nodeList.begin();
itr!=nodeList.end();
++itr)
@@ -116,7 +185,7 @@ Node* osgDB::readNodeFiles(std::vector<std::string>& fileList,const Options* opt
}
Node* osgDB::readNodeFiles(osg::ArgumentParser& arguments,const Options* options)
osg::ref_ptr<Node> osgDB::readRefNodeFiles(osg::ArgumentParser& arguments,const Options* options)
{
typedef std::vector< osg::ref_ptr<osg::Node> > NodeList;
@@ -131,7 +200,7 @@ Node* osgDB::readNodeFiles(osg::ArgumentParser& arguments,const Options* options
while (arguments.read("--image",filename))
{
osg::ref_ptr<osg::Image> image = readImageFile(filename.c_str(), options);
osg::ref_ptr<osg::Image> image = readRefImageFile(filename.c_str(), options);
if (image.valid())
{
osg::Geode* geode = osg::createGeodeForImage(image.get());
@@ -149,7 +218,7 @@ Node* osgDB::readNodeFiles(osg::ArgumentParser& arguments,const Options* options
while (arguments.read("--movie",filename))
{
osg::ref_ptr<osg::Image> image = readImageFile(filename.c_str(), options);
osg::ref_ptr<osg::Image> image = readRefImageFile(filename.c_str(), options);
osg::ref_ptr<osg::ImageStream> imageStream = dynamic_cast<osg::ImageStream*>(image.get());
if (imageStream.valid())
{
@@ -200,11 +269,11 @@ Node* osgDB::readNodeFiles(osg::ArgumentParser& arguments,const Options* options
while (arguments.read("--dem",filename))
{
osg::HeightField* hf = readHeightFieldFile(filename.c_str(), options);
osg::ref_ptr<osg::HeightField> hf = readRefHeightFieldFile(filename.c_str(), options);
if (hf)
{
osg::Geode* geode = new osg::Geode;
geode->addDrawable(new osg::ShapeDrawable(hf));
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
geode->addDrawable(new osg::ShapeDrawable(hf.get()));
nodeList.push_back(geode);
}
}
@@ -215,7 +284,7 @@ Node* osgDB::readNodeFiles(osg::ArgumentParser& arguments,const Options* options
if (!arguments.isOption(pos))
{
// not an option so assume string is a filename.
osg::Node *node = osgDB::readNodeFile( arguments[pos], options);
osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFile( arguments[pos], options);
if(node)
{
@@ -237,73 +306,15 @@ Node* osgDB::readNodeFiles(osg::ArgumentParser& arguments,const Options* options
}
else // size >1
{
osg::Group* group = new osg::Group;
osg::ref_ptr<osg::Group> group = new osg::Group;
for(NodeList::iterator itr=nodeList.begin();
itr!=nodeList.end();
++itr)
{
group->addChild((*itr).get());
group->addChild(*itr);
}
return group;
}
}
Script* osgDB::readScriptFile(const std::string& filename,const Options* options)
{
ReaderWriter::ReadResult rr = Registry::instance()->readScript(filename,options);
if (rr.validScript()) return rr.takeScript();
if (rr.error()) OSG_WARN << rr.message() << std::endl;
return NULL;
}
osg::ref_ptr<osg::Object> osgDB::readRefObjectFile(const std::string& filename,const Options* options)
{
ReaderWriter::ReadResult rr = Registry::instance()->readObject(filename,options);
if (rr.validObject()) return osg::ref_ptr<osg::Object>(rr.getObject());
if (rr.error()) OSG_WARN << rr.message() << std::endl;
return NULL;
}
osg::ref_ptr<osg::Image> osgDB::readRefImageFile(const std::string& filename,const Options* options)
{
ReaderWriter::ReadResult rr = Registry::instance()->readImage(filename,options);
if (rr.validImage()) return osg::ref_ptr<osg::Image>(rr.getImage());
if (rr.error()) OSG_WARN << rr.message() << std::endl;
return NULL;
}
osg::ref_ptr<osg::Shader> osgDB::readRefShaderFile(const std::string& filename,const Options* options)
{
ReaderWriter::ReadResult rr = Registry::instance()->readShader(filename,options);
if (rr.validShader()) return osg::ref_ptr<osg::Shader>(rr.getShader());
if (rr.error()) OSG_WARN << rr.message() << std::endl;
return NULL;
}
osg::ref_ptr<osg::HeightField> osgDB::readRefHeightFieldFile(const std::string& filename,const Options* options)
{
ReaderWriter::ReadResult rr = Registry::instance()->readHeightField(filename,options);
if (rr.validHeightField()) return osg::ref_ptr<osg::HeightField>(rr.getHeightField());
if (rr.error()) OSG_WARN << rr.message() << std::endl;
return NULL;
}
osg::ref_ptr<osg::Node> osgDB::readRefNodeFile(const std::string& filename,const Options* options)
{
ReaderWriter::ReadResult rr = Registry::instance()->readNode(filename,options);
if (rr.validNode()) return osg::ref_ptr<osg::Node>(rr.getNode());
if (rr.error()) OSG_WARN << rr.message() << std::endl;
return NULL;
}
osg::ref_ptr<osg::Script> osgDB::readRefScriptFile(const std::string& filename,const Options* options)
{
ReaderWriter::ReadResult rr = Registry::instance()->readScript(filename,options);
if (rr.validScript()) return osg::ref_ptr<osg::Script>(rr.getScript());
if (rr.error()) OSG_WARN << rr.message() << std::endl;
return NULL;
}

View File

@@ -626,7 +626,7 @@ void BumpMapping::setUpDemo()
// set up diffuse texture
if (!_diffuse_tex.valid()) {
_diffuse_tex = new osg::Texture2D;
_diffuse_tex->setImage(osgDB::readImageFile("Images/whitemetal_diffuse.jpg"));
_diffuse_tex->setImage(osgDB::readRefImageFile("Images/whitemetal_diffuse.jpg"));
_diffuse_tex->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR);
_diffuse_tex->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
_diffuse_tex->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
@@ -637,7 +637,7 @@ void BumpMapping::setUpDemo()
// set up normal map texture
if (!_normal_tex.valid()) {
_normal_tex = new osg::Texture2D;
_normal_tex->setImage(osgDB::readImageFile("Images/whitemetal_normal.jpg"));
_normal_tex->setImage(osgDB::readRefImageFile("Images/whitemetal_normal.jpg"));
_normal_tex->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR);
_normal_tex->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
_normal_tex->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);

View File

@@ -249,7 +249,7 @@ void osgParticle::ParticleSystem::setDefaultAttributes(const std::string& textur
if (!texturefile.empty()) {
osg::Texture2D *texture = new osg::Texture2D;
texture->setImage(osgDB::readImageFile(texturefile));
texture->setImage(osgDB::readRefImageFile(texturefile));
texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);
texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);
texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::MIRROR);
@@ -292,7 +292,7 @@ void osgParticle::ParticleSystem::setDefaultAttributesUsingShaders(const std::st
if (!texturefile.empty())
{
osg::Texture2D *texture = new osg::Texture2D;
texture->setImage(osgDB::readImageFile(texturefile));
texture->setImage(osgDB::readRefImageFile(texturefile));
texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);
texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);
texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::MIRROR);

View File

@@ -1088,7 +1088,7 @@ static osgDB::ReaderWriter::Options* createOptions()
static osg::Image* loadImage(const char *fileName, osgDB::ReaderWriter::Options *options)
{
osg::ref_ptr<osg::Image> osgImage = osgDB::readImageFile(fileName, options);
osg::ref_ptr<osg::Image> osgImage = osgDB::readRefImageFile(fileName, options);
if (!osgImage)
{

View File

@@ -220,9 +220,9 @@ protected:
material->setDiffuse (osg::Material::FRONT_AND_BACK,osg::Vec4(diffuse,alpha));
material->setSpecular(osg::Material::FRONT_AND_BACK,osg::Vec4(specular,alpha));
material->setEmission(osg::Material::FRONT_AND_BACK,osg::Vec4(emissive,alpha));
if (shininess>=0.0f)
{
{
material->setShininess(osg::Material::FRONT_AND_BACK,shininess);
}
else
@@ -276,7 +276,7 @@ protected:
material->setEmission(osg::Material::FRONT_AND_BACK,osg::Vec4(emissive,alpha));
if (shininess>=0.0f)
{
{
material->setShininess(osg::Material::FRONT_AND_BACK,shininess);
}
else
@@ -346,7 +346,7 @@ protected:
// Read attribute file
std::string attrname = filename + ".attr";
osg::ref_ptr<AttrData> attr = dynamic_cast<AttrData*>(osgDB::readObjectFile(attrname,document.getOptions()));
osg::ref_ptr<AttrData> attr = osgDB::readRefFile<AttrData>(attrname,document.getOptions());
if (attr.valid())
{
// Wrap mode
@@ -899,7 +899,7 @@ protected:
std::string vertexProgramFilePath = osgDB::findDataFile(vertexProgramFilename,document.getOptions());
if (!vertexProgramFilePath.empty())
{
osg::Shader* vertexShader = osg::Shader::readShaderFile(osg::Shader::VERTEX, vertexProgramFilePath);
osg::ref_ptr<osg::Shader> vertexShader = osgDB::readRefShaderFile(osg::Shader::VERTEX, vertexProgramFilePath);
if (vertexShader)
program->addShader( vertexShader );
}
@@ -913,7 +913,7 @@ protected:
std::string fragmentProgramFilePath = osgDB::findDataFile(fragmentProgramFilename,document.getOptions());
if (!fragmentProgramFilePath.empty())
{
osg::Shader* fragmentShader = osg::Shader::readShaderFile(osg::Shader::FRAGMENT, fragmentProgramFilePath);
osg::ref_ptr<osg::Shader> fragmentShader = osgDB::readRefShaderFile(osg::Shader::FRAGMENT, fragmentProgramFilePath);
if (fragmentShader)
program->addShader( fragmentShader );
}

View File

@@ -12,7 +12,7 @@
*/
//
// OpenFlight<EFBFBD> loader for OpenSceneGraph
// OpenFlight loader for OpenSceneGraph
//
// Copyright (C) 2005-2007 Brede Johansen
//
@@ -174,7 +174,7 @@ public:
std::string filename = node.getFileName(pos);
// read external
osg::ref_ptr<osg::Node> external = osgDB::readNodeFile(filename,_options.get());
osg::ref_ptr<osg::Node> external = osgDB::readRefNodeFile(filename,_options.get());
if (external.valid())
{
if (_cloneExternalReferences)

View File

@@ -518,7 +518,7 @@ ref_ptr<Group> VBSPEntity::createModelGeometry()
ref_ptr<Group> entityGroup;
// Try to load the model
modelNode = osgDB::readNodeFile(entity_model);
modelNode = osgDB::readRefNodeFile(entity_model);
if (modelNode.valid())
{
// Create a group and add the model to it

View File

@@ -1094,7 +1094,7 @@ void VBSPReader::createScene()
// Load the prop's model
propModel = bsp_data->getStaticPropModel(staticProp.prop_type);
propNode = osgDB::readNodeFile(propModel);
propNode = osgDB::readRefNodeFile(propModel);
// If we loaded the prop correctly, add it to the scene
if (propNode.valid())

View File

@@ -62,7 +62,7 @@ FbxMaterialToOsgStateSet::convert(const FbxSurfaceMaterial* pFbxMat)
if (transparentColor[0] < 1.0 || transparentColor[1] < 1.0 || transparentColor[2] < 1.0) {
transparencyColorFactor = transparentColor[0]*0.30 + transparentColor[1]*0.59 + transparentColor[2]*0.11;
useTransparencyColorFactor = true;
}
}
int lNbTex = lOpacityProperty.GetSrcObjectCount<FbxFileTexture>();
for (int lTextureIndex = 0; lTextureIndex < lNbTex; lTextureIndex++)
@@ -187,7 +187,7 @@ FbxMaterialToOsgStateSet::convert(const FbxSurfaceMaterial* pFbxMat)
static_cast<float>(color[1] * factor),
static_cast<float>(color[2] * factor),
1.0f));
// Since Maya and 3D studio Max stores their glossiness values in exponential format (2^(log2(x))
// Since Maya and 3D studio Max stores their glossiness values in exponential format (2^(log2(x))
// We need to linearize to values between 0-100 and then scale to values between 0-128.
// Glossiness values above 100 will result in shininess larger than 128.0 and will be clamped
double shininess = (64.0 * log (pFbxPhong->Shininess.Get())) / (5.0 * log(2.0));
@@ -226,9 +226,9 @@ FbxMaterialToOsgStateSet::fbxTextureToOsgTexture(const FbxFileTexture* fbx)
// Warning: fbx->GetRelativeFileName() is relative TO EXECUTION DIR
// fbx->GetFileName() is as stored initially in the FBX
if ((pImage = osgDB::readImageFile(osgDB::concatPaths(_dir, fbx->GetFileName()), _options)) || // First try "export dir/name"
(pImage = osgDB::readImageFile(fbx->GetFileName(), _options)) || // Then try "name" (if absolute)
(pImage = osgDB::readImageFile(osgDB::concatPaths(_dir, fbx->GetRelativeFileName()), _options))) // Else try "current dir/name"
if ((pImage = osgDB::readRefImageFile(osgDB::concatPaths(_dir, fbx->GetFileName()), _options)) || // First try "export dir/name"
(pImage = osgDB::readRefImageFile(fbx->GetFileName(), _options)) || // Then try "name" (if absolute)
(pImage = osgDB::readRefImageFile(osgDB::concatPaths(_dir, fbx->GetRelativeFileName()), _options))) // Else try "current dir/name"
{
osg::ref_ptr<osg::Texture2D> pOsgTex = new osg::Texture2D;
pOsgTex->setImage(pImage.get());

View File

@@ -133,7 +133,7 @@ public:
return ReadResult::FILE_NOT_HANDLED;
// recursively load the subfile.
osg::ref_ptr<osg::Node> node = osgDB::readNodeFile( realName, options );
osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFile( realName, options );
if( !node )
{
// propagate the read failure upwards

View File

@@ -57,7 +57,7 @@ class ReaderWriterGLSL : public osgDB::ReaderWriter
const std::string filename = code.substr( pos2 + 1, pos3 - pos2 - 1 );
osg::ref_ptr<osg::Shader> innerShader = osgDB::readShaderFile( shader->getType(), filename, options );
osg::ref_ptr<osg::Shader> innerShader = osgDB::readRefShaderFile( shader->getType(), filename, options );
if ( !innerShader.valid() )
{

View File

@@ -1914,7 +1914,7 @@ osgTerrain::Layer* DataInputStream::readLayer()
else if (layerid==IVEPROXYLAYER)
{
std::string filename = readString();
osg::ref_ptr<osg::Object> object = osgDB::readObjectFile(filename+".gdal");
osg::ref_ptr<osg::Object> object = osgDB::readRefObjectFile(filename+".gdal");
osgTerrain::ProxyLayer* proxyLayer = dynamic_cast<osgTerrain::ProxyLayer*>(object.get());
osg::ref_ptr<osgTerrain::Locator> locator = readLocator();

View File

@@ -107,7 +107,7 @@ void HeightFieldLayer::read(DataInputStream* in)
if (in->getVersion()>=VERSION_0035)
{
osg::HeightField* hf = new osg::HeightField;
osg::ref_ptr<osg::HeightField> hf = new osg::HeightField;
// Read HeightField's properties
//setColor(in->readVec4());
@@ -128,13 +128,13 @@ void HeightFieldLayer::read(DataInputStream* in)
in->readPackedFloatArray(hf->getFloatArray());
}
setHeightField(hf);
setHeightField(hf.get());
}
else
{
osg::Shape* shape = in->readShape();
setHeightField(dynamic_cast<osg::HeightField*>(shape));
osg::ref_ptr<osg::Shape> shape = in->readShape();
setHeightField(dynamic_cast<osg::HeightField*>(shape.get()));
}
}
@@ -143,7 +143,8 @@ void HeightFieldLayer::read(DataInputStream* in)
std::string filename = in->readString();
setFileName(filename);
setHeightField(osgDB::readHeightFieldFile(filename,in->getOptions()));
osg::ref_ptr<osg::HeightField> hf = osgDB::readRefHeightFieldFile(filename,in->getOptions());
if (hf) setHeightField(hf.get());
}
}

View File

@@ -190,8 +190,7 @@ osgTerrain::Layer* LayerHelper::readLayer(DataInputStream* in)
else if (id==IVEPROXYLAYER)
{
std::string filename = in->readString();
osg::ref_ptr<osg::Object> object = osgDB::readObjectFile(filename+".gdal");
osgTerrain::ProxyLayer* proxyLayer = dynamic_cast<osgTerrain::ProxyLayer*>(object.get());
osg::ref_ptr<osgTerrain::ProxyLayer> proxyLayer = osgDB::readRefFile<osgTerrain::ProxyLayer>(filename+".gdal");
osg::ref_ptr<osgTerrain::Locator> locator = readLocator(in);
unsigned int minLevel = in->readUInt();
@@ -205,7 +204,7 @@ osgTerrain::Layer* LayerHelper::readLayer(DataInputStream* in)
proxyLayer->setMaxLevel(maxLevel);
}
return proxyLayer;
return proxyLayer.release();
}
return new osgTerrain::ImageLayer;

View File

@@ -205,7 +205,7 @@ void ProxyNode::read(DataInputStream* in)
{
osgDB::FilePathList& fpl = ((osgDB::ReaderWriter::Options*)in->getOptions())->getDatabasePathList();
fpl.push_front( fpl.empty() ? osgDB::getFilePath(getFileName(i)) : fpl.front()+'/'+ osgDB::getFilePath(getFileName(i)));
osg::Node *node = osgDB::readNodeFile(getFileName(i), in->getOptions());
osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFile(getFileName(i), in->getOptions());
fpl.pop_front();
if(node)

View File

@@ -1767,7 +1767,7 @@ static int readObjectFile(lua_State * _lua)
if (n==1 && lua_type(_lua, 1)==LUA_TSTRING)
{
std::string filename = lua_tostring(_lua, 1);
osg::ref_ptr<osg::Object> object = osgDB::readObjectFile(filename);
osg::ref_ptr<osg::Object> object = osgDB::readRefObjectFile(filename);
if (object.valid())
{
lse->pushObject(object.get());
@@ -1785,7 +1785,7 @@ static int readImageFile(lua_State * _lua)
if (n==1 && lua_type(_lua, 1)==LUA_TSTRING)
{
std::string filename = lua_tostring(_lua, 1);
osg::ref_ptr<osg::Image> image = osgDB::readImageFile(filename);
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile(filename);
if (image.valid())
{
lse->pushObject(image.get());
@@ -1803,7 +1803,7 @@ static int readNodeFile(lua_State * _lua)
if (n==1 && lua_type(_lua, 1)==LUA_TSTRING)
{
std::string filename = lua_tostring(_lua, 1);
osg::ref_ptr<osg::Node> node = osgDB::readNodeFile(filename);
osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFile(filename);
if (node.valid())
{
lse->pushObject(node.get());

View File

@@ -107,7 +107,7 @@ osg::Group *SceneLoader::load(const std::string &filename, const osgDB::ReaderWr
std::getline(ifs, field);
version_ = atoi(field.c_str());
std::string identifier;
while (ifs >> identifier) {
@@ -256,7 +256,7 @@ bool SceneLoader::parse_block(const std::string &name, const std::string &data)
OSG_NOTICE << "Loading object \"" << filename << "\"" << std::endl;
objnode = dynamic_cast<osg::Group *>(osgDB::readNodeFile(filename));
objnode = osgDB::readRefFile<osg::Group>(filename);
if (!objnode.valid()) return false;
objects_[filename] = objnode;

View File

@@ -77,7 +77,7 @@ class NormalsReader: public osgDB::ReaderWriter
std::string nodeName = osgDB::getNameLessExtension( fileName );
if( !nodeName.empty() )
{
osg::ref_ptr<osg::Node> node = osgDB::readNodeFile( nodeName );
osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFile( nodeName );
if( node.valid() )
{
osg::ref_ptr<osg::Group> group = new osg::Group;

View File

@@ -201,7 +201,7 @@ public:
}
is.decompress(); CATCH_EXCEPTION(is);
osg::Object* obj = is.readObject(); CATCH_EXCEPTION(is);
osg::ref_ptr<osg::Object> obj = is.readObject(); CATCH_EXCEPTION(is);
return obj;
}
@@ -231,7 +231,7 @@ public:
}
is.decompress(); CATCH_EXCEPTION(is);
osg::Image* image = is.readImage(); CATCH_EXCEPTION(is);
osg::ref_ptr<osg::Image> image = is.readImage(); CATCH_EXCEPTION(is);
return image;
}
@@ -262,7 +262,7 @@ public:
}
is.decompress(); CATCH_EXCEPTION(is);
osg::Node* node = dynamic_cast<osg::Node*>(is.readObject()); CATCH_EXCEPTION(is);
osg::ref_ptr<osg::Node> node = is.readObjectOfType<osg::Node>(); CATCH_EXCEPTION(is);
if ( !node ) return ReadResult::FILE_NOT_HANDLED;
return node;
}

View File

@@ -231,7 +231,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterJSON::readNode(const std::string& fi
fileName = osgDB::findDataFile( fileName, options );
if (fileName.empty()) return ReadResult::FILE_NOT_FOUND;
osg::Node *node = osgDB::readNodeFile( fileName, options );
osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFile( fileName, options );
if (!node)
return ReadResult::FILE_NOT_HANDLED;

View File

@@ -656,7 +656,7 @@ JSONObject* WriteVisitor::createJSONPagedLOD(osg::PagedLOD *plod)
ss << i;
std::string str = ss.str();
// We need to convert first from osg format to osgjs format.
osg::ref_ptr<osg::Node> n = osgDB::readNodeFile(plod->getFileName(i)+".gles");
osg::ref_ptr<osg::Node> n = osgDB::readRefNodeFile(plod->getFileName(i)+".gles");
if (n)
{
std::string filename(osgDB::getStrippedName(plod->getFileName(i))+".osgjs");

View File

@@ -91,7 +91,7 @@ class sgReaderWriterOSGTGZ : public osgDB::ReaderWriter
std::string file_ext = osgDB::getLowerCaseFileExtension(*itr);
if (osgDB::equalCaseInsensitive(file_ext,"osg"))
{
osg::Node *node = osgDB::readNodeFile( *itr, local_options.get() );
osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFile( *itr, local_options.get() );
grp->addChild( node );
}
}

View File

@@ -1370,7 +1370,7 @@ void ReaderWriterP3DXML::parseVolume(osgPresentation::SlideShowConstructor& cons
std::string vs;
if (getProperty(cur, "vs", vs) || getProperty(cur, "VolumeSettings", vs))
{
volumeData.volumeSettings = osgDB::readFile<osgVolume::VolumeSettings>(vs);
volumeData.volumeSettings = osgDB::readRefFile<osgVolume::VolumeSettings>(vs);
if (volumeData.volumeSettings.valid())
{
OSG_NOTICE<<"VolumeSetting read "<<vs<<" "<<volumeData.volumeSettings.get()<<std::endl;
@@ -1438,12 +1438,12 @@ void ReaderWriterP3DXML::parseVolume(osgPresentation::SlideShowConstructor& cons
std::string transferFunctionFile;
if (getTrimmedProperty(cur, "tf", transferFunctionFile))
{
volumeData.transferFunction = osgDB::readFile<osg::TransferFunction1D>(transferFunctionFile);
volumeData.transferFunction = osgDB::readRefFile<osg::TransferFunction1D>(transferFunctionFile);
}
if (getTrimmedProperty(cur, "tf-255", transferFunctionFile))
{
volumeData.transferFunction = osgDB::readFile<osg::TransferFunction1D>(transferFunctionFile);
volumeData.transferFunction = osgDB::readRefFile<osg::TransferFunction1D>(transferFunctionFile);
}
if (getProperty(cur, "options", volumeData.options)) {}
@@ -2567,7 +2567,7 @@ void ReaderWriterP3DXML::parseRunScriptFile(osgPresentation::SlideShowConstructo
std::string function = "";
getProperty(cur, "function", function);
osg::ref_ptr<osg::Script> script = osgDB::readFile<osg::Script>(cur->getTrimmedContents());
osg::ref_ptr<osg::Script> script = osgDB::readRefFile<osg::Script>(cur->getTrimmedContents());
if (script.valid())
{
osg::ScriptEngine* se = constructor.getOrCreateScriptEngine(script->getLanguage());

View File

@@ -114,8 +114,7 @@ class ReaderWriterRevisions : public osgDB::ReaderWriter
{
std::string complete_path = osgDB::concatPaths(revisions_path, filename);
OSG_INFO<<" complete_path="<<complete_path<<std::endl;
osg::ref_ptr<osg::Object> object = osgDB::readObjectFile(complete_path, options);
fileList = dynamic_cast<osgDB::FileList*>(object.get());
fileList = osgDB::readRefFile<osgDB::FileList>(complete_path, options);
}
if (!fileList)

View File

@@ -139,7 +139,7 @@ public:
}
// recursively load the subfile.
osg::Node *node = osgDB::readNodeFile( subFileName, options );
osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFile( subFileName, options );
if( !node )
{
// propagate the read failure upwards
@@ -147,7 +147,7 @@ public:
return ReadResult::FILE_NOT_HANDLED;
}
osg::MatrixTransform *xform = new osg::MatrixTransform;
osg::ref_ptr<osg::MatrixTransform> xform = new osg::MatrixTransform;
xform->setDataVariance( osg::Object::STATIC );
xform->setMatrix( osg::Matrix::rotate(
osg::DegreesToRadians( rx ), osg::Vec3( 1, 0, 0 ),

View File

@@ -152,7 +152,7 @@ public:
}
// recursively load the subfile.
osg::Node *node = osgDB::readNodeFile( subFileName, options );
osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFile( subFileName, options );
if( !node )
{
// propagate the read failure upwards
@@ -160,7 +160,7 @@ public:
return ReadResult::FILE_NOT_HANDLED;
}
osg::MatrixTransform *xform = new osg::MatrixTransform;
osg::ref_ptr<osg::MatrixTransform> xform = new osg::MatrixTransform;
xform->setDataVariance( osg::Object::STATIC );
xform->setMatrix( osg::Matrix::scale( sx, sy, sz ) );
xform->addChild( node );

View File

@@ -121,7 +121,7 @@ public:
if (!technique) technique = new osgShadow::ShadowVolume;
// recursively load the subfile.
osg::Node *node = osgDB::readNodeFile( subFileName, options );
osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFile( subFileName, options );
if( !node )
{
// propagate the read failure upwards
@@ -130,7 +130,7 @@ public:
}
osgShadow::ShadowedScene* shadowedScene = new osgShadow::ShadowedScene;
shadowedScene->setShadowTechnique(technique.get());
shadowedScene->setShadowTechnique(technique);
shadowedScene->addChild( node );
return shadowedScene;
}

View File

@@ -83,7 +83,7 @@ class ReaderWriterTerrain : public osgDB::ReaderWriter
if (fr.matchSequence("file %s") || fr.matchSequence("file %w") )
{
osg::Node* node = osgDB::readNodeFile(fr[1].getStr());
osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFile(fr[1].getStr());
if (node) group->addChild(node);
@@ -94,7 +94,7 @@ class ReaderWriterTerrain : public osgDB::ReaderWriter
osg::ref_ptr<osg::Node> node = fr.readNode();
if (node.valid())
{
group->addChild(node.get());
group->addChild(node);
itrAdvanced = true;
}
@@ -105,7 +105,7 @@ class ReaderWriterTerrain : public osgDB::ReaderWriter
}
}
if (group->getNumChildren()>0) return group.release();
if (group->getNumChildren()>0) return group;
else return 0;
}

View File

@@ -113,8 +113,8 @@ class ReaderWriterTGZ : public osgDB::ReaderWriter
*itr!=std::string(".") &&
*itr!=std::string(".."))
{
osg::Node *node = osgDB::readNodeFile(*itr, local_options.get());
grp->addChild( node );
osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFile(*itr, local_options.get());
if (node) grp->addChild( node );
}
}
@@ -136,7 +136,7 @@ class ReaderWriterTGZ : public osgDB::ReaderWriter
return ReadResult::FILE_NOT_HANDLED;
}
return grp.get();
return grp;
}

View File

@@ -139,7 +139,7 @@ public:
}
// recursively load the subfile.
osg::Node *node = osgDB::readNodeFile( subFileName, options );
osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFile( subFileName, options );
if( !node )
{
// propagate the read failure upwards
@@ -147,7 +147,7 @@ public:
return ReadResult::FILE_NOT_HANDLED;
}
osg::MatrixTransform *xform = new osg::MatrixTransform;
osg::ref_ptr<osg::MatrixTransform> xform = new osg::MatrixTransform;
xform->setDataVariance( osg::Object::STATIC );
xform->setMatrix( osg::Matrix::translate( tx, ty, tz ) );
xform->addChild( node );

View File

@@ -169,7 +169,7 @@ struct AssignDirectionColour
osg::ref_ptr<osg::StateSet> stateset = geometry->getOrCreateStateSet();
osg::ref_ptr<osg::Program> program = new osg::Program;
osg::ref_ptr<osg::Shader> vertexShader = osgDB::readShaderFile(osg::Shader::VERTEX, vertexShaderFile);
osg::ref_ptr<osg::Shader> vertexShader = osgDB::readRefShaderFile(osg::Shader::VERTEX, vertexShaderFile);
if (!vertexShader)
{
vertexShader = new osg::Shader(osg::Shader::VERTEX, vert_shader_str);

View File

@@ -434,7 +434,7 @@ bool TXPArchive::loadModel(int ix)
mod->GetName(name,1023);
// Load the model. It's probably not TerraPage
osg::Node *osg_model = osgDB::readNodeFile( name );
osg::ref_ptr<osg::Node> osg_model = osgDB::readRefNodeFile( name );
if ( !osg_model )
{
OSG_WARN << "TrPageArchive::LoadModels() error: "
@@ -642,9 +642,8 @@ bool TXPArchive::loadTextStyles()
continue;
std::string fontfilename = fontmap[*fontName];
if ( !fontfilename.length() )
fontfilename = "arial.ttf";
osg::ref_ptr< osgText::Font > font = osgText::readFontFile(fontfilename);
if ( !fontfilename.length() ) fontfilename = "arial.ttf";
osg::ref_ptr< osgText::Font > font = osgText::readRefFontFile(fontfilename);
_fonts[itr->first] = font;

View File

@@ -845,7 +845,7 @@ void ToVRML::findTextureName(osg::Texture2D* tex, std::string& name, bool& alrea
std::string::size_type pos = nameInput.find_last_of(".");
std::string ext = nameInput.substr(pos, nameInput.length() - pos);
osg::ref_ptr < osg::Image > imgIn = osgDB::readImageFile(nameInput);
osg::ref_ptr < osg::Image > imgIn = osgDB::readRefImageFile(nameInput);
if (!imgIn.valid()) {
osg::notify(osg::ALWAYS) << "WARNING: couldn't read texture named: -" << nameOri << "- use default one instead -" << _defaultImage->getFileName() << "-" << std::endl;
tex->setImage(_defaultImage.get());

View File

@@ -77,7 +77,7 @@ void Cursor::initializeCursor()
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
osg::ref_ptr<osg::Image> image = osgDB::readImageFile(osgDB::findDataFile(_filename));
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile(osgDB::findDataFile(_filename));
osg::ref_ptr<osg::Texture2D> texture = (image.valid()) ? new osg::Texture2D(image.get()) : 0;
// full cursor

View File

@@ -321,7 +321,7 @@ void SlideShowConstructor::addScriptEngine(const std::string& scriptEngineName)
OSG_NOTICE<<"Script engine "<<scriptEngineName<<" already loaded."<<std::endl;
}
osg::ref_ptr<osg::ScriptEngine> scriptEngine = osgDB::readFile<osg::ScriptEngine>(std::string("ScriptEngine.")+scriptEngineName);
osg::ref_ptr<osg::ScriptEngine> scriptEngine = osgDB::readRefFile<osg::ScriptEngine>(std::string("ScriptEngine.")+scriptEngineName);
if (scriptEngine.valid())
{
_scriptEngines[scriptEngineName] = scriptEngine;
@@ -340,7 +340,7 @@ void SlideShowConstructor::addScriptEngine(const std::string& scriptEngineName)
void SlideShowConstructor::addScriptFile(const std::string& name, const std::string& filename)
{
OSG_NOTICE<<"addScriptFile() name="<<name<<", filename = "<<filename<<std::endl;
osg::ref_ptr<osg::Script> script = osgDB::readFile<osg::Script>(filename);
osg::ref_ptr<osg::Script> script = osgDB::readRefFile<osg::Script>(filename);
if (script.valid())
{
_scripts[name] = script;
@@ -467,7 +467,7 @@ void SlideShowConstructor::addLayer(bool inheritPreviousLayers, bool defineAsBas
// OSG_NOTICE<<" new layer background = "<<_slideBackgroundImageFileName<<std::endl;
osg::ref_ptr<osg::Image> image = !_slideBackgroundImageFileName.empty() ?
osgDB::readImageFile(_slideBackgroundImageFileName, _options.get()) :
osgDB::readRefImageFile(_slideBackgroundImageFileName, _options.get()) :
0;
// create the background and title..
@@ -532,7 +532,7 @@ void SlideShowConstructor::addLayer(bool inheritPreviousLayers, bool defineAsBas
osg::Vec3 localPosition = computePositionInModelCoords(_titlePositionData);
osgText::Text* text = new osgText::Text;
text->setFont(osgText::readFontFile(_titleFontData.font, _options.get()));
text->setFont(osgText::readRefFontFile(_titleFontData.font, _options.get()));
text->setColor(_titleFontData.color);
text->setCharacterSize(_titleFontData.characterSize*_slideHeight);
text->setFontResolution(110,120);
@@ -813,7 +813,7 @@ void SlideShowConstructor::addBullet(const std::string& bullet, PositionData& po
osg::Vec3 localPosition = computePositionInModelCoords(positionData);
text->setFont(osgText::readFontFile(fontData.font, _options.get()));
text->setFont(osgText::readRefFontFile(fontData.font, _options.get()));
text->setColor(fontData.color);
text->setCharacterSize(fontData.characterSize*_slideHeight);
text->setCharacterSizeMode(fontData.characterSizeMode);
@@ -863,7 +863,7 @@ void SlideShowConstructor::addParagraph(const std::string& paragraph, PositionDa
osgText::Text* text = new osgText::Text;
text->setFont(osgText::readFontFile(fontData.font, _options.get()));
text->setFont(osgText::readRefFontFile(fontData.font, _options.get()));
text->setColor(fontData.color);
text->setCharacterSize(fontData.characterSize*_slideHeight);
text->setCharacterSizeMode(fontData.characterSizeMode);
@@ -1148,7 +1148,7 @@ osg::Image* SlideShowConstructor::readImage(const std::string& filename, const I
if (filenames.size()==1)
{
image = osgDB::readImageFile(filenames[0], options.get());
image = osgDB::readRefImageFile(filenames[0], options.get());
if (image.valid()) recordOptionsFilePath(options.get() );
}
else
@@ -1169,7 +1169,7 @@ osg::Image* SlideShowConstructor::readImage(const std::string& filename, const I
if (imageSequence->getMode()==osg::ImageSequence::PRE_LOAD_ALL_IMAGES)
{
OSG_INFO<<"Attempting to read "<<*itr<<std::endl;
osg::ref_ptr<osg::Image> loadedImage = osgDB::readImageFile(*itr, options.get());
osg::ref_ptr<osg::Image> loadedImage = osgDB::readRefImageFile(*itr, options.get());
if (loadedImage.valid())
{
OSG_INFO<<"Loaded image "<<*itr<<std::endl;
@@ -1182,7 +1182,7 @@ osg::Image* SlideShowConstructor::readImage(const std::string& filename, const I
imageSequence->addImageFile(*itr);
if (firstLoad)
{
osg::ref_ptr<osg::Image> loadedImage = osgDB::readImageFile(*itr, options.get());
osg::ref_ptr<osg::Image> loadedImage = osgDB::readRefImageFile(*itr, options.get());
if (loadedImage.valid())
{
imageSequence->addImage(loadedImage.get());
@@ -1732,7 +1732,7 @@ void SlideShowConstructor::addGraph(const std::string& contents, const PositionD
}
else
{
osg::ref_ptr<osg::Node> model = osgDB::readNodeFile(filename, _options.get());
osg::ref_ptr<osg::Node> model = osgDB::readRefNodeFile(filename, _options.get());
if (!model) return;
dotFileName = tmpDirectory+osgDB::getStrippedName(filename)+std::string(".dot");
@@ -1823,7 +1823,7 @@ osg::Image* SlideShowConstructor::addInteractiveImage(const std::string& filenam
options->setOptionString(imageData.options);
}
osg::Image* image = osgDB::readImageFile(filename, options.get());
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile(filename, options.get());
OSG_INFO<<"addInteractiveImage("<<filename<<") "<<image<<std::endl;
@@ -1852,9 +1852,9 @@ osg::Image* SlideShowConstructor::addInteractiveImage(const std::string& filenam
osg::Vec3 image_pos = positionData.autoRotate ? image_local_pos : (pos+image_local_pos);
bool usedTextureRectangle = false;
osg::Geometry* pictureQuad = createTexturedQuadGeometry(image_pos, positionData.rotate, image_width, image_height, image, usedTextureRectangle);
osg::Geometry* pictureQuad = createTexturedQuadGeometry(image_pos, positionData.rotate, image_width, image_height, image.get(), usedTextureRectangle);
osg::ref_ptr<osgViewer::InteractiveImageHandler> handler = new osgViewer::InteractiveImageHandler(image);
osg::ref_ptr<osgViewer::InteractiveImageHandler> handler = new osgViewer::InteractiveImageHandler(image.get());
pictureQuad->setEventCallback(handler.get());
pictureQuad->setCullCallback(handler.get());
@@ -1939,7 +1939,7 @@ osg::Image* SlideShowConstructor::addInteractiveImage(const std::string& filenam
addToCurrentLayer(subgraph);
osgWidget::PdfImage* pdfImage = dynamic_cast<osgWidget::PdfImage*>(image);
osgWidget::PdfImage* pdfImage = dynamic_cast<osgWidget::PdfImage*>(image.get());
if (pdfImage && imageData.page>=0)
{
getOrCreateLayerAttributes(_currentLayer.get())->addEnterCallback(new SetPageCallback(pdfImage, imageData.page));
@@ -1959,7 +1959,7 @@ osg::Image* SlideShowConstructor::addInteractiveImage(const std::string& filenam
if (scriptData.hasScripts()) addScriptsToNode(scriptData, subgraph);
return image;
return image.release();
}
std::string SlideShowConstructor::findFileAndRecordPath(const std::string& filename)
@@ -2070,7 +2070,7 @@ void SlideShowConstructor::addModel(const std::string& filename, const PositionD
}
else
{
subgraph = osgDB::readNodeFile(filename, options.get());
subgraph = osgDB::readRefNodeFile(filename, options.get());
if (subgraph) recordOptionsFilePath(options.get());
}
@@ -2682,7 +2682,7 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position
itr != filenames.end();
++itr)
{
osg::ref_ptr<osg::Image> loadedImage = osgDB::readImageFile(*itr, options.get());
osg::ref_ptr<osg::Image> loadedImage = osgDB::readRefImageFile(*itr, options.get());
if (loadedImage.valid())
{
images.push_back(loadedImage.get());
@@ -2702,26 +2702,26 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position
if (fileType == osgDB::DIRECTORY)
{
image = osgDB::readImageFile(foundFile+".dicom", options.get());
image = osgDB::readRefImageFile(foundFile+".dicom", options.get());
}
else if (fileType == osgDB::REGULAR_FILE)
{
std::string ext = osgDB::getFileExtension(foundFile);
if (ext=="osg" || ext=="ive" || ext=="osgx" || ext=="osgb" || ext=="osgt")
{
osg::ref_ptr<osg::Object> obj = osgDB::readObjectFile(foundFile);
osg::ref_ptr<osg::Object> obj = osgDB::readRefObjectFile(foundFile);
image = dynamic_cast<osg::Image*>(obj.get());
volume = dynamic_cast<osgVolume::Volume*>(obj.get());
}
else
{
image = osgDB::readImageFile( foundFile, options.get() );
image = osgDB::readRefImageFile( foundFile, options.get() );
}
}
else
{
// not found image, so fallback to plugins/callbacks to find the model.
image = osgDB::readImageFile( filename, options.get() );
image = osgDB::readRefImageFile( filename, options.get() );
if (image) recordOptionsFilePath(options.get() );
}
}
@@ -3056,7 +3056,7 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position
if (!volumeData.hull.empty())
{
osg::ref_ptr<osg::Node> hull = osgDB::readNodeFile(volumeData.hull, _options.get());
osg::ref_ptr<osg::Node> hull = osgDB::readRefNodeFile(volumeData.hull, _options.get());
if (hull.valid())
{
hull = decorateSubgraphForPositionAndAnimation(hull.get(), volumeData.hullPositionData);
@@ -3100,7 +3100,7 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position
#if 1
osgUI::Widget* widget = vs.valid() ? osgDB::readFile<osgUI::Widget>("ui/VolumeSettings.lua") : 0;
osg::ref_ptr<osgUI::Widget> widget = vs.valid() ? osgDB::readRefFile<osgUI::Widget>("ui/VolumeSettings.lua") : 0;
if (widget)
{
OSG_NOTICE<<"Adding widget"<<std::endl;
@@ -3170,7 +3170,7 @@ bool SlideShowConstructor::attachTexMat(osg::StateSet* stateset, const ImageData
osg::Node* SlideShowConstructor::attachMaterialAnimation(osg::Node* model, const PositionData& positionData)
{
AnimationMaterial* animationMaterial = 0;
osg::ref_ptr<AnimationMaterial> animationMaterial = 0;
if (!positionData.animation_material_filename.empty())
{
@@ -3186,8 +3186,7 @@ osg::Node* SlideShowConstructor::attachMaterialAnimation(osg::Node* model, const
}
}
#else
osg::ref_ptr<osg::Object> object = osgDB::readObjectFile(positionData.animation_material_filename, _options.get());
animationMaterial = dynamic_cast<AnimationMaterial*>(object.get());
animationMaterial = osgDB::readRefFile<AnimationMaterial>(positionData.animation_material_filename, _options.get());
#endif
}
@@ -3214,7 +3213,7 @@ osg::Node* SlideShowConstructor::attachMaterialAnimation(osg::Node* model, const
{
animationMaterial->setLoopMode(positionData.animation_material_loop_mode);
AnimationMaterialCallback* animationMaterialCallback = new AnimationMaterialCallback(animationMaterial);
AnimationMaterialCallback* animationMaterialCallback = new AnimationMaterialCallback(animationMaterial.get());
animationMaterialCallback->setTimeOffset(positionData.animation_material_time_offset);
animationMaterialCallback->setTimeMultiplier(positionData.animation_material_time_multiplier);
@@ -3243,7 +3242,7 @@ osg::AnimationPathCallback* SlideShowConstructor::getAnimationPathCallback(const
osg::ref_ptr<osgDB::Options> options = _options.valid() ? _options->cloneOptions() : new osgDB::Options;
options->setObjectCacheHint(osgDB::Options::CACHE_NONE);
osg::ref_ptr<osg::Object> object = osgDB::readObjectFile(positionData.path, options.get());
osg::ref_ptr<osg::Object> object = osgDB::readRefObjectFile(positionData.path, options.get());
osg::AnimationPath* animation = dynamic_cast<osg::AnimationPath*>(object.get());
if (animation)
{

View File

@@ -50,7 +50,7 @@ osg::Node* DatabaseCacheReadCallback::readNodeFile(const std::string& filename)
}
// now load the file.
osg::ref_ptr<osg::Node> node = osgDB::readNodeFile(filename);
osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFile(filename);
// insert into the cache.
if (node.valid())

View File

@@ -205,7 +205,7 @@ void ScalarBar::createDrawables()
float characterSize = _textProperties._characterSize;
if(characterSize == 0) characterSize = _width * 0.03f;
osgText::Font* font = osgText::readFontFile(_textProperties._fontFile.c_str());
osg::ref_ptr<osgText::Font> font = osgText::readRefFontFile(_textProperties._fontFile.c_str());
std::vector<osgText::Text*> texts(_numLabels); // We'll need to collect pointers to these for later
float labelIncr = (_numLabels>0) ? (_stc->getMax()-_stc->getMin())/(_numLabels-1) : 0.0f;

View File

@@ -601,21 +601,18 @@ osg::ref_ptr<osg::Program> GeometryPool::getOrCreateProgram(LayerTypes& layerTyp
_programMap[layerTypes] = program;
// add shader that provides the lighting functions
program->addShader(osgDB::readShaderFile("shaders/lighting.vert"));
program->addShader(osgDB::readRefShaderFile("shaders/lighting.vert"));
// OSG_NOTICE<<") creating new Program "<<program.get()<<std::endl;
{
#include "shaders/terrain_displacement_mapping_vert.cpp"
osg::ref_ptr<osg::Shader> shader = osgDB::readShaderFileWithFallback(osg::Shader::VERTEX, "shaders/terrain_displacement_mapping.vert", terrain_displacement_mapping_vert);
program->addShader(shader.get());
program->addShader(osgDB::readRefShaderFileWithFallback(osg::Shader::VERTEX, "shaders/terrain_displacement_mapping.vert", terrain_displacement_mapping_vert));
}
{
#include "shaders/terrain_displacement_mapping_geom.cpp"
osg::ref_ptr<osg::Shader> shader = osgDB::readShaderFileWithFallback(osg::Shader::GEOMETRY, "shaders/terrain_displacement_mapping.geom", terrain_displacement_mapping_geom);
program->addShader(shader.get());
program->addShader(osgDB::readRefShaderFileWithFallback(osg::Shader::GEOMETRY, "shaders/terrain_displacement_mapping.geom", terrain_displacement_mapping_geom));
program->setParameter( GL_GEOMETRY_VERTICES_OUT, 4 );
program->setParameter( GL_GEOMETRY_INPUT_TYPE, GL_LINES_ADJACENCY );
@@ -629,13 +626,7 @@ osg::ref_ptr<osg::Program> GeometryPool::getOrCreateProgram(LayerTypes& layerTyp
{
#include "shaders/terrain_displacement_mapping_frag.cpp"
osg::ref_ptr<osg::Shader> shader = osgDB::readShaderFileWithFallback(osg::Shader::FRAGMENT, "shaders/terrain_displacement_mapping.frag", terrain_displacement_mapping_frag);
if (shader.valid())
{
program->addShader(shader.get());
}
program->addShader(osgDB::readRefShaderFileWithFallback(osg::Shader::FRAGMENT, "shaders/terrain_displacement_mapping.frag", terrain_displacement_mapping_frag));
}
return program;

View File

@@ -305,7 +305,7 @@ bool WhiteListTileLoadedCallback::readImageLayer(osgTerrain::ImageLayer* imageLa
{
if (layerAcceptable(imageLayer->getSetName()))
{
osg::ref_ptr<osg::Image> image = osgDB::readImageFile(imageLayer->getFileName(), options);
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile(imageLayer->getFileName(), options);
imageLayer->setImage(image.get());
}
}

View File

@@ -107,6 +107,7 @@ std::string osgText::findFontFile(const std::string& str)
return std::string();
}
#ifdef OSG_PROVIDE_READFILE
osgText::Font* osgText::readFontFile(const std::string& filename, const osgDB::ReaderWriter::Options* userOptions)
{
if (filename.empty()) return 0;
@@ -167,6 +168,7 @@ osgText::Font* osgText::readFontStream(std::istream& stream, const osgDB::Reader
if (object && object->referenceCount()==0) object->unref();
return 0;
}
#endif
osg::ref_ptr<Font> osgText::readRefFontFile(const std::string& filename, const osgDB::ReaderWriter::Options* userOptions)
{

View File

@@ -259,7 +259,7 @@ osg::Node* Style::createText(const osg::BoundingBox& extents, const AlignmentSet
osg::Node* Style::createIcon(const osg::BoundingBox& extents, const std::string& filename, const osg::Vec4& color)
{
osg::ref_ptr<osg::Object> object = osgDB::readObjectFile(filename);
osg::ref_ptr<osg::Object> object = osgDB::readRefObjectFile(filename);
if (!object)
{
//OSG_NOTICE<<"Warning: Style::createIcon(.., "<<filename<<") could not find icon file."<<std::endl;

View File

@@ -135,7 +135,7 @@ CompositeViewer::~CompositeViewer()
bool CompositeViewer::readConfiguration(const std::string& filename)
{
OSG_NOTICE<<"CompositeViewer::readConfiguration("<<filename<<")"<<std::endl;
osg::ref_ptr<osg::Object> obj = osgDB::readObjectFile(filename);
osg::ref_ptr<osg::Object> obj = osgDB::readRefObjectFile(filename);
osgViewer::View * view = dynamic_cast<osgViewer::View *>(obj.get());
if (view)
{
@@ -1114,7 +1114,7 @@ void CompositeViewer::eventTraversal()
// create a frame event for the new frame.
{
osg::ref_ptr<osgGA::GUIEventAdapter> event = view->getEventQueue()->frame( getFrameStamp()->getReferenceTime() );
if (!_previousEvent || _previousEvent->getNumPointerData()<2)
{
generatePointerData(*event);
@@ -1124,7 +1124,7 @@ void CompositeViewer::eventTraversal()
reprojectPointerData(*_previousEvent, *event);
}
}
view->getEventQueue()->takeEvents(viewEventsMap[view], cutOffTime);
}

View File

@@ -573,7 +573,7 @@ bool Keystone::loadKeystoneFiles(osg::DisplaySettings* ds)
++itr)
{
const std::string& filename = *itr;
osg::ref_ptr<osgViewer::Keystone> keystone = osgDB::readFile<osgViewer::Keystone>(filename);
osg::ref_ptr<osgViewer::Keystone> keystone = osgDB::readRefFile<osgViewer::Keystone>(filename);
if (keystone.valid())
{
keystone->setUserValue("filename",filename);

View File

@@ -165,7 +165,7 @@ Viewer::Viewer(osg::ArgumentParser& arguments)
std::string intensityMapFilename;
while (arguments.read("--im",intensityMapFilename)) {}
osg::ref_ptr<osg::Image> intensityMap = intensityMapFilename.empty() ? 0 : osgDB::readImageFile(intensityMapFilename);
osg::ref_ptr<osg::Image> intensityMap = intensityMapFilename.empty() ? 0 : osgDB::readRefImageFile(intensityMapFilename);
if (screenNum<0) screenNum = 0;
@@ -297,7 +297,7 @@ bool Viewer::readConfiguration(const std::string& filename)
{
OSG_INFO<<"Viewer::readConfiguration("<<filename<<")"<<std::endl;
osg::ref_ptr<osg::Object> object = osgDB::readObjectFile(filename);
osg::ref_ptr<osg::Object> object = osgDB::readRefObjectFile(filename);
if (!object)
{
//OSG_NOTICE<<"Error: Unable to load configuration file \""<<filename<<"\""<<std::endl;
@@ -308,7 +308,7 @@ bool Viewer::readConfiguration(const std::string& filename)
if (config)
{
OSG_INFO<<"Using osgViewer::Config : "<<config->className()<<std::endl;
config->configure(*this);
//osgDB::writeObjectFile(*config,"test.osgt");
@@ -986,7 +986,7 @@ void Viewer::eventTraversal()
// create a frame event for the new frame.
{
osg::ref_ptr<osgGA::GUIEventAdapter> event = _eventQueue->frame( getFrameStamp()->getReferenceTime() );
if (!eventState || eventState->getNumPointerData()<2)
{
generatePointerData(*event);
@@ -996,7 +996,7 @@ void Viewer::eventTraversal()
reprojectPointerData(*eventState, *event);
}
}
// OSG_NOTICE<<"mouseEventState Xmin = "<<eventState->getXmin()<<" Ymin="<<eventState->getYmin()<<" xMax="<<eventState->getXmax()<<" Ymax="<<eventState->getYmax()<<std::endl;
_eventQueue->takeEvents(events, cutOffTime);

View File

@@ -105,7 +105,7 @@ bool Browser::assign(BrowserImage* browserImage, const GeometryHints& hints)
bool Browser::open(const std::string& hostname, const GeometryHints& hints)
{
osg::ref_ptr<osg::Image> image = osgDB::readImageFile(hostname+".gecko");
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile(hostname+".gecko");
return assign(dynamic_cast<BrowserImage*>(image.get()), hints);
}

View File

@@ -67,7 +67,7 @@ bool PdfReader::assign(PdfImage* pdfImage, const GeometryHints& hints)
osg::StateAttribute::ON);
osg::ref_ptr<osgViewer::InteractiveImageHandler> iih = new osgViewer::InteractiveImageHandler(_pdfImage.get());
pictureQuad->setEventCallback(iih.get());
pictureQuad->setCullCallback(iih.get());
@@ -78,7 +78,7 @@ bool PdfReader::assign(PdfImage* pdfImage, const GeometryHints& hints)
bool PdfReader::open(const std::string& filename, const GeometryHints& hints)
{
osg::ref_ptr<osg::Image> image = osgDB::readImageFile(filename);
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile(filename);
return assign(dynamic_cast<PdfImage*>(image.get()), hints);
}

View File

@@ -62,7 +62,7 @@ bool VncClient::assign(VncImage* vncImage, const GeometryHints& hints)
osg::StateAttribute::ON);
osg::ref_ptr<osgViewer::InteractiveImageHandler> iih = new osgViewer::InteractiveImageHandler(_vncImage.get());
pictureQuad->setEventCallback(iih.get());
pictureQuad->setCullCallback(iih.get());
@@ -73,7 +73,7 @@ bool VncClient::assign(VncImage* vncImage, const GeometryHints& hints)
bool VncClient::connect(const std::string& hostname, const GeometryHints& hints)
{
osg::ref_ptr<osg::Image> image = osgDB::readImageFile(hostname+".vnc");
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile(hostname+".vnc");
return assign(dynamic_cast<VncImage*>(image.get()), hints);
}

View File

@@ -339,7 +339,8 @@ bool Widget::setImage(const std::string& filePath, bool setTexCoords, bool useTe
return false;
}
return setImage(osgDB::readImageFile(filePath), setTexCoords, useTextRect);
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile(filePath);
return setImage(image.get(), setTexCoords, useTextRect);
}
bool Widget::setTexture(osg::Texture* texture, bool setTexCoords, bool useTextRect) {

View File

@@ -147,7 +147,7 @@ bool ProxyNode_readLocalData(Object& obj, Input& fr)
{
osgDB::FilePathList& fpl = ((osgDB::ReaderWriter::Options*)fr.getOptions())->getDatabasePathList();
fpl.push_front( fpl.empty() ? osgDB::getFilePath(proxyNode.getFileName(i)) : fpl.front()+'/'+ osgDB::getFilePath(proxyNode.getFileName(i)));
osg::Node *node = osgDB::readNodeFile(proxyNode.getFileName(i), fr.getOptions());
osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFile(proxyNode.getFileName(i), fr.getOptions());
fpl.pop_front();
if(node)
{

View File

@@ -46,7 +46,7 @@ bool Shader_readLocalData(Object& obj, Input& fr)
if (fr.matchSequence("file %w") || fr.matchSequence("file %s") )
{
osg::ref_ptr<Shader> s = osgDB::readShaderFile(fr[1].getStr(), fr.getOptions());
osg::ref_ptr<Shader> s = osgDB::readRefShaderFile(fr[1].getStr(), fr.getOptions());
if(s.get())
shader.setShaderSource(s->getShaderSource());
else

View File

@@ -41,7 +41,7 @@ bool Texture1D_readLocalData(Object& obj, Input& fr)
if (fr[0].matchWord("file") && fr[1].isString())
{
std::string filename = fr[1].getStr();
Image* image = fr.readImage(filename.c_str());
osg::ref_ptr<Image> image = fr.readImage(filename.c_str());
if (image)
{
// name will have already been set by the image plugin,
@@ -57,7 +57,7 @@ bool Texture1D_readLocalData(Object& obj, Input& fr)
if (fr[0].matchWord("ImageSequence") || fr[0].matchWord("Image"))
{
osg::Image* image = fr.readImage();
osg::ref_ptr<osg::Image> image = fr.readImage();
if (image) texture.setImage(image);
}

View File

@@ -50,7 +50,7 @@ bool Texture2D_readLocalData(Object& obj, Input& fr)
if (fr[0].matchWord("file") && fr[1].isString())
{
std::string filename = fr[1].getStr();
Image* image = fr.readImage(filename.c_str());
osg::ref_ptr<Image> image = fr.readImage(filename.c_str());
if (image)
{
// name will have already been set by the image plugin,
@@ -66,7 +66,7 @@ bool Texture2D_readLocalData(Object& obj, Input& fr)
if (fr[0].matchWord("ImageSequence") || fr[0].matchWord("Image"))
{
osg::Image* image = fr.readImage();
osg::ref_ptr<osg::Image> image = fr.readImage();
if (image) texture.setImage(image);
}

View File

@@ -33,12 +33,10 @@ bool Texture2DArray_readLocalData(Object& obj, Input& fr)
Texture2DArray& texture = static_cast<Texture2DArray&>(obj);
while (fr[0].matchWord("file") ||
fr[0].matchWord("ImageSequence") ||
fr[0].matchWord("Image") && matched)
while (matched && (fr[0].matchWord("file") || fr[0].matchWord("ImageSequence") || fr[0].matchWord("Image")))
{
matched = false;
Image* image = NULL;
osg::ref_ptr<Image> image;
if (fr[0].matchWord("file") && fr[1].isString())
{
std::string filename = fr[1].getStr();
@@ -62,8 +60,8 @@ bool Texture2DArray_readLocalData(Object& obj, Input& fr)
textureW = image->s();
textureH = image->t();
}
else if(textureW != image->s() ||
textureH != image->t())
else if(textureW != image->s() ||
textureH != image->t())
{
//scale to match size of first image.
image->scaleImage(textureW,textureH,1);
@@ -108,4 +106,4 @@ bool Texture2DArray_writeLocalData(const Object& obj, Output& fw)
}
}
return true;
}
}

View File

@@ -41,7 +41,7 @@ bool Texture3D_readLocalData(Object& obj, Input& fr)
if (fr[0].matchWord("file") && fr[1].isString())
{
std::string filename = fr[1].getStr();
Image* image = fr.readImage(filename.c_str());
osg::ref_ptr<Image> image = fr.readImage(filename.c_str());
if (image)
{
// name will have already been set by the image plugin,
@@ -57,7 +57,7 @@ bool Texture3D_readLocalData(Object& obj, Input& fr)
if (fr[0].matchWord("ImageSequence") || fr[0].matchWord("Image"))
{
osg::Image* image = fr.readImage();
osg::ref_ptr<osg::Image> image = fr.readImage();
if (image) texture.setImage(image);
}

View File

@@ -38,8 +38,8 @@ REGISTER_DOTOSGWRAPPER(TextureCubeMap)
} \
else if (fr[2].isString())\
{ \
Image* image = fr.readImage(fr[2].getStr());\
if (image) texture.setImage(osg::TextureCubeMap::FACE,image);\
osg::ref_ptr<Image> image = fr.readImage(fr[2].getStr());\
if (image) texture.setImage(osg::TextureCubeMap::FACE,image.get());\
fr += 3;\
iteratorAdvanced = true; \
matched = true;\

View File

@@ -41,7 +41,7 @@ bool TextureRectangle_readLocalData(Object& obj, Input& fr)
if (fr[0].matchWord("file") && fr[1].isString())
{
std::string filename = fr[1].getStr();
Image* image = fr.readImage(filename.c_str());
osg::ref_ptr<Image> image = fr.readImage(filename.c_str());
if (image)
{
// name will have already been set by the image plugin,
@@ -57,7 +57,7 @@ bool TextureRectangle_readLocalData(Object& obj, Input& fr)
if (fr[0].matchWord("ImageSequence") || fr[0].matchWord("Image"))
{
osg::Image* image = fr.readImage();
osg::ref_ptr<osg::Image> image = fr.readImage();
if (image) texture.setImage(image);
}

View File

@@ -31,9 +31,9 @@ bool AnisotropicLighting_readLocalData(osg::Object &obj, osgDB::Input &fr)
}
if (fr[0].matchWord("lightingMapFileName") && fr[1].isString()) {
osg::Image *lmap = fr.readImage(fr[1].getStr());
osg::ref_ptr<osg::Image> lmap = fr.readImage(fr[1].getStr());
if (lmap) {
myobj.setLightingMap(lmap);
myobj.setLightingMap(lmap.get());
}
fr += 2;
itAdvanced = true;

View File

@@ -38,7 +38,7 @@ bool HeightFieldLayer_readLocalData(osg::Object& obj, osgDB::Input &fr)
osgTerrain::extractSetNameAndFileName(fr[1].getStr(),setname, filename);
if (!filename.empty())
{
osg::ref_ptr<osg::HeightField> hf = osgDB::readHeightFieldFile(filename);
osg::ref_ptr<osg::HeightField> hf = osgDB::readRefHeightFieldFile(filename);
if (hf.valid())
{
layer.setName(setname);

View File

@@ -143,7 +143,7 @@ bool TerrainTile_readLocalData(osg::Object& obj, osgDB::Input &fr)
if (fr.matchSequence("ProxyFile %s") || fr.matchSequence("ProxyFile %w") )
{
osg::ref_ptr<osg::Object> image = osgDB::readObjectFile(std::string(fr[1].getStr())+".gdal");
osg::ref_ptr<osg::Object> image = osgDB::readRefObjectFile(std::string(fr[1].getStr())+".gdal");
osgTerrain::ProxyLayer* proxyLayer = dynamic_cast<osgTerrain::ProxyLayer*>(image.get());
if (proxyLayer)
{

View File

@@ -54,12 +54,12 @@ static osg::Camera::Attachment readBufferAttachment( osgDB::InputStream& is )
else if ( type==1 )
{
is >> is.PROPERTY("Image");
attachment._image = dynamic_cast<osg::Image*>( is.readObject() );
attachment._image = is.readObjectOfType<osg::Image>();
}
else if ( type==2 )
{
is >> is.PROPERTY("Texture");
attachment._texture = dynamic_cast<osg::Texture*>( is.readObject() );
attachment._texture = is.readObjectOfType<osg::Texture>();
is >> is.PROPERTY("Level") >> attachment._level;
is >> is.PROPERTY("Face") >> attachment._face;
is >> is.PROPERTY("MipMapGeneration") >> attachment._mipMapGeneration;

View File

@@ -13,7 +13,7 @@ static bool readChildren( osgDB::InputStream& is, osg::CompositeShape& shape )
unsigned int size = 0; is >> size >> is.BEGIN_BRACKET;
for ( unsigned int i=0; i<size; ++i )
{
osg::Shape* child = dynamic_cast<osg::Shape*>( is.readObject() );
osg::ref_ptr<osg::Shape> child = is.readObjectOfType<osg::Shape>();
if ( child ) shape.addChild( child );
}
is >> is.END_BRACKET;

View File

@@ -15,7 +15,7 @@ static bool readDrawables( osgDB::InputStream& is, osg::Geode& node )
unsigned int size = 0; is >> size >> is.BEGIN_BRACKET;
for ( unsigned int i=0; i<size; ++i )
{
osg::Drawable* drawable = dynamic_cast<osg::Drawable*>( is.readObject() );
osg::ref_ptr<osg::Drawable> drawable = is.readObjectOfType<osg::Drawable>();
if ( drawable )
{
node.addDrawable( drawable );

View File

@@ -31,17 +31,18 @@ static bool checkHeights( const osg::HeightField& shape )
static bool readHeights( osgDB::InputStream& is, osg::HeightField& shape )
{
osg::FloatArray* array = dynamic_cast<osg::FloatArray*>( is.readArray() );
if ( array )
osg::ref_ptr<osg::Array> array = is.readArray();
osg::FloatArray* farray = dynamic_cast<osg::FloatArray*>( array.get() );
if ( farray )
{
unsigned int numCols = shape.getNumColumns(), numRows = shape.getNumRows();
if ( array->size()<numRows*numCols ) return false;
if ( farray->size()<numRows*numCols ) return false;
unsigned int index = 0;
for ( unsigned int r=0; r<numRows; ++r )
{
for ( unsigned int c=0; c<numCols; ++c )
shape.setHeight( c, r, (*array)[index++] );
shape.setHeight( c, r, (*farray)[index++] );
}
}
return true;

View File

@@ -48,7 +48,7 @@ static bool readImages( osgDB::InputStream& is, osg::ImageSequence& image )
unsigned int images = is.readSize(); is >> is.BEGIN_BRACKET;
for ( unsigned int i=0; i<images; ++i )
{
osg::Image* img = dynamic_cast<osg::Image*>( is.readObject() );
osg::ref_ptr<osg::Image> img = is.readImage();
if ( img ) image.addImage( img );
}
is >> is.END_BRACKET;

View File

@@ -14,7 +14,7 @@ static bool checkUserData( const osg::Object& obj )
static bool readUserData( osgDB::InputStream& is, osg::Object& obj )
{
is >> is.BEGIN_BRACKET;
osg::Object* object = is.readObject();
osg::ref_ptr<osg::Object> object = is.readObject();
if(object) obj.setUserData(object);
is >> is.END_BRACKET;
return true;

View File

@@ -102,7 +102,7 @@ static bool readChildren( osgDB::InputStream& is, osg::PagedLOD& node )
is >> is.BEGIN_BRACKET;
for ( unsigned int i=0; i<size; ++i )
{
osg::Node* child = dynamic_cast<osg::Node*>( is.readObject() );
osg::ref_ptr<osg::Node> child = is.readObjectOfType<osg::Node>();
if ( child ) node.addChild( child );
}
is >> is.END_BRACKET;

View File

@@ -58,7 +58,7 @@ static bool readShaders( osgDB::InputStream& is, osg::Program& attr )
unsigned int size = is.readSize(); is >> is.BEGIN_BRACKET;
for ( unsigned int i=0; i<size; ++i )
{
osg::Shader* shader = dynamic_cast<osg::Shader*>( is.readObject() );
osg::ref_ptr<osg::Shader> shader = is.readObjectOfType<osg::Shader>();
if ( shader ) attr.addShader( shader );
}
is >> is.END_BRACKET;

View File

@@ -50,7 +50,7 @@ static bool readChildren( osgDB::InputStream& is, osg::ProxyNode& node )
is >> is.BEGIN_BRACKET;
for ( unsigned int i=0; i<size; ++i )
{
osg::Node* child = dynamic_cast<osg::Node*>( is.readObject() );
osg::ref_ptr<osg::Node> child = is.readObjectOfType<osg::Node>();
if ( child ) node.addChild( child );
}
is >> is.END_BRACKET;
@@ -117,7 +117,7 @@ struct ProxyNodeFinishedObjectReadCallback : public osgDB::FinishedObjectReadCal
{
osgDB::FilePathList& fpl = ((osgDB::ReaderWriter::Options*)is.getOptions())->getDatabasePathList();
fpl.push_front( fpl.empty() ? osgDB::getFilePath(proxyNode.getFileName(i)) : fpl.front()+'/'+ osgDB::getFilePath(proxyNode.getFileName(i)));
osg::Node* node = osgDB::readNodeFile(proxyNode.getFileName(i), is.getOptions());
osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFile(proxyNode.getFileName(i), is.getOptions());
fpl.pop_front();
if(node)
proxyNode.insertChild(i, node);

View File

@@ -46,7 +46,7 @@ static void readAttributes( osgDB::InputStream& is, osg::StateSet::AttributeList
is >> is.BEGIN_BRACKET;
for ( unsigned int i=0; i<size; ++i )
{
osg::StateAttribute* sa = dynamic_cast<osg::StateAttribute*>( is.readObject() );
osg::ref_ptr<osg::StateAttribute> sa = is.readObjectOfType<osg::StateAttribute>();
is >> is.PROPERTY("Value");
int value = readValue( is );
if ( sa )
@@ -144,7 +144,7 @@ static bool readAttributeList( osgDB::InputStream& is, osg::StateSet& ss )
for ( osg::StateSet::AttributeList::iterator itr=attrs.begin();
itr!=attrs.end(); ++itr )
{
ss.setAttribute( itr->second.first.get(), itr->second.second );
ss.setAttribute( itr->second.first, itr->second.second );
}
return true;
}
@@ -211,7 +211,7 @@ static bool readTextureAttributeList( osgDB::InputStream& is, osg::StateSet& ss
for ( osg::StateSet::AttributeList::iterator itr=attrs.begin();
itr!=attrs.end(); ++itr )
{
ss.setTextureAttribute( i, itr->second.first.get(), itr->second.second );
ss.setTextureAttribute( i, itr->second.first, itr->second.second );
}
attrs.clear();
}
@@ -244,7 +244,7 @@ static bool readUniformList( osgDB::InputStream& is, osg::StateSet& ss )
unsigned int size = is.readSize(); is >> is.BEGIN_BRACKET;
for ( unsigned int i=0; i<size; ++i )
{
osg::Uniform* uniform = dynamic_cast<osg::Uniform*>( is.readObject() );
osg::ref_ptr<osg::Uniform> uniform = is.readObjectOfType<osg::Uniform>();
is >> is.PROPERTY("Value");
int value = readValue( is );
if ( uniform )

View File

@@ -13,7 +13,7 @@ static bool readImages( osgDB::InputStream& is, osg::Texture2DArray& tex )
unsigned int size = 0; is >> size >> is.BEGIN_BRACKET;
for ( unsigned int i=0; i<size; ++i )
{
osg::Image* image = is.readImage();
osg::ref_ptr<osg::Image> image = is.readImage();
if ( image ) tex.setImage( i, image );
}
is >> is.END_BRACKET;

View File

@@ -8,7 +8,8 @@
return shape.get##PROP()!=NULL; \
} \
static bool read##PROP(osgDB::InputStream& is, osg::TriangleMesh& shape) { \
shape.set##PROP( dynamic_cast<TYPE*>(is.readArray()) ); \
osg::ref_ptr<osg::Array> array = is.readArray(); \
shape.set##PROP( dynamic_cast<TYPE*>(array.get()) ); \
return true; \
} \
static bool write##PROP(osgDB::OutputStream& os, const osg::TriangleMesh& shape) { \

View File

@@ -13,17 +13,17 @@ static bool readElements( osgDB::InputStream& is, osg::Uniform& uniform )
bool hasArray; is >> hasArray;
if ( hasArray )
{
osg::Array* array = is.readArray();
osg::ref_ptr<osg::Array> array = is.readArray();
switch ( array->getType() )
{
case osg::Array::FloatArrayType:
uniform.setArray( static_cast<osg::FloatArray*>(array) ); break;
uniform.setArray( static_cast<osg::FloatArray*>(array.get()) ); break;
case osg::Array::DoubleArrayType:
uniform.setArray( static_cast<osg::DoubleArray*>(array) ); break;
uniform.setArray( static_cast<osg::DoubleArray*>(array.get()) ); break;
case osg::Array::IntArrayType:
uniform.setArray( static_cast<osg::IntArray*>(array) ); break;
uniform.setArray( static_cast<osg::IntArray*>(array.get()) ); break;
case osg::Array::UIntArrayType:
uniform.setArray( static_cast<osg::UIntArray*>(array) ); break;
uniform.setArray( static_cast<osg::UIntArray*>(array.get()) ); break;
default: break;
}
}

View File

@@ -12,7 +12,7 @@ static bool checkUDC_UserData( const osg::DefaultUserDataContainer& udc )
static bool readUDC_UserData( osgDB::InputStream& is, osg::DefaultUserDataContainer& udc )
{
is >> is.BEGIN_BRACKET;
osg::Object* object = is.readObject();
osg::ref_ptr<osg::Object> object = is.readObject();
if(object) udc.setUserData(object);
is >> is.END_BRACKET;
return true;
@@ -70,7 +70,7 @@ static bool readUDC_UserObjects( osgDB::InputStream& is, osg::DefaultUserDataCon
unsigned int size = is.readSize(); is >> is.BEGIN_BRACKET;
for( unsigned int i=0; i<size; ++i )
{
osg::Object* read_object = is.readObject();
osg::ref_ptr<osg::Object> read_object = is.readObject();
if (read_object) udc.addUserObject( read_object );
}
is >> is.END_BRACKET;

View File

@@ -17,9 +17,8 @@ static bool readStackedTransforms( osgDB::InputStream& is, osgAnimation::UpdateM
unsigned int size = is.readSize(); is >> is.BEGIN_BRACKET;
for ( unsigned int i=0; i<size; ++i )
{
osgAnimation::StackedTransformElement* element =
dynamic_cast<osgAnimation::StackedTransformElement*>( is.readObject() );
if ( element ) transform.push_back( element );
osg::ref_ptr<osgAnimation::StackedTransformElement> element = is.readObjectOfType<osgAnimation::StackedTransformElement>();
if ( element ) transform.push_back( element.get() );
}
is >> is.END_BRACKET;
return true;

View File

@@ -13,7 +13,8 @@ static bool checkLightingMap( const osgFX::AnisotropicLighting& effect )
static bool readLightingMap( osgDB::InputStream& is, osgFX::AnisotropicLighting& effect )
{
std::string fileName; is.readWrappedString( fileName );
effect.setLightingMap( osgDB::readImageFile(fileName) );
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile(fileName, is.getOptions());
effect.setLightingMap( image.get() );
return true;
}

View File

@@ -13,7 +13,7 @@ static bool readDraggers( osgDB::InputStream& is, osgManipulator::CompositeDragg
unsigned int size = 0; is >> size >> is.BEGIN_BRACKET;
for ( unsigned int i=0; i<size; ++i )
{
osgManipulator::Dragger* child = dynamic_cast<osgManipulator::Dragger*>( is.readObject() );
osg::ref_ptr<osgManipulator::Dragger> child = is.readObjectOfType<osgManipulator::Dragger>();
if ( child ) dragger.addDragger( child );
}
is >> is.END_BRACKET;

View File

@@ -18,8 +18,8 @@ static bool readTransformUpdating( osgDB::InputStream& is, osgManipulator::Dragg
std::string name; is >> name >> is.BEGIN_BRACKET;
if ( name=="DraggerTransformCallback" )
{
osg::MatrixTransform* transform = dynamic_cast<osg::MatrixTransform*>( is.readObject() );
if ( transform ) dragger.addTransformUpdating( transform );
osg::ref_ptr<osg::MatrixTransform> transform = is.readObjectOfType<osg::MatrixTransform>();
if ( transform ) dragger.addTransformUpdating( transform.get() );
}
is >> is.END_BRACKET;
}

View File

@@ -7,7 +7,7 @@
static bool check##PROP( const osgManipulator::Scale1DDragger& dragger ) \
{ return dragger.get##PROP()!=NULL; } \
static bool read##PROP( osgDB::InputStream& is, osgManipulator::Scale1DDragger& dragger ) { \
osg::Node* node = dynamic_cast<osg::Node*>( is.readObject() ); \
osg::ref_ptr<osg::Node> node = is.readObjectOfType<osg::Node>(); \
if ( node ) dragger.set##PROP( *node ); return true; \
} \
static bool write##PROP( osgDB::OutputStream& os, const osgManipulator::Scale1DDragger& dragger ) { \

View File

@@ -7,7 +7,7 @@
static bool check##PROP( const osgManipulator::Scale2DDragger& dragger ) \
{ return dragger.get##PROP()!=NULL; } \
static bool read##PROP( osgDB::InputStream& is, osgManipulator::Scale2DDragger& dragger ) { \
osg::Node* node = dynamic_cast<osg::Node*>( is.readObject() ); \
osg::ref_ptr<osg::Node> node = is.readObjectOfType<osg::Node>(); \
if ( node ) dragger.set##PROP( *node ); return true; \
} \
static bool write##PROP( osgDB::OutputStream& os, const osgManipulator::Scale2DDragger& dragger ) { \

View File

@@ -13,8 +13,8 @@ static bool readPlacers( osgDB::InputStream& is, osgParticle::CompositePlacer& c
unsigned int size = 0; is >> size >> is.BEGIN_BRACKET;
for ( unsigned int i=0; i<size; ++i )
{
osgParticle::Placer* p = dynamic_cast<osgParticle::Placer*>( is.readObject() );
if ( p ) cp.addPlacer( p );
osg::ref_ptr<osgParticle::Placer> p = is.readObjectOfType<osgParticle::Placer>();
if ( p ) cp.addPlacer( p.get() );
}
is >> is.END_BRACKET;
return true;

View File

@@ -13,8 +13,8 @@ static bool readOperators( osgDB::InputStream& is, osgParticle::ModularProgram&
unsigned int size = 0; is >> size >> is.BEGIN_BRACKET;
for ( unsigned int i=0; i<size; ++i )
{
osgParticle::Operator* op = dynamic_cast<osgParticle::Operator*>( is.readObject() );
if ( op ) prog.addOperator( op );
osg::ref_ptr<osgParticle::Operator> op = is.readObjectOfType<osgParticle::Operator>();
if ( op ) prog.addOperator( op.get() );
}
is >> is.END_BRACKET;
return true;

View File

@@ -35,21 +35,21 @@ bool readParticle( osgDB::InputStream& is, osgParticle::Particle& p )
if ( hasInterpolator )
{
is >> is.BEGIN_BRACKET;
p.setSizeInterpolator( static_cast<osgParticle::Interpolator*>(is.readObject()) );
p.setAlphaInterpolator( is.readObjectOfType<osgParticle::Interpolator>() );
is >> is.END_BRACKET;
}
is >> is.PROPERTY("AlphaInterpolator") >> hasInterpolator;
if ( hasInterpolator )
{
is >> is.BEGIN_BRACKET;
p.setAlphaInterpolator( static_cast<osgParticle::Interpolator*>(is.readObject()) );
p.setAlphaInterpolator( is.readObjectOfType<osgParticle::Interpolator>() );
is >> is.END_BRACKET;
}
is >> is.PROPERTY("ColorInterpolator") >> hasInterpolator;
if ( hasInterpolator )
{
is >> is.BEGIN_BRACKET;
p.setColorInterpolator( static_cast<osgParticle::Interpolator*>(is.readObject()) );
p.setAlphaInterpolator( is.readObjectOfType<osgParticle::Interpolator>() );
is >> is.END_BRACKET;
}
@@ -73,7 +73,7 @@ bool readParticle( osgDB::InputStream& is, osgParticle::Particle& p )
if ( hasObject )
{
is >> is.BEGIN_BRACKET;
p.setDrawable( dynamic_cast<osg::Drawable*>(is.readObject()) );
p.setDrawable( is.readObjectOfType<osg::Drawable>() );
is >> is.END_BRACKET;
}

View File

@@ -13,7 +13,8 @@ static bool readParticleSystem( osgDB::InputStream& is, osgParticle::ParticleEff
{
is >> is.BEGIN_BRACKET;
effect.setUseLocalParticleSystem( false );
effect.setParticleSystem( static_cast<osgParticle::ParticleSystem*>(is.readObject()) );
osg::ref_ptr<osgParticle::ParticleSystem> ps = is.readObjectOfType<osgParticle::ParticleSystem>();
effect.setParticleSystem( ps.get() );
is >> is.END_BRACKET;
return true;
}

View File

@@ -13,8 +13,8 @@ static bool readParticleSystems( osgDB::InputStream& is, osgParticle::ParticleSy
unsigned int size = 0; is >> size >> is.BEGIN_BRACKET;
for ( unsigned int i=0; i<size; ++i )
{
osgParticle::ParticleSystem* ps = dynamic_cast<osgParticle::ParticleSystem*>( is.readObject() );
if ( ps ) updater.addParticleSystem( ps );
osg::ref_ptr<osgParticle::ParticleSystem> ps = is.readObjectOfType<osgParticle::ParticleSystem>();
if ( ps ) updater.addParticleSystem( ps.get() );
}
is >> is.END_BRACKET;
return true;

View File

@@ -26,14 +26,14 @@ static bool readLightPointList( osgDB::InputStream& is, osgSim::LightPointNode&
if ( hasObject )
{
is >> is.BEGIN_BRACKET;
pt._sector = dynamic_cast<osgSim::Sector*>( is.readObject() );
pt._sector = is.readObjectOfType<osgSim::Sector>();
is >> is.END_BRACKET;
}
hasObject = false; is >> is.PROPERTY("BlinkSequence") >> hasObject;
if ( hasObject )
{
is >> is.BEGIN_BRACKET;
pt._blinkSequence = dynamic_cast<osgSim::BlinkSequence*>( is.readObject() );
pt._blinkSequence = is.readObjectOfType<osgSim::BlinkSequence>();
is >> is.END_BRACKET;
}
is >> is.END_BRACKET;

View File

@@ -17,7 +17,7 @@ static bool readLayers( osgDB::InputStream& is, osgTerrain::CompositeLayer& laye
is >> type;
if ( type=="Object" )
{
osgTerrain::Layer* child = dynamic_cast<osgTerrain::Layer*>( is.readObject() );
osg::ref_ptr<osgTerrain::Layer> child = is.readObjectOfType<osgTerrain::Layer>();
if ( child ) layer.addLayer( child );
}
else if ( type=="File" )

View File

@@ -36,7 +36,7 @@ static bool readColorLayers( osgDB::InputStream& is, osgTerrain::TerrainTile& ti
for ( unsigned int i=0; i<numValidLayers; ++i )
{
unsigned int layerNum=0; is >> is.PROPERTY("Layer") >> layerNum;
osgTerrain::Layer* layer = dynamic_cast<osgTerrain::Layer*>( is.readObject() );
osg::ref_ptr<osgTerrain::Layer> layer = is.readObjectOfType<osgTerrain::Layer>();
if ( layer ) tile.setColorLayer( layerNum, layer );
}
is >> is.END_BRACKET;

View File

@@ -12,7 +12,8 @@ static bool checkFont( const osgText::TextBase& text )
static bool readFont( osgDB::InputStream& is, osgText::TextBase& text )
{
std::string fontName; is.readWrappedString( fontName );
text.setFont( osgText::readFontFile(fontName) );
osg::ref_ptr<osgText::Font> font = osgText::readRefFontFile(fontName);
text.setFont( font );
return true;
}
@@ -77,11 +78,12 @@ static bool readText( osgDB::InputStream& is, osgText::TextBase& text )
}
else
{
osg::UIntArray* array = dynamic_cast<osg::UIntArray*>( is.readArray() );
if ( array )
osg::ref_ptr<osg::Array> array = is.readArray();
osg::UIntArray* uiarray = dynamic_cast<osg::UIntArray*>( array.get() );
if ( uiarray )
{
osgText::String string;
for ( osg::UIntArray::iterator itr=array->begin(); itr!=array->end(); ++itr )
for ( osg::UIntArray::iterator itr=uiarray->begin(); itr!=uiarray->end(); ++itr )
{
string.push_back( *itr );
}

View File

@@ -13,7 +13,7 @@ static bool readLayers( osgDB::InputStream& is, osgVolume::CompositeLayer& layer
unsigned int size = 0; is >> size >> is.BEGIN_BRACKET;
for ( unsigned int i=0; i<size; ++i )
{
osgVolume::Layer* child = dynamic_cast<osgVolume::Layer*>( is.readObject() );
osg::ref_ptr<osgVolume::Layer> child = is.readObjectOfType<osgVolume::Layer>();
if ( child ) layer.addLayer( child );
}
is >> is.END_BRACKET;

View File

@@ -13,7 +13,7 @@ static bool readProperties( osgDB::InputStream& is, osgVolume::CompositeProperty
unsigned int size = 0; is >> size >> is.BEGIN_BRACKET;
for ( unsigned int i=0; i<size; ++i )
{
osgVolume::Property* child = dynamic_cast<osgVolume::Property*>( is.readObject() );
osg::ref_ptr<osgVolume::Property> child = is.readObjectOfType<osgVolume::Property>();
if ( child ) prop.addProperty( child );
}
is >> is.END_BRACKET;

View File

@@ -13,8 +13,7 @@ static bool readLocatorCallbacks( osgDB::InputStream& is, osgVolume::Locator& lo
unsigned int size = is.readSize(); is >> is.BEGIN_BRACKET;
for ( unsigned int i=0; i<size; ++i )
{
osgVolume::Locator::LocatorCallback* cb =
dynamic_cast<osgVolume::Locator::LocatorCallback*>( is.readObject() );
osg::ref_ptr<osgVolume::Locator::LocatorCallback> cb = is.readObjectOfType<osgVolume::Locator::LocatorCallback>();
if ( cb ) locator.addCallback( cb );
}
is >> is.END_BRACKET;