OpenSceneGraph 3.6.5
ReadFile
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
26namespace osgDB {
27
28
36extern OSGDB_EXPORT osg::ref_ptr<osg::Object> readRefObjectFile(const std::string& filename,const Options* options);
37
44inline osg::ref_ptr<osg::Object> readRefObjectFile(const std::string& filename)
45{
46 return readRefObjectFile(filename, Registry::instance()->getOptions());
47}
48
49template<class T>
50inline osg::ref_ptr<T> readRefFile(const std::string& filename, const Options* options)
51{
52 osg::ref_ptr<osg::Object> object = readRefObjectFile(filename, options);
53 osg::ref_ptr<T> t = dynamic_cast<T*>(object.get());
54 return t;
55}
56
57template<class T>
58inline osg::ref_ptr<T> readRefFile(const std::string& filename)
59{
60 return readRefFile<T>(filename, Registry::instance()->getOptions());
61}
62
63
71extern OSGDB_EXPORT osg::ref_ptr<osg::Image> readRefImageFile(const std::string& filename,const Options* options);
72
79inline osg::ref_ptr<osg::Image> readRefImageFile(const std::string& filename)
80{
81 return readRefImageFile(filename,Registry::instance()->getOptions());
82}
83
91extern OSGDB_EXPORT osg::ref_ptr<osg::HeightField> readRefHeightFieldFile(const std::string& filename,const Options* options);
92
99inline osg::ref_ptr<osg::HeightField> readRefHeightFieldFile(const std::string& filename)
100{
101 return readRefHeightFieldFile(filename,Registry::instance()->getOptions());
102}
103
111extern OSGDB_EXPORT osg::ref_ptr<osg::Node> readRefNodeFile(const std::string& filename,const Options* options);
112
119inline osg::ref_ptr<osg::Node> readRefNodeFile(const std::string& filename)
120{
121 return readRefNodeFile(filename,Registry::instance()->getOptions());
122}
123
128extern OSGDB_EXPORT osg::ref_ptr<osg::Node> readRefNodeFiles(std::vector<std::string>& fileList,const Options* options);
129
132inline osg::ref_ptr<osg::Node> readRefNodeFiles(std::vector<std::string>& fileList)
133{
134 return readRefNodeFiles(fileList, Registry::instance()->getOptions());
135}
136
137
142
146{
147 return readRefNodeFiles(parser,Registry::instance()->getOptions());
148}
149
157extern OSGDB_EXPORT osg::ref_ptr<osg::Shader> readRefShaderFile(const std::string& filename,const Options* options);
158
165inline osg::ref_ptr<osg::Shader> readRefShaderFile(const std::string& filename)
166{
167 return readRefShaderFile(filename, Registry::instance()->getOptions());
168}
169
177inline osg::ref_ptr<osg::Shader> readRefShaderFile(osg::Shader::Type type, const std::string& filename, const Options* options)
178{
179 osg::ref_ptr<osg::Shader> shader = readRefShaderFile(filename, options);
180 if (shader.valid() && type != osg::Shader::UNDEFINED) shader->setType(type);
181 return shader;
182}
183
190inline osg::ref_ptr<osg::Shader> readRefShaderFile(osg::Shader::Type type, const std::string& filename)
191{
192 return readRefShaderFile(type, filename, Registry::instance()->getOptions());
193}
194
200extern OSGDB_EXPORT osg::ref_ptr<osg::Shader> readRefShaderFileWithFallback(osg::Shader::Type type, const std::string& filename, const Options* options, const char* fallback);
201
206inline osg::ref_ptr<osg::Shader> readRefShaderFileWithFallback(osg::Shader::Type type, const std::string& filename, const char* fallback)
207{
208 return osgDB::readRefShaderFileWithFallback(type, filename, Registry::instance()->getOptions(), fallback);
209}
210
218extern OSGDB_EXPORT osg::ref_ptr<osg::Script> readRefScriptFile(const std::string& filename,const Options* options);
219
226inline osg::ref_ptr<osg::Script> readRefScriptFile(const std::string& filename)
227{
228 return readRefScriptFile(filename,Registry::instance()->getOptions());
229}
230
231#ifdef OSG_PROVIDE_READFILE
239extern OSGDB_EXPORT osg::Object* readObjectFile(const std::string& filename,const Options* options);
240
247inline osg::Object* readObjectFile(const std::string& filename)
248{
249 return readObjectFile(filename, Registry::instance()->getOptions());
250}
251
252template<typename T>
253inline T* readFile(const std::string& filename, const Options* options)
254{
255 osg::ref_ptr<osg::Object> object = readRefObjectFile(filename, options);
256 osg::ref_ptr<T> t = dynamic_cast<T*>(object.get());
257 object = 0;
258 return t.release();
259}
260
261template<typename T>
262inline T* readFile(const std::string& filename)
263{
264 return readFile<T>(filename, Registry::instance()->getOptions());
265}
266
267
275extern OSGDB_EXPORT osg::Image* readImageFile(const std::string& filename,const Options* options);
276
283inline osg::Image* readImageFile(const std::string& filename)
284{
285 return readImageFile(filename,Registry::instance()->getOptions());
286}
287
295extern OSGDB_EXPORT osg::HeightField* readHeightFieldFile(const std::string& filename,const Options* options);
296
303inline osg::HeightField* readHeightFieldFile(const std::string& filename)
304{
305 return readHeightFieldFile(filename,Registry::instance()->getOptions());
306}
307
315extern OSGDB_EXPORT osg::Node* readNodeFile(const std::string& filename,const Options* options);
316
323inline osg::Node* readNodeFile(const std::string& filename)
324{
325 return readNodeFile(filename,Registry::instance()->getOptions());
326}
327
328
333extern OSGDB_EXPORT osg::Node* readNodeFiles(std::vector<std::string>& fileList,const Options* options);
334
337inline osg::Node* readNodeFiles(std::vector<std::string>& fileList)
338{
339 return readNodeFiles(fileList,Registry::instance()->getOptions());
340}
341
342
346extern OSGDB_EXPORT osg::Node* readNodeFiles(osg::ArgumentParser& parser,const Options* options);
347
350inline osg::Node* readNodeFiles(osg::ArgumentParser& parser)
351{
352 return readNodeFiles(parser,Registry::instance()->getOptions());
353}
354
362extern OSGDB_EXPORT osg::Shader* readShaderFile(const std::string& filename,const Options* options);
363
370inline osg::Shader* readShaderFile(const std::string& filename)
371{
372 return readShaderFile(filename,Registry::instance()->getOptions());
373}
374
382inline osg::Shader* readShaderFile(osg::Shader::Type type, const std::string& filename,const Options* options)
383{
384 osg::Shader* shader = readShaderFile(filename, options);
385 if (shader && type != osg::Shader::UNDEFINED) shader->setType(type);
386 return shader;
387}
388
395inline osg::Shader* readShaderFile(osg::Shader::Type type, const std::string& filename)
396{
397 return readShaderFile(type, filename,Registry::instance()->getOptions());
398}
399
400
406inline osg::Shader* readShaderFileWithFallback(osg::Shader::Type type, const std::string& filename, const Options* options, const char* fallback)
407{
408 osg::Shader* shader = readShaderFile(filename, options);
409 if (shader && type != osg::Shader::UNDEFINED) shader->setType(type);
410 if (!shader) shader = new osg::Shader(type, fallback);
411 return shader;
412}
413
418inline osg::Shader* readShaderFileWithFallback(osg::Shader::Type type, const std::string& filename, const char* fallback)
419{
420 return osgDB::readShaderFileWithFallback(type, filename, Registry::instance()->getOptions(), fallback);
421}
422
430extern OSGDB_EXPORT osg::Script* readScriptFile(const std::string& filename,const Options* options);
431
438inline osg::Script* readScriptFile(const std::string& filename)
439{
440 return readScriptFile(filename,Registry::instance()->getOptions());
441}
442#endif
443
444
445}
446
447#endif
The osgDB library provides support for reading and writing scene graphs, providing a plugin framework...
Definition Archive:24
OSGDB_EXPORT osg::ref_ptr< osg::Node > readRefNodeFile(const std::string &filename, const Options *options)
Read an osg::Node from file.
OSGDB_EXPORT osg::ref_ptr< osg::Object > readRefObjectFile(const std::string &filename, const Options *options)
Read an osg::Object from file.
OSGDB_EXPORT osg::ref_ptr< osg::Script > readRefScriptFile(const std::string &filename, const Options *options)
Read an osg::Script from file.
OSGDB_EXPORT osg::ref_ptr< osg::Shader > readRefShaderFile(const std::string &filename, const Options *options)
Read an osg::Shader from file.
OSGDB_EXPORT osg::ref_ptr< osg::Image > readRefImageFile(const std::string &filename, const Options *options)
Read an osg::Image from file.
OSGDB_EXPORT osg::ref_ptr< osg::Shader > readRefShaderFileWithFallback(osg::Shader::Type type, const std::string &filename, const Options *options, const char *fallback)
Read an osg::Shader from file and set to specified shader type, if a shader isn't loaded fallback to ...
OSGDB_EXPORT osg::ref_ptr< osg::Node > readRefNodeFiles(std::vector< std::string > &fileList, const Options *options)
Read an osg::Node subgraph from files, creating a osg::Group to contain the nodes if more than one su...
osg::ref_ptr< T > readRefFile(const std::string &filename, const Options *options)
Definition ReadFile:50
OSGDB_EXPORT osg::ref_ptr< osg::HeightField > readRefHeightFieldFile(const std::string &filename, const Options *options)
Read an osg::HeightField from file.
Definition ArgumentParser:28
Base class/standard interface for objects which require IO support, cloning and reference counting.
Definition Object:61
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
T * release()
release the pointer from ownership by this ref_ptr<>, decrementing the objects refencedCount() via un...
Definition ref_ptr:126
bool valid() const
Definition ref_ptr:120
bool setType(Type t)
Set the Shader type as an enum.
Type
Definition Shader:92
@ UNDEFINED
Definition Shader:99
Options base class used for passing options into plugins to control their operation.
Definition Options:30
static Registry * instance(bool erase=false)
#define OSGDB_EXPORT
Definition Export:39

osg logo
Generated at Sun Jul 27 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.