Added access methods to Serializer to help with using wrappers for other purposes such as script integration.

Added Vec*i and Vec*ui support to serializers
This commit is contained in:
Robert Osfield
2013-09-11 15:44:08 +00:00
parent 31cd80cea7
commit 24ecfb1a48
6 changed files with 130 additions and 4 deletions

View File

@@ -64,6 +64,13 @@ const int ID_VEC2US_ARRAY = 23;
const int ID_VEC3US_ARRAY = 24;
const int ID_VEC4US_ARRAY = 25;
const int ID_VEC2I_ARRAY = 26;
const int ID_VEC3I_ARRAY = 27;
const int ID_VEC4I_ARRAY = 28;
const int ID_VEC2UI_ARRAY = 29;
const int ID_VEC3UI_ARRAY = 30;
const int ID_VEC4UI_ARRAY = 31;
const int ID_DRAWARRAYS = 50;
const int ID_DRAWARRAY_LENGTH = 51;
const int ID_DRAWELEMENTS_UBYTE = 52;

View File

@@ -93,14 +93,14 @@ struct UpdateWrapperVersionProxy
UpdateWrapperVersionProxy( ObjectWrapper* w, int v ): _wrapper(w)
{
_lastVersion = w->getUpdatedVersion();
w->setUpdatedVersion(v);
w->setUpdatedVersion(v);
}
~UpdateWrapperVersionProxy()
{
_wrapper->setUpdatedVersion(_lastVersion);
}
ObjectWrapper* _wrapper;
int _lastVersion;
};
@@ -133,6 +133,9 @@ public:
IntLookup::Value getValue( const std::string& group, const std::string& str ) { return findLookup(group).getValue(str.c_str()); }
const std::string& getString( const std::string& group, IntLookup::Value value ) { return findLookup(group).getString(value); }
IntLookupMap& getLookupMap() { return _globalMap; }
const IntLookupMap& getLookupMap() const { return _globalMap; }
protected:
friend class osgDB::Registry;

View File

@@ -82,6 +82,12 @@ public:
return itr->second;
}
StringToValue& getStringToValue() { return _stringToValue; }
const StringToValue& getStringToValue() const { return _stringToValue; }
ValueToString& getValueToString() { return _valueToString; }
const ValueToString& getValueToString() const { return _valueToString; }
protected:
StringToValue _stringToValue;
ValueToString _valueToString;
@@ -127,7 +133,7 @@ public:
RW_MATRIXF, RW_MATRIXD, RW_MATRIX, RW_GLENUM, RW_STRING, RW_ENUM,
RW_VEC2B, RW_VEC2UB, RW_VEC2S, RW_VEC2US, RW_VEC2I, RW_VEC2UI,
RW_VEC3B, RW_VEC3UB, RW_VEC3S, RW_VEC3US, RW_VEC3I, RW_VEC3UI,
RW_VEC4B, RW_VEC4UB, RW_VEC4S, RW_VEC4US, RW_VEC4I, RE_VEC4UI
RW_VEC4B, RW_VEC4UB, RW_VEC4S, RW_VEC4US, RW_VEC4I, RW_VEC4UI
};
BaseSerializer() : _firstVersion(0), _lastVersion(INT_MAX) {}

View File

@@ -488,6 +488,51 @@ osg::Array* InputStream::readArray()
array = va;
}
break;
case ID_VEC2I_ARRAY:
{
osg::Vec2iArray* va = new osg::Vec2iArray;
readArrayImplementation( va, 2, INT_SIZE );
array = va;
}
break;
case ID_VEC3I_ARRAY:
{
osg::Vec3iArray* va = new osg::Vec3iArray;
readArrayImplementation( va, 3, INT_SIZE );
array = va;
}
break;
case ID_VEC4I_ARRAY:
{
osg::Vec4iArray* va = new osg::Vec4iArray;
readArrayImplementation( va, 4, INT_SIZE );
array = va;
}
break;
case ID_VEC2UI_ARRAY:
{
osg::Vec2uiArray* va = new osg::Vec2uiArray;
readArrayImplementation( va, 2, INT_SIZE );
array = va;
}
break;
case ID_VEC3UI_ARRAY:
{
osg::Vec3uiArray* va = new osg::Vec3uiArray;
readArrayImplementation( va, 3, INT_SIZE );
array = va;
}
break;
case ID_VEC4UI_ARRAY:
{
osg::Vec4uiArray* va = new osg::Vec4uiArray;
readArrayImplementation( va, 4, INT_SIZE );
array = va;
}
break;
default:
throwException( "InputStream::readArray(): Unsupported array type." );
}

View File

@@ -535,6 +535,13 @@ ObjectWrapperManager::ObjectWrapperManager()
arrayTable.add( "Vec3dArray", ID_VEC3D_ARRAY );
arrayTable.add( "Vec4dArray", ID_VEC4D_ARRAY );
arrayTable.add( "Vec2iArray", ID_VEC2I_ARRAY );
arrayTable.add( "Vec3iArray", ID_VEC3I_ARRAY );
arrayTable.add( "Vec4iArray", ID_VEC4I_ARRAY );
arrayTable.add( "Vec2uiArray", ID_VEC2UI_ARRAY );
arrayTable.add( "Vec3uiArray", ID_VEC3UI_ARRAY );
arrayTable.add( "Vec4uiArray", ID_VEC4UI_ARRAY );
IntLookup& primitiveTable = _globalMap["PrimitiveType"];
primitiveTable.add( "DrawArrays", ID_DRAWARRAYS );

View File

@@ -82,6 +82,7 @@ OutputStream& OutputStream::operator<<( const osg::Vec3b& v )
OutputStream& OutputStream::operator<<( const osg::Vec4b& v )
{ *this << v.x() << v.y() << v.z() << v.w(); return *this; }
OutputStream& OutputStream::operator<<( const osg::Vec2ub& v )
{ *this << v.x() << v.y(); return *this; }
@@ -91,6 +92,7 @@ OutputStream& OutputStream::operator<<( const osg::Vec3ub& v )
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; }
@@ -100,6 +102,7 @@ OutputStream& OutputStream::operator<<( const osg::Vec3s& v )
OutputStream& OutputStream::operator<<( const osg::Vec4s& v )
{ *this << v.x() << v.y() << v.z() << v.w(); return *this; }
OutputStream& OutputStream::operator<<( const osg::Vec2us& v )
{ *this << v.x() << v.y(); return *this; }
@@ -109,6 +112,7 @@ OutputStream& OutputStream::operator<<( const osg::Vec3us& v )
OutputStream& OutputStream::operator<<( const osg::Vec4us& 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; }
@@ -118,6 +122,7 @@ OutputStream& OutputStream::operator<<( const osg::Vec3f& v )
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; }
@@ -127,6 +132,27 @@ OutputStream& OutputStream::operator<<( const osg::Vec3d& v )
OutputStream& OutputStream::operator<<( const osg::Vec4d& v )
{ *this << v.x() << v.y() << v.z() << v.w(); return *this; }
OutputStream& OutputStream::operator<<( const osg::Vec2i& v )
{ *this << v.x() << v.y(); return *this; }
OutputStream& OutputStream::operator<<( const osg::Vec3i& v )
{ *this << v.x() << v.y() << v.z(); return *this; }
OutputStream& OutputStream::operator<<( const osg::Vec4i& v )
{ *this << v.x() << v.y() << v.z() << v.w(); return *this; }
OutputStream& OutputStream::operator<<( const osg::Vec2ui& v )
{ *this << v.x() << v.y(); return *this; }
OutputStream& OutputStream::operator<<( const osg::Vec3ui& v )
{ *this << v.x() << v.y() << v.z(); return *this; }
OutputStream& OutputStream::operator<<( const osg::Vec4ui& 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; }
@@ -231,6 +257,7 @@ void OutputStream::writeArray( const osg::Array* a )
*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() );
@@ -243,6 +270,7 @@ void OutputStream::writeArray( const osg::Array* a )
*this << MAPPEE(ArrayType, ID_VEC4B_ARRAY);
writeArrayImplementation( static_cast<const osg::Vec4bArray*>(a), a->getNumElements() );
break;
case osg::Array::Vec2ubArrayType:
*this << MAPPEE(ArrayType, ID_VEC2UB_ARRAY);
writeArrayImplementation( static_cast<const osg::Vec2ubArray*>(a), a->getNumElements() );
@@ -255,6 +283,7 @@ void OutputStream::writeArray( const osg::Array* a )
*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() );
@@ -267,6 +296,7 @@ void OutputStream::writeArray( const osg::Array* a )
*this << MAPPEE(ArrayType, ID_VEC4S_ARRAY);
writeArrayImplementation( static_cast<const osg::Vec4sArray*>(a), a->getNumElements() );
break;
case osg::Array::Vec2usArrayType:
*this << MAPPEE(ArrayType, ID_VEC2US_ARRAY);
writeArrayImplementation( static_cast<const osg::Vec2usArray*>(a), a->getNumElements() );
@@ -279,6 +309,7 @@ void OutputStream::writeArray( const osg::Array* a )
*this << MAPPEE(ArrayType, ID_VEC4US_ARRAY);
writeArrayImplementation( static_cast<const osg::Vec4usArray*>(a), a->getNumElements() );
break;
case osg::Array::Vec2ArrayType:
*this << MAPPEE(ArrayType, ID_VEC2_ARRAY);
writeArrayImplementation( static_cast<const osg::Vec2Array*>(a), a->getNumElements() );
@@ -291,6 +322,7 @@ void OutputStream::writeArray( const osg::Array* a )
*this << MAPPEE(ArrayType, ID_VEC4_ARRAY);
writeArrayImplementation( static_cast<const osg::Vec4Array*>(a), a->getNumElements() );
break;
case osg::Array::Vec2dArrayType:
*this << MAPPEE(ArrayType, ID_VEC2D_ARRAY);
writeArrayImplementation( static_cast<const osg::Vec2dArray*>(a), a->getNumElements() );
@@ -303,6 +335,32 @@ void OutputStream::writeArray( const osg::Array* a )
*this << MAPPEE(ArrayType, ID_VEC4D_ARRAY);
writeArrayImplementation( static_cast<const osg::Vec4dArray*>(a), a->getNumElements() );
break;
case osg::Array::Vec2iArrayType:
*this << MAPPEE(ArrayType, ID_VEC2I_ARRAY);
writeArrayImplementation( static_cast<const osg::Vec2iArray*>(a), a->getNumElements() );
break;
case osg::Array::Vec3iArrayType:
*this << MAPPEE(ArrayType, ID_VEC3I_ARRAY);
writeArrayImplementation( static_cast<const osg::Vec3iArray*>(a), a->getNumElements() );
break;
case osg::Array::Vec4iArrayType:
*this << MAPPEE(ArrayType, ID_VEC4I_ARRAY);
writeArrayImplementation( static_cast<const osg::Vec4iArray*>(a), a->getNumElements() );
break;
case osg::Array::Vec2uiArrayType:
*this << MAPPEE(ArrayType, ID_VEC2UI_ARRAY);
writeArrayImplementation( static_cast<const osg::Vec2uiArray*>(a), a->getNumElements() );
break;
case osg::Array::Vec3uiArrayType:
*this << MAPPEE(ArrayType, ID_VEC3UI_ARRAY);
writeArrayImplementation( static_cast<const osg::Vec3uiArray*>(a), a->getNumElements() );
break;
case osg::Array::Vec4uiArrayType:
*this << MAPPEE(ArrayType, ID_VEC4UI_ARRAY);
writeArrayImplementation( static_cast<const osg::Vec4uiArray*>(a), a->getNumElements() );
break;
default:
throwException( "OutputStream::writeArray(): Unsupported array type." );
}