From d5aea9c0f266d7b06021515eb7c7710904ccf050 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 16 Mar 2010 18:44:27 +0000 Subject: [PATCH] Updated various serialization support for .osg, .osgt/b/x and .ive. --- include/osgDB/Serializer | 9 +++++++++ src/osgPlugins/ive/IveVersion.h | 3 ++- src/osgPlugins/ive/TerrainTile.cpp | 10 ++++++++++ .../deprecated-dotosg/osgTerrain/Terrain.cpp | 17 ++++++++++++++++ .../osgTerrain/TerrainTile.cpp | 17 ++++++++++++++++ .../introspection/osgTerrain/TerrainTile.cpp | 20 +++++++++++++++++++ .../serializers/osgTerrain/Terrain.cpp | 7 +++++++ .../serializers/osgTerrain/TerrainTile.cpp | 6 ++++++ 8 files changed, 88 insertions(+), 1 deletion(-) diff --git a/include/osgDB/Serializer b/include/osgDB/Serializer index 34682c82d..089f3fa19 100644 --- a/include/osgDB/Serializer +++ b/include/osgDB/Serializer @@ -862,9 +862,18 @@ public: osg::ref_ptr serializer = new MySerializer( \ #PROP, MyClass::DEF, &MyClass::get##PROP, &MyClass::set##PROP) +#define BEGIN_ENUM_SERIALIZER4(PROPERTIES_CLASS, PROP, DEF) \ + { typedef osgDB::EnumSerializer MySerializer; \ + osg::ref_ptr serializer = new MySerializer( \ + #PROP, PROPERTIES_CLASS::DEF, &MyClass::get##PROP, &MyClass::set##PROP) + + #define ADD_ENUM_VALUE(VALUE) \ serializer->add(#VALUE, MyClass::VALUE) +#define ADD_ENUM_CLASS_VALUE(CLASS, VALUE) \ + serializer->add(#VALUE, CLASS::VALUE) + #define END_ENUM_SERIALIZER() \ wrapper->addSerializer(serializer.get()); } diff --git a/src/osgPlugins/ive/IveVersion.h b/src/osgPlugins/ive/IveVersion.h index 4edd629b3..6096b6ec3 100644 --- a/src/osgPlugins/ive/IveVersion.h +++ b/src/osgPlugins/ive/IveVersion.h @@ -52,8 +52,9 @@ #define VERSION_0041 41 #define VERSION_0042 42 #define VERSION_0043 43 +#define VERSION_0044 44 -#define VERSION VERSION_0043 +#define VERSION VERSION_0044 /* The BYTE_SEX tag is used to check the endian of the IVE file being read in. The IVE format diff --git a/src/osgPlugins/ive/TerrainTile.cpp b/src/osgPlugins/ive/TerrainTile.cpp index 403b15882..96b5aee29 100644 --- a/src/osgPlugins/ive/TerrainTile.cpp +++ b/src/osgPlugins/ive/TerrainTile.cpp @@ -31,6 +31,11 @@ void TerrainTile::write(DataOutputStream* out) else out_THROW_EXCEPTION("Terrain::write(): Could not cast this osgTerrain::Terrain to an osg::Group."); + if (out->getVersion() >= VERSION_0044) + { + out->writeInt(getBlendingPolicy()); + } + if (out->getVersion() >= VERSION_0026) { out->writeInt(getTileID().level); @@ -84,6 +89,11 @@ void TerrainTile::read(DataInputStream* in) else in_THROW_EXCEPTION("Terrain::read(): Could not cast this osgTerrain::Terrain to an osg::Group."); + if (in->getVersion() >= VERSION_0044) + { + setBlendingPolicy(static_cast(in->readInt())); + } + if (in->getVersion() >= VERSION_0026) { diff --git a/src/osgWrappers/deprecated-dotosg/osgTerrain/Terrain.cpp b/src/osgWrappers/deprecated-dotosg/osgTerrain/Terrain.cpp index 5fb6932c3..025caec9e 100644 --- a/src/osgWrappers/deprecated-dotosg/osgTerrain/Terrain.cpp +++ b/src/osgWrappers/deprecated-dotosg/osgTerrain/Terrain.cpp @@ -28,6 +28,15 @@ bool Terrain_readLocalData(osg::Object& obj, osgDB::Input& fr) if (fr.read("SampleRatio",value)) terrain.setSampleRatio(value); if (fr.read("VerticalScale",value)) terrain.setVerticalScale(value); + std::string blendingPolicy; + if (fr.read("BlendingPolicy",blendingPolicy)) + { + if (blendingPolicy == "INHERIT") terrain.setBlendingPolicy(osgTerrain::TerrainTile::INHERIT); + else if (blendingPolicy == "DO_NOT_SET_BLENDING") terrain.setBlendingPolicy(osgTerrain::TerrainTile::DO_NOT_SET_BLENDING); + else if (blendingPolicy == "ENABLE_BLENDING") terrain.setBlendingPolicy(osgTerrain::TerrainTile::ENABLE_BLENDING); + else if (blendingPolicy == "ENABLE_BLENDING_WHEN_ALPHA_PRESENT") terrain.setBlendingPolicy(osgTerrain::TerrainTile::ENABLE_BLENDING_WHEN_ALPHA_PRESENT); + } + return iteratorAdvanced; } @@ -38,5 +47,13 @@ bool Terrain_writeLocalData(const osg::Object& obj, osgDB::Output& fw) fw.indent()<<"SampleRatio "< readObject = fr.readObjectOfType(osgDB::type_wrapper()); if (readObject.valid()) itrAdvanced = true; + std::string blendingPolicy; + if (fr.read("BlendingPolicy",blendingPolicy)) + { + if (blendingPolicy == "INHERIT") terrainTile.setBlendingPolicy(osgTerrain::TerrainTile::INHERIT); + else if (blendingPolicy == "DO_NOT_SET_BLENDING") terrainTile.setBlendingPolicy(osgTerrain::TerrainTile::DO_NOT_SET_BLENDING); + else if (blendingPolicy == "ENABLE_BLENDING") terrainTile.setBlendingPolicy(osgTerrain::TerrainTile::ENABLE_BLENDING); + else if (blendingPolicy == "ENABLE_BLENDING_WHEN_ALPHA_PRESENT") terrainTile.setBlendingPolicy(osgTerrain::TerrainTile::ENABLE_BLENDING_WHEN_ALPHA_PRESENT); + } + osgTerrain::Locator* locator = dynamic_cast(readObject.get()); if (locator) terrainTile.setLocator(locator); @@ -193,6 +202,14 @@ bool TerrainTile_writeLocalData(const osg::Object& obj, osgDB::Output& fw) int prec = fw.precision(); fw.precision(15); + switch(terrainTile.getBlendingPolicy()) + { + case(osgTerrain::TerrainTile::INHERIT): fw.indent()<<"BlendingPolicy INHERIT"<