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.
"
This commit is contained in:
@@ -50,33 +50,39 @@ public:
|
||||
|
||||
ObjectWrapper( osg::Object* proto, const std::string& name,
|
||||
const std::string& associates );
|
||||
void setUpdatedVersion( int ver ) { _version = ver; }
|
||||
|
||||
const osg::Object* getProto() const { return _proto.get(); }
|
||||
const std::string& getName() const { return _name; }
|
||||
const StringList& getAssociates() const { return _associates; }
|
||||
|
||||
void addSerializer( BaseSerializer* s ) { _serializers.push_back(s); }
|
||||
|
||||
void addSerializer( BaseSerializer* s, BaseSerializer::Type t=BaseSerializer::RW_UNDEFINED )
|
||||
{ s->_version = _version; _serializers.push_back(s); _typeList.push_back(static_cast<int>(t)); }
|
||||
|
||||
void markSerializerAsRemoved( const std::string& name );
|
||||
BaseSerializer* getSerializer( const std::string& name );
|
||||
void addFinishedObjectReadCallback ( FinishedObjectReadCallback* forc) { _finishedObjectReadCallbacks.push_back(forc); }
|
||||
|
||||
|
||||
bool read( InputStream&, osg::Object& );
|
||||
bool write( OutputStream&, const osg::Object& );
|
||||
|
||||
bool readSchema( const StringList& properties );
|
||||
void writeSchema( StringList& properties );
|
||||
|
||||
bool readSchema( const StringList& properties, const std::vector<int>& types );
|
||||
void writeSchema( StringList& properties, std::vector<int>& types );
|
||||
void resetSchema()
|
||||
{ if ( _backupSerializers.size()>0 ) _serializers = _backupSerializers; }
|
||||
|
||||
protected:
|
||||
ObjectWrapper() {}
|
||||
ObjectWrapper() : _version(0) {}
|
||||
virtual ~ObjectWrapper() {}
|
||||
|
||||
|
||||
osg::ref_ptr<osg::Object> _proto;
|
||||
std::string _name;
|
||||
StringList _associates;
|
||||
SerializerList _serializers;
|
||||
SerializerList _backupSerializers;
|
||||
std::vector<int> _typeList;
|
||||
FinishedObjectReadCallbackList _finishedObjectReadCallbacks;
|
||||
int _version; // Last updated version of the wrapper
|
||||
};
|
||||
|
||||
class Registry;
|
||||
@@ -143,6 +149,7 @@ protected:
|
||||
};
|
||||
|
||||
#define REGISTER_OBJECT_WRAPPER(NAME, PROTO, CLASS, ASSOCIATES) \
|
||||
extern "C" void wrapper_serializer_##NAME(void) {} \
|
||||
extern void wrapper_propfunc_##NAME(osgDB::ObjectWrapper*); \
|
||||
static osgDB::RegisterWrapperProxy wrapper_proxy_##NAME( \
|
||||
PROTO, #CLASS, ASSOCIATES, &wrapper_propfunc_##NAME); \
|
||||
@@ -150,6 +157,7 @@ protected:
|
||||
void wrapper_propfunc_##NAME(osgDB::ObjectWrapper* wrapper)
|
||||
|
||||
#define REGISTER_OBJECT_WRAPPER2(NAME, PROTO, CLASS, CLASSNAME, ASSOCIATES) \
|
||||
extern "C" void wrapper_serializer_##NAME(void) {} \
|
||||
extern void wrapper_propfunc_##NAME(osgDB::ObjectWrapper*); \
|
||||
static osgDB::RegisterWrapperProxy wrapper_proxy_##NAME( \
|
||||
PROTO, CLASSNAME, ASSOCIATES, &wrapper_propfunc_##NAME); \
|
||||
@@ -167,6 +175,7 @@ protected:
|
||||
};
|
||||
|
||||
#define REGISTER_COMPRESSOR(NAME, CLASS) \
|
||||
extern "C" void wrapper_compressor_##CLASS(void) {} \
|
||||
static osgDB::RegisterCompressorProxy compressor_proxy_##CLASS(NAME, new CLASS);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user