From David Callu, serializer support for new Vec* and Vec*Array classes

This commit is contained in:
Robert Osfield
2013-06-28 08:57:42 +00:00
parent f2c1a7597c
commit 4fd6566e00
7 changed files with 138 additions and 5 deletions

View File

@@ -101,9 +101,23 @@ InputStream& InputStream::operator>>( osg::Vec4b& v )
return *this;
}
InputStream& InputStream::operator>>( osg::Vec2ub& v )
{
unsigned char x, y; *this >> x >> y;
v.set( x, y );
return *this;
}
InputStream& InputStream::operator>>( osg::Vec3ub& v )
{
unsigned char x, y, z; *this >> x >> y >> z;
v.set( x, y, z );
return *this;
}
InputStream& InputStream::operator>>( osg::Vec4ub& v )
{
char r, g, b, a; *this >> r >> g >> b >> a;
unsigned char r, g, b, a; *this >> r >> g >> b >> a;
v.set( r, g, b, a );
return *this;
}
@@ -117,6 +131,15 @@ InputStream& InputStream::operator>>( osg::Vec3s& v )
InputStream& InputStream::operator>>( osg::Vec4s& v )
{ *this >> v.x() >> v.y() >> v.z() >> v.w(); return *this; }
InputStream& InputStream::operator>>( osg::Vec2us& v )
{ *this >> v.x() >> v.y(); return *this; }
InputStream& InputStream::operator>>( osg::Vec3us& v )
{ *this >> v.x() >> v.y() >> v.z(); return *this; }
InputStream& InputStream::operator>>( osg::Vec4us& v )
{ *this >> v.x() >> v.y() >> v.z() >> v.w(); return *this; }
InputStream& InputStream::operator>>( osg::Vec2i& v )
{ *this >> v.x() >> v.y(); return *this; }
@@ -360,6 +383,20 @@ osg::Array* InputStream::readArray()
array = va;
}
break;
case ID_VEC2UB_ARRAY:
{
osg::Vec2ubArray* va = new osg::Vec2ubArray;
readArrayImplementation( va, 2, CHAR_SIZE );
array = va;
}
break;
case ID_VEC3UB_ARRAY:
{
osg::Vec3ubArray* va = new osg::Vec3ubArray;
readArrayImplementation( va, 3, CHAR_SIZE );
array = va;
}
break;
case ID_VEC4UB_ARRAY:
{
osg::Vec4ubArray* va = new osg::Vec4ubArray;
@@ -388,6 +425,27 @@ osg::Array* InputStream::readArray()
array = va;
}
break;
case ID_VEC2US_ARRAY:
{
osg::Vec2usArray* va = new osg::Vec2usArray;
readArrayImplementation( va, 2, SHORT_SIZE );
array = va;
}
break;
case ID_VEC3US_ARRAY:
{
osg::Vec3usArray* va = new osg::Vec3usArray;
readArrayImplementation( va, 3, SHORT_SIZE );
array = va;
}
break;
case ID_VEC4US_ARRAY:
{
osg::Vec4usArray* va = new osg::Vec4usArray;
readArrayImplementation( va, 4, SHORT_SIZE );
array = va;
}
break;
case ID_VEC2_ARRAY:
{
osg::Vec2Array* va = new osg::Vec2Array;

View File

@@ -519,10 +519,15 @@ ObjectWrapperManager::ObjectWrapperManager()
arrayTable.add( "Vec2bArray", ID_VEC2B_ARRAY );
arrayTable.add( "Vec3bArray", ID_VEC3B_ARRAY );
arrayTable.add( "Vec4bArray", ID_VEC4B_ARRAY );
arrayTable.add( "Vec2ubArray", ID_VEC2UB_ARRAY );
arrayTable.add( "Vec3ubArray", ID_VEC3UB_ARRAY );
arrayTable.add( "Vec4ubArray", ID_VEC4UB_ARRAY );
arrayTable.add( "Vec2sArray", ID_VEC2S_ARRAY );
arrayTable.add( "Vec3sArray", ID_VEC3S_ARRAY );
arrayTable.add( "Vec4sArray", ID_VEC4S_ARRAY );
arrayTable.add( "Vec2usArray", ID_VEC2US_ARRAY );
arrayTable.add( "Vec3usArray", ID_VEC3US_ARRAY );
arrayTable.add( "Vec4usArray", ID_VEC4US_ARRAY );
arrayTable.add( "Vec2fArray", ID_VEC2_ARRAY );
arrayTable.add( "Vec3fArray", ID_VEC3_ARRAY );
arrayTable.add( "Vec4fArray", ID_VEC4_ARRAY );

View File

@@ -81,6 +81,12 @@ 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; }
OutputStream& OutputStream::operator<<( const osg::Vec3ub& v )
{ *this << v.x() << v.y() << v.z(); return *this; }
OutputStream& OutputStream::operator<<( const osg::Vec4ub& v )
{ *this << v.r() << v.g() << v.b() << v.a(); return *this; }
@@ -93,6 +99,15 @@ 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; }
OutputStream& OutputStream::operator<<( const osg::Vec3us& v )
{ *this << v.x() << v.y() << v.z(); return *this; }
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; }
@@ -227,6 +242,14 @@ 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() );
break;
case osg::Array::Vec3ubArrayType:
*this << MAPPEE(ArrayType, ID_VEC3UB_ARRAY);
writeArrayImplementation( static_cast<const osg::Vec3ubArray*>(a), a->getNumElements() );
break;
case osg::Array::Vec4ubArrayType:
*this << MAPPEE(ArrayType, ID_VEC4UB_ARRAY);
writeArrayImplementation( static_cast<const osg::Vec4ubArray*>(a), a->getNumElements() );
@@ -243,6 +266,18 @@ 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() );
break;
case osg::Array::Vec3usArrayType:
*this << MAPPEE(ArrayType, ID_VEC3US_ARRAY);
writeArrayImplementation( static_cast<const osg::Vec3usArray*>(a), a->getNumElements() );
break;
case osg::Array::Vec4usArrayType:
*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() );