14 #ifndef OSGDB_REGISTRY
15 #define OSGDB_REGISTRY 1
17 #include <OpenThreads/ReentrantMutex>
19 #include <osg/ref_ptr>
20 #include <osg/ArgumentParser>
23 #include <osgDB/DynamicLibrary>
24 #include <osgDB/ReaderWriter>
25 #include <osgDB/Options>
26 #include <osgDB/DotOsgWrapper>
27 #include <osgDB/ObjectWrapper>
28 #include <osgDB/FileCache>
29 #include <osgDB/ObjectCache>
30 #include <osgDB/SharedStateManager>
31 #include <osgDB/ImageProcessor>
60 static Registry* instance(
bool erase =
false);
70 void addFileExtensionAlias(
const std::string mapExt,
const std::string toExt);
75 bool readPluginAliasConfigurationFile(
const std::string& file );
83 void addMimeTypeExtensionMapping(
const std::string fromMimeType,
const std::string toExt);
94 std::string createLibraryNameForFile(
const std::string& fileName);
97 std::string createLibraryNameForExtension(
const std::string& ext);
100 std::string createLibraryNameForNodeKit(
const std::string& name);
110 LoadStatus loadLibrary(
const std::string& fileName);
113 bool closeLibrary(
const std::string& fileName);
116 void closeAllLibraries();
121 ReaderWriter* getReaderWriterForExtension(
const std::string& ext);
125 ReaderWriter* getReaderWriterForMimeType(
const std::string& mimeType);
134 void getReaderWriterListForProtocol(
const std::string& protocol, ReaderWriterList& results)
const;
136 ReaderWriter* getReaderWriterForProtocolAndExtension(
const std::string& protocol,
const std::string& extension);
145 ImageProcessor* getImageProcessorForExtension(
const std::string& ext);
172 else if (_findFileCallback.valid())
return _findFileCallback->findDataFile(fileName, options, caseSensitivity);
173 else return findDataFileImplementation(fileName, options, caseSensitivity);
175 std::string findDataFileImplementation(
const std::string& fileName,
const Options* options,
CaseSensitivity caseSensitivity);
180 else if (_findFileCallback.valid())
return _findFileCallback->findLibraryFile(fileName, options, caseSensitivity);
181 else return findLibraryFileImplementation(fileName, options, caseSensitivity);
183 std::string findLibraryFileImplementation(
const std::string& fileName,
const Options* options,
CaseSensitivity caseSensitivity);
200 else if (_readFileCallback.valid())
return _readFileCallback->openArchive(fileName, status, indexBlockSizeHint, options);
201 else return openArchiveImplementation(fileName, status, indexBlockSizeHint, options);
209 else if (_readFileCallback.valid()) result = _readFileCallback->readObject(fileName,options);
210 else result = readObjectImplementation(fileName,options);
212 if (buildKdTreeIfRequired) _buildKdTreeIfRequired(result, options);
221 else if (_readFileCallback.valid())
return _readFileCallback->readImage(fileName,options);
222 else return readImageImplementation(fileName,options);
229 else if (_readFileCallback.valid())
return _readFileCallback->readHeightField(fileName,options);
230 else return readHeightFieldImplementation(fileName,options);
238 else if (_readFileCallback.valid()) result = _readFileCallback->readNode(fileName,options);
239 else result = readNodeImplementation(fileName,options);
241 if (buildKdTreeIfRequired) _buildKdTreeIfRequired(result, options);
250 if (_readFileCallback.valid())
return _readFileCallback->readShader(fileName,options);
251 else return readShaderImplementation(fileName,options);
258 else if (_readFileCallback.valid())
return _readFileCallback->readScript(fileName,options);
259 else return readScriptImplementation(fileName,options);
277 else if (_writeFileCallback.valid())
return _writeFileCallback->writeObject(obj,fileName,options);
278 else return writeObjectImplementation(obj,fileName,options);
285 else if (_writeFileCallback.valid())
return _writeFileCallback->writeImage(obj,fileName,options);
286 else return writeImageImplementation(obj,fileName,options);
293 else if (_writeFileCallback.valid())
return _writeFileCallback->writeHeightField(obj,fileName,options);
294 else return writeHeightFieldImplementation(obj,fileName,options);
301 else if (_writeFileCallback.valid())
return _writeFileCallback->writeNode(node,fileName,options);
302 else return writeNodeImplementation(node,fileName,options);
309 else if (_writeFileCallback.valid())
return _writeFileCallback->writeShader(obj,fileName,options);
310 else return writeShaderImplementation(obj,fileName,options);
317 else if (_writeFileCallback.valid())
return _writeFileCallback->writeScript(obj,fileName,options);
318 else return writeScriptImplementation(obj,fileName,options);
328 if (doKdTreeBuilder && _kdTreeBuilder.valid() && result.
validNode())
391 void initDataFilePathList();
407 void initLibraryFilePathList();
443 void updateTimeStampOfObjectsInCacheWithExternalReferences(
const osg::FrameStamp& frameStamp);
452 void clearObjectCache();
455 void addEntryToObjectCache(
const std::string& filename,
osg::Object*
object,
double timestamp = 0.0);
458 void removeFromObjectCache(
const std::string& fileName);
461 osg::Object* getFromObjectCache(
const std::string& fileName);
469 void addToArchiveCache(
const std::string& fileName,
osgDB::Archive* archive);
472 void removeFromArchiveCache(
const std::string& fileName);
481 void clearArchiveCache();
501 void addArchiveExtension(
const std::string ext);
504 void registerProtocol(
const std::string& protocol);
507 bool isProtocolRegistered(
const std::string& protocol);
525 typedef std::map<std::string, osg::ref_ptr<osgDB::Archive> >
ArchiveCache;
535 DynamicLibraryList::iterator getLibraryItr(
const std::string& fileName);
559 virtual bool isValid(
osg::Object*
object)
const = 0;
572 struct ReadObjectFunctor;
573 struct ReadImageFunctor;
574 struct ReadHeightFieldFunctor;
575 struct ReadNodeFunctor;
576 struct ReadArchiveFunctor;
577 struct ReadShaderFunctor;
578 struct ReadScriptFunctor;
582 friend struct ReadObjectFunctor;
583 friend struct ReadImageFunctor;
584 friend struct ReadHeightFieldFunctor;
585 friend struct ReadNodeFunctor;
586 friend struct ReadArchiveFunctor;
587 friend struct ReadShaderFunctor;
588 friend struct ReadScriptFunctor;
595 class AvailableReaderWriterIterator;
596 friend class AvailableReaderWriterIterator;
597 class AvailableArchiveIterator;
598 friend class AvailableArchiveIterator;
623 static std::string trim(
const std::string& str );
672 T*
get() {
return _rw.get(); }
701 T*
get() {
return _rw.get(); }
712 #define USE_OSGPLUGIN(ext) \
713 extern "C" void osgdb_##ext(void); \
714 static osgDB::PluginFunctionProxy proxy_##ext(osgdb_##ext);
716 #define USE_DOTOSGWRAPPER(classname) \
717 extern "C" void dotosgwrapper_##classname(void); \
718 static osgDB::PluginFunctionProxy proxy_dotosgwrapper_##classname(dotosgwrapper_##classname);
720 #define USE_DOTOSGWRAPPER_LIBRARY(libname) \
721 extern "C" void dotosgwrapper_library_##libname(void); \
722 static osgDB::PluginFunctionProxy proxy_dotosgwrapper_library_##libname(dotosgwrapper_library_##libname);
724 #define USE_SERIALIZER_WRAPPER(classname) \
725 extern "C" void wrapper_serializer_##classname(void); \
726 static osgDB::PluginFunctionProxy proxy_serializer_##classname(wrapper_serializer_##classname);
728 #define USE_SERIALIZER_WRAPPER_LIBRARY(libname) \
729 extern "C" void wrapper_serializer_library_##libname(void); \
730 static osgDB::PluginFunctionProxy proxy_serializer_library_##libname(wrapper_serializer_library_##libname);
732 #define USE_COMPRESSOR_WRAPPER(classname) \
733 extern "C" void wrapper_compressor_##classname(void); \
734 static osgDB::PluginFunctionProxy proxy_compressor_##classname(wrapper_compressor_##classname);
736 #define REGISTER_OSGPLUGIN(ext, classname) \
737 extern "C" void osgdb_##ext(void) {} \
738 static osgDB::RegisterReaderWriterProxy<classname> g_proxy_##classname;
740 #define REGISTER_OSGIMAGEPROCESSOR(ext, classname) \
741 extern "C" void osgdb_##ext(void) {} \
742 static osgDB::RegisterImageProcessorProxy<classname> g_proxy_##classname;
std::map< std::string, std::string > MimeTypeExtensionMap
virtual ReaderWriter::WriteResult writeObject(const osg::Object &obj, const std::string &fileName, const Options *options)
WriteFileCallback * getWriteFileCallback() const
ReaderWriter::ReadResult readImage(const std::string &fileName, const Options *options)
ArchiveCache _archiveCache
CacheHintOptions
bit mask for setting up which object types get cached by readObject/Image/HeightField/Node(filename) ...
const MimeTypeExtensionMap & getMimeTypeExtensionMap() const
void setDataFilePathList(const FilePathList &filepath)
void setOptions(Options *opt)
BuildKdTreesHint getBuildKdTreesHint() const
ReaderWriter::WriteResult writeImage(const osg::Image &obj, const std::string &fileName, const Options *options)
ObjectWrapperManager * getObjectWrapperManager()
virtual ReaderWriter::ReadResult readHeightField(const std::string &filename, const Options *options)
BuildKdTreesHint
range of options of whether to build kdtrees automatically on loading
class osgDB::ReadFileCallback ReadFileCallback
Options::BuildKdTreesHint _buildKdTreesHint
void setDataFilePathList(const FilePathList &filepath)
virtual ReaderWriter::ReadResult openArchive(const std::string &filename, ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, const Options *useObjectCache)
bool getCreateNodeFromImage() const
virtual ReaderWriter::WriteResult writeImage(const osg::Image &obj, const std::string &fileName, const Options *options)
osg::ref_ptr< FindFileCallback > _findFileCallback
ReaderWriter::WriteResult writeNode(const osg::Node &node, const std::string &fileName, const Options *options)
virtual ReaderWriter::WriteResult writeScript(const osg::Script &obj, const std::string &fileName, const Options *options)
osg::ref_ptr< WriteFileCallback > _writeFileCallback
class osgDB::WriteFileCallback WriteFileCallback
AuthenticationMap * getAuthenticationMap()
osg::ref_ptr< SharedStateManager > _sharedStateManager
void setExpiryDelay(double expiryDelay)
WriteFileCallback * getWriteFileCallback()
ReaderWriterList & getReaderWriterList()
ReadFileCallback * getReadFileCallback() const
ReaderWriter::WriteResult writeShader(const osg::Shader &obj, const std::string &fileName, const Options *options)
const FileCache * getFileCache() const
void setObjectCache(ObjectCache *objectCache)
ReadFileCallback * getReadFileCallback()
void removeReaderWriter(ReaderWriter *rw)
std::set< std::string > RegisteredProtocolsSet
virtual ReaderWriter::ReadResult readNode(const std::string &filename, const Options *options)
FilePathList & getDataFilePathList()
ReaderWriter::WriteResult writeScript(const osg::Script &obj, const std::string &fileName, const Options *options)
std::vector< osg::ref_ptr< DynamicLibrary > > DynamicLibraryList
void readCommandLine(osg::ArgumentParser &parser)
void setWriteFileCallback(WriteFileCallback *cb)
ImageProcessorList _ipList
const AuthenticationMap * getAuthenticationMap() const
void setFileLocationCallback(FileLocationCallback *cb)
OpenThreads::ReentrantMutex _archiveCacheMutex
DynamicLibraryList _dlList
virtual ReaderWriter::WriteResult writeShader(const osg::Shader &obj, const std::string &fileName, const Options *options)
const FilePathList & getLibraryFilePathList() const
osg::ref_ptr< DeprecatedDotOsgWrapperManager > _deprecatedDotOsgWrapperManager
ReaderWriter::WriteResult writeHeightField(const osg::HeightField &obj, const std::string &fileName, const Options *options)
ReaderWriter::ReadResult openArchive(const std::string &fileName, ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, const Options *options)
void readCommandLine(osg::ArgumentParser &commandLine)
FileCache * getFileCache()
ObjectCache * getObjectCache()
const ImageProcessorList & getImageProcessorList() const
void addReaderWriter(ReaderWriter *rw)
ExtensionAliasMap _extAliasMap
osg::ref_ptr< ObjectCache > _objectCache
const ReaderWriterList & getReaderWriterList() const
virtual ReaderWriter::WriteResult writeNode(const osg::Node &obj, const std::string &fileName, const Options *options)
virtual ReaderWriter::ReadResult readScript(const std::string &filename, const Options *options)
void removeImageProcessor(ImageProcessor *ip)
osg::ref_ptr< FileCache > _fileCache
class osgDB::FindFileCallback FindFileCallback
ImageProcessorList & getImageProcessorList()
std::map< std::string, osg::ref_ptr< osgDB::Archive > > ArchiveCache
typedef void(GL_APIENTRY *GLTexImage3DProc)(GLenum target
std::string findLibraryFile(const std::string &fileName, const Options *options, CaseSensitivity caseSensitivity)
void setSharedStateManager(SharedStateManager *SharedStateManager)
virtual ReaderWriter::ReadResult readImage(const std::string &filename, const Options *options)
T * cloneType(const T *t)
virtual Object * clone(const CopyOp &) const =0
class osgDB::FileLocationCallback FileLocationCallback
SharedStateManager * getSharedStateManager()
virtual void accept(NodeVisitor &nv)
void setBuildKdTreesHint(Options::BuildKdTreesHint hint)
void setAuthenticationMap(AuthenticationMap *authenticationMap)
virtual ReaderWriter::ReadResult readObject(const std::string &filename, const Options *options)
double getExpiryDelay() const
void setKdTreeBuilder(osg::KdTreeBuilder *builder)
ReadFunctor(const std::string &filename, const Options *options)
osg::ref_ptr< Options > _options
std::map< std::string, std::string > ExtensionAliasMap
void _buildKdTreeIfRequired(ReaderWriter::ReadResult &result, const Options *options)
MimeTypeExtensionMap & getMimeTypeExtensionMap()
ArchiveExtensionList _archiveExtList
void addImageProcessor(ImageProcessor *ip)
void setLibraryFilePathList(const FilePathList &filepaths)
void setFindFileCallback(FindFileCallback *cb)
ReaderWriter::ReadResult readScript(const std::string &fileName, const Options *options)
Options::BuildKdTreesHint getBuildKdTreesHint() const
const WriteFileCallback * getWriteFileCallback() const
std::deque< std::string > FilePathList
void setReadFileCallback(ReadFileCallback *cb)
osg::ref_ptr< ObjectWrapperManager > _objectWrapperManager
~RegisterReaderWriterProxy()
std::vector< osg::ref_ptr< ImageProcessor > > ImageProcessorList
void setCreateNodeFromImage(bool flag)
const Options * getOptions() const
RegisteredProtocolsSet _registeredProtocols
ReaderWriter::WriteResult writeObject(const osg::Object &obj, const std::string &fileName, const Options *options)
osg::ref_ptr< osg::KdTreeBuilder > _kdTreeBuilder
const ReadFileCallback * getReadFileCallback() const
ReaderWriter::ReadResult readObject(const std::string &fileName, const Options *options, bool buildKdTreeIfRequired=true)
static Registry * instance(bool erase=false)
PluginFunctionProxy(CPluginFunction function)
FindFileCallback * getFindFileCallback()
std::vector< osg::ref_ptr< ReaderWriter > > ReaderWriterList
const ObjectCache * getObjectCache() const
FilePathList _libraryFilePath
void setFileCache(FileCache *fileCache)
ReaderWriter::ReadResult readNode(const std::string &fileName, const Options *options, bool buildKdTreeIfRequired=true)
osg::ref_ptr< AuthenticationMap > _authenticationMap
osg::KdTreeBuilder * getKdTreeBuilder()
OpenThreads::ReentrantMutex _pluginMutex
osg::ref_ptr< ReadFileCallback > _readFileCallback
FileLocationCallback * getFileLocationCallback() const
FilePathList & getLibraryFilePathList()
const ArchiveExtensionList & getArchiveExtensions() const
MimeTypeExtensionMap _mimeTypeExtMap
std::vector< std::string > ArchiveExtensionList
ReaderWriter::ReadResult readShader(const std::string &fileName, const Options *options)
virtual ReaderWriter::WriteResult writeHeightField(const osg::HeightField &obj, const std::string &fileName, const Options *options)
bool _createNodeFromImage
~RegisterImageProcessorProxy()
const FilePathList & getDataFilePathList() const
RegisterImageProcessorProxy()
virtual std::string findLibraryFile(const std::string &filename, const Options *options, CaseSensitivity caseSensitivity)
void setLibraryFilePathList(const FilePathList &filepath)
RegisterReaderWriterProxy()
virtual ReaderWriter::ReadResult readShader(const std::string &filename, const Options *options)
FilePathList _dataFilePath
std::string findDataFile(const std::string &fileName, const Options *options, CaseSensitivity caseSensitivity)
void(* CPluginFunction)(void)
virtual std::string findDataFile(const std::string &filename, const Options *options, CaseSensitivity caseSensitivity)
ReaderWriter::ReadResult readHeightField(const std::string &fileName, const Options *options)
osg::ref_ptr< FileLocationCallback > _fileLocationCallback
DeprecatedDotOsgWrapperManager * getDeprecatedDotOsgObjectWrapperManager()
FindFileCallback * getFindFileCallback() const
const FindFileCallback * getFindFileCallback() const