2010-01-21 04:13:33 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
// Written by Wang Rui, (C) 2010
|
|
|
|
|
|
|
|
#include <osg/Version>
|
|
|
|
#include <osg/Notify>
|
|
|
|
#include <osgDB/FileUtils>
|
|
|
|
#include <osgDB/WriteFile>
|
|
|
|
#include <osgDB/ObjectWrapper>
|
|
|
|
#include <fstream>
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#include <sstream>
|
2010-01-21 04:13:33 +08:00
|
|
|
|
|
|
|
using namespace osgDB;
|
|
|
|
|
2010-01-25 19:03:21 +08:00
|
|
|
OutputStream::OutputStream( const osgDB::Options* options )
|
From Wang Rui, "The file attached includes two new features for the serialization IO functionality. First, custom serializer version control should work now, just by defining a new REGISTER_CUSTOM_OBJECT_WRAPPER macro. For example:
// A custom class
namespace CustomDomain {
class MyGroup : public osg::Group
{
public:
META_Node( CustomDomain, MyGroup );
void setMyName( const std::string& n );
const std::string& getMyName() const;
void setMyID( int id );
int getMyID() const;
...
};
}
// The serialization wrapper using a custom domain name
REGISTER_CUSTOM_OBJECT_WRAPPER( MyDomain,
CustomDomain_MyGroup,
new CustomDomain::MyGroup,
CustomDomain::MyGroup,
"osg::Object osg::Node osg::Group CustomDomain::MyGroup" )
{
ADD_STRING_SERIALIZER( MyName, std::string() );
{
UPDATE_TO_VERSION_SCOPED( 1 ); // Updated for a new domain version
ADD_INT_SERIALIZER( MyID, 0 );
}
}
Save the class instance as follows:
osgDB::writeNodeFile( *myGroup, "serializer_test.osgt", new osgDB::Options("CustomDomains=MyDomain:1") );
The output file will include the domain version definition and all the class data, and can be read back. We can also force setting the domain version by the CustomDomains option while reading the saved files. If we save the class instance without any options, MyID will be ignored because the default domain version is 0.
This may help third-party libraries like osgEarth to maintain their own serializers without regarding to the OSG soversion changes.
Another feature added is a more robust binary format, which in fact adds a size-offset at each block's beginning. When there are problems or unsupported data types while reading, we can now directly jump to the block end indicated by the offset value. So a .osgb file will automatically ignore bad data and read remains as normal (at present it will fail at all). This feature will not break the backward compatibility, and can be disabled by setting "RobustBinaryFormat=false" while writing out.
Hope these changes can work smoothly with present and future community projects. Maybe we should also consider have an osgserializer example to test and demonstrate all things we can do now."
2013-06-24 16:48:55 +08:00
|
|
|
: _writeImageHint(WRITE_USE_IMAGE_HINT), _useSchemaData(false), _useRobustBinaryFormat(true)
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
2012-04-05 21:53:47 +08:00
|
|
|
BEGIN_BRACKET.set( "{", +INDENT_VALUE );
|
|
|
|
END_BRACKET.set( "}", -INDENT_VALUE );
|
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
if ( !options ) return;
|
2010-02-26 01:53:51 +08:00
|
|
|
_options = options;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
From Wang Rui, "The file attached includes two new features for the serialization IO functionality. First, custom serializer version control should work now, just by defining a new REGISTER_CUSTOM_OBJECT_WRAPPER macro. For example:
// A custom class
namespace CustomDomain {
class MyGroup : public osg::Group
{
public:
META_Node( CustomDomain, MyGroup );
void setMyName( const std::string& n );
const std::string& getMyName() const;
void setMyID( int id );
int getMyID() const;
...
};
}
// The serialization wrapper using a custom domain name
REGISTER_CUSTOM_OBJECT_WRAPPER( MyDomain,
CustomDomain_MyGroup,
new CustomDomain::MyGroup,
CustomDomain::MyGroup,
"osg::Object osg::Node osg::Group CustomDomain::MyGroup" )
{
ADD_STRING_SERIALIZER( MyName, std::string() );
{
UPDATE_TO_VERSION_SCOPED( 1 ); // Updated for a new domain version
ADD_INT_SERIALIZER( MyID, 0 );
}
}
Save the class instance as follows:
osgDB::writeNodeFile( *myGroup, "serializer_test.osgt", new osgDB::Options("CustomDomains=MyDomain:1") );
The output file will include the domain version definition and all the class data, and can be read back. We can also force setting the domain version by the CustomDomains option while reading the saved files. If we save the class instance without any options, MyID will be ignored because the default domain version is 0.
This may help third-party libraries like osgEarth to maintain their own serializers without regarding to the OSG soversion changes.
Another feature added is a more robust binary format, which in fact adds a size-offset at each block's beginning. When there are problems or unsupported data types while reading, we can now directly jump to the block end indicated by the offset value. So a .osgb file will automatically ignore bad data and read remains as normal (at present it will fail at all). This feature will not break the backward compatibility, and can be disabled by setting "RobustBinaryFormat=false" while writing out.
Hope these changes can work smoothly with present and future community projects. Maybe we should also consider have an osgserializer example to test and demonstrate all things we can do now."
2013-06-24 16:48:55 +08:00
|
|
|
if ( options->getPluginStringData("RobustBinaryFormat")=="false" )
|
|
|
|
_useRobustBinaryFormat = false;
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
if ( options->getPluginStringData("SchemaData")=="true" )
|
|
|
|
_useSchemaData = true;
|
|
|
|
if ( !options->getPluginStringData("SchemaFile").empty() )
|
|
|
|
_schemaName = options->getPluginStringData("SchemaFile");
|
|
|
|
if ( !options->getPluginStringData("Compressor").empty() )
|
|
|
|
_compressorName = options->getPluginStringData("Compressor");
|
|
|
|
if ( !options->getPluginStringData("WriteImageHint").empty() )
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
std::string hintString = options->getPluginStringData("WriteImageHint");
|
|
|
|
if ( hintString=="IncludeData" ) _writeImageHint = WRITE_INLINE_DATA;
|
|
|
|
else if ( hintString=="IncludeFile" ) _writeImageHint = WRITE_INLINE_FILE;
|
|
|
|
else if ( hintString=="UseExternal" ) _writeImageHint = WRITE_USE_EXTERNAL;
|
|
|
|
else if ( hintString=="WriteOut" ) _writeImageHint = WRITE_EXTERNAL_FILE;
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
From Wang Rui, "The file attached includes two new features for the serialization IO functionality. First, custom serializer version control should work now, just by defining a new REGISTER_CUSTOM_OBJECT_WRAPPER macro. For example:
// A custom class
namespace CustomDomain {
class MyGroup : public osg::Group
{
public:
META_Node( CustomDomain, MyGroup );
void setMyName( const std::string& n );
const std::string& getMyName() const;
void setMyID( int id );
int getMyID() const;
...
};
}
// The serialization wrapper using a custom domain name
REGISTER_CUSTOM_OBJECT_WRAPPER( MyDomain,
CustomDomain_MyGroup,
new CustomDomain::MyGroup,
CustomDomain::MyGroup,
"osg::Object osg::Node osg::Group CustomDomain::MyGroup" )
{
ADD_STRING_SERIALIZER( MyName, std::string() );
{
UPDATE_TO_VERSION_SCOPED( 1 ); // Updated for a new domain version
ADD_INT_SERIALIZER( MyID, 0 );
}
}
Save the class instance as follows:
osgDB::writeNodeFile( *myGroup, "serializer_test.osgt", new osgDB::Options("CustomDomains=MyDomain:1") );
The output file will include the domain version definition and all the class data, and can be read back. We can also force setting the domain version by the CustomDomains option while reading the saved files. If we save the class instance without any options, MyID will be ignored because the default domain version is 0.
This may help third-party libraries like osgEarth to maintain their own serializers without regarding to the OSG soversion changes.
Another feature added is a more robust binary format, which in fact adds a size-offset at each block's beginning. When there are problems or unsupported data types while reading, we can now directly jump to the block end indicated by the offset value. So a .osgb file will automatically ignore bad data and read remains as normal (at present it will fail at all). This feature will not break the backward compatibility, and can be disabled by setting "RobustBinaryFormat=false" while writing out.
Hope these changes can work smoothly with present and future community projects. Maybe we should also consider have an osgserializer example to test and demonstrate all things we can do now."
2013-06-24 16:48:55 +08:00
|
|
|
|
|
|
|
if ( !options->getPluginStringData("CustomDomains").empty() )
|
|
|
|
{
|
|
|
|
StringList domains, keyAndValue;
|
|
|
|
split( options->getPluginStringData("CustomDomains"), domains, ';' );
|
|
|
|
for ( unsigned int i=0; i<domains.size(); ++i )
|
|
|
|
{
|
|
|
|
split( domains[i], keyAndValue, ':' );
|
|
|
|
if ( keyAndValue.size()>1 )
|
|
|
|
_domainVersionMap[keyAndValue.front()] = atoi(keyAndValue.back().c_str());
|
|
|
|
}
|
|
|
|
}
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
OutputStream::~OutputStream()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
From Wang Rui, "The file attached includes two new features for the serialization IO functionality. First, custom serializer version control should work now, just by defining a new REGISTER_CUSTOM_OBJECT_WRAPPER macro. For example:
// A custom class
namespace CustomDomain {
class MyGroup : public osg::Group
{
public:
META_Node( CustomDomain, MyGroup );
void setMyName( const std::string& n );
const std::string& getMyName() const;
void setMyID( int id );
int getMyID() const;
...
};
}
// The serialization wrapper using a custom domain name
REGISTER_CUSTOM_OBJECT_WRAPPER( MyDomain,
CustomDomain_MyGroup,
new CustomDomain::MyGroup,
CustomDomain::MyGroup,
"osg::Object osg::Node osg::Group CustomDomain::MyGroup" )
{
ADD_STRING_SERIALIZER( MyName, std::string() );
{
UPDATE_TO_VERSION_SCOPED( 1 ); // Updated for a new domain version
ADD_INT_SERIALIZER( MyID, 0 );
}
}
Save the class instance as follows:
osgDB::writeNodeFile( *myGroup, "serializer_test.osgt", new osgDB::Options("CustomDomains=MyDomain:1") );
The output file will include the domain version definition and all the class data, and can be read back. We can also force setting the domain version by the CustomDomains option while reading the saved files. If we save the class instance without any options, MyID will be ignored because the default domain version is 0.
This may help third-party libraries like osgEarth to maintain their own serializers without regarding to the OSG soversion changes.
Another feature added is a more robust binary format, which in fact adds a size-offset at each block's beginning. When there are problems or unsupported data types while reading, we can now directly jump to the block end indicated by the offset value. So a .osgb file will automatically ignore bad data and read remains as normal (at present it will fail at all). This feature will not break the backward compatibility, and can be disabled by setting "RobustBinaryFormat=false" while writing out.
Hope these changes can work smoothly with present and future community projects. Maybe we should also consider have an osgserializer example to test and demonstrate all things we can do now."
2013-06-24 16:48:55 +08:00
|
|
|
int OutputStream::getFileVersion( const std::string& d ) const
|
|
|
|
{
|
|
|
|
if ( d.empty() ) return OPENSCENEGRAPH_SOVERSION;
|
2013-06-24 17:02:32 +08:00
|
|
|
VersionMap::const_iterator itr = _domainVersionMap.find(d);
|
From Wang Rui, "The file attached includes two new features for the serialization IO functionality. First, custom serializer version control should work now, just by defining a new REGISTER_CUSTOM_OBJECT_WRAPPER macro. For example:
// A custom class
namespace CustomDomain {
class MyGroup : public osg::Group
{
public:
META_Node( CustomDomain, MyGroup );
void setMyName( const std::string& n );
const std::string& getMyName() const;
void setMyID( int id );
int getMyID() const;
...
};
}
// The serialization wrapper using a custom domain name
REGISTER_CUSTOM_OBJECT_WRAPPER( MyDomain,
CustomDomain_MyGroup,
new CustomDomain::MyGroup,
CustomDomain::MyGroup,
"osg::Object osg::Node osg::Group CustomDomain::MyGroup" )
{
ADD_STRING_SERIALIZER( MyName, std::string() );
{
UPDATE_TO_VERSION_SCOPED( 1 ); // Updated for a new domain version
ADD_INT_SERIALIZER( MyID, 0 );
}
}
Save the class instance as follows:
osgDB::writeNodeFile( *myGroup, "serializer_test.osgt", new osgDB::Options("CustomDomains=MyDomain:1") );
The output file will include the domain version definition and all the class data, and can be read back. We can also force setting the domain version by the CustomDomains option while reading the saved files. If we save the class instance without any options, MyID will be ignored because the default domain version is 0.
This may help third-party libraries like osgEarth to maintain their own serializers without regarding to the OSG soversion changes.
Another feature added is a more robust binary format, which in fact adds a size-offset at each block's beginning. When there are problems or unsupported data types while reading, we can now directly jump to the block end indicated by the offset value. So a .osgb file will automatically ignore bad data and read remains as normal (at present it will fail at all). This feature will not break the backward compatibility, and can be disabled by setting "RobustBinaryFormat=false" while writing out.
Hope these changes can work smoothly with present and future community projects. Maybe we should also consider have an osgserializer example to test and demonstrate all things we can do now."
2013-06-24 16:48:55 +08:00
|
|
|
return itr==_domainVersionMap.end() ? 0 : itr->second;
|
|
|
|
}
|
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
OutputStream& OutputStream::operator<<( const osg::Vec2b& v )
|
|
|
|
{ *this << v.x() << v.y(); return *this; }
|
|
|
|
|
|
|
|
OutputStream& OutputStream::operator<<( const osg::Vec3b& v )
|
|
|
|
{ *this << v.x() << v.y() << v.z(); return *this; }
|
|
|
|
|
|
|
|
OutputStream& OutputStream::operator<<( const osg::Vec4b& v )
|
|
|
|
{ *this << v.x() << v.y() << v.z() << v.w(); return *this; }
|
|
|
|
|
|
|
|
OutputStream& OutputStream::operator<<( const osg::Vec4ub& v )
|
|
|
|
{ *this << v.r() << v.g() << v.b() << v.a(); return *this; }
|
|
|
|
|
|
|
|
OutputStream& OutputStream::operator<<( const osg::Vec2s& v )
|
|
|
|
{ *this << v.x() << v.y(); return *this; }
|
|
|
|
|
|
|
|
OutputStream& OutputStream::operator<<( const osg::Vec3s& v )
|
|
|
|
{ *this << v.x() << v.y() << v.z(); return *this; }
|
|
|
|
|
|
|
|
OutputStream& OutputStream::operator<<( const osg::Vec4s& v )
|
|
|
|
{ *this << v.x() << v.y() << v.z() << v.w(); return *this; }
|
|
|
|
|
|
|
|
OutputStream& OutputStream::operator<<( const osg::Vec2f& v )
|
|
|
|
{ *this << v.x() << v.y(); return *this; }
|
|
|
|
|
|
|
|
OutputStream& OutputStream::operator<<( const osg::Vec3f& v )
|
|
|
|
{ *this << v.x() << v.y() << v.z(); return *this; }
|
|
|
|
|
|
|
|
OutputStream& OutputStream::operator<<( const osg::Vec4f& v )
|
|
|
|
{ *this << v.x() << v.y() << v.z() << v.w(); return *this; }
|
|
|
|
|
|
|
|
OutputStream& OutputStream::operator<<( const osg::Vec2d& v )
|
|
|
|
{ *this << v.x() << v.y(); return *this; }
|
|
|
|
|
|
|
|
OutputStream& OutputStream::operator<<( const osg::Vec3d& v )
|
|
|
|
{ *this << v.x() << v.y() << v.z(); return *this; }
|
|
|
|
|
|
|
|
OutputStream& OutputStream::operator<<( const osg::Vec4d& v )
|
|
|
|
{ *this << v.x() << v.y() << v.z() << v.w(); return *this; }
|
|
|
|
|
|
|
|
OutputStream& OutputStream::operator<<( const osg::Quat& q )
|
|
|
|
{ *this << q.x() << q.y() << q.z() << q.w(); return *this; }
|
|
|
|
|
|
|
|
OutputStream& OutputStream::operator<<( const osg::Plane& p )
|
|
|
|
{ *this << (double)p[0] << (double)p[1] << (double)p[2] << (double)p[3]; return *this; }
|
|
|
|
|
2010-10-04 23:23:19 +08:00
|
|
|
|
|
|
|
#if 0
|
2010-01-21 04:13:33 +08:00
|
|
|
OutputStream& OutputStream::operator<<( const osg::Matrixf& mat )
|
|
|
|
{
|
2010-10-04 23:23:19 +08:00
|
|
|
*this << PROPERTY("Matrixf")<<BEGIN_BRACKET << std::endl;
|
2010-01-21 04:13:33 +08:00
|
|
|
for ( int r=0; r<4; ++r )
|
|
|
|
{
|
|
|
|
*this << mat(r, 0) << mat(r, 1)
|
|
|
|
<< mat(r, 2) << mat(r, 3) << std::endl;
|
|
|
|
}
|
|
|
|
*this << END_BRACKET << std::endl;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
OutputStream& OutputStream::operator<<( const osg::Matrixd& mat )
|
|
|
|
{
|
2010-10-04 23:23:19 +08:00
|
|
|
*this << PROPERTY("Matrixd")<<BEGIN_BRACKET << std::endl;
|
2010-01-21 04:13:33 +08:00
|
|
|
for ( int r=0; r<4; ++r )
|
|
|
|
{
|
|
|
|
*this << mat(r, 0) << mat(r, 1)
|
|
|
|
<< mat(r, 2) << mat(r, 3) << std::endl;
|
|
|
|
}
|
|
|
|
*this << END_BRACKET << std::endl;
|
|
|
|
return *this;
|
|
|
|
}
|
2010-10-04 23:23:19 +08:00
|
|
|
#else
|
|
|
|
OutputStream& OutputStream::operator<<( const osg::Matrixf& mat )
|
|
|
|
{
|
|
|
|
*this << BEGIN_BRACKET << std::endl;
|
|
|
|
for ( int r=0; r<4; ++r )
|
|
|
|
{
|
|
|
|
*this << (double)mat(r, 0) << (double)mat(r, 1)
|
|
|
|
<< (double)mat(r, 2) << (double)mat(r, 3) << std::endl;
|
|
|
|
}
|
|
|
|
*this << END_BRACKET << std::endl;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
OutputStream& OutputStream::operator<<( const osg::Matrixd& mat )
|
|
|
|
{
|
|
|
|
*this << BEGIN_BRACKET << std::endl;
|
|
|
|
for ( int r=0; r<4; ++r )
|
|
|
|
{
|
|
|
|
*this << mat(r, 0) << mat(r, 1)
|
|
|
|
<< mat(r, 2) << mat(r, 3) << std::endl;
|
|
|
|
}
|
|
|
|
*this << END_BRACKET << std::endl;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
#endif
|
2010-01-21 04:13:33 +08:00
|
|
|
|
|
|
|
void OutputStream::writeArray( const osg::Array* a )
|
|
|
|
{
|
|
|
|
if ( !a ) return;
|
2010-09-24 00:12:05 +08:00
|
|
|
|
|
|
|
bool newID = false;
|
|
|
|
unsigned int id = findOrCreateArrayID( a, newID );
|
2010-01-21 04:13:33 +08:00
|
|
|
*this << PROPERTY("ArrayID") << id;
|
2010-09-24 00:12:05 +08:00
|
|
|
if ( !newID ) // Shared array
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
|
|
|
*this << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
switch ( a->getType() )
|
|
|
|
{
|
|
|
|
case osg::Array::ByteArrayType:
|
|
|
|
*this << MAPPEE(ArrayType, ID_BYTE_ARRAY);
|
|
|
|
writeArrayImplementation( static_cast<const osg::ByteArray*>(a), a->getNumElements(), 4 );
|
|
|
|
break;
|
|
|
|
case osg::Array::UByteArrayType:
|
|
|
|
*this << MAPPEE(ArrayType, ID_UBYTE_ARRAY);
|
|
|
|
writeArrayImplementation( static_cast<const osg::UByteArray*>(a), a->getNumElements(), 4 );
|
|
|
|
break;
|
|
|
|
case osg::Array::ShortArrayType:
|
|
|
|
*this << MAPPEE(ArrayType, ID_SHORT_ARRAY);
|
|
|
|
writeArrayImplementation( static_cast<const osg::ShortArray*>(a), a->getNumElements(), 4 );
|
|
|
|
break;
|
|
|
|
case osg::Array::UShortArrayType:
|
|
|
|
*this << MAPPEE(ArrayType, ID_USHORT_ARRAY);
|
|
|
|
writeArrayImplementation( static_cast<const osg::UShortArray*>(a), a->getNumElements(), 4 );
|
|
|
|
break;
|
|
|
|
case osg::Array::IntArrayType:
|
|
|
|
*this << MAPPEE(ArrayType, ID_INT_ARRAY);
|
|
|
|
writeArrayImplementation( static_cast<const osg::IntArray*>(a), a->getNumElements(), 4 );
|
|
|
|
break;
|
|
|
|
case osg::Array::UIntArrayType:
|
|
|
|
*this << MAPPEE(ArrayType, ID_UINT_ARRAY);
|
|
|
|
writeArrayImplementation( static_cast<const osg::UIntArray*>(a), a->getNumElements(), 4 );
|
|
|
|
break;
|
|
|
|
case osg::Array::FloatArrayType:
|
|
|
|
*this << MAPPEE(ArrayType, ID_FLOAT_ARRAY);
|
|
|
|
writeArrayImplementation( static_cast<const osg::FloatArray*>(a), a->getNumElements(), 4 );
|
|
|
|
break;
|
|
|
|
case osg::Array::DoubleArrayType:
|
|
|
|
*this << MAPPEE(ArrayType, ID_DOUBLE_ARRAY);
|
|
|
|
writeArrayImplementation( static_cast<const osg::DoubleArray*>(a), a->getNumElements(), 4 );
|
|
|
|
break;
|
|
|
|
case osg::Array::Vec2bArrayType:
|
|
|
|
*this << MAPPEE(ArrayType, ID_VEC2B_ARRAY);
|
|
|
|
writeArrayImplementation( static_cast<const osg::Vec2bArray*>(a), a->getNumElements() );
|
|
|
|
break;
|
|
|
|
case osg::Array::Vec3bArrayType:
|
|
|
|
*this << MAPPEE(ArrayType, ID_VEC3B_ARRAY);
|
|
|
|
writeArrayImplementation( static_cast<const osg::Vec3bArray*>(a), a->getNumElements() );
|
|
|
|
break;
|
|
|
|
case osg::Array::Vec4bArrayType:
|
|
|
|
*this << MAPPEE(ArrayType, ID_VEC4B_ARRAY);
|
|
|
|
writeArrayImplementation( static_cast<const osg::Vec4bArray*>(a), a->getNumElements() );
|
|
|
|
break;
|
|
|
|
case osg::Array::Vec4ubArrayType:
|
|
|
|
*this << MAPPEE(ArrayType, ID_VEC4UB_ARRAY);
|
|
|
|
writeArrayImplementation( static_cast<const osg::Vec4ubArray*>(a), a->getNumElements() );
|
|
|
|
break;
|
|
|
|
case osg::Array::Vec2sArrayType:
|
|
|
|
*this << MAPPEE(ArrayType, ID_VEC2S_ARRAY);
|
|
|
|
writeArrayImplementation( static_cast<const osg::Vec2sArray*>(a), a->getNumElements() );
|
|
|
|
break;
|
|
|
|
case osg::Array::Vec3sArrayType:
|
|
|
|
*this << MAPPEE(ArrayType, ID_VEC3S_ARRAY);
|
|
|
|
writeArrayImplementation( static_cast<const osg::Vec3sArray*>(a), a->getNumElements() );
|
|
|
|
break;
|
|
|
|
case osg::Array::Vec4sArrayType:
|
|
|
|
*this << MAPPEE(ArrayType, ID_VEC4S_ARRAY);
|
|
|
|
writeArrayImplementation( static_cast<const osg::Vec4sArray*>(a), a->getNumElements() );
|
|
|
|
break;
|
|
|
|
case osg::Array::Vec2ArrayType:
|
|
|
|
*this << MAPPEE(ArrayType, ID_VEC2_ARRAY);
|
|
|
|
writeArrayImplementation( static_cast<const osg::Vec2Array*>(a), a->getNumElements() );
|
|
|
|
break;
|
|
|
|
case osg::Array::Vec3ArrayType:
|
|
|
|
*this << MAPPEE(ArrayType, ID_VEC3_ARRAY);
|
|
|
|
writeArrayImplementation( static_cast<const osg::Vec3Array*>(a), a->getNumElements() );
|
|
|
|
break;
|
|
|
|
case osg::Array::Vec4ArrayType:
|
|
|
|
*this << MAPPEE(ArrayType, ID_VEC4_ARRAY);
|
|
|
|
writeArrayImplementation( static_cast<const osg::Vec4Array*>(a), a->getNumElements() );
|
|
|
|
break;
|
|
|
|
case osg::Array::Vec2dArrayType:
|
2011-05-27 00:34:33 +08:00
|
|
|
*this << MAPPEE(ArrayType, ID_VEC2D_ARRAY);
|
2010-01-21 04:13:33 +08:00
|
|
|
writeArrayImplementation( static_cast<const osg::Vec2dArray*>(a), a->getNumElements() );
|
|
|
|
break;
|
|
|
|
case osg::Array::Vec3dArrayType:
|
2011-05-27 00:34:33 +08:00
|
|
|
*this << MAPPEE(ArrayType, ID_VEC3D_ARRAY);
|
2010-01-21 04:13:33 +08:00
|
|
|
writeArrayImplementation( static_cast<const osg::Vec3dArray*>(a), a->getNumElements() );
|
|
|
|
break;
|
|
|
|
case osg::Array::Vec4dArrayType:
|
|
|
|
*this << MAPPEE(ArrayType, ID_VEC4D_ARRAY);
|
|
|
|
writeArrayImplementation( static_cast<const osg::Vec4dArray*>(a), a->getNumElements() );
|
|
|
|
break;
|
|
|
|
default:
|
2010-01-28 01:09:05 +08:00
|
|
|
throwException( "OutputStream::writeArray(): Unsupported array type." );
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OutputStream::writePrimitiveSet( const osg::PrimitiveSet* p )
|
|
|
|
{
|
|
|
|
if ( !p ) return;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
switch ( p->getType() )
|
|
|
|
{
|
|
|
|
case osg::PrimitiveSet::DrawArraysPrimitiveType:
|
|
|
|
*this << MAPPEE(PrimitiveType, ID_DRAWARRAYS);
|
|
|
|
{
|
|
|
|
const osg::DrawArrays* da = static_cast<const osg::DrawArrays*>(p);
|
2013-02-07 19:10:24 +08:00
|
|
|
*this << MAPPEE(PrimitiveType, da->getMode()) << da->getNumInstances()
|
2010-01-21 04:13:33 +08:00
|
|
|
<< da->getFirst() << da->getCount() << std::endl;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case osg::PrimitiveSet::DrawArrayLengthsPrimitiveType:
|
|
|
|
*this << MAPPEE(PrimitiveType, ID_DRAWARRAY_LENGTH);
|
|
|
|
{
|
|
|
|
const osg::DrawArrayLengths* dl = static_cast<const osg::DrawArrayLengths*>(p);
|
2013-02-07 19:10:24 +08:00
|
|
|
*this << MAPPEE(PrimitiveType, dl->getMode()) << dl->getNumInstances() << dl->getFirst();
|
2010-01-21 04:13:33 +08:00
|
|
|
writeArrayImplementation( dl, dl->size(), 4 );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case osg::PrimitiveSet::DrawElementsUBytePrimitiveType:
|
|
|
|
*this << MAPPEE(PrimitiveType, ID_DRAWELEMENTS_UBYTE);
|
|
|
|
{
|
|
|
|
const osg::DrawElementsUByte* de = static_cast<const osg::DrawElementsUByte*>(p);
|
2013-02-07 19:10:24 +08:00
|
|
|
*this << MAPPEE(PrimitiveType, de->getMode()) << de->getNumInstances();
|
2010-01-21 04:13:33 +08:00
|
|
|
writeArrayImplementation( de, de->size(), 4 );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case osg::PrimitiveSet::DrawElementsUShortPrimitiveType:
|
|
|
|
*this << MAPPEE(PrimitiveType, ID_DRAWELEMENTS_USHORT);
|
|
|
|
{
|
|
|
|
const osg::DrawElementsUShort* de = static_cast<const osg::DrawElementsUShort*>(p);
|
2013-02-07 19:10:24 +08:00
|
|
|
*this << MAPPEE(PrimitiveType, de->getMode()) << de->getNumInstances();
|
2010-01-21 04:13:33 +08:00
|
|
|
writeArrayImplementation( de, de->size(), 4 );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case osg::PrimitiveSet::DrawElementsUIntPrimitiveType:
|
|
|
|
*this << MAPPEE(PrimitiveType, ID_DRAWELEMENTS_UINT);
|
|
|
|
{
|
|
|
|
const osg::DrawElementsUInt* de = static_cast<const osg::DrawElementsUInt*>(p);
|
2013-02-07 19:10:24 +08:00
|
|
|
*this << MAPPEE(PrimitiveType, de->getMode()) << de->getNumInstances();
|
2010-01-21 04:13:33 +08:00
|
|
|
writeArrayImplementation( de, de->size(), 4 );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2010-01-28 01:09:05 +08:00
|
|
|
throwException( "OutputStream::writePrimitiveSet(): Unsupported primitive type." );
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OutputStream::writeImage( const osg::Image* img )
|
|
|
|
{
|
|
|
|
if ( !img ) return;
|
2010-09-24 00:12:05 +08:00
|
|
|
|
2013-01-28 22:56:52 +08:00
|
|
|
std::string name = img->libraryName();
|
|
|
|
name += std::string("::") + img->className();
|
2010-09-24 00:12:05 +08:00
|
|
|
|
|
|
|
bool newID = false;
|
|
|
|
unsigned int id = findOrCreateObjectID( img, newID );
|
|
|
|
|
2013-01-28 22:56:52 +08:00
|
|
|
*this << PROPERTY("ClassName") << name << std::endl; // Write object name
|
|
|
|
*this << PROPERTY("UniqueID") << id << std::endl; // Write image ID
|
2010-01-28 01:09:05 +08:00
|
|
|
if ( getException() ) return;
|
2010-09-24 00:12:05 +08:00
|
|
|
|
|
|
|
if (newID)
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
2010-09-24 00:12:05 +08:00
|
|
|
int decision = IMAGE_EXTERNAL;
|
|
|
|
switch ( _writeImageHint )
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
2010-09-24 00:12:05 +08:00
|
|
|
case OutputStream::WRITE_INLINE_DATA: decision = IMAGE_INLINE_DATA; break;
|
|
|
|
case OutputStream::WRITE_INLINE_FILE: decision = IMAGE_INLINE_FILE; break;
|
2011-04-26 19:51:21 +08:00
|
|
|
case OutputStream::WRITE_EXTERNAL_FILE: decision = IMAGE_WRITE_OUT; break;
|
|
|
|
case OutputStream::WRITE_USE_EXTERNAL: decision = IMAGE_EXTERNAL; break;
|
2010-09-24 00:12:05 +08:00
|
|
|
default:
|
|
|
|
if ( img->getWriteHint()==osg::Image::EXTERNAL_FILE )
|
|
|
|
decision = IMAGE_EXTERNAL;
|
|
|
|
else if ( isBinary() )
|
|
|
|
decision = IMAGE_INLINE_DATA;
|
|
|
|
break;
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
2010-09-24 00:12:05 +08:00
|
|
|
|
2011-12-23 20:42:18 +08:00
|
|
|
|
|
|
|
std::string imageFileName = img->getFileName();
|
2010-09-24 00:12:05 +08:00
|
|
|
if ( decision==IMAGE_WRITE_OUT || _writeImageHint==WRITE_EXTERNAL_FILE )
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
2011-12-23 20:42:18 +08:00
|
|
|
if (imageFileName.empty())
|
|
|
|
{
|
|
|
|
OSG_NOTICE<<"Empty Image::FileName resetting to image.dds"<<std::endl;
|
|
|
|
imageFileName = "image.dds";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool result = osgDB::writeImageFile( *img, imageFileName );
|
|
|
|
OSG_NOTICE << "OutputStream::writeImage(): Write image data to external file " << imageFileName << std::endl;
|
2010-09-24 00:12:05 +08:00
|
|
|
if ( !result )
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
2011-12-23 20:42:18 +08:00
|
|
|
OSG_WARN << "OutputStream::writeImage(): Failed to write " << img->getFileName() << std::endl;
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
}
|
2010-09-24 00:12:05 +08:00
|
|
|
|
2011-12-23 20:42:18 +08:00
|
|
|
*this << PROPERTY("FileName"); writeWrappedString(imageFileName); *this << std::endl;
|
|
|
|
*this << PROPERTY("WriteHint") << (int)img->getWriteHint();
|
|
|
|
if ( getException() ) return;
|
|
|
|
|
|
|
|
*this << decision << std::endl;
|
|
|
|
|
2010-09-24 00:12:05 +08:00
|
|
|
switch ( decision )
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
2010-09-24 00:12:05 +08:00
|
|
|
case IMAGE_INLINE_DATA:
|
|
|
|
if ( isBinary() )
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
2010-09-24 00:12:05 +08:00
|
|
|
*this << img->getOrigin(); // _origin
|
|
|
|
*this << img->s() << img->t() << img->r(); // _s & _t & _r
|
|
|
|
*this << img->getInternalTextureFormat(); // _internalTextureFormat
|
|
|
|
*this << img->getPixelFormat(); // _pixelFormat
|
|
|
|
*this << img->getDataType(); // _dataType
|
|
|
|
*this << img->getPacking(); // _packing
|
|
|
|
*this << img->getAllocationMode(); // _allocationMode
|
|
|
|
|
|
|
|
// _data
|
|
|
|
unsigned int size = img->getTotalSizeInBytesIncludingMipmaps();
|
2012-01-24 22:34:02 +08:00
|
|
|
writeSize(size);
|
|
|
|
|
|
|
|
for(osg::Image::DataIterator img_itr(img); img_itr.valid(); ++img_itr)
|
|
|
|
{
|
|
|
|
writeCharArray( (char*)img_itr.data(), img_itr.size() );
|
|
|
|
}
|
2010-09-24 00:12:05 +08:00
|
|
|
|
|
|
|
// _mipmapData
|
2012-01-24 22:34:02 +08:00
|
|
|
unsigned int numMipmaps = img->getNumMipmapLevels()-1;
|
|
|
|
writeSize(numMipmaps);
|
|
|
|
int s = img->s();
|
|
|
|
int t = img->t();
|
|
|
|
int r = img->r();
|
|
|
|
unsigned int offset = 0;
|
|
|
|
for (unsigned int i=0; i<numMipmaps; ++i)
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
2012-01-24 22:34:02 +08:00
|
|
|
unsigned int size = osg::Image::computeImageSizeInBytes(s,t,r,img->getPixelFormat(),img->getDataType(),img->getPacking());
|
|
|
|
offset += size;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2012-01-24 22:34:02 +08:00
|
|
|
*this << offset;
|
|
|
|
|
|
|
|
s >>= 1;
|
|
|
|
t >>= 1;
|
|
|
|
r >>= 1;
|
|
|
|
if (s<1) s=1;
|
|
|
|
if (t<1) t=1;
|
2012-03-22 01:36:20 +08:00
|
|
|
if (r<1) r=1;
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
}
|
2010-09-24 00:12:05 +08:00
|
|
|
break;
|
|
|
|
case IMAGE_INLINE_FILE:
|
|
|
|
if ( isBinary() )
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
2010-09-24 00:12:05 +08:00
|
|
|
std::string fullPath = osgDB::findDataFile( img->getFileName() );
|
|
|
|
std::ifstream infile( fullPath.c_str(), std::ios::in|std::ios::binary );
|
|
|
|
if ( infile )
|
|
|
|
{
|
|
|
|
infile.seekg( 0, std::ios::end );
|
|
|
|
unsigned int size = infile.tellg();
|
|
|
|
writeSize(size);
|
|
|
|
|
|
|
|
if ( size>0 )
|
|
|
|
{
|
|
|
|
char* data = new char[size];
|
|
|
|
if ( !data )
|
2011-06-21 03:15:53 +08:00
|
|
|
{
|
2010-09-24 00:12:05 +08:00
|
|
|
throwException( "OutputStream::writeImage(): Out of memory." );
|
2011-06-21 03:15:53 +08:00
|
|
|
if ( getException() ) return;
|
|
|
|
}
|
2010-09-24 00:12:05 +08:00
|
|
|
|
|
|
|
infile.seekg( 0, std::ios::beg );
|
|
|
|
infile.read( data, size );
|
|
|
|
writeCharArray( data, size );
|
|
|
|
delete[] data;
|
|
|
|
}
|
|
|
|
infile.close();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OSG_WARN << "OutputStream::writeImage(): Failed to open image file "
|
|
|
|
<< img->getFileName() << std::endl;
|
|
|
|
*this << (unsigned int)0;
|
|
|
|
}
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
2010-09-24 00:12:05 +08:00
|
|
|
break;
|
|
|
|
case IMAGE_EXTERNAL:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
2010-09-24 00:12:05 +08:00
|
|
|
|
|
|
|
writeObjectFields( img );
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
2010-09-24 00:12:05 +08:00
|
|
|
|
|
|
|
// *this << END_BRACKET << std::endl;
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void OutputStream::writeObject( const osg::Object* obj )
|
|
|
|
{
|
|
|
|
if ( !obj ) return;
|
2010-09-24 00:12:05 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
std::string name = obj->libraryName();
|
|
|
|
name += std::string("::") + obj->className();
|
2010-09-24 00:12:05 +08:00
|
|
|
|
|
|
|
bool newID = false;
|
|
|
|
unsigned int id = findOrCreateObjectID( obj, newID );
|
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
*this << name << BEGIN_BRACKET << std::endl; // Write object name
|
|
|
|
*this << PROPERTY("UniqueID") << id << std::endl; // Write object ID
|
2010-01-28 01:09:05 +08:00
|
|
|
if ( getException() ) return;
|
2010-09-24 00:12:05 +08:00
|
|
|
|
|
|
|
if (newID)
|
|
|
|
{
|
|
|
|
writeObjectFields(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
*this << END_BRACKET << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OutputStream::writeObjectFields( const osg::Object* obj )
|
|
|
|
{
|
|
|
|
std::string name = obj->libraryName();
|
|
|
|
name += std::string("::") + obj->className();
|
|
|
|
|
|
|
|
ObjectWrapper* wrapper = Registry::instance()->getObjectWrapperManager()->findWrapper( name );
|
|
|
|
if ( !wrapper )
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
2010-09-24 00:12:05 +08:00
|
|
|
OSG_WARN << "OutputStream::writeObject(): Unsupported wrapper class "
|
|
|
|
<< name << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const StringList& associates = wrapper->getAssociates();
|
|
|
|
for ( StringList::const_iterator itr=associates.begin(); itr!=associates.end(); ++itr )
|
|
|
|
{
|
|
|
|
const std::string& assocName = *itr;
|
|
|
|
ObjectWrapper* assocWrapper = Registry::instance()->getObjectWrapperManager()->findWrapper(assocName);
|
|
|
|
if ( !assocWrapper )
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
2010-09-24 00:12:05 +08:00
|
|
|
OSG_WARN << "OutputStream::writeObject(): Unsupported associated class "
|
|
|
|
<< assocName << std::endl;
|
|
|
|
continue;
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
2010-09-24 00:12:05 +08:00
|
|
|
else if ( _useSchemaData )
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
2010-09-24 00:12:05 +08:00
|
|
|
if ( _inbuiltSchemaMap.find(assocName)==_inbuiltSchemaMap.end() )
|
2010-05-13 04:02:31 +08:00
|
|
|
{
|
2010-09-24 00:12:05 +08:00
|
|
|
StringList properties;
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
std::vector<int> types;
|
|
|
|
assocWrapper->writeSchema( properties, types );
|
2012-03-22 01:36:20 +08:00
|
|
|
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
unsigned int size = osg::minimum( properties.size(), types.size() );
|
|
|
|
if ( size>0 )
|
2010-05-13 04:02:31 +08:00
|
|
|
{
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
std::stringstream propertiesStream;
|
|
|
|
for ( unsigned int i=0; i<size; ++i )
|
2010-05-13 04:02:31 +08:00
|
|
|
{
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
propertiesStream << properties[i] << ":" << types[i] << " ";
|
2010-05-13 04:02:31 +08:00
|
|
|
}
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
_inbuiltSchemaMap[assocName] = propertiesStream.str();
|
2010-05-13 04:02:31 +08:00
|
|
|
}
|
|
|
|
}
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
2010-09-24 00:12:05 +08:00
|
|
|
_fields.push_back( assocWrapper->getName() );
|
|
|
|
|
|
|
|
assocWrapper->write( *this, *obj );
|
|
|
|
if ( getException() ) return;
|
|
|
|
|
2010-01-28 01:09:05 +08:00
|
|
|
_fields.pop_back();
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-25 19:03:21 +08:00
|
|
|
void OutputStream::start( OutputIterator* outIterator, OutputStream::WriteType type )
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
2010-01-28 01:09:05 +08:00
|
|
|
_fields.clear();
|
|
|
|
_fields.push_back( "Start" );
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-25 19:03:21 +08:00
|
|
|
_out = outIterator;
|
|
|
|
if ( !_out )
|
2010-01-28 01:09:05 +08:00
|
|
|
throwException( "OutputStream: Null stream specified." );
|
|
|
|
if ( getException() ) return;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
if ( isBinary() )
|
|
|
|
{
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
*this << (unsigned int)type << (unsigned int)OPENSCENEGRAPH_SOVERSION;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-05-13 04:02:31 +08:00
|
|
|
bool useCompressSource = false;
|
|
|
|
unsigned int attributes = 0;
|
2010-10-04 23:23:19 +08:00
|
|
|
|
From Wang Rui, "The file attached includes two new features for the serialization IO functionality. First, custom serializer version control should work now, just by defining a new REGISTER_CUSTOM_OBJECT_WRAPPER macro. For example:
// A custom class
namespace CustomDomain {
class MyGroup : public osg::Group
{
public:
META_Node( CustomDomain, MyGroup );
void setMyName( const std::string& n );
const std::string& getMyName() const;
void setMyID( int id );
int getMyID() const;
...
};
}
// The serialization wrapper using a custom domain name
REGISTER_CUSTOM_OBJECT_WRAPPER( MyDomain,
CustomDomain_MyGroup,
new CustomDomain::MyGroup,
CustomDomain::MyGroup,
"osg::Object osg::Node osg::Group CustomDomain::MyGroup" )
{
ADD_STRING_SERIALIZER( MyName, std::string() );
{
UPDATE_TO_VERSION_SCOPED( 1 ); // Updated for a new domain version
ADD_INT_SERIALIZER( MyID, 0 );
}
}
Save the class instance as follows:
osgDB::writeNodeFile( *myGroup, "serializer_test.osgt", new osgDB::Options("CustomDomains=MyDomain:1") );
The output file will include the domain version definition and all the class data, and can be read back. We can also force setting the domain version by the CustomDomains option while reading the saved files. If we save the class instance without any options, MyID will be ignored because the default domain version is 0.
This may help third-party libraries like osgEarth to maintain their own serializers without regarding to the OSG soversion changes.
Another feature added is a more robust binary format, which in fact adds a size-offset at each block's beginning. When there are problems or unsupported data types while reading, we can now directly jump to the block end indicated by the offset value. So a .osgb file will automatically ignore bad data and read remains as normal (at present it will fail at all). This feature will not break the backward compatibility, and can be disabled by setting "RobustBinaryFormat=false" while writing out.
Hope these changes can work smoothly with present and future community projects. Maybe we should also consider have an osgserializer example to test and demonstrate all things we can do now."
2013-06-24 16:48:55 +08:00
|
|
|
// From SOVERSION 98, start to support custom wrapper domains, enabling the attribute bit
|
2013-06-24 17:02:32 +08:00
|
|
|
if ( _domainVersionMap.size()>0 ) attributes |= 0x1;
|
From Wang Rui, "The file attached includes two new features for the serialization IO functionality. First, custom serializer version control should work now, just by defining a new REGISTER_CUSTOM_OBJECT_WRAPPER macro. For example:
// A custom class
namespace CustomDomain {
class MyGroup : public osg::Group
{
public:
META_Node( CustomDomain, MyGroup );
void setMyName( const std::string& n );
const std::string& getMyName() const;
void setMyID( int id );
int getMyID() const;
...
};
}
// The serialization wrapper using a custom domain name
REGISTER_CUSTOM_OBJECT_WRAPPER( MyDomain,
CustomDomain_MyGroup,
new CustomDomain::MyGroup,
CustomDomain::MyGroup,
"osg::Object osg::Node osg::Group CustomDomain::MyGroup" )
{
ADD_STRING_SERIALIZER( MyName, std::string() );
{
UPDATE_TO_VERSION_SCOPED( 1 ); // Updated for a new domain version
ADD_INT_SERIALIZER( MyID, 0 );
}
}
Save the class instance as follows:
osgDB::writeNodeFile( *myGroup, "serializer_test.osgt", new osgDB::Options("CustomDomains=MyDomain:1") );
The output file will include the domain version definition and all the class data, and can be read back. We can also force setting the domain version by the CustomDomains option while reading the saved files. If we save the class instance without any options, MyID will be ignored because the default domain version is 0.
This may help third-party libraries like osgEarth to maintain their own serializers without regarding to the OSG soversion changes.
Another feature added is a more robust binary format, which in fact adds a size-offset at each block's beginning. When there are problems or unsupported data types while reading, we can now directly jump to the block end indicated by the offset value. So a .osgb file will automatically ignore bad data and read remains as normal (at present it will fail at all). This feature will not break the backward compatibility, and can be disabled by setting "RobustBinaryFormat=false" while writing out.
Hope these changes can work smoothly with present and future community projects. Maybe we should also consider have an osgserializer example to test and demonstrate all things we can do now."
2013-06-24 16:48:55 +08:00
|
|
|
|
2010-05-13 04:02:31 +08:00
|
|
|
if ( _useSchemaData )
|
|
|
|
{
|
|
|
|
attributes |= 0x2; // Record if we use inbuilt schema data or not
|
|
|
|
useCompressSource = true;
|
|
|
|
}
|
2013-06-24 17:02:32 +08:00
|
|
|
|
From Wang Rui, "The file attached includes two new features for the serialization IO functionality. First, custom serializer version control should work now, just by defining a new REGISTER_CUSTOM_OBJECT_WRAPPER macro. For example:
// A custom class
namespace CustomDomain {
class MyGroup : public osg::Group
{
public:
META_Node( CustomDomain, MyGroup );
void setMyName( const std::string& n );
const std::string& getMyName() const;
void setMyID( int id );
int getMyID() const;
...
};
}
// The serialization wrapper using a custom domain name
REGISTER_CUSTOM_OBJECT_WRAPPER( MyDomain,
CustomDomain_MyGroup,
new CustomDomain::MyGroup,
CustomDomain::MyGroup,
"osg::Object osg::Node osg::Group CustomDomain::MyGroup" )
{
ADD_STRING_SERIALIZER( MyName, std::string() );
{
UPDATE_TO_VERSION_SCOPED( 1 ); // Updated for a new domain version
ADD_INT_SERIALIZER( MyID, 0 );
}
}
Save the class instance as follows:
osgDB::writeNodeFile( *myGroup, "serializer_test.osgt", new osgDB::Options("CustomDomains=MyDomain:1") );
The output file will include the domain version definition and all the class data, and can be read back. We can also force setting the domain version by the CustomDomains option while reading the saved files. If we save the class instance without any options, MyID will be ignored because the default domain version is 0.
This may help third-party libraries like osgEarth to maintain their own serializers without regarding to the OSG soversion changes.
Another feature added is a more robust binary format, which in fact adds a size-offset at each block's beginning. When there are problems or unsupported data types while reading, we can now directly jump to the block end indicated by the offset value. So a .osgb file will automatically ignore bad data and read remains as normal (at present it will fail at all). This feature will not break the backward compatibility, and can be disabled by setting "RobustBinaryFormat=false" while writing out.
Hope these changes can work smoothly with present and future community projects. Maybe we should also consider have an osgserializer example to test and demonstrate all things we can do now."
2013-06-24 16:48:55 +08:00
|
|
|
// From SOVERSION 98, start to support binary begin/end brackets so we can easily ignore
|
|
|
|
// errors and unsupport classes, enabling the attribute bit
|
|
|
|
if ( _useRobustBinaryFormat )
|
|
|
|
{
|
|
|
|
outIterator->setSupportBinaryBrackets( true );
|
|
|
|
attributes |= 0x4;
|
|
|
|
}
|
2010-05-13 04:02:31 +08:00
|
|
|
*this << attributes;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
From Wang Rui, "The file attached includes two new features for the serialization IO functionality. First, custom serializer version control should work now, just by defining a new REGISTER_CUSTOM_OBJECT_WRAPPER macro. For example:
// A custom class
namespace CustomDomain {
class MyGroup : public osg::Group
{
public:
META_Node( CustomDomain, MyGroup );
void setMyName( const std::string& n );
const std::string& getMyName() const;
void setMyID( int id );
int getMyID() const;
...
};
}
// The serialization wrapper using a custom domain name
REGISTER_CUSTOM_OBJECT_WRAPPER( MyDomain,
CustomDomain_MyGroup,
new CustomDomain::MyGroup,
CustomDomain::MyGroup,
"osg::Object osg::Node osg::Group CustomDomain::MyGroup" )
{
ADD_STRING_SERIALIZER( MyName, std::string() );
{
UPDATE_TO_VERSION_SCOPED( 1 ); // Updated for a new domain version
ADD_INT_SERIALIZER( MyID, 0 );
}
}
Save the class instance as follows:
osgDB::writeNodeFile( *myGroup, "serializer_test.osgt", new osgDB::Options("CustomDomains=MyDomain:1") );
The output file will include the domain version definition and all the class data, and can be read back. We can also force setting the domain version by the CustomDomains option while reading the saved files. If we save the class instance without any options, MyID will be ignored because the default domain version is 0.
This may help third-party libraries like osgEarth to maintain their own serializers without regarding to the OSG soversion changes.
Another feature added is a more robust binary format, which in fact adds a size-offset at each block's beginning. When there are problems or unsupported data types while reading, we can now directly jump to the block end indicated by the offset value. So a .osgb file will automatically ignore bad data and read remains as normal (at present it will fail at all). This feature will not break the backward compatibility, and can be disabled by setting "RobustBinaryFormat=false" while writing out.
Hope these changes can work smoothly with present and future community projects. Maybe we should also consider have an osgserializer example to test and demonstrate all things we can do now."
2013-06-24 16:48:55 +08:00
|
|
|
// Record all custom versions
|
|
|
|
if ( _domainVersionMap.size()>0 )
|
|
|
|
{
|
|
|
|
unsigned int numDomains = _domainVersionMap.size();
|
|
|
|
*this << numDomains;
|
2013-06-24 17:02:32 +08:00
|
|
|
for ( VersionMap::iterator itr=_domainVersionMap.begin();
|
From Wang Rui, "The file attached includes two new features for the serialization IO functionality. First, custom serializer version control should work now, just by defining a new REGISTER_CUSTOM_OBJECT_WRAPPER macro. For example:
// A custom class
namespace CustomDomain {
class MyGroup : public osg::Group
{
public:
META_Node( CustomDomain, MyGroup );
void setMyName( const std::string& n );
const std::string& getMyName() const;
void setMyID( int id );
int getMyID() const;
...
};
}
// The serialization wrapper using a custom domain name
REGISTER_CUSTOM_OBJECT_WRAPPER( MyDomain,
CustomDomain_MyGroup,
new CustomDomain::MyGroup,
CustomDomain::MyGroup,
"osg::Object osg::Node osg::Group CustomDomain::MyGroup" )
{
ADD_STRING_SERIALIZER( MyName, std::string() );
{
UPDATE_TO_VERSION_SCOPED( 1 ); // Updated for a new domain version
ADD_INT_SERIALIZER( MyID, 0 );
}
}
Save the class instance as follows:
osgDB::writeNodeFile( *myGroup, "serializer_test.osgt", new osgDB::Options("CustomDomains=MyDomain:1") );
The output file will include the domain version definition and all the class data, and can be read back. We can also force setting the domain version by the CustomDomains option while reading the saved files. If we save the class instance without any options, MyID will be ignored because the default domain version is 0.
This may help third-party libraries like osgEarth to maintain their own serializers without regarding to the OSG soversion changes.
Another feature added is a more robust binary format, which in fact adds a size-offset at each block's beginning. When there are problems or unsupported data types while reading, we can now directly jump to the block end indicated by the offset value. So a .osgb file will automatically ignore bad data and read remains as normal (at present it will fail at all). This feature will not break the backward compatibility, and can be disabled by setting "RobustBinaryFormat=false" while writing out.
Hope these changes can work smoothly with present and future community projects. Maybe we should also consider have an osgserializer example to test and demonstrate all things we can do now."
2013-06-24 16:48:55 +08:00
|
|
|
itr!=_domainVersionMap.end(); ++itr )
|
|
|
|
{
|
|
|
|
*this << itr->first << itr->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
if ( !_compressorName.empty() )
|
|
|
|
{
|
2010-01-22 23:16:22 +08:00
|
|
|
BaseCompressor* compressor = Registry::instance()->getObjectWrapperManager()->findCompressor(_compressorName);
|
2010-01-21 04:13:33 +08:00
|
|
|
if ( !compressor )
|
|
|
|
{
|
2010-05-28 23:52:45 +08:00
|
|
|
OSG_WARN << "OutputStream::start(): No such compressor "
|
2010-01-21 04:13:33 +08:00
|
|
|
<< _compressorName << std::endl;
|
2010-05-13 04:02:31 +08:00
|
|
|
_compressorName.clear();
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-05-13 04:02:31 +08:00
|
|
|
useCompressSource = true;
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
}
|
2010-05-13 04:02:31 +08:00
|
|
|
if ( !_compressorName.empty() ) *this << _compressorName;
|
|
|
|
else *this << std::string("0"); // No compressor
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-05-13 04:02:31 +08:00
|
|
|
// Compressors and inbuilt schema use a new stream, which will be merged with the original one at the end.
|
|
|
|
if ( useCompressSource )
|
|
|
|
{
|
|
|
|
_out->flush();
|
|
|
|
_out->setStream( &_compressSource );
|
|
|
|
}
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::string typeString("Unknown");
|
|
|
|
switch ( type )
|
|
|
|
{
|
|
|
|
case WRITE_SCENE: typeString = "Scene"; break;
|
|
|
|
case WRITE_IMAGE: typeString = "Image"; break;
|
2010-03-10 21:48:41 +08:00
|
|
|
case WRITE_OBJECT: typeString = "Object"; break;
|
2010-01-21 04:13:33 +08:00
|
|
|
default: break;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-28 01:09:05 +08:00
|
|
|
*this << typeString << std::endl;
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
*this << PROPERTY("#Version") << (unsigned int)OPENSCENEGRAPH_SOVERSION << std::endl;
|
2010-01-21 04:13:33 +08:00
|
|
|
*this << PROPERTY("#Generator") << std::string("OpenSceneGraph")
|
|
|
|
<< std::string(osgGetVersion()) << std::endl;
|
From Wang Rui, "The file attached includes two new features for the serialization IO functionality. First, custom serializer version control should work now, just by defining a new REGISTER_CUSTOM_OBJECT_WRAPPER macro. For example:
// A custom class
namespace CustomDomain {
class MyGroup : public osg::Group
{
public:
META_Node( CustomDomain, MyGroup );
void setMyName( const std::string& n );
const std::string& getMyName() const;
void setMyID( int id );
int getMyID() const;
...
};
}
// The serialization wrapper using a custom domain name
REGISTER_CUSTOM_OBJECT_WRAPPER( MyDomain,
CustomDomain_MyGroup,
new CustomDomain::MyGroup,
CustomDomain::MyGroup,
"osg::Object osg::Node osg::Group CustomDomain::MyGroup" )
{
ADD_STRING_SERIALIZER( MyName, std::string() );
{
UPDATE_TO_VERSION_SCOPED( 1 ); // Updated for a new domain version
ADD_INT_SERIALIZER( MyID, 0 );
}
}
Save the class instance as follows:
osgDB::writeNodeFile( *myGroup, "serializer_test.osgt", new osgDB::Options("CustomDomains=MyDomain:1") );
The output file will include the domain version definition and all the class data, and can be read back. We can also force setting the domain version by the CustomDomains option while reading the saved files. If we save the class instance without any options, MyID will be ignored because the default domain version is 0.
This may help third-party libraries like osgEarth to maintain their own serializers without regarding to the OSG soversion changes.
Another feature added is a more robust binary format, which in fact adds a size-offset at each block's beginning. When there are problems or unsupported data types while reading, we can now directly jump to the block end indicated by the offset value. So a .osgb file will automatically ignore bad data and read remains as normal (at present it will fail at all). This feature will not break the backward compatibility, and can be disabled by setting "RobustBinaryFormat=false" while writing out.
Hope these changes can work smoothly with present and future community projects. Maybe we should also consider have an osgserializer example to test and demonstrate all things we can do now."
2013-06-24 16:48:55 +08:00
|
|
|
if ( _domainVersionMap.size()>0 )
|
|
|
|
{
|
2013-06-24 17:02:32 +08:00
|
|
|
for ( VersionMap::iterator itr=_domainVersionMap.begin();
|
From Wang Rui, "The file attached includes two new features for the serialization IO functionality. First, custom serializer version control should work now, just by defining a new REGISTER_CUSTOM_OBJECT_WRAPPER macro. For example:
// A custom class
namespace CustomDomain {
class MyGroup : public osg::Group
{
public:
META_Node( CustomDomain, MyGroup );
void setMyName( const std::string& n );
const std::string& getMyName() const;
void setMyID( int id );
int getMyID() const;
...
};
}
// The serialization wrapper using a custom domain name
REGISTER_CUSTOM_OBJECT_WRAPPER( MyDomain,
CustomDomain_MyGroup,
new CustomDomain::MyGroup,
CustomDomain::MyGroup,
"osg::Object osg::Node osg::Group CustomDomain::MyGroup" )
{
ADD_STRING_SERIALIZER( MyName, std::string() );
{
UPDATE_TO_VERSION_SCOPED( 1 ); // Updated for a new domain version
ADD_INT_SERIALIZER( MyID, 0 );
}
}
Save the class instance as follows:
osgDB::writeNodeFile( *myGroup, "serializer_test.osgt", new osgDB::Options("CustomDomains=MyDomain:1") );
The output file will include the domain version definition and all the class data, and can be read back. We can also force setting the domain version by the CustomDomains option while reading the saved files. If we save the class instance without any options, MyID will be ignored because the default domain version is 0.
This may help third-party libraries like osgEarth to maintain their own serializers without regarding to the OSG soversion changes.
Another feature added is a more robust binary format, which in fact adds a size-offset at each block's beginning. When there are problems or unsupported data types while reading, we can now directly jump to the block end indicated by the offset value. So a .osgb file will automatically ignore bad data and read remains as normal (at present it will fail at all). This feature will not break the backward compatibility, and can be disabled by setting "RobustBinaryFormat=false" while writing out.
Hope these changes can work smoothly with present and future community projects. Maybe we should also consider have an osgserializer example to test and demonstrate all things we can do now."
2013-06-24 16:48:55 +08:00
|
|
|
itr!=_domainVersionMap.end(); ++itr )
|
|
|
|
{
|
|
|
|
*this << PROPERTY("#CustomDomain") << itr->first << itr->second << std::endl;
|
|
|
|
}
|
|
|
|
}
|
2010-01-21 04:13:33 +08:00
|
|
|
*this << std::endl;
|
|
|
|
}
|
2010-01-28 01:09:05 +08:00
|
|
|
_fields.pop_back();
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void OutputStream::compress( std::ostream* ostream )
|
|
|
|
{
|
2010-01-28 01:09:05 +08:00
|
|
|
_fields.clear();
|
2010-05-13 04:02:31 +08:00
|
|
|
if ( !isBinary() ) return;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-05-13 04:02:31 +08:00
|
|
|
std::stringstream schemaSource;
|
|
|
|
if ( _useSchemaData )
|
2010-03-10 21:48:41 +08:00
|
|
|
{
|
2010-05-13 04:02:31 +08:00
|
|
|
_fields.push_back( "SchemaData" );
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-05-13 04:02:31 +08:00
|
|
|
std::string schemaData;
|
2013-06-24 17:02:32 +08:00
|
|
|
for ( SchemaMap::iterator itr=_inbuiltSchemaMap.begin();
|
2010-05-13 04:02:31 +08:00
|
|
|
itr!=_inbuiltSchemaMap.end(); ++itr )
|
|
|
|
{
|
|
|
|
schemaData += itr->first + '=';
|
|
|
|
schemaData += itr->second;
|
|
|
|
schemaData += '\n';
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-05-13 04:02:31 +08:00
|
|
|
int size = schemaData.size();
|
|
|
|
schemaSource.write( (char*)&size, INT_SIZE );
|
|
|
|
schemaSource.write( schemaData.c_str(), size );
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-05-13 04:02:31 +08:00
|
|
|
_inbuiltSchemaMap.clear();
|
2010-03-10 21:48:41 +08:00
|
|
|
_fields.pop_back();
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-05-13 04:02:31 +08:00
|
|
|
if ( !_compressorName.empty() )
|
|
|
|
{
|
|
|
|
_fields.push_back( "Compression" );
|
|
|
|
BaseCompressor* compressor = Registry::instance()->getObjectWrapperManager()->findCompressor(_compressorName);
|
|
|
|
if ( !compressor || !ostream )
|
|
|
|
{
|
|
|
|
_fields.pop_back();
|
|
|
|
return;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-05-13 04:02:31 +08:00
|
|
|
if ( !compressor->compress(*ostream, schemaSource.str() + _compressSource.str()) )
|
|
|
|
throwException( "OutputStream: Failed to compress stream." );
|
|
|
|
if ( getException() ) return;
|
|
|
|
_fields.pop_back();
|
|
|
|
}
|
|
|
|
else if ( _useSchemaData )
|
|
|
|
{
|
|
|
|
std::string str = schemaSource.str() + _compressSource.str();
|
|
|
|
ostream->write( str.c_str(), str.size() );
|
|
|
|
}
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void OutputStream::writeSchema( std::ostream& fout )
|
|
|
|
{
|
|
|
|
// Write to external ascii stream
|
2010-01-22 23:16:22 +08:00
|
|
|
const ObjectWrapperManager::WrapperMap& wrappers = Registry::instance()->getObjectWrapperManager()->getWrapperMap();
|
|
|
|
for ( ObjectWrapperManager::WrapperMap::const_iterator itr=wrappers.begin();
|
2010-01-21 04:13:33 +08:00
|
|
|
itr!=wrappers.end(); ++itr )
|
|
|
|
{
|
|
|
|
ObjectWrapper* wrapper = itr->second.get();
|
|
|
|
fout << itr->first << " =";
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
StringList properties;
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
std::vector<int> types;
|
|
|
|
wrapper->writeSchema( properties, types );
|
2012-03-22 01:36:20 +08:00
|
|
|
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
std::string propertiesString;
|
|
|
|
unsigned int size = osg::minimum( properties.size(), types.size() );
|
|
|
|
for ( unsigned int i=0; i<size; ++i )
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
fout << " " << properties[i] << ":" << types[i];
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
fout << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-28 01:09:05 +08:00
|
|
|
// PROTECTED METHODS
|
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
template<typename T>
|
2010-02-11 01:03:09 +08:00
|
|
|
void OutputStream::writeArrayImplementation( const T* a, int write_size, unsigned int numInRow )
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
2010-02-11 01:03:09 +08:00
|
|
|
*this << write_size << BEGIN_BRACKET;
|
2010-01-21 04:13:33 +08:00
|
|
|
if ( numInRow>1 )
|
|
|
|
{
|
2010-02-11 01:03:09 +08:00
|
|
|
for ( int i=0; i<write_size; ++i )
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
|
|
|
if ( !(i%numInRow) )
|
|
|
|
{
|
|
|
|
*this << std::endl << (*a)[i];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*this << (*a)[i];
|
|
|
|
}
|
|
|
|
*this << std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*this << std::endl;
|
2010-02-11 01:03:09 +08:00
|
|
|
for ( int i=0; i<write_size; ++i )
|
2010-01-21 04:13:33 +08:00
|
|
|
*this << (*a)[i] << std::endl;
|
|
|
|
}
|
|
|
|
*this << END_BRACKET << std::endl;
|
|
|
|
}
|
|
|
|
|
2010-09-24 00:12:05 +08:00
|
|
|
unsigned int OutputStream::findOrCreateArrayID( const osg::Array* array, bool& newID )
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
|
|
|
ArrayMap::iterator itr = _arrayMap.find( array );
|
|
|
|
if ( itr==_arrayMap.end() )
|
|
|
|
{
|
|
|
|
unsigned int id = _arrayMap.size()+1;
|
|
|
|
_arrayMap[array] = id;
|
2010-09-24 00:12:05 +08:00
|
|
|
newID = true;
|
2010-01-21 04:13:33 +08:00
|
|
|
return id;
|
|
|
|
}
|
2010-09-24 00:12:05 +08:00
|
|
|
newID = false;
|
2010-01-21 04:13:33 +08:00
|
|
|
return itr->second;
|
|
|
|
}
|
|
|
|
|
2010-09-24 00:12:05 +08:00
|
|
|
unsigned int OutputStream::findOrCreateObjectID( const osg::Object* obj, bool& newID )
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
|
|
|
ObjectMap::iterator itr = _objectMap.find( obj );
|
|
|
|
if ( itr==_objectMap.end() )
|
|
|
|
{
|
|
|
|
unsigned int id = _objectMap.size()+1;
|
|
|
|
_objectMap[obj] = id;
|
2010-09-24 00:12:05 +08:00
|
|
|
newID = true;
|
2010-01-21 04:13:33 +08:00
|
|
|
return id;
|
|
|
|
}
|
2010-09-24 00:12:05 +08:00
|
|
|
newID = false;
|
2010-01-21 04:13:33 +08:00
|
|
|
return itr->second;
|
|
|
|
}
|