Added readScript/writeScript methods to ReaderWriter
git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14366 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
@@ -65,6 +65,8 @@ class OSGDB_EXPORT ReadFileCallback : public virtual osg::Referenced
|
||||
|
||||
virtual ReaderWriter::ReadResult readShader(const std::string& filename, const Options* options);
|
||||
|
||||
virtual ReaderWriter::ReadResult readScript(const std::string& filename, const Options* options);
|
||||
|
||||
protected:
|
||||
virtual ~ReadFileCallback() {}
|
||||
};
|
||||
@@ -83,6 +85,8 @@ class OSGDB_EXPORT WriteFileCallback : public virtual osg::Referenced
|
||||
|
||||
virtual ReaderWriter::WriteResult writeShader(const osg::Shader& obj, const std::string& fileName,const Options* options);
|
||||
|
||||
virtual ReaderWriter::WriteResult writeScript(const osg::Script& obj, const std::string& fileName,const Options* options);
|
||||
|
||||
protected:
|
||||
virtual ~WriteFileCallback() {}
|
||||
};
|
||||
|
||||
@@ -194,6 +194,29 @@ inline osg::Shader* readShaderFile(osg::Shader::Type type, const std::string& fi
|
||||
return readShaderFile(type, filename,Registry::instance()->getOptions());
|
||||
}
|
||||
|
||||
|
||||
/** Read an osg::Script from file.
|
||||
* Return valid osg::Script on success,
|
||||
* return NULL on failure.
|
||||
* Use the Options object to control cache operations and file search paths in osgDB::Registry.
|
||||
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
|
||||
* for the filename extension, and this plugin then handles the request
|
||||
* to read the specified file.*/
|
||||
extern OSGDB_EXPORT osg::Script* readScriptFile(const std::string& filename,const Options* options);
|
||||
|
||||
/** Read an osg::Script from file.
|
||||
* Return valid osg::Script on success,
|
||||
* return NULL on failure.
|
||||
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
|
||||
* for the filename extension, and this plugin then handles the request
|
||||
* to read the specified file.*/
|
||||
inline osg::Script* readScriptFile(const std::string& filename)
|
||||
{
|
||||
return readScriptFile(filename,Registry::instance()->getOptions());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Read an osg::Object from file.
|
||||
* Return an assigned osg::ref_ptr on success,
|
||||
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
|
||||
@@ -221,7 +244,7 @@ inline osg::ref_ptr<osg::Object> readRefObjectFile(const std::string& filename)
|
||||
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
|
||||
* for the filename extension, and this plugin then handles the request
|
||||
* to read the specified file.*/
|
||||
extern OSGDB_EXPORT osg::ref_ptr<osg::Image> readRefImageFile(const std::string& filename,const Options* options);
|
||||
extern OSGDB_EXPORT osg::ref_ptr<osg::Image> readRefImageFile(const std::string& filename,const Options* options);
|
||||
|
||||
/** Read an osg::Image from file.
|
||||
* Return an assigned osg::ref_ptr on success,
|
||||
@@ -229,7 +252,7 @@ extern OSGDB_EXPORT osg::ref_ptr<osg::Image> readRefImageFile(const std::string
|
||||
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
|
||||
* for the filename extension, and this plugin then handles the request
|
||||
* to read the specified file.*/
|
||||
inline osg::ref_ptr<osg::Image> readRefImageFile(const std::string& filename)
|
||||
inline osg::ref_ptr<osg::Image> readRefImageFile(const std::string& filename)
|
||||
{
|
||||
return readRefImageFile(filename,Registry::instance()->getOptions());
|
||||
}
|
||||
@@ -241,7 +264,7 @@ inline osg::ref_ptr<osg::Image> readRefImageFile(const std::string& filename)
|
||||
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
|
||||
* for the filename extension, and this plugin then handles the request
|
||||
* to read the specified file.*/
|
||||
extern OSGDB_EXPORT osg::ref_ptr<osg::HeightField> readRefHeightFieldFile(const std::string& filename,const Options* options);
|
||||
extern OSGDB_EXPORT osg::ref_ptr<osg::HeightField> readRefHeightFieldFile(const std::string& filename,const Options* options);
|
||||
|
||||
/** Read an osg::HeightField from file.
|
||||
* Return an assigned osg::ref_ptr on success,
|
||||
@@ -249,7 +272,7 @@ extern OSGDB_EXPORT osg::ref_ptr<osg::HeightField> readRefHeightFieldFile(const
|
||||
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
|
||||
* for the filename extension, and this plugin then handles the request
|
||||
* to read the specified file.*/
|
||||
inline osg::ref_ptr<osg::HeightField> readRefHeightFieldFile(const std::string& filename)
|
||||
inline osg::ref_ptr<osg::HeightField> readRefHeightFieldFile(const std::string& filename)
|
||||
{
|
||||
return readRefHeightFieldFile(filename,Registry::instance()->getOptions());
|
||||
}
|
||||
@@ -261,7 +284,7 @@ inline osg::ref_ptr<osg::HeightField> readRefHeightFieldFile(const std::string&
|
||||
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
|
||||
* for the filename extension, and this plugin then handles the request
|
||||
* to read the specified file.*/
|
||||
extern OSGDB_EXPORT osg::ref_ptr<osg::Node> readRefNodeFile(const std::string& filename,const Options* options);
|
||||
extern OSGDB_EXPORT osg::ref_ptr<osg::Node> readRefNodeFile(const std::string& filename,const Options* options);
|
||||
|
||||
/** Read an osg::Node from file.
|
||||
* Return an assigned osg::ref_ptr on success,
|
||||
@@ -269,7 +292,7 @@ extern OSGDB_EXPORT osg::ref_ptr<osg::Node> readRefNodeFile(const std::string&
|
||||
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
|
||||
* for the filename extension, and this plugin then handles the request
|
||||
* to read the specified file.*/
|
||||
inline osg::ref_ptr<osg::Node> readRefNodeFile(const std::string& filename)
|
||||
inline osg::ref_ptr<osg::Node> readRefNodeFile(const std::string& filename)
|
||||
{
|
||||
return readRefNodeFile(filename,Registry::instance()->getOptions());
|
||||
}
|
||||
@@ -289,7 +312,7 @@ extern OSGDB_EXPORT osg::ref_ptr<osg::Shader> readRefShaderFile(const std::strin
|
||||
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
|
||||
* for the filename extension, and this plugin then handles the request
|
||||
* to read the specified file.*/
|
||||
inline osg::ref_ptr<osg::Shader> readRefShaderFile(const std::string& filename)
|
||||
inline osg::ref_ptr<osg::Shader> readRefShaderFile(const std::string& filename)
|
||||
{
|
||||
return readRefShaderFile(filename, Registry::instance()->getOptions());
|
||||
}
|
||||
@@ -320,6 +343,26 @@ inline osg::ref_ptr<osg::Shader> readRefShaderFile(osg::Shader::Type type, const
|
||||
}
|
||||
|
||||
|
||||
/** Read an osg::Script from file.
|
||||
* Return an assigned osg::ref_ptr on success,
|
||||
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
|
||||
* Use the Options object to control cache operations and file search paths in osgDB::Registry.
|
||||
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
|
||||
* for the filename extension, and this plugin then handles the request
|
||||
* to read the specified file.*/
|
||||
extern OSGDB_EXPORT osg::ref_ptr<osg::Script> readRefScriptFile(const std::string& filename,const Options* options);
|
||||
|
||||
/** Read an osg::Script from file.
|
||||
* Return an assigned osg::ref_ptr on success,
|
||||
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
|
||||
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
|
||||
* for the filename extension, and this plugin then handles the request
|
||||
* to read the specified file.*/
|
||||
inline osg::ref_ptr<osg::Script> readRefScriptFile(const std::string& filename)
|
||||
{
|
||||
return readRefScriptFile(filename,Registry::instance()->getOptions());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <osg/Image>
|
||||
#include <osg/Shape>
|
||||
#include <osg/Node>
|
||||
#include <osg/ScriptEngine>
|
||||
|
||||
#include <osgDB/AuthenticationMap>
|
||||
|
||||
@@ -64,7 +65,7 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
|
||||
|
||||
/** Return true if ReaderWriter accepts specified file extension.*/
|
||||
virtual bool acceptsExtension(const std::string& /*extension*/) const;
|
||||
|
||||
|
||||
virtual bool acceptsProtocol(const std::string& protocol) const;
|
||||
|
||||
/// Bit mask for setting up which feature types are available for read and/or write
|
||||
@@ -81,16 +82,20 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
|
||||
FEATURE_WRITE_HEIGHT_FIELD = 1<<7,
|
||||
FEATURE_WRITE_NODE = 1<<8,
|
||||
FEATURE_WRITE_SHADER = 1<<9,
|
||||
FEATURE_READ_SCRIPT = 1<<10,
|
||||
FEATURE_WRITE_SCRIPT = 1<<11,
|
||||
FEATURE_ALL = FEATURE_READ_OBJECT |
|
||||
FEATURE_READ_IMAGE |
|
||||
FEATURE_READ_HEIGHT_FIELD |
|
||||
FEATURE_READ_NODE |
|
||||
FEATURE_READ_SHADER |
|
||||
FEATURE_READ_SCRIPT |
|
||||
FEATURE_WRITE_OBJECT |
|
||||
FEATURE_WRITE_IMAGE |
|
||||
FEATURE_WRITE_HEIGHT_FIELD |
|
||||
FEATURE_WRITE_NODE |
|
||||
FEATURE_WRITE_SHADER
|
||||
FEATURE_WRITE_SHADER |
|
||||
FEATURE_WRITE_SCRIPT
|
||||
};
|
||||
/** Return available features*/
|
||||
virtual Features supportedFeatures() const;
|
||||
@@ -124,13 +129,14 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
|
||||
ReadResult& operator = (const ReadResult& rr) { if (this==&rr) return *this; _status=rr._status; _message=rr._message;_object=rr._object; return *this; }
|
||||
|
||||
bool operator < (const ReadResult& rhs) const { return _status < rhs._status; }
|
||||
|
||||
|
||||
osg::Object* getObject();
|
||||
osg::Image* getImage();
|
||||
osg::HeightField* getHeightField();
|
||||
osg::Node* getNode();
|
||||
osgDB::Archive* getArchive();
|
||||
osg::Shader* getShader();
|
||||
osg::Script* getScript();
|
||||
|
||||
bool validObject() { return _object.valid(); }
|
||||
bool validImage() { return getImage()!=0; }
|
||||
@@ -138,6 +144,7 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
|
||||
bool validNode() { return getNode()!=0; }
|
||||
bool validArchive() { return getArchive()!=0; }
|
||||
bool validShader() { return getShader()!=0; }
|
||||
bool validScript() { return getScript()!=0; }
|
||||
|
||||
osg::Object* takeObject();
|
||||
osg::Image* takeImage();
|
||||
@@ -145,6 +152,7 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
|
||||
osg::Node* takeNode();
|
||||
osgDB::Archive* takeArchive();
|
||||
osg::Shader* takeShader();
|
||||
osg::Script* takeScript();
|
||||
|
||||
std::string& message() { return _message; }
|
||||
const std::string& message() const { return _message; }
|
||||
@@ -223,24 +231,28 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
|
||||
virtual ReadResult readHeightField(const std::string& /*fileName*/,const Options* =NULL) const { return ReadResult(ReadResult::NOT_IMPLEMENTED); }
|
||||
virtual ReadResult readNode(const std::string& /*fileName*/,const Options* =NULL) const { return ReadResult(ReadResult::NOT_IMPLEMENTED); }
|
||||
virtual ReadResult readShader(const std::string& /*fileName*/,const Options* =NULL) const { return ReadResult(ReadResult::NOT_IMPLEMENTED); }
|
||||
virtual ReadResult readScript(const std::string& /*fileName*/,const Options* =NULL) const { return ReadResult(ReadResult::NOT_IMPLEMENTED); }
|
||||
|
||||
virtual WriteResult writeObject(const osg::Object& /*obj*/,const std::string& /*fileName*/,const Options* =NULL) const {return WriteResult(WriteResult::NOT_IMPLEMENTED); }
|
||||
virtual WriteResult writeImage(const osg::Image& /*image*/,const std::string& /*fileName*/,const Options* =NULL) const {return WriteResult(WriteResult::NOT_IMPLEMENTED); }
|
||||
virtual WriteResult writeHeightField(const osg::HeightField& /*heightField*/,const std::string& /*fileName*/,const Options* =NULL) const {return WriteResult(WriteResult::NOT_IMPLEMENTED); }
|
||||
virtual WriteResult writeNode(const osg::Node& /*node*/,const std::string& /*fileName*/,const Options* =NULL) const { return WriteResult(WriteResult::NOT_IMPLEMENTED); }
|
||||
virtual WriteResult writeShader(const osg::Shader& /*shader*/,const std::string& /*fileName*/,const Options* =NULL) const {return WriteResult(WriteResult::NOT_IMPLEMENTED); }
|
||||
virtual WriteResult writeScript(const osg::Script& /*script*/,const std::string& /*fileName*/,const Options* =NULL) const {return WriteResult(WriteResult::NOT_IMPLEMENTED); }
|
||||
|
||||
virtual ReadResult readObject(std::istream& /*fin*/,const Options* =NULL) const { return ReadResult(ReadResult::NOT_IMPLEMENTED); }
|
||||
virtual ReadResult readImage(std::istream& /*fin*/,const Options* =NULL) const { return ReadResult(ReadResult::NOT_IMPLEMENTED); }
|
||||
virtual ReadResult readHeightField(std::istream& /*fin*/,const Options* =NULL) const { return ReadResult(ReadResult::NOT_IMPLEMENTED); }
|
||||
virtual ReadResult readNode(std::istream& /*fin*/,const Options* =NULL) const { return ReadResult(ReadResult::NOT_IMPLEMENTED); }
|
||||
virtual ReadResult readShader(std::istream& /*fin*/,const Options* =NULL) const { return ReadResult(ReadResult::NOT_IMPLEMENTED); }
|
||||
virtual ReadResult readScript(std::istream& /*fin*/,const Options* =NULL) const { return ReadResult(ReadResult::NOT_IMPLEMENTED); }
|
||||
|
||||
virtual WriteResult writeObject(const osg::Object& /*obj*/,std::ostream& /*fout*/,const Options* =NULL) const { return WriteResult(WriteResult::NOT_IMPLEMENTED); }
|
||||
virtual WriteResult writeImage(const osg::Image& /*image*/,std::ostream& /*fout*/,const Options* =NULL) const { return WriteResult(WriteResult::NOT_IMPLEMENTED); }
|
||||
virtual WriteResult writeHeightField(const osg::HeightField& /*heightField*/,std::ostream& /*fout*/,const Options* =NULL) const { return WriteResult(WriteResult::NOT_IMPLEMENTED); }
|
||||
virtual WriteResult writeNode(const osg::Node& /*node*/,std::ostream& /*fout*/,const Options* =NULL) const { return WriteResult(WriteResult::NOT_IMPLEMENTED); }
|
||||
virtual WriteResult writeShader(const osg::Shader& /*shader*/,std::ostream& /*fout*/,const Options* =NULL) const { return WriteResult(WriteResult::NOT_IMPLEMENTED); }
|
||||
virtual WriteResult writeScript(const osg::Script& /*script*/,std::ostream& /*fout*/,const Options* =NULL) const { return WriteResult(WriteResult::NOT_IMPLEMENTED); }
|
||||
|
||||
/** Specify fmt string as a supported protocol.
|
||||
* Please note, this method should usually only be used internally by subclasses of ReaderWriter, Only in special cases
|
||||
|
||||
@@ -128,10 +128,10 @@ class OSGDB_EXPORT Registry : public osg::Referenced
|
||||
|
||||
/** get const list of all registered ReaderWriters.*/
|
||||
const ReaderWriterList& getReaderWriterList() const { return _rwList; }
|
||||
|
||||
|
||||
/** get a list of registered ReaderWriters which can handle given protocol */
|
||||
void getReaderWriterListForProtocol(const std::string& protocol, ReaderWriterList& results) const;
|
||||
|
||||
|
||||
ReaderWriter* getReaderWriterForProtocolAndExtension(const std::string& protocol, const std::string& extension);
|
||||
|
||||
|
||||
@@ -251,6 +251,14 @@ class OSGDB_EXPORT Registry : public osg::Referenced
|
||||
}
|
||||
ReaderWriter::ReadResult readShaderImplementation(const std::string& fileName,const Options* options);
|
||||
|
||||
ReaderWriter::ReadResult readScript(const std::string& fileName,const Options* options)
|
||||
{
|
||||
if (options && options->getReadFileCallback()) return options->getReadFileCallback()->readScript(fileName,options);
|
||||
else if (_readFileCallback.valid()) return _readFileCallback->readScript(fileName,options);
|
||||
else return readScriptImplementation(fileName,options);
|
||||
}
|
||||
ReaderWriter::ReadResult readScriptImplementation(const std::string& fileName,const Options* options);
|
||||
|
||||
|
||||
/** Set the Registry callback to use in place of the default writeFile calls.*/
|
||||
void setWriteFileCallback( WriteFileCallback* cb) { _writeFileCallback = cb; }
|
||||
@@ -302,6 +310,13 @@ class OSGDB_EXPORT Registry : public osg::Referenced
|
||||
}
|
||||
ReaderWriter::WriteResult writeShaderImplementation(const osg::Shader& obj, const std::string& fileName,const Options* options);
|
||||
|
||||
ReaderWriter::WriteResult writeScript(const osg::Script& obj, const std::string& fileName,const Options* options)
|
||||
{
|
||||
if (options && options->getWriteFileCallback()) return options->getWriteFileCallback()->writeScript(obj,fileName,options);
|
||||
else if (_writeFileCallback.valid()) return _writeFileCallback->writeScript(obj,fileName,options);
|
||||
else return writeScriptImplementation(obj,fileName,options);
|
||||
}
|
||||
ReaderWriter::WriteResult writeScriptImplementation(const osg::Script& obj, const std::string& fileName,const Options* options);
|
||||
|
||||
inline void _buildKdTreeIfRequired(ReaderWriter::ReadResult& result, const Options* options)
|
||||
{
|
||||
@@ -551,6 +566,7 @@ class OSGDB_EXPORT Registry : public osg::Referenced
|
||||
struct ReadNodeFunctor;
|
||||
struct ReadArchiveFunctor;
|
||||
struct ReadShaderFunctor;
|
||||
struct ReadScriptFunctor;
|
||||
|
||||
// make helper classes friends to get round VS6.0 "issues"
|
||||
friend struct ReadFunctor;
|
||||
@@ -560,6 +576,7 @@ class OSGDB_EXPORT Registry : public osg::Referenced
|
||||
friend struct ReadNodeFunctor;
|
||||
friend struct ReadArchiveFunctor;
|
||||
friend struct ReadShaderFunctor;
|
||||
friend struct ReadScriptFunctor;
|
||||
|
||||
ReaderWriter::ReadResult read(const ReadFunctor& readFunctor);
|
||||
ReaderWriter::ReadResult readImplementation(const ReadFunctor& readFunctor,Options::CacheHintOptions cacheHint);
|
||||
|
||||
@@ -125,6 +125,26 @@ inline bool writeShaderFile(const osg::Shader& shader, const std::string& filena
|
||||
return writeShaderFile( shader, filename, Registry::instance()->getOptions() );
|
||||
}
|
||||
|
||||
/** Write an osg::Script to file.
|
||||
* Return true on success,
|
||||
* return false on failure.
|
||||
* Use the Options object to control cache operations and file search paths in osgDB::Registry.
|
||||
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
|
||||
* for the filename extension, and this plugin then handles the request
|
||||
* to write the specified file.*/
|
||||
extern OSGDB_EXPORT bool writeScriptFile(const osg::Script& image, const std::string& filename, const Options* options );
|
||||
|
||||
/** Write an osg::Script to file.
|
||||
* Return true on success,
|
||||
* return false on failure.
|
||||
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
|
||||
* for the filename extension, and this plugin then handles the request
|
||||
* to write the specified file.*/
|
||||
inline bool writeScriptFile(const osg::Script& image, const std::string& filename)
|
||||
{
|
||||
return writeScriptFile( image, filename, Registry::instance()->getOptions() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user