root/OpenSceneGraph/trunk/include/osgDB/Options @ 13041

Revision 13041, 11.5 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
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.
7 *
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.
12*/
13
14#ifndef OSGDB_OPTIONS
15#define OSGDB_OPTIONS 1
16
17#include <osgDB/Callbacks>
18#include <osg/ObserverNodePath>
19
20#include <deque>
21#include <list>
22#include <iosfwd>
23
24namespace osgDB {
25
26
27/** Options base class used for passing options into plugins to control their operation.*/
28class OSGDB_EXPORT Options : public osg::Object
29{
30    public:
31
32        /// bit mask for setting up which object types get cached by readObject/Image/HeightField/Node(filename) calls
33        enum CacheHintOptions
34        {   /// do not cache objects of any type
35            CACHE_NONE          = 0,
36
37            /// cache nodes loaded via readNode(filename)
38            CACHE_NODES         = 1<<0,
39
40            /// cache images loaded via readImage(filename)
41            CACHE_IMAGES        = 1<<1,
42
43            /// cache heightfield loaded via readHeightField(filename)
44            CACHE_HEIGHTFIELDS  = 1<<2,
45
46            /// cache heightfield loaded via readHeightField(filename)
47            CACHE_ARCHIVES      = 1<<3,
48
49            /// cache objects loaded via readObject(filename)
50            CACHE_OBJECTS       = 1<<4,
51
52            /// cache shaders loaded via readShader(filename)
53            CACHE_SHADERS       = 1<<5,
54
55            /// cache on all read*(filename) calls
56            CACHE_ALL           = CACHE_NODES |
57                                    CACHE_IMAGES |
58                                    CACHE_HEIGHTFIELDS |
59                                    CACHE_ARCHIVES |
60                                    CACHE_OBJECTS |
61                                    CACHE_SHADERS
62        };
63
64        /// Bit mask for which geometry attributes should be imported with double precision where source data is held in double precision
65        /// This is useful for data that will be pre-processed before rendering.
66        /// In general the geometry should be converted to floating point before rendering to ensure good performance.
67        enum PrecisionHint
68        {
69            FLOAT_PRECISION_ALL              = 0,
70
71            DOUBLE_PRECISION_VERTEX          = 1<<0,
72            DOUBLE_PRECISION_NORMAL          = 1<<1,
73            DOUBLE_PRECISION_COLOR           = 1<<2,
74            DOUBLE_PRECISION_SECONDARY_COLOR = 1<<3,
75            DOUBLE_PRECISION_FOG_COORD       = 1<<4,
76            DOUBLE_PRECISION_TEX_COORD       = 1<<5,
77            DOUBLE_PRECISION_VERTEX_ATTRIB   = 1<<6,
78
79            DOUBLE_PRECISION_ALL = DOUBLE_PRECISION_VERTEX |
80                                   DOUBLE_PRECISION_NORMAL |
81                                   DOUBLE_PRECISION_COLOR |
82                                   DOUBLE_PRECISION_SECONDARY_COLOR |
83                                   DOUBLE_PRECISION_FOG_COORD |
84                                   DOUBLE_PRECISION_TEX_COORD |
85                                   DOUBLE_PRECISION_VERTEX_ATTRIB
86        };
87
88        /// range of options of whether to build kdtrees automatically on loading
89        enum BuildKdTreesHint
90        {
91            NO_PREFERENCE,
92            DO_NOT_BUILD_KDTREES,
93            BUILD_KDTREES
94        };
95
96
97        Options():
98            osg::Object(true),
99            _objectCacheHint(CACHE_ARCHIVES),
100            _precisionHint(FLOAT_PRECISION_ALL),
101            _buildKdTreesHint(NO_PREFERENCE) {}
102
103        Options(const std::string& str):
104            osg::Object(true),
105            _str(str),
106            _objectCacheHint(CACHE_ARCHIVES),
107            _precisionHint(FLOAT_PRECISION_ALL),
108            _buildKdTreesHint(NO_PREFERENCE)
109        {
110            parsePluginStringData(str);
111        }
112
113        Options(const Options& options,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
114
115        META_Object(osgDB,Options);
116
117        Options* cloneOptions(const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) const { return static_cast<Options*>(clone(copyop)); }
118
119        /** Set the general Options string.*/
120        void setOptionString(const std::string& str) { _str = str; parsePluginStringData(str); }
121
122        /** Get the general Options string.*/
123        const std::string& getOptionString() const { return _str; }
124
125        /** Set the database path to use a hint of where to look when loading models.*/
126        void setDatabasePath(const std::string& str) { _databasePaths.clear();  _databasePaths.push_back(str); }
127
128        /** Get the database path which is used a hint of where to look when loading models.*/
129        FilePathList& getDatabasePathList() { return _databasePaths; }
130
131        /** Get the const database path which is used a hint of where to look when loading models.*/
132        const FilePathList& getDatabasePathList() const { return _databasePaths; }
133
134
135        /** Set whether the Registry::ObjectCache should be used by default.*/
136        void setObjectCacheHint(CacheHintOptions useObjectCache) { _objectCacheHint = useObjectCache; }
137
138        /** Get whether the Registry::ObjectCache should be used by default.*/
139        CacheHintOptions getObjectCacheHint() const { return _objectCacheHint; }
140
141        /** Set which geometry attributes plugins should import at double precision. */
142        void setPrecisionHint(PrecisionHint hint) { _precisionHint = hint; }
143
144        /** Get which geometry attributes plugins should import at double precision. */
145        PrecisionHint getPrecisionHint() const { return _precisionHint; }
146
147        /** Set whether the KdTrees should be built for geometry in the loader model. */
148        void setBuildKdTreesHint(BuildKdTreesHint hint) { _buildKdTreesHint = hint; }
149
150        /** Get whether the KdTrees should be built for geometry in the loader model. */
151        BuildKdTreesHint getBuildKdTreesHint() const { return _buildKdTreesHint; }
152
153
154        /** Set the password map to be used by plugins when access files from secure locations.*/
155        void setAuthenticationMap(AuthenticationMap* authenticationMap) { _authenticationMap = authenticationMap; }
156
157        /** Get the password map to be used by plugins when access files from secure locations.*/
158        const AuthenticationMap* getAuthenticationMap() const { return _authenticationMap.get(); }
159
160
161        /** Sets a plugindata value PluginData with a string */
162        void setPluginData(const std::string& s, void* v) const { _pluginData[s] = v; }
163
164        /** Get a value from the PluginData */
165        void* getPluginData(const std::string& s) { return _pluginData[s]; }
166
167        /** Get a value from the PluginData */
168        const void* getPluginData(const std::string& s) const
169        {
170            PluginDataMap::const_iterator itr = _pluginData.find(s);
171            return (itr == _pluginData.end()) ? 0 : itr->second;
172        }
173
174        /** Remove a value from the PluginData */
175        void removePluginData(const std::string& s) const { _pluginData.erase(s); }
176
177        /** Get number of PluginData values */
178        unsigned int getNumPluginData() const { return _pluginData.size(); }
179
180
181        /** Sets a plugindata value PluginData with a string */
182        void setPluginStringData(const std::string& s, const std::string& v) const { _pluginStringData[s] = v; }
183
184        /** Get a string from the PluginStrData */
185        std::string& getPluginStringData(const std::string& s) { return _pluginStringData[s]; }
186
187        /** Get a value from the PluginData */
188        const std::string getPluginStringData(const std::string& s) const
189        {
190            PluginStringDataMap::const_iterator itr = _pluginStringData.find(s);
191            return (itr == _pluginStringData.end()) ? std::string("") : itr->second;
192        }
193
194        /** Remove a value from the PluginData */
195        void removePluginStringData(const std::string& s) const { _pluginStringData.erase(s); }
196
197        /** Get number of PluginStrData values */
198        unsigned int getNumPluginStringData() const { return _pluginStringData.size(); }
199
200        /** Parse string into plugin string data. This will be automatically done in Options(const std::string&) */
201        void parsePluginStringData(const std::string& str, char separator1=' ', char separator2='=');
202
203
204        /** Set the find callback to use in place of the default findFile calls.*/
205        void setFindFileCallback( FindFileCallback* cb) { _findFileCallback = cb; }
206
207        /** Get the const findFile callback.*/
208        FindFileCallback* getFindFileCallback() const { return _findFileCallback.get(); }
209
210
211        /** Set the read callback to use in place of the default readFile calls.*/
212        void setReadFileCallback( ReadFileCallback* cb) { _readFileCallback = cb; }
213
214        /** Get the const readFile callback.*/
215        ReadFileCallback* getReadFileCallback() const { return _readFileCallback.get(); }
216
217
218        /** Set the callback to use in place of the default writeFile calls.*/
219        void setWriteFileCallback( WriteFileCallback* cb) { _writeFileCallback = cb; }
220
221        /** Get the const writeFile callback.*/
222        WriteFileCallback* getWriteFileCallback() const { return _writeFileCallback.get(); }
223
224
225        /** Set the callback to use inform the DatabasePager whether a file is located on local or remote file system.*/
226        void setFileLocationCallback( FileLocationCallback* cb) { _fileLocationCallback = cb; }
227
228        /** Get the callback to use inform the DatabasePager whether a file is located on local or remote file system.*/
229        FileLocationCallback* getFileLocationCallback() const { return _fileLocationCallback.get(); }
230
231        /** Set the FileCache that is used to manage local storage of files downloaded from the internet.*/
232        void setFileCache(FileCache* fileCache) { _fileCache = fileCache; }
233
234        /** Get the FileCache that is used to manage local storage of files downloaded from the internet.*/
235        FileCache* getFileCache() const { return _fileCache.get(); }
236
237
238        /** Set the terrain observer_ptr, use to decorate any osgTerrain subgraphs.*/
239        void setTerrain(osg::observer_ptr<osg::Node>& terrain) { _terrain = terrain; }
240
241        /** Get the terrain observer_ptr, use to decorate any osgTerrain subgraphs.*/
242        const osg::observer_ptr<osg::Node>& getTerrain() const { return _terrain; }
243
244
245    protected:
246
247        virtual ~Options() {}
248
249        std::string                     _str;
250        FilePathList                    _databasePaths;
251        CacheHintOptions                _objectCacheHint;
252        PrecisionHint                   _precisionHint;
253        BuildKdTreesHint                _buildKdTreesHint;
254        osg::ref_ptr<AuthenticationMap> _authenticationMap;
255
256        typedef std::map<std::string,void*> PluginDataMap;
257        mutable PluginDataMap _pluginData;
258        typedef std::map<std::string,std::string> PluginStringDataMap;
259        mutable PluginStringDataMap _pluginStringData;
260
261        osg::ref_ptr<FindFileCallback>      _findFileCallback;
262        osg::ref_ptr<ReadFileCallback>      _readFileCallback;
263        osg::ref_ptr<WriteFileCallback>     _writeFileCallback;
264        osg::ref_ptr<FileLocationCallback>  _fileLocationCallback;
265
266        osg::ref_ptr<FileCache>             _fileCache;
267
268        osg::observer_ptr<osg::Node>        _terrain;
269};
270
271}
272
273#endif // OSGDB_OPTIONS
Note: See TracBrowser for help on using the browser.