From Serge Lages, introduce readRef*File() methods which pass back ref_ptr<> rather than C pointers.
This commit is contained in:
@@ -344,7 +344,7 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl
|
||||
_activeGraphicsContexts.end(),
|
||||
bind1st(mem_fun(&osg::Texture::getTextureObject),
|
||||
texture))
|
||||
== _activeGraphicsContexts.size());
|
||||
== (int)_activeGraphicsContexts.size());
|
||||
}
|
||||
|
||||
inline static bool isCompiled(const osg::StateSet* stateSet,
|
||||
@@ -376,7 +376,7 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl
|
||||
_activeGraphicsContexts.end(),
|
||||
bind1st(mem_fun(&osg::Texture::getTextureObject),
|
||||
texture))
|
||||
!= _activeGraphicsContexts.size()))
|
||||
!= (int)_activeGraphicsContexts.size()))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -402,7 +402,7 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl
|
||||
_activeGraphicsContexts.end(),
|
||||
bind1st(mem_fun(&osg::Drawable::getDisplayList),
|
||||
drawable))
|
||||
== _activeGraphicsContexts.size());
|
||||
== (int)_activeGraphicsContexts.size());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,6 @@ inline osg::Object* readObjectFile(const std::string& filename)
|
||||
return readObjectFile(filename,Registry::instance()->getOptions());
|
||||
}
|
||||
|
||||
|
||||
/** Read an osg::Image from file.
|
||||
* Return valid osg::Image on success,
|
||||
* return NULL on failure.
|
||||
@@ -133,6 +132,88 @@ inline osg::Node* readNodeFiles(osg::ArgumentParser& parser)
|
||||
return readNodeFiles(parser,Registry::instance()->getOptions());
|
||||
}
|
||||
|
||||
|
||||
/** Read an osg::Object from file.
|
||||
* Return an assigned osg::ref_ptr on success,
|
||||
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
|
||||
* Use the Options object to control cache operations and file search paths in osgDB::Registry.
|
||||
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
|
||||
* for the filename extension, and this plugin then handles the request
|
||||
* to read the specified file.*/
|
||||
extern OSGDB_EXPORT osg::ref_ptr<osg::Object> readRefObjectFile(const std::string& filename,const ReaderWriter::Options* options);
|
||||
|
||||
/** Read an osg::Object from file.
|
||||
* Return an assigned osg::ref_ptr on success,
|
||||
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
|
||||
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
|
||||
* for the filename extension, and this plugin then handles the request
|
||||
* to read the specified file.*/
|
||||
inline osg::ref_ptr<osg::Object> readRefObjectFile(const std::string& filename)
|
||||
{
|
||||
return readRefObjectFile(filename,Registry::instance()->getOptions());
|
||||
}
|
||||
|
||||
/** Read an osg::Image from file.
|
||||
* Return an assigned osg::ref_ptr on success,
|
||||
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
|
||||
* Use the Options object to control cache operations and file search paths in osgDB::Registry.
|
||||
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
|
||||
* for the filename extension, and this plugin then handles the request
|
||||
* to read the specified file.*/
|
||||
extern OSGDB_EXPORT osg::ref_ptr<osg::Image> readRefImageFile(const std::string& filename,const ReaderWriter::Options* options);
|
||||
|
||||
/** Read an osg::Image from file.
|
||||
* Return an assigned osg::ref_ptr on success,
|
||||
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
|
||||
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
|
||||
* for the filename extension, and this plugin then handles the request
|
||||
* to read the specified file.*/
|
||||
inline osg::ref_ptr<osg::Image> readRefImageFile(const std::string& filename)
|
||||
{
|
||||
return readRefImageFile(filename,Registry::instance()->getOptions());
|
||||
}
|
||||
|
||||
/** Read an osg::HeightField from file.
|
||||
* Return an assigned osg::ref_ptr on success,
|
||||
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
|
||||
* Use the Options object to control cache operations and file search paths in osgDB::Registry.
|
||||
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
|
||||
* for the filename extension, and this plugin then handles the request
|
||||
* to read the specified file.*/
|
||||
extern OSGDB_EXPORT osg::ref_ptr<osg::HeightField> readRefHeightFieldFile(const std::string& filename,const ReaderWriter::Options* options);
|
||||
|
||||
/** Read an osg::HeightField from file.
|
||||
* Return an assigned osg::ref_ptr on success,
|
||||
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
|
||||
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
|
||||
* for the filename extension, and this plugin then handles the request
|
||||
* to read the specified file.*/
|
||||
inline osg::ref_ptr<osg::HeightField> readRefHeightFieldFile(const std::string& filename)
|
||||
{
|
||||
return readRefHeightFieldFile(filename,Registry::instance()->getOptions());
|
||||
}
|
||||
|
||||
/** Read an osg::Node from file.
|
||||
* Return an assigned osg::ref_ptr on success,
|
||||
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
|
||||
* Use the Options object to control cache operations and file search paths in osgDB::Registry.
|
||||
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
|
||||
* for the filename extension, and this plugin then handles the request
|
||||
* to read the specified file.*/
|
||||
extern OSGDB_EXPORT osg::ref_ptr<osg::Node> readRefNodeFile(const std::string& filename,const ReaderWriter::Options* options);
|
||||
|
||||
/** Read an osg::Node from file.
|
||||
* Return an assigned osg::ref_ptr on success,
|
||||
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
|
||||
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
|
||||
* for the filename extension, and this plugin then handles the request
|
||||
* to read the specified file.*/
|
||||
inline osg::ref_ptr<osg::Node> readRefNodeFile(const std::string& filename)
|
||||
{
|
||||
return readRefNodeFile(filename,Registry::instance()->getOptions());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -59,6 +59,10 @@ extern OSGTEXT_EXPORT Font* readFontFile(const std::string& filename, const osgD
|
||||
/** read a font from specified stream.*/
|
||||
extern OSGTEXT_EXPORT Font* readFontStream(std::istream& stream, const osgDB::ReaderWriter::Options* userOptions = 0);
|
||||
|
||||
extern OSGTEXT_EXPORT osg::ref_ptr<Font> readRefFontFile(const std::string& filename, const osgDB::ReaderWriter::Options* userOptions = 0);
|
||||
|
||||
extern OSGTEXT_EXPORT osg::ref_ptr<Font> readRefFontStream(std::istream& stream, const osgDB::ReaderWriter::Options* userOptions = 0);
|
||||
|
||||
extern OSGTEXT_EXPORT std::string findFontFile(const std::string& str);
|
||||
|
||||
/** Pure virtual base class for fonts.
|
||||
|
||||
@@ -54,6 +54,10 @@ extern OSGTEXT_EXPORT Font3D* readFont3DFile(const std::string& filename, const
|
||||
/** read a font from specified stream.*/
|
||||
extern OSGTEXT_EXPORT Font3D* readFont3DStream(std::istream& stream, const osgDB::ReaderWriter::Options* userOptions = 0);
|
||||
|
||||
extern OSGTEXT_EXPORT osg::ref_ptr<Font3D> readRefFont3DFile(const std::string& filename, const osgDB::ReaderWriter::Options* userOptions = 0);
|
||||
|
||||
extern OSGTEXT_EXPORT osg::ref_ptr<Font3D> readRefFont3DStream(std::istream& stream, const osgDB::ReaderWriter::Options* userOptions = 0);
|
||||
|
||||
extern OSGTEXT_EXPORT std::string findFont3DFile(const std::string& str);
|
||||
|
||||
/** Pure virtual base class for fonts.
|
||||
|
||||
@@ -687,13 +687,13 @@ void DatabasePager::run()
|
||||
// do *not* assume that we only have one DatabasePager, or that reaNodeFile is thread safe...
|
||||
static OpenThreads::Mutex s_serialize_readNodeFile_mutex;
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_serialize_readNodeFile_mutex);
|
||||
databaseRequest->_loadedModel = osgDB::readNodeFile(databaseRequest->_fileName,
|
||||
databaseRequest->_loadedModel = osgDB::readRefNodeFile(databaseRequest->_fileName,
|
||||
databaseRequest->_loadOptions.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
// assume that we only have one DatabasePager, or that readNodeFile is thread safe...
|
||||
databaseRequest->_loadedModel = osgDB::readNodeFile(databaseRequest->_fileName,
|
||||
databaseRequest->_loadedModel = osgDB::readRefNodeFile(databaseRequest->_fileName,
|
||||
databaseRequest->_loadOptions.get());
|
||||
}
|
||||
|
||||
|
||||
@@ -238,3 +238,35 @@ Node* osgDB::readNodeFiles(osg::ArgumentParser& arguments,const ReaderWriter::Op
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Object> osgDB::readRefObjectFile(const std::string& filename,const ReaderWriter::Options* options)
|
||||
{
|
||||
ReaderWriter::ReadResult rr = Registry::instance()->readObject(filename,options);
|
||||
if (rr.validObject()) return osg::ref_ptr<osg::Object>(rr.getObject());
|
||||
if (rr.error()) notify(WARN) << rr.message() << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Image> osgDB::readRefImageFile(const std::string& filename,const ReaderWriter::Options* options)
|
||||
{
|
||||
ReaderWriter::ReadResult rr = Registry::instance()->readImage(filename,options);
|
||||
if (rr.validImage()) return osg::ref_ptr<osg::Image>(rr.getImage());
|
||||
if (rr.error()) notify(WARN) << rr.message() << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::HeightField> osgDB::readRefHeightFieldFile(const std::string& filename,const ReaderWriter::Options* options)
|
||||
{
|
||||
ReaderWriter::ReadResult rr = Registry::instance()->readHeightField(filename,options);
|
||||
if (rr.validHeightField()) return osg::ref_ptr<osg::HeightField>(rr.getHeightField());
|
||||
if (rr.error()) notify(WARN) << rr.message() << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Node> osgDB::readRefNodeFile(const std::string& filename,const ReaderWriter::Options* options)
|
||||
{
|
||||
ReaderWriter::ReadResult rr = Registry::instance()->readNode(filename,options);
|
||||
if (rr.validNode()) return osg::ref_ptr<osg::Node>(rr.getNode());
|
||||
if (rr.error()) notify(WARN) << rr.message() << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -151,6 +151,59 @@ osgText::Font* osgText::readFontStream(std::istream& stream, const osgDB::Reader
|
||||
return 0;
|
||||
}
|
||||
|
||||
osg::ref_ptr<Font> osgText::readRefFontFile(const std::string& filename, const osgDB::ReaderWriter::Options* userOptions)
|
||||
{
|
||||
if (filename=="") return 0;
|
||||
|
||||
std::string foundFile = findFontFile(filename);
|
||||
if (foundFile.empty()) return 0;
|
||||
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_FontFileMutex);
|
||||
|
||||
osg::ref_ptr<osgDB::ReaderWriter::Options> localOptions;
|
||||
if (!userOptions)
|
||||
{
|
||||
localOptions = new osgDB::ReaderWriter::Options;
|
||||
localOptions->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_OBJECTS);
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Object> object = osgDB::readRefObjectFile(foundFile, userOptions ? userOptions : localOptions.get());
|
||||
|
||||
// if the object is a font then return it.
|
||||
osgText::Font* font = dynamic_cast<osgText::Font*>(object.get());
|
||||
if (font) return osg::ref_ptr<Font>(font);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
osg::ref_ptr<Font> osgText::readRefFontStream(std::istream& stream, const osgDB::ReaderWriter::Options* userOptions)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_FontFileMutex);
|
||||
|
||||
osg::ref_ptr<osgDB::ReaderWriter::Options> localOptions;
|
||||
if (!userOptions)
|
||||
{
|
||||
localOptions = new osgDB::ReaderWriter::Options;
|
||||
localOptions->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_OBJECTS);
|
||||
}
|
||||
|
||||
// there should be a better way to get the FreeType ReaderWriter by name...
|
||||
osgDB::ReaderWriter *reader = osgDB::Registry::instance()->getReaderWriterForExtension("ttf");
|
||||
if (reader == 0) return 0;
|
||||
osgDB::ReaderWriter::ReadResult rr = reader->readObject(stream, userOptions ? userOptions : localOptions.get());
|
||||
if (rr.error())
|
||||
{
|
||||
osg::notify(osg::WARN) << rr.message() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
if (!rr.validObject()) return 0;
|
||||
|
||||
// if the object is a font then return it.
|
||||
osgText::Font* font = dynamic_cast<osgText::Font*>(rr.getObject());
|
||||
if (font) return osg::ref_ptr<Font>(font);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Font::Font(FontImplementation* implementation):
|
||||
osg::Object(true),
|
||||
|
||||
@@ -168,6 +168,72 @@ osgText::Font3D* readFont3DStream(std::istream& stream, const osgDB::ReaderWrite
|
||||
return 0;
|
||||
}
|
||||
|
||||
osg::ref_ptr<Font3D> readRefFont3DFile(const std::string& filename, const osgDB::ReaderWriter::Options* userOptions)
|
||||
{
|
||||
if (filename=="") return 0;
|
||||
|
||||
std::string foundFile = findFont3DFile(filename);
|
||||
if (foundFile.empty()) return 0;
|
||||
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_Font3DFileMutex);
|
||||
|
||||
osg::ref_ptr<osgDB::ReaderWriter::Options> localOptions;
|
||||
if (!userOptions)
|
||||
{
|
||||
localOptions = new osgDB::ReaderWriter::Options;
|
||||
localOptions->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_OBJECTS);
|
||||
// ** HACK to load Font3D instead of Font
|
||||
localOptions->setPluginData("3D", (void*) 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
userOptions->setPluginData("3D", (void*) 1);
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Object> object = osgDB::readRefObjectFile(foundFile, userOptions ? userOptions : localOptions.get());
|
||||
|
||||
// if the object is a font then return it.
|
||||
osgText::Font3D* font3D = dynamic_cast<osgText::Font3D*>(object.get());
|
||||
if (font3D) return osg::ref_ptr<Font3D>(font3D);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
osg::ref_ptr<Font3D> readRefFont3DStream(std::istream& stream, const osgDB::ReaderWriter::Options* userOptions)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_Font3DFileMutex);
|
||||
|
||||
osg::ref_ptr<osgDB::ReaderWriter::Options> localOptions;
|
||||
if (!userOptions)
|
||||
{
|
||||
localOptions = new osgDB::ReaderWriter::Options;
|
||||
localOptions->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_OBJECTS);
|
||||
localOptions->setPluginData("3D", (void*) 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
userOptions->setPluginData("3D", (void*) 1);
|
||||
}
|
||||
|
||||
// there should be a better way to get the FreeType ReaderWriter by name...
|
||||
osgDB::ReaderWriter *reader = osgDB::Registry::instance()->getReaderWriterForExtension("ttf");
|
||||
if (reader == 0) return 0;
|
||||
|
||||
osgDB::ReaderWriter::ReadResult rr = reader->readObject(stream, userOptions ? userOptions : localOptions.get());
|
||||
if (rr.error())
|
||||
{
|
||||
osg::notify(osg::WARN) << rr.message() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
if (!rr.validObject()) return 0;
|
||||
|
||||
// if the object is a font then return it.
|
||||
osgText::Font3D* font3D = dynamic_cast<osgText::Font3D*>(rr.getObject());
|
||||
if (font3D) return osg::ref_ptr<Font3D>(font3D);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Font3D::Font3D(Font3DImplementation* implementation):
|
||||
osg::Object(true),
|
||||
_depth(1),
|
||||
|
||||
@@ -86,7 +86,7 @@ void Text::setFont(Font* font)
|
||||
|
||||
void Text::setFont(const std::string& fontfile)
|
||||
{
|
||||
setFont(readFontFile(fontfile));
|
||||
setFont(readRefFontFile(fontfile).get());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ void Text3D::setFont(Font3D * font)
|
||||
|
||||
void Text3D::setFont(const std::string & fontfile)
|
||||
{
|
||||
setFont(readFont3DFile(fontfile));
|
||||
setFont(readRefFont3DFile(fontfile).get());
|
||||
}
|
||||
|
||||
String::iterator Text3D::computeLastCharacterOnLine(osg::Vec2& cursor, String::iterator first,String::iterator last)
|
||||
|
||||
Reference in New Issue
Block a user