OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ReadFile.h
Go to the documentation of this file.
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_READFILE
15 #define OSGDB_READFILE 1
16 
17 #include <string>
18 
19 #include <osg/Node>
20 #include <osg/Image>
21 #include <osg/ArgumentParser>
22 
23 #include <osgDB/Export>
24 #include <osgDB/Registry>
25 
26 namespace osgDB {
27 
28 
36 extern OSGDB_EXPORT osg::Object* readObjectFile(const std::string& filename,const Options* options);
37 
44 inline osg::Object* readObjectFile(const std::string& filename)
45 {
46  return readObjectFile(filename, Registry::instance()->getOptions());
47 }
48 
49 template<typename T>
50 inline T* readFile(const std::string& filename, const Options* options)
51 {
52  osg::ref_ptr<osg::Object> object = readObjectFile(filename, options);
53  osg::ref_ptr<T> t = dynamic_cast<T*>(object.get());
54  object = 0;
55  return t.release();
56 }
57 
58 template<typename T>
59 inline T* readFile(const std::string& filename)
60 {
61  return readFile<T>(filename, Registry::instance()->getOptions());
62 }
63 
64 
72 extern OSGDB_EXPORT osg::Image* readImageFile(const std::string& filename,const Options* options);
73 
80 inline osg::Image* readImageFile(const std::string& filename)
81 {
82  return readImageFile(filename,Registry::instance()->getOptions());
83 }
84 
92 extern OSGDB_EXPORT osg::HeightField* readHeightFieldFile(const std::string& filename,const Options* options);
93 
100 inline osg::HeightField* readHeightFieldFile(const std::string& filename)
101 {
102  return readHeightFieldFile(filename,Registry::instance()->getOptions());
103 }
104 
112 extern OSGDB_EXPORT osg::Node* readNodeFile(const std::string& filename,const Options* options);
113 
120 inline osg::Node* readNodeFile(const std::string& filename)
121 {
122  return readNodeFile(filename,Registry::instance()->getOptions());
123 }
124 
125 
130 extern OSGDB_EXPORT osg::Node* readNodeFiles(std::vector<std::string>& fileList,const Options* options);
131 
134 inline osg::Node* readNodeFiles(std::vector<std::string>& fileList)
135 {
136  return readNodeFiles(fileList,Registry::instance()->getOptions());
137 }
138 
139 
143 extern OSGDB_EXPORT osg::Node* readNodeFiles(osg::ArgumentParser& parser,const Options* options);
144 
148 {
149  return readNodeFiles(parser,Registry::instance()->getOptions());
150 }
151 
159 extern OSGDB_EXPORT osg::Shader* readShaderFile(const std::string& filename,const Options* options);
160 
167 inline osg::Shader* readShaderFile(const std::string& filename)
168 {
169  return readShaderFile(filename,Registry::instance()->getOptions());
170 }
171 
179 inline osg::Shader* readShaderFile(osg::Shader::Type type, const std::string& filename,const Options* options)
180 {
181  osg::Shader* shader = readShaderFile(filename, options);
182  if (shader && type != osg::Shader::UNDEFINED) shader->setType(type);
183  return shader;
184 }
185 
192 inline osg::Shader* readShaderFile(osg::Shader::Type type, const std::string& filename)
193 {
194  return readShaderFile(type, filename,Registry::instance()->getOptions());
195 }
196 
197 
203 inline osg::Shader* readShaderFileWithFallback(osg::Shader::Type type, const std::string& filename, const Options* options, const char* fallback)
204 {
205  osg::Shader* shader = readShaderFile(filename, options);
206  if (shader && type != osg::Shader::UNDEFINED) shader->setType(type);
207  if (!shader) shader = new osg::Shader(type, fallback);
208  return shader;
209 }
210 
215 inline osg::Shader* readShaderFileWithFallback(osg::Shader::Type type, const std::string& filename, const char* fallback)
216 {
217  return osgDB::readShaderFileWithFallback(type, filename, Registry::instance()->getOptions(), fallback);
218 }
219 
227 extern OSGDB_EXPORT osg::Script* readScriptFile(const std::string& filename,const Options* options);
228 
235 inline osg::Script* readScriptFile(const std::string& filename)
236 {
237  return readScriptFile(filename,Registry::instance()->getOptions());
238 }
239 
240 
241 
249 extern OSGDB_EXPORT osg::ref_ptr<osg::Object> readRefObjectFile(const std::string& filename,const Options* options);
250 
257 inline osg::ref_ptr<osg::Object> readRefObjectFile(const std::string& filename)
258 {
259  return readRefObjectFile(filename,Registry::instance()->getOptions());
260 }
261 
269 extern OSGDB_EXPORT osg::ref_ptr<osg::Image> readRefImageFile(const std::string& filename,const Options* options);
270 
277 inline osg::ref_ptr<osg::Image> readRefImageFile(const std::string& filename)
278 {
279  return readRefImageFile(filename,Registry::instance()->getOptions());
280 }
281 
289 extern OSGDB_EXPORT osg::ref_ptr<osg::HeightField> readRefHeightFieldFile(const std::string& filename,const Options* options);
290 
297 inline osg::ref_ptr<osg::HeightField> readRefHeightFieldFile(const std::string& filename)
298 {
299  return readRefHeightFieldFile(filename,Registry::instance()->getOptions());
300 }
301 
309 extern OSGDB_EXPORT osg::ref_ptr<osg::Node> readRefNodeFile(const std::string& filename,const Options* options);
310 
317 inline osg::ref_ptr<osg::Node> readRefNodeFile(const std::string& filename)
318 {
319  return readRefNodeFile(filename,Registry::instance()->getOptions());
320 }
321 
329 extern OSGDB_EXPORT osg::ref_ptr<osg::Shader> readRefShaderFile(const std::string& filename,const Options* options);
330 
337 inline osg::ref_ptr<osg::Shader> readRefShaderFile(const std::string& filename)
338 {
339  return readRefShaderFile(filename, Registry::instance()->getOptions());
340 }
341 
349 inline osg::ref_ptr<osg::Shader> readRefShaderFile(osg::Shader::Type type, const std::string& filename, const Options* options)
350 {
351  osg::ref_ptr<osg::Shader> shader = readShaderFile(filename, options);
352  if (shader.valid() && type != osg::Shader::UNDEFINED) shader->setType(type);
353  return shader;
354 }
355 
363 {
364  return readRefShaderFile(type, filename, Registry::instance()->getOptions());
365 }
366 
367 
375 extern OSGDB_EXPORT osg::ref_ptr<osg::Script> readRefScriptFile(const std::string& filename,const Options* options);
376 
383 inline osg::ref_ptr<osg::Script> readRefScriptFile(const std::string& filename)
384 {
385  return readRefScriptFile(filename,Registry::instance()->getOptions());
386 }
387 
388 }
389 
390 #endif
OSGDB_EXPORT osg::ref_ptr< osg::Object > readRefObjectFile(const std::string &filename, const Options *options)
OSGDB_EXPORT osg::ref_ptr< osg::Shader > readRefShaderFile(const std::string &filename, const Options *options)
OSGDB_EXPORT osg::ref_ptr< osg::Image > readRefImageFile(const std::string &filename, const Options *options)
bool setType(Type t)
OSGDB_EXPORT osg::ref_ptr< osg::Script > readRefScriptFile(const std::string &filename, const Options *options)
OSGDB_EXPORT osg::ref_ptr< osg::HeightField > readRefHeightFieldFile(const std::string &filename, const Options *options)
bool valid() const
Definition: ref_ptr.h:95
Options * getOptions()
Definition: Registry.h:381
OSGDB_EXPORT osg::Script * readScriptFile(const std::string &filename, const Options *options)
OSGDB_EXPORT osg::HeightField * readHeightFieldFile(const std::string &filename, const Options *options)
T * release()
Definition: ref_ptr.h:101
OSGDB_EXPORT osg::Shader * readShaderFile(const std::string &filename, const Options *options)
OSGDB_EXPORT osg::ref_ptr< osg::Node > readRefNodeFile(const std::string &filename, const Options *options)
T * readFile(const std::string &filename, const Options *options)
Definition: ReadFile.h:50
Definition: Archive.h:24
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
Definition: GLU.h:71
#define OSGDB_EXPORT
Definition: Export.h:39
osg::Shader * readShaderFileWithFallback(osg::Shader::Type type, const std::string &filename, const Options *options, const char *fallback)
Definition: ReadFile.h:203
static Registry * instance(bool erase=false)
Definition: Node.h:71
OSGDB_EXPORT osg::Node * readNodeFile(const std::string &filename, const Options *options)
OSGDB_EXPORT osg::Object * readObjectFile(const std::string &filename, const Options *options)
OSGDB_EXPORT osg::Image * readImageFile(const std::string &filename, const Options *options)
OSGDB_EXPORT osg::Node * readNodeFiles(std::vector< std::string > &fileList, const Options *options)