1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
15#define OSGDB_REGISTRY 1
17#include <OpenThreads/ReentrantMutex>
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>
39 typedef void (* CPluginFunction) (void);
46 Registry is a singleton factory which stores
47 the reader/writers which are linked in
48 at runtime for reading non-native file formats.
50 The RegisterReaderWriterProxy can be used to automatically
51 register at runtime a reader/writer with the Registry.
53class OSGDB_EXPORT Registry : public osg::Referenced
60 static Registry* instance(bool erase = false);
62 /** read the command line arguments.*/
63 void readCommandLine(osg::ArgumentParser& commandLine);
65 /** register an .fileextension alias to mapExt toExt, the later
66 * should be the extension name of the readerwriter plugin library.
67 * For example to map .tif files to the tiff loader, use
68 * addExtAlias("tif","tiff") which will enable .tif to be read
69 * by the libdb_tiff readerwriter plugin.*/
70 void addFileExtensionAlias(const std::string mapExt, const std::string toExt);
72 /** Reads a file that configures extension mappings. File is ASCII text
73 * and each line contains the parameters to the addFileExtensionAlias
74 * method. Lines can be commented out with an initial '#' character.*/
75 bool readPluginAliasConfigurationFile( const std::string& file );
77 typedef std::map< std::string, std::string> MimeTypeExtensionMap;
79 /** Registers a mapping of a mime-type to an extension. A process fetching data
80 * over HTTP can use this facility to determine the proper ReaderWriter to use
81 * when there is no filename extension to rely upon.
83 void addMimeTypeExtensionMapping(const std::string fromMimeType, const std::string toExt);
84 MimeTypeExtensionMap& getMimeTypeExtensionMap() { return _mimeTypeExtMap; }
85 const MimeTypeExtensionMap& getMimeTypeExtensionMap() const { return _mimeTypeExtMap; }
87 void addReaderWriter(ReaderWriter* rw);
88 void removeReaderWriter(ReaderWriter* rw);
90 void addImageProcessor(ImageProcessor* ip);
91 void removeImageProcessor(ImageProcessor* ip);
93 /** create the platform specific library name associated with file.*/
94 std::string createLibraryNameForFile(const std::string& fileName);
96 /** create the platform specific library name associated with file extension.*/
97 std::string createLibraryNameForExtension(const std::string& ext);
99 /** create the platform specific library name associated with nodekit library name.*/
100 std::string createLibraryNameForNodeKit(const std::string& name);
109 /** find the library in the OSG_LIBRARY_PATH and load it.*/
110 LoadStatus loadLibrary(const std::string& fileName);
112 /** close the attached library with specified name.*/
113 bool closeLibrary(const std::string& fileName);
115 /** close all libraries.*/
116 void closeAllLibraries();
118 typedef std::vector< osg::ref_ptr<ReaderWriter> > ReaderWriterList;
120 /** get a reader writer which handles specified extension.*/
121 ReaderWriter* getReaderWriterForExtension(const std::string& ext);
123 /** gets a reader/writer that handles the extension mapped to by one of
124 * the registered mime-types. */
125 ReaderWriter* getReaderWriterForMimeType(const std::string& mimeType);
127 /** get list of all registered ReaderWriters.*/
128 ReaderWriterList& getReaderWriterList() { return _rwList; }
130 /** get const list of all registered ReaderWriters.*/
131 const ReaderWriterList& getReaderWriterList() const { return _rwList; }
133 /** get a list of registered ReaderWriters which can handle given protocol */
134 void getReaderWriterListForProtocol(const std::string& protocol, ReaderWriterList& results) const;
136 ReaderWriter* getReaderWriterForProtocolAndExtension(const std::string& protocol, const std::string& extension);
139 typedef std::vector< osg::ref_ptr<ImageProcessor> > ImageProcessorList;
141 /** get a image processor if available.*/
142 ImageProcessor* getImageProcessor();
144 /** get a image processor which is associated specified extension.*/
145 ImageProcessor* getImageProcessorForExtension(const std::string& ext);
147 /** get list of all registered ImageProcessors.*/
148 ImageProcessorList& getImageProcessorList() { return _ipList; }
150 /** get const list of all registered ImageProcessors.*/
151 const ImageProcessorList& getImageProcessorList() const { return _ipList; }
154 typedef class osgDB::FindFileCallback FindFileCallback;
155 typedef class osgDB::ReadFileCallback ReadFileCallback;
156 typedef class osgDB::WriteFileCallback WriteFileCallback;
157 typedef class osgDB::FileLocationCallback FileLocationCallback;
159 /** Set the Registry callback to use in place of the default findFile calls.*/
160 void setFindFileCallback( FindFileCallback* cb) { _findFileCallback = cb; }
162 /** Get the findFile callback.*/
163 FindFileCallback* getFindFileCallback() { return _findFileCallback.get(); }
165 /** Get the const findFile callback.*/
166 const FindFileCallback* getFindFileCallback() const { return _findFileCallback.get(); }
169 std::string findDataFile(const std::string& fileName, const Options* options, CaseSensitivity caseSensitivity)
171 if (options && options->getFindFileCallback()) return options->getFindFileCallback()->findDataFile(fileName, options, caseSensitivity);
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);
177 std::string findLibraryFile(const std::string& fileName, const Options* options, CaseSensitivity caseSensitivity)
179 if (options && options->getFindFileCallback()) return options->getFindFileCallback()->findLibraryFile(fileName, options, 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);
187 /** Set the Registry callback to use in place of the default readFile calls.*/
188 void setReadFileCallback( ReadFileCallback* cb) { _readFileCallback = cb; }
190 /** Get the readFile callback.*/
191 ReadFileCallback* getReadFileCallback() { return _readFileCallback.get(); }
193 /** Get the const readFile callback.*/
194 const ReadFileCallback* getReadFileCallback() const { return _readFileCallback.get(); }
197 ReaderWriter::ReadResult openArchive(const std::string& fileName,ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, const Options* options)
199 if (options && options->getReadFileCallback()) return options->getReadFileCallback()->openArchive(fileName, status, indexBlockSizeHint, options);
200 else if (_readFileCallback.valid()) return _readFileCallback->openArchive(fileName, status, indexBlockSizeHint, options);
201 else return openArchiveImplementation(fileName, status, indexBlockSizeHint, options);
203 ReaderWriter::ReadResult openArchiveImplementation(const std::string& fileName, ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, const Options* options);
205 ReaderWriter::ReadResult readObject(const std::string& fileName,const Options* options, bool buildKdTreeIfRequired=true)
207 ReaderWriter::ReadResult result;
208 if (options && options->getReadFileCallback()) result = options->getReadFileCallback()->readObject(fileName,options);
209 else if (_readFileCallback.valid()) result = _readFileCallback->readObject(fileName,options);
210 else result = readObjectImplementation(fileName,options);
212 if (buildKdTreeIfRequired) _buildKdTreeIfRequired(result, options);
216 ReaderWriter::ReadResult readObjectImplementation(const std::string& fileName,const Options* options);
218 ReaderWriter::ReadResult readImage(const std::string& fileName,const Options* options)
220 if (options && options->getReadFileCallback()) return options->getReadFileCallback()->readImage(fileName,options);
221 else if (_readFileCallback.valid()) return _readFileCallback->readImage(fileName,options);
222 else return readImageImplementation(fileName,options);
224 ReaderWriter::ReadResult readImageImplementation(const std::string& fileName,const Options* options);
226 ReaderWriter::ReadResult readHeightField(const std::string& fileName,const Options* options)
228 if (options && options->getReadFileCallback()) return options->getReadFileCallback()->readHeightField(fileName,options);
229 else if (_readFileCallback.valid()) return _readFileCallback->readHeightField(fileName,options);
230 else return readHeightFieldImplementation(fileName,options);
232 ReaderWriter::ReadResult readHeightFieldImplementation(const std::string& fileName,const Options* options);
234 ReaderWriter::ReadResult readNode(const std::string& fileName,const Options* options, bool buildKdTreeIfRequired=true)
236 ReaderWriter::ReadResult result;
237 if (options && options->getReadFileCallback()) result = options->getReadFileCallback()->readNode(fileName,options);
238 else if (_readFileCallback.valid()) result = _readFileCallback->readNode(fileName,options);
239 else result = readNodeImplementation(fileName,options);
241 if (buildKdTreeIfRequired) _buildKdTreeIfRequired(result, options);
245 ReaderWriter::ReadResult readNodeImplementation(const std::string& fileName,const Options* options);
247 ReaderWriter::ReadResult readShader(const std::string& fileName,const Options* options)
249 if (options && options->getReadFileCallback()) return options->getReadFileCallback()->readShader(fileName,options);
250 if (_readFileCallback.valid()) return _readFileCallback->readShader(fileName,options);
251 else return readShaderImplementation(fileName,options);
253 ReaderWriter::ReadResult readShaderImplementation(const std::string& fileName,const Options* options);
255 ReaderWriter::ReadResult readScript(const std::string& fileName,const Options* options)
257 if (options && options->getReadFileCallback()) return options->getReadFileCallback()->readScript(fileName,options);
258 else if (_readFileCallback.valid()) return _readFileCallback->readScript(fileName,options);
259 else return readScriptImplementation(fileName,options);
261 ReaderWriter::ReadResult readScriptImplementation(const std::string& fileName,const Options* options);
264 /** Set the Registry callback to use in place of the default writeFile calls.*/
265 void setWriteFileCallback( WriteFileCallback* cb) { _writeFileCallback = cb; }
267 /** Get the writeFile callback.*/
268 WriteFileCallback* getWriteFileCallback() { return _writeFileCallback.get(); }
270 /** Get the const writeFile callback.*/
271 const WriteFileCallback* getWriteFileCallback() const { return _writeFileCallback.get(); }
274 ReaderWriter::WriteResult writeObject(const osg::Object& obj, const std::string& fileName,const Options* options)
276 if (options && options->getWriteFileCallback()) return options->getWriteFileCallback()->writeObject(obj,fileName,options);
277 else if (_writeFileCallback.valid()) return _writeFileCallback->writeObject(obj,fileName,options);
278 else return writeObjectImplementation(obj,fileName,options);
280 ReaderWriter::WriteResult writeObjectImplementation(const osg::Object& obj, const std::string& fileName,const Options* options);
282 ReaderWriter::WriteResult writeImage(const osg::Image& obj, const std::string& fileName,const Options* options)
284 if (options && options->getWriteFileCallback()) return options->getWriteFileCallback()->writeImage(obj,fileName,options);
285 else if (_writeFileCallback.valid()) return _writeFileCallback->writeImage(obj,fileName,options);
286 else return writeImageImplementation(obj,fileName,options);
288 ReaderWriter::WriteResult writeImageImplementation(const osg::Image& obj, const std::string& fileName,const Options* options);
290 ReaderWriter::WriteResult writeHeightField(const osg::HeightField& obj, const std::string& fileName,const Options* options)
292 if (options && options->getWriteFileCallback()) return options->getWriteFileCallback()->writeHeightField(obj,fileName,options);
293 else if (_writeFileCallback.valid()) return _writeFileCallback->writeHeightField(obj,fileName,options);
294 else return writeHeightFieldImplementation(obj,fileName,options);
296 ReaderWriter::WriteResult writeHeightFieldImplementation(const osg::HeightField& obj, const std::string& fileName,const Options* options);
298 ReaderWriter::WriteResult writeNode(const osg::Node& node, const std::string& fileName,const Options* options)
300 if (options && options->getWriteFileCallback()) return options->getWriteFileCallback()->writeNode(node,fileName,options);
301 else if (_writeFileCallback.valid()) return _writeFileCallback->writeNode(node,fileName,options);
302 else return writeNodeImplementation(node,fileName,options);
304 ReaderWriter::WriteResult writeNodeImplementation(const osg::Node& node, const std::string& fileName,const Options* options);
306 ReaderWriter::WriteResult writeShader(const osg::Shader& obj, const std::string& fileName,const Options* options)
308 if (options && options->getWriteFileCallback()) return options->getWriteFileCallback()->writeShader(obj,fileName,options);
309 else if (_writeFileCallback.valid()) return _writeFileCallback->writeShader(obj,fileName,options);
310 else return writeShaderImplementation(obj,fileName,options);
312 ReaderWriter::WriteResult writeShaderImplementation(const osg::Shader& obj, const std::string& fileName,const Options* options);
314 ReaderWriter::WriteResult writeScript(const osg::Script& obj, const std::string& fileName,const Options* options)
316 if (options && options->getWriteFileCallback()) return options->getWriteFileCallback()->writeScript(obj,fileName,options);
317 else if (_writeFileCallback.valid()) return _writeFileCallback->writeScript(obj,fileName,options);
318 else return writeScriptImplementation(obj,fileName,options);
320 ReaderWriter::WriteResult writeScriptImplementation(const osg::Script& obj, const std::string& fileName,const Options* options);
322 inline void _buildKdTreeIfRequired(ReaderWriter::ReadResult& result, const Options* options)
324 bool doKdTreeBuilder = (options && options->getBuildKdTreesHint()!=Options::NO_PREFERENCE) ?
325 options->getBuildKdTreesHint() == Options::BUILD_KDTREES :
326 _buildKdTreesHint == Options::BUILD_KDTREES;
328 if (doKdTreeBuilder && _kdTreeBuilder.valid() && result.validNode())
330 osg::ref_ptr<osg::KdTreeBuilder> builder = _kdTreeBuilder->clone();
331 result.getNode()->accept(*builder);
335 /** Set the callback to use inform to the DatabasePager whether a file is located on local or remote file system.*/
336 void setFileLocationCallback( FileLocationCallback* cb) { _fileLocationCallback = cb; }
338 /** Get the callback to use inform to the DatabasePager whether a file is located on local or remote file system.*/
339 FileLocationCallback* getFileLocationCallback() const { return _fileLocationCallback.get(); }
343 /** Set whether the KdTrees should be built for geometry in the loader model. */
344 void setBuildKdTreesHint(Options::BuildKdTreesHint hint) { _buildKdTreesHint = hint; }
346 /** Get whether the KdTrees should be built for geometry in the loader model. */
347 Options::BuildKdTreesHint getBuildKdTreesHint() const { return _buildKdTreesHint; }
349 /** Set the KdTreeBuilder visitor that is used to build KdTree on loaded models.*/
350 void setKdTreeBuilder(osg::KdTreeBuilder* builder) { _kdTreeBuilder = builder; }
352 /** Get the KdTreeBuilder visitor that is used to build KdTree on loaded models.*/
353 osg::KdTreeBuilder* getKdTreeBuilder() { return _kdTreeBuilder.get(); }
356 /** Set the FileCache that is used to manage local storage of files downloaded from the internet.*/
357 void setFileCache(FileCache* fileCache) { _fileCache = fileCache; }
359 /** Get the FileCache that is used to manage local storage of files downloaded from the internet.*/
360 FileCache* getFileCache() { return _fileCache.get(); }
362 /** Get the const FileCache that is used to manage local storage of files downloaded from the internet.*/
363 const FileCache* getFileCache() const { return _fileCache.get(); }
366 /** Set the password map to be used by plugins when access files from secure locations.*/
367 void setAuthenticationMap(AuthenticationMap* authenticationMap) { _authenticationMap = authenticationMap; }
369 /** Get the password map to be used by plugins when access files from secure locations. Create a AuthenticationMap if one isn't already assigned.*/
370 AuthenticationMap* getOrCreateAuthenticationMap()
372 if (!_authenticationMap) _authenticationMap = new AuthenticationMap;
373 return _authenticationMap.get();
376 /** Get the password map to be used by plugins when access files from secure locations.*/
377 AuthenticationMap* getAuthenticationMap() { return _authenticationMap.get(); }
379 /** Get the password map to be used by plugins when access files from secure locations.*/
380 const AuthenticationMap* getAuthenticationMap() const { return _authenticationMap.get(); }
383 void setCreateNodeFromImage(bool flag) { _createNodeFromImage = flag; }
384 bool getCreateNodeFromImage() const { return _createNodeFromImage; }
387 void setOptions(Options* opt) { _options = opt; }
388 Options* getOptions() { return _options.get(); }
389 const Options* getOptions() const { return _options.get(); }
392 /** initialize both the Data and Library FilePaths, by default called by the
393 * constructor, so it should only be required if you want to force
394 * the re-reading of environmental variables.*/
395 void initFilePathLists() { initDataFilePathList(); initLibraryFilePathList(); }
397 /** initialize the Data FilePath by reading the OSG_FILE_PATH environmental variable.*/
398 void initDataFilePathList();
400 /** Set the data file path using a list of paths stored in a FilePath, which is used when search for data files.*/
401 void setDataFilePathList(const FilePathList& filepath) { _dataFilePath = filepath; }
403 /** Set the data file path using a single string delimited either with ';' (Windows) or ':' (All other platforms), which is used when search for data files.*/
404 void setDataFilePathList(const std::string& paths);
406 /** get the data file path which is used when search for data files.*/
407 FilePathList& getDataFilePathList() { return _dataFilePath; }
409 /** get the const data file path which is used when search for data files.*/
410 const FilePathList& getDataFilePathList() const { return _dataFilePath; }
412 /** initialize the Library FilePath by reading the OSG_LIBRARY_PATH
413 * and the appropriate system environmental variables*/
414 void initLibraryFilePathList();
416 /** Set the library file path using a list of paths stored in a FilePath, which is used when search for data files.*/
417 void setLibraryFilePathList(const FilePathList& filepath) { _libraryFilePath = filepath; }
419 /** Set the library file path using a single string delimited either with ';' (Windows) or ':' (All other platforms), which is used when search for data files.*/
420 void setLibraryFilePathList(const std::string& paths);
422 /** get the library file path which is used when search for library (dso/dll's) files.*/
423 FilePathList& getLibraryFilePathList() { return _libraryFilePath; }
425 /** get the const library file path which is used when search for library (dso/dll's) files.*/
426 const FilePathList& getLibraryFilePathList() const { return _libraryFilePath; }
430 /** Set the ObjectCache that is used to manage local storage of files downloaded from the internet.*/
431 void setObjectCache(ObjectCache* objectCache) { _objectCache = objectCache; }
433 /** Get the ObjectCache that is used to manage local storage of files downloaded from the internet.*/
434 ObjectCache* getObjectCache() { return _objectCache.get(); }
436 /** Get the const ObjectCache that is used to manage local storage of files downloaded from the internet.*/
437 const ObjectCache* getObjectCache() const { return _objectCache.get(); }
439 /** set hint to viewer code calling removeExpiredObjectsInCache to specify how long it should give before expiring objects in Registry cache,*/
440 void setExpiryDelay(double expiryDelay) { _expiryDelay = expiryDelay; }
442 double getExpiryDelay() const { return _expiryDelay; }
444 /** For each object in the cache which has an reference count greater than 1
445 * (and therefore referenced by elsewhere in the application) set the time stamp
446 * for that object in the cache to specified time.
447 * This would typically be called once per frame by applications which are doing database paging,
448 * and need to prune objects that are no longer required.
449 * The time used is taken from the FrameStamp::getReferenceTime().*/
450 void updateTimeStampOfObjectsInCacheWithExternalReferences(const osg::FrameStamp& frameStamp);
452 /** Removed object in the cache which have a time stamp at or before the specified expiry time.
453 * This would typically be called once per frame by applications which are doing database paging,
454 * and need to prune objects that are no longer required, and called after the a called
455 * after the call to updateTimeStampOfObjectsInCacheWithExternalReferences(frameStamp).*/
456 void removeExpiredObjectsInCache(const osg::FrameStamp& frameStamp);
458 /** Remove all objects in the cache regardless of having external references or expiry times.*/
459 void clearObjectCache();
461 /** Add a filename,object,timestamp triple to the Registry::ObjectCache.*/
462 void addEntryToObjectCache(const std::string& filename, osg::Object* object, double timestamp = 0.0, Options *options = NULL);
464 /** Remove Object from cache.*/
465 void removeFromObjectCache(const std::string& fileName, Options *options = NULL);
467 /** Get an Object from the object cache*/
468 osg::Object* getFromObjectCache(const std::string& fileName, Options *options = NULL);
470 /** Get an ref_ptr<Object> from the object cache*/
471 osg::ref_ptr<osg::Object> getRefFromObjectCache(const std::string& fileName, Options *options = NULL);
475 /** Add archive to archive cache so that future calls reference this archive.*/
476 void addToArchiveCache(const std::string& fileName, osgDB::Archive* archive);
478 /** Remove Archive from cache.*/
479 void removeFromArchiveCache(const std::string& fileName);
481 /** Get an Archive from the archive cache.*/
482 osgDB::Archive* getFromArchiveCache(const std::string& fileName);
484 /** Get an ref_ptr<Archive> from the archive cache.*/
485 osg::ref_ptr<osgDB::Archive> getRefFromArchiveCache(const std::string& fileName);
487 /** Remove all archives from the archive cache.*/
488 void clearArchiveCache();
490 /** If State is non-zero, this function releases OpenGL objects for
491 * the specified graphics context. Otherwise, releases OpenGL objexts
492 * for all graphics contexts. */
493 void releaseGLObjects(osg::State* state=0);
495 /** get the attached library with specified name.*/
496 DynamicLibrary* getLibrary(const std::string& fileName);
498 /** Set the SharedStateManager.*/
499 void setSharedStateManager(SharedStateManager* SharedStateManager) { _sharedStateManager = SharedStateManager; }
501 /** Get the SharedStateManager, creating one if one is not already created.*/
502 SharedStateManager* getOrCreateSharedStateManager();
504 /** Get the SharedStateManager. Return 0 if no SharedStateManager has been assigned.*/
505 SharedStateManager* getSharedStateManager() { return _sharedStateManager.get(); }
507 /** Add an Archive extension.*/
508 void addArchiveExtension(const std::string ext);
510 /** registers a protocol */
511 void registerProtocol(const std::string& protocol);
513 /** returns true, if named protocol is registered */
514 bool isProtocolRegistered(const std::string& protocol);
516 /** Get the ObjectWrapperManager that is used to store all the ObjectWrappers. */
517 ObjectWrapperManager* getObjectWrapperManager() { return _objectWrapperManager.get(); }
519 /** Get the ObjectWrapperManager that is used to store all the ObjectWrappers. */
520 DeprecatedDotOsgWrapperManager* getDeprecatedDotOsgObjectWrapperManager() { return _deprecatedDotOsgWrapperManager.get(); }
522 typedef std::vector< std::string> ArchiveExtensionList;
523 const ArchiveExtensionList& getArchiveExtensions() const { return _archiveExtList; }
529 typedef std::vector< osg::ref_ptr<DynamicLibrary> > DynamicLibraryList;
530 typedef std::map< std::string, std::string> ExtensionAliasMap;
532 typedef std::map<std::string, osg::ref_ptr<osgDB::Archive> > ArchiveCache;
534 typedef std::set<std::string> RegisteredProtocolsSet;
536 /** constructor is private, as its a singleton, preventing
537 construction other than via the instance() method and
538 therefore ensuring only one copy is ever constructed*/
541 /** get the attached library with specified name.*/
542 DynamicLibraryList::iterator getLibraryItr(const std::string& fileName);
544 Options::BuildKdTreesHint _buildKdTreesHint;
545 osg::ref_ptr<osg::KdTreeBuilder> _kdTreeBuilder;
547 osg::ref_ptr<FileCache> _fileCache;
549 osg::ref_ptr<AuthenticationMap> _authenticationMap;
551 bool _createNodeFromImage;
553 RegisteredProtocolsSet _registeredProtocols;
556 /** Functor used in internal implementations.*/
557 struct ReadFunctor : public osg::Referenced
559 ReadFunctor(const std::string& filename, const Options* options):
563 virtual ~ReadFunctor() {}
564 virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw) const = 0;
565 virtual bool isValid(ReaderWriter::ReadResult& readResult) const = 0;
566 virtual bool isValid(osg::Object* object) const = 0;
568 virtual ReadFunctor* cloneType(const std::string& filename, const Options* options) const = 0;
570 std::string _filename;
571 const Options* _options;
578 // forward declare helper classes
579 struct ReadObjectFunctor;
580 struct ReadImageFunctor;
581 struct ReadHeightFieldFunctor;
582 struct ReadNodeFunctor;
583 struct ReadArchiveFunctor;
584 struct ReadShaderFunctor;
585 struct ReadScriptFunctor;
587 // make helper classes friends to get round VS6.0 "issues"
588 friend struct ReadFunctor;
589 friend struct ReadObjectFunctor;
590 friend struct ReadImageFunctor;
591 friend struct ReadHeightFieldFunctor;
592 friend struct ReadNodeFunctor;
593 friend struct ReadArchiveFunctor;
594 friend struct ReadShaderFunctor;
595 friend struct ReadScriptFunctor;
597 ReaderWriter::ReadResult read(const ReadFunctor& readFunctor);
598 ReaderWriter::ReadResult readImplementation(const ReadFunctor& readFunctor,Options::CacheHintOptions cacheHint);
601 // forward declare helper class
602 class AvailableReaderWriterIterator;
603 friend class AvailableReaderWriterIterator;
604 class AvailableArchiveIterator;
605 friend class AvailableArchiveIterator;
608 osg::ref_ptr<FindFileCallback> _findFileCallback;
609 osg::ref_ptr<ReadFileCallback> _readFileCallback;
610 osg::ref_ptr<WriteFileCallback> _writeFileCallback;
611 osg::ref_ptr<FileLocationCallback> _fileLocationCallback;
613 OpenThreads::ReentrantMutex _pluginMutex;
614 ReaderWriterList _rwList;
615 ImageProcessorList _ipList;
616 DynamicLibraryList _dlList;
618 OpenThreads::ReentrantMutex _archiveCacheMutex;
619 ArchiveCache _archiveCache;
621 bool _openingLibrary;
623 // map to alias to extensions to plugins.
624 ExtensionAliasMap _extAliasMap;
626 // maps mime-types to extensions.
627 MimeTypeExtensionMap _mimeTypeExtMap;
629 // Utility: Removes whitespace from both ends of a string.
630 static std::string trim( const std::string& str );
632 // options to pass to reader writers.
633 osg::ref_ptr<Options> _options;
635 FilePathList _dataFilePath;
636 FilePathList _libraryFilePath;
638 osg::ref_ptr<ObjectCache> _objectCache;
643 ArchiveExtensionList _archiveExtList;
645 osg::ref_ptr<SharedStateManager> _sharedStateManager;
647 osg::ref_ptr<ObjectWrapperManager> _objectWrapperManager;
648 osg::ref_ptr<DeprecatedDotOsgWrapperManager> _deprecatedDotOsgWrapperManager;
651/** read the command line arguments.*/
652inline void readCommandLine(osg::ArgumentParser& parser)
654 Registry::instance()->readCommandLine(parser);
657/** Proxy class for automatic registration of reader/writers with the Registry.*/
659class RegisterReaderWriterProxy
662 RegisterReaderWriterProxy()
664 if (Registry::instance())
667 Registry::instance()->addReaderWriter(_rw.get());
671 ~RegisterReaderWriterProxy()
673 if (Registry::instance())
675 Registry::instance()->removeReaderWriter(_rw.get());
679 T* get() { return _rw.get(); }
686/** Proxy class for automatic registration of reader/writers with the Registry.*/
688class RegisterImageProcessorProxy
691 RegisterImageProcessorProxy()
693 if (Registry::instance())
696 Registry::instance()->addImageProcessor(_rw.get());
700 ~RegisterImageProcessorProxy()
702 if (Registry::instance())
704 Registry::instance()->removeImageProcessor(_rw.get());
708 T* get() { return _rw.get(); }
714struct PluginFunctionProxy
716 PluginFunctionProxy(CPluginFunction function) { (function)(); }
719#define USE_OSGPLUGIN(ext) \
720 extern "C" void osgdb_##ext(void); \
721 static osgDB::PluginFunctionProxy proxy_##ext(osgdb_##ext);
723#define USE_DOTOSGWRAPPER(classname) \
724 extern "C" void dotosgwrapper_##classname(void); \
725 static osgDB::PluginFunctionProxy proxy_dotosgwrapper_##classname(dotosgwrapper_##classname);
727#define USE_DOTOSGWRAPPER_LIBRARY(libname) \
728 extern "C" void dotosgwrapper_library_##libname(void); \
729 static osgDB::PluginFunctionProxy proxy_dotosgwrapper_library_##libname(dotosgwrapper_library_##libname);
731#define USE_SERIALIZER_WRAPPER(classname) \
732 extern "C" void wrapper_serializer_##classname(void); \
733 static osgDB::PluginFunctionProxy proxy_serializer_##classname(wrapper_serializer_##classname);
735#define USE_SERIALIZER_WRAPPER_LIBRARY(libname) \
736 extern "C" void wrapper_serializer_library_##libname(void); \
737 static osgDB::PluginFunctionProxy proxy_serializer_library_##libname(wrapper_serializer_library_##libname);
739#define USE_COMPRESSOR_WRAPPER(classname) \
740 extern "C" void wrapper_compressor_##classname(void); \
741 static osgDB::PluginFunctionProxy proxy_compressor_##classname(wrapper_compressor_##classname);
743#define REGISTER_OSGPLUGIN(ext, classname) \
744 extern "C" void osgdb_##ext(void) {} \
745 static osgDB::RegisterReaderWriterProxy<classname> g_proxy_##classname;
747#define REGISTER_OSGIMAGEPROCESSOR(ext, classname) \
748 extern "C" void osgdb_##ext(void) {} \
749 static osgDB::RegisterImageProcessorProxy<classname> g_proxy_##classname;