2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2009-05-09 16:49:27 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
2009-05-09 16:49:27 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2009-05-09 16:49:27 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2009-05-09 16:49:27 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OSGDB_OPTIONS
|
|
|
|
#define OSGDB_OPTIONS 1
|
|
|
|
|
2009-05-12 00:38:40 +08:00
|
|
|
#include <osgDB/Callbacks>
|
2014-11-13 17:40:11 +08:00
|
|
|
#include <osgDB/ObjectCache>
|
2011-01-13 03:29:24 +08:00
|
|
|
#include <osg/ObserverNodePath>
|
2009-05-09 16:49:27 +08:00
|
|
|
|
|
|
|
#include <deque>
|
|
|
|
#include <list>
|
|
|
|
#include <iosfwd>
|
|
|
|
|
|
|
|
namespace osgDB {
|
|
|
|
|
2009-05-11 19:39:12 +08:00
|
|
|
|
2009-05-09 16:49:27 +08:00
|
|
|
/** Options base class used for passing options into plugins to control their operation.*/
|
2009-05-11 19:39:12 +08:00
|
|
|
class OSGDB_EXPORT Options : public osg::Object
|
2009-05-09 16:49:27 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// bit mask for setting up which object types get cached by readObject/Image/HeightField/Node(filename) calls
|
|
|
|
enum CacheHintOptions
|
|
|
|
{ /// do not cache objects of any type
|
|
|
|
CACHE_NONE = 0,
|
|
|
|
|
|
|
|
/// cache nodes loaded via readNode(filename)
|
|
|
|
CACHE_NODES = 1<<0,
|
|
|
|
|
|
|
|
/// cache images loaded via readImage(filename)
|
|
|
|
CACHE_IMAGES = 1<<1,
|
|
|
|
|
|
|
|
/// cache heightfield loaded via readHeightField(filename)
|
|
|
|
CACHE_HEIGHTFIELDS = 1<<2,
|
|
|
|
|
|
|
|
/// cache heightfield loaded via readHeightField(filename)
|
|
|
|
CACHE_ARCHIVES = 1<<3,
|
|
|
|
|
|
|
|
/// cache objects loaded via readObject(filename)
|
|
|
|
CACHE_OBJECTS = 1<<4,
|
|
|
|
|
|
|
|
/// cache shaders loaded via readShader(filename)
|
|
|
|
CACHE_SHADERS = 1<<5,
|
|
|
|
|
|
|
|
/// cache on all read*(filename) calls
|
|
|
|
CACHE_ALL = CACHE_NODES |
|
|
|
|
CACHE_IMAGES |
|
|
|
|
CACHE_HEIGHTFIELDS |
|
|
|
|
CACHE_ARCHIVES |
|
|
|
|
CACHE_OBJECTS |
|
|
|
|
CACHE_SHADERS
|
|
|
|
};
|
|
|
|
|
2010-04-13 21:06:27 +08:00
|
|
|
/// Bit mask for which geometry attributes should be imported with double precision where source data is held in double precision
|
|
|
|
/// This is useful for data that will be pre-processed before rendering.
|
|
|
|
/// In general the geometry should be converted to floating point before rendering to ensure good performance.
|
|
|
|
enum PrecisionHint
|
|
|
|
{
|
|
|
|
FLOAT_PRECISION_ALL = 0,
|
|
|
|
|
|
|
|
DOUBLE_PRECISION_VERTEX = 1<<0,
|
|
|
|
DOUBLE_PRECISION_NORMAL = 1<<1,
|
|
|
|
DOUBLE_PRECISION_COLOR = 1<<2,
|
|
|
|
DOUBLE_PRECISION_SECONDARY_COLOR = 1<<3,
|
|
|
|
DOUBLE_PRECISION_FOG_COORD = 1<<4,
|
|
|
|
DOUBLE_PRECISION_TEX_COORD = 1<<5,
|
|
|
|
DOUBLE_PRECISION_VERTEX_ATTRIB = 1<<6,
|
|
|
|
|
|
|
|
DOUBLE_PRECISION_ALL = DOUBLE_PRECISION_VERTEX |
|
|
|
|
DOUBLE_PRECISION_NORMAL |
|
|
|
|
DOUBLE_PRECISION_COLOR |
|
|
|
|
DOUBLE_PRECISION_SECONDARY_COLOR |
|
|
|
|
DOUBLE_PRECISION_FOG_COORD |
|
|
|
|
DOUBLE_PRECISION_TEX_COORD |
|
|
|
|
DOUBLE_PRECISION_VERTEX_ATTRIB
|
|
|
|
};
|
|
|
|
|
2009-05-09 16:49:27 +08:00
|
|
|
/// range of options of whether to build kdtrees automatically on loading
|
|
|
|
enum BuildKdTreesHint
|
|
|
|
{
|
|
|
|
NO_PREFERENCE,
|
|
|
|
DO_NOT_BUILD_KDTREES,
|
|
|
|
BUILD_KDTREES
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Options():
|
|
|
|
osg::Object(true),
|
|
|
|
_objectCacheHint(CACHE_ARCHIVES),
|
2010-04-13 21:06:27 +08:00
|
|
|
_precisionHint(FLOAT_PRECISION_ALL),
|
2009-05-09 16:49:27 +08:00
|
|
|
_buildKdTreesHint(NO_PREFERENCE) {}
|
|
|
|
|
|
|
|
Options(const std::string& str):
|
|
|
|
osg::Object(true),
|
|
|
|
_str(str),
|
|
|
|
_objectCacheHint(CACHE_ARCHIVES),
|
2010-04-13 21:06:27 +08:00
|
|
|
_precisionHint(FLOAT_PRECISION_ALL),
|
2010-11-03 18:37:02 +08:00
|
|
|
_buildKdTreesHint(NO_PREFERENCE)
|
|
|
|
{
|
|
|
|
parsePluginStringData(str);
|
|
|
|
}
|
2009-05-09 16:49:27 +08:00
|
|
|
|
2009-05-09 16:54:38 +08:00
|
|
|
Options(const Options& options,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
2009-05-09 16:49:27 +08:00
|
|
|
|
|
|
|
META_Object(osgDB,Options);
|
|
|
|
|
2011-02-15 00:05:33 +08:00
|
|
|
Options* cloneOptions(const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) const { return static_cast<Options*>(clone(copyop)); }
|
2009-06-25 00:03:49 +08:00
|
|
|
|
2009-05-09 16:49:27 +08:00
|
|
|
/** Set the general Options string.*/
|
2010-11-03 18:37:02 +08:00
|
|
|
void setOptionString(const std::string& str) { _str = str; parsePluginStringData(str); }
|
2009-05-09 16:49:27 +08:00
|
|
|
|
|
|
|
/** Get the general Options string.*/
|
|
|
|
const std::string& getOptionString() const { return _str; }
|
|
|
|
|
|
|
|
/** Set the database path to use a hint of where to look when loading models.*/
|
|
|
|
void setDatabasePath(const std::string& str) { _databasePaths.clear(); _databasePaths.push_back(str); }
|
|
|
|
|
|
|
|
/** Get the database path which is used a hint of where to look when loading models.*/
|
|
|
|
FilePathList& getDatabasePathList() { return _databasePaths; }
|
|
|
|
|
|
|
|
/** Get the const database path which is used a hint of where to look when loading models.*/
|
|
|
|
const FilePathList& getDatabasePathList() const { return _databasePaths; }
|
|
|
|
|
|
|
|
|
|
|
|
/** Set whether the Registry::ObjectCache should be used by default.*/
|
|
|
|
void setObjectCacheHint(CacheHintOptions useObjectCache) { _objectCacheHint = useObjectCache; }
|
|
|
|
|
|
|
|
/** Get whether the Registry::ObjectCache should be used by default.*/
|
|
|
|
CacheHintOptions getObjectCacheHint() const { return _objectCacheHint; }
|
|
|
|
|
2014-11-13 17:40:11 +08:00
|
|
|
/** Set the ObjectCache that is used to cache previously loaded data.*/
|
|
|
|
void setObjectCache(ObjectCache* objectCache) { _objectCache = objectCache; }
|
|
|
|
|
|
|
|
/** Get the ObjectCache that is used to cache previously loaded data.*/
|
|
|
|
ObjectCache* getObjectCache() const { return _objectCache.get(); }
|
|
|
|
|
|
|
|
|
2010-04-13 21:06:27 +08:00
|
|
|
/** Set which geometry attributes plugins should import at double precision. */
|
|
|
|
void setPrecisionHint(PrecisionHint hint) { _precisionHint = hint; }
|
|
|
|
|
|
|
|
/** Get which geometry attributes plugins should import at double precision. */
|
|
|
|
PrecisionHint getPrecisionHint() const { return _precisionHint; }
|
2009-05-09 16:49:27 +08:00
|
|
|
|
|
|
|
/** Set whether the KdTrees should be built for geometry in the loader model. */
|
|
|
|
void setBuildKdTreesHint(BuildKdTreesHint hint) { _buildKdTreesHint = hint; }
|
|
|
|
|
|
|
|
/** Get whether the KdTrees should be built for geometry in the loader model. */
|
|
|
|
BuildKdTreesHint getBuildKdTreesHint() const { return _buildKdTreesHint; }
|
|
|
|
|
|
|
|
|
|
|
|
/** Set the password map to be used by plugins when access files from secure locations.*/
|
|
|
|
void setAuthenticationMap(AuthenticationMap* authenticationMap) { _authenticationMap = authenticationMap; }
|
|
|
|
|
|
|
|
/** Get the password map to be used by plugins when access files from secure locations.*/
|
|
|
|
const AuthenticationMap* getAuthenticationMap() const { return _authenticationMap.get(); }
|
|
|
|
|
|
|
|
|
|
|
|
/** Sets a plugindata value PluginData with a string */
|
|
|
|
void setPluginData(const std::string& s, void* v) const { _pluginData[s] = v; }
|
|
|
|
|
|
|
|
/** Get a value from the PluginData */
|
|
|
|
void* getPluginData(const std::string& s) { return _pluginData[s]; }
|
|
|
|
|
|
|
|
/** Get a value from the PluginData */
|
|
|
|
const void* getPluginData(const std::string& s) const
|
|
|
|
{
|
|
|
|
PluginDataMap::const_iterator itr = _pluginData.find(s);
|
|
|
|
return (itr == _pluginData.end()) ? 0 : itr->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Remove a value from the PluginData */
|
|
|
|
void removePluginData(const std::string& s) const { _pluginData.erase(s); }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-11-03 18:37:02 +08:00
|
|
|
/** Get number of PluginData values */
|
2013-05-15 00:12:21 +08:00
|
|
|
unsigned int getNumPluginData() const { return static_cast<unsigned int>(_pluginData.size()); }
|
2009-05-09 16:49:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
/** Sets a plugindata value PluginData with a string */
|
|
|
|
void setPluginStringData(const std::string& s, const std::string& v) const { _pluginStringData[s] = v; }
|
|
|
|
|
|
|
|
/** Get a string from the PluginStrData */
|
2009-05-14 03:46:16 +08:00
|
|
|
std::string& getPluginStringData(const std::string& s) { return _pluginStringData[s]; }
|
2009-05-09 16:49:27 +08:00
|
|
|
|
|
|
|
/** Get a value from the PluginData */
|
|
|
|
const std::string getPluginStringData(const std::string& s) const
|
|
|
|
{
|
|
|
|
PluginStringDataMap::const_iterator itr = _pluginStringData.find(s);
|
|
|
|
return (itr == _pluginStringData.end()) ? std::string("") : itr->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Remove a value from the PluginData */
|
|
|
|
void removePluginStringData(const std::string& s) const { _pluginStringData.erase(s); }
|
|
|
|
|
2010-11-03 18:37:02 +08:00
|
|
|
/** Get number of PluginStrData values */
|
2013-05-15 00:12:21 +08:00
|
|
|
unsigned int getNumPluginStringData() const { return static_cast<unsigned int>(_pluginStringData.size()); }
|
2010-11-03 18:37:02 +08:00
|
|
|
|
|
|
|
/** Parse string into plugin string data. This will be automatically done in Options(const std::string&) */
|
|
|
|
void parsePluginStringData(const std::string& str, char separator1=' ', char separator2='=');
|
2009-05-09 16:49:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
/** Set the find callback to use in place of the default findFile calls.*/
|
|
|
|
void setFindFileCallback( FindFileCallback* cb) { _findFileCallback = cb; }
|
|
|
|
|
|
|
|
/** Get the const findFile callback.*/
|
|
|
|
FindFileCallback* getFindFileCallback() const { return _findFileCallback.get(); }
|
|
|
|
|
|
|
|
|
|
|
|
/** Set the read callback to use in place of the default readFile calls.*/
|
|
|
|
void setReadFileCallback( ReadFileCallback* cb) { _readFileCallback = cb; }
|
|
|
|
|
|
|
|
/** Get the const readFile callback.*/
|
|
|
|
ReadFileCallback* getReadFileCallback() const { return _readFileCallback.get(); }
|
|
|
|
|
|
|
|
|
2009-05-11 19:39:12 +08:00
|
|
|
/** Set the callback to use in place of the default writeFile calls.*/
|
2009-05-09 16:49:27 +08:00
|
|
|
void setWriteFileCallback( WriteFileCallback* cb) { _writeFileCallback = cb; }
|
|
|
|
|
|
|
|
/** Get the const writeFile callback.*/
|
|
|
|
WriteFileCallback* getWriteFileCallback() const { return _writeFileCallback.get(); }
|
|
|
|
|
|
|
|
|
2009-05-18 18:28:14 +08:00
|
|
|
/** Set the callback to use inform the DatabasePager whether a file is located on local or remote file system.*/
|
2009-05-11 19:39:12 +08:00
|
|
|
void setFileLocationCallback( FileLocationCallback* cb) { _fileLocationCallback = cb; }
|
|
|
|
|
2009-05-18 18:28:14 +08:00
|
|
|
/** Get the callback to use inform the DatabasePager whether a file is located on local or remote file system.*/
|
2009-05-11 19:39:12 +08:00
|
|
|
FileLocationCallback* getFileLocationCallback() const { return _fileLocationCallback.get(); }
|
|
|
|
|
|
|
|
/** Set the FileCache that is used to manage local storage of files downloaded from the internet.*/
|
|
|
|
void setFileCache(FileCache* fileCache) { _fileCache = fileCache; }
|
|
|
|
|
|
|
|
/** Get the FileCache that is used to manage local storage of files downloaded from the internet.*/
|
|
|
|
FileCache* getFileCache() const { return _fileCache.get(); }
|
|
|
|
|
|
|
|
|
2011-01-13 03:29:24 +08:00
|
|
|
/** Set the terrain observer_ptr, use to decorate any osgTerrain subgraphs.*/
|
|
|
|
void setTerrain(osg::observer_ptr<osg::Node>& terrain) { _terrain = terrain; }
|
|
|
|
|
|
|
|
/** Get the terrain observer_ptr, use to decorate any osgTerrain subgraphs.*/
|
|
|
|
const osg::observer_ptr<osg::Node>& getTerrain() const { return _terrain; }
|
|
|
|
|
|
|
|
|
2009-05-09 16:49:27 +08:00
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual ~Options() {}
|
|
|
|
|
|
|
|
std::string _str;
|
|
|
|
FilePathList _databasePaths;
|
2014-11-13 17:40:11 +08:00
|
|
|
|
2009-05-09 16:49:27 +08:00
|
|
|
CacheHintOptions _objectCacheHint;
|
2014-11-13 17:40:11 +08:00
|
|
|
osg::ref_ptr<ObjectCache> _objectCache;
|
|
|
|
|
2010-04-13 21:06:27 +08:00
|
|
|
PrecisionHint _precisionHint;
|
2009-05-09 16:49:27 +08:00
|
|
|
BuildKdTreesHint _buildKdTreesHint;
|
|
|
|
osg::ref_ptr<AuthenticationMap> _authenticationMap;
|
|
|
|
|
|
|
|
typedef std::map<std::string,void*> PluginDataMap;
|
|
|
|
mutable PluginDataMap _pluginData;
|
|
|
|
typedef std::map<std::string,std::string> PluginStringDataMap;
|
|
|
|
mutable PluginStringDataMap _pluginStringData;
|
|
|
|
|
|
|
|
osg::ref_ptr<FindFileCallback> _findFileCallback;
|
|
|
|
osg::ref_ptr<ReadFileCallback> _readFileCallback;
|
|
|
|
osg::ref_ptr<WriteFileCallback> _writeFileCallback;
|
2009-05-11 19:39:12 +08:00
|
|
|
osg::ref_ptr<FileLocationCallback> _fileLocationCallback;
|
|
|
|
|
|
|
|
osg::ref_ptr<FileCache> _fileCache;
|
2011-01-13 03:29:24 +08:00
|
|
|
|
|
|
|
osg::observer_ptr<osg::Node> _terrain;
|
2009-05-09 16:49:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // OSGDB_OPTIONS
|