diff --git a/src/osgPlugins/ive/CMakeLists.txt b/src/osgPlugins/ive/CMakeLists.txt index 02769b584..ee503238b 100644 --- a/src/osgPlugins/ive/CMakeLists.txt +++ b/src/osgPlugins/ive/CMakeLists.txt @@ -3,8 +3,8 @@ SET(TARGET_SRC AlphaFunc.cpp - AnimationPath.cpp AnimationPathCallback.cpp + AnimationPath.cpp AutoTransform.cpp AzimElevationSector.cpp AzimSector.cpp @@ -18,44 +18,50 @@ SET(TARGET_SRC ClipPlane.cpp ClusterCullingCallback.cpp ColorMask.cpp + CompositeLayer.cpp ConeSector.cpp ConvexPlanarOccluder.cpp ConvexPlanarPolygon.cpp CoordinateSystemNode.cpp CullFace.cpp - DOFTransform.cpp DataInputStream.cpp DataOutputStream.cpp Depth.cpp DirectionalSector.cpp + DOFTransform.cpp + Drawable.cpp DrawArrayLengths.cpp DrawArrays.cpp DrawElementsUByte.cpp DrawElementsUInt.cpp DrawElementsUShort.cpp - Drawable.cpp ElevationSector.cpp EllipsoidModel.cpp Exception.cpp + Fog.cpp FragmentProgram.cpp FrontFace.cpp Geode.cpp Geometry.cpp Group.cpp + HeightFieldLayer.cpp Image.cpp + ImageLayer.cpp Impostor.cpp - LOD.cpp + Layer.cpp Light.cpp LightModel.cpp LightPoint.cpp LightPointNode.cpp LightSource.cpp LineWidth.cpp + Locator.cpp + LOD.cpp Material.cpp MatrixTransform.cpp + Multisample.cpp MultiSwitch.cpp MultiTextureControl.cpp - Multisample.cpp Node.cpp Object.cpp OccluderNode.cpp @@ -79,24 +85,19 @@ SET(TARGET_SRC StateSet.cpp Stencil.cpp Switch.cpp - TexEnv.cpp + TerrainTile.cpp TexEnvCombine.cpp + TexEnv.cpp TexGen.cpp TexGenNode.cpp TexMat.cpp Text.cpp - Texture.cpp Texture1D.cpp Texture2D.cpp Texture3D.cpp + Texture.cpp TextureCubeMap.cpp TextureRectangle.cpp - TerrainTile.cpp - Locator.cpp - Layer.cpp - HeightFieldLayer.cpp - ImageLayer.cpp - CompositeLayer.cpp Transform.cpp Uniform.cpp VertexProgram.cpp @@ -105,8 +106,8 @@ SET(TARGET_SRC ) SET(TARGET_H AlphaFunc.h - AnimationPath.h AnimationPathCallback.h + AnimationPath.h AutoTransform.h AzimElevationSector.h AzimSector.h @@ -120,41 +121,47 @@ SET(TARGET_H ClipPlane.h ClusterCullingCallback.h ColorMask.h + CompositeLayer.h ConeSector.h ConvexPlanarOccluder.h ConvexPlanarPolygon.h CoordinateSystemNode.h CullFace.h - DOFTransform.h DataInputStream.h DataOutputStream.h DataTypeSize.h Depth.h DirectionalSector.h + DOFTransform.h + Drawable.h DrawArrayLengths.h DrawArrays.h DrawElementsUByte.h DrawElementsUInt.h DrawElementsUShort.h - Drawable.h ElevationSector.h EllipsoidModel.h Exception.h + Fog.h FragmentProgram.h FrontFace.h Geode.h Geometry.h Group.h + HeightFieldLayer.h Image.h + ImageLayer.h Impostor.h IveVersion.h - LOD.h + Layer.h Light.h LightModel.h LightPoint.h LightPointNode.h LightSource.h LineWidth.h + Locator.h + LOD.h Material.h MatrixTransform.h MultiSwitch.h @@ -177,30 +184,25 @@ SET(TARGET_H Sequence.h ShadeModel.h Shader.h - Shape.h ShapeDrawable.h + Shape.h StateSet.h Stencil.h Switch.h - TexEnv.h + TerrainTile.h TexEnvCombine.h + TexEnv.h TexGen.h TexGenNode.h TexMat.h Text.h - Texture.h Texture1D.h Texture2D.h Texture3D.h TextureCubeMap.h + Texture.h TextureRectangle.h - TerrainTile.h Transform.h - Locator.h - Layer.h - HeightFieldLayer.h - ImageLayer.h - CompositeLayer.h Uniform.h VertexProgram.h Viewport.h diff --git a/src/osgPlugins/ive/DataInputStream.cpp b/src/osgPlugins/ive/DataInputStream.cpp index b9e4338cf..ab5fc4afe 100644 --- a/src/osgPlugins/ive/DataInputStream.cpp +++ b/src/osgPlugins/ive/DataInputStream.cpp @@ -51,6 +51,7 @@ #include "Image.h" #include "PointSprite.h" #include "Multisample.h" +#include "Fog.h" #include "Group.h" @@ -1181,6 +1182,10 @@ osg::StateAttribute* DataInputStream::readStateAttribute() attribute = new osg::Stencil(); ((ive::Stencil*)(attribute))->read(this); } + else if(attributeID == IVEFOG){ + attribute = new osg::Fog(); + ((ive::Fog*)(attribute))->read(this); + } else{ throw Exception("Unknown StateAttribute in StateSet::read()"); } diff --git a/src/osgPlugins/ive/DataOutputStream.cpp b/src/osgPlugins/ive/DataOutputStream.cpp index 723eccab0..c9d71a1e6 100644 --- a/src/osgPlugins/ive/DataOutputStream.cpp +++ b/src/osgPlugins/ive/DataOutputStream.cpp @@ -54,6 +54,7 @@ #include "Image.h" #include "PointSprite.h" #include "Multisample.h" +#include "Fog.h" #include "Group.h" #include "MatrixTransform.h" @@ -828,6 +829,10 @@ void DataOutputStream::writeStateAttribute(const osg::StateAttribute* attribute) else if(dynamic_cast(attribute)){ ((ive::Multisample*)(attribute))->write(this); } + // This is a Fog + else if(dynamic_cast(attribute)){ + ((ive::Fog*)(attribute))->write(this); + } else{ std::string className = attribute->className(); diff --git a/src/osgPlugins/ive/Fog.cpp b/src/osgPlugins/ive/Fog.cpp new file mode 100644 index 000000000..e356376d9 --- /dev/null +++ b/src/osgPlugins/ive/Fog.cpp @@ -0,0 +1,67 @@ +/********************************************************************** + * + * FILE: Fog.cpp + * + * DESCRIPTION: Read/Write osg::Fog in binary format to disk. + * + * CREATED BY: Liang Aibin + * + * HISTORY: Created 17.06.2008 + * + **********************************************************************/ + +#include "Exception.h" +#include "Fog.h" +#include "Object.h" + +using namespace ive; + +void Fog::write(DataOutputStream* out){ + + // write Fog's identification + out->writeInt(IVEFOG); + + // if the osg class is inherited by any other class we should also write this to file + osg::Object* obj = dynamic_cast(this); + if(obj) + ((ive::Object*)(obj))->write(out); + else + throw Exception("Fog::write(): Could not cast this osg::Fog to an osg::Object."); + + // write Fog's properties + out->writeInt(getMode()); + out->writeFloat(getDensity()); + out->writeFloat(getStart()); + out->writeFloat(getEnd()); + out->writeVec4(getColor()); + out->writeInt(getFogCoordinateSource()); +} + +void Fog::read(DataInputStream* in){ + + // peek on Fog's identification + int id = in->peekInt(); + if(id == IVEFOG) + { + // read Fog's identification + id = in->readInt(); + + // if the osg class is inherited by any other class we should also read this from file + osg::Object* obj = dynamic_cast(this); + if(obj) + ((ive::Object*)(obj))->read(in); + else + throw Exception("Fog::read(): Could not cast this osg::Fog to an osg::Object."); + + // Read Fog's properties + setMode(osg::Fog::Mode(in->readInt())); + setDensity(in->readFloat()); + setStart(in->readFloat()); + setEnd(in->readFloat()); + setColor(in->readVec4()); + setFogCoordinateSource(in->readInt()); + } + else{ + throw Exception("Fog::read(): Expected Fog identification."); + } +} diff --git a/src/osgPlugins/ive/Fog.h b/src/osgPlugins/ive/Fog.h new file mode 100644 index 000000000..431b28450 --- /dev/null +++ b/src/osgPlugins/ive/Fog.h @@ -0,0 +1,15 @@ +#ifndef IVE_FOG +#define IVE_FOG 1 + +#include +#include "ReadWrite.h" + +namespace ive{ + class Fog : public osg::Fog, public ReadWrite { + public: + void write(DataOutputStream* out); + void read(DataInputStream* in); + }; +} + +#endif diff --git a/src/osgPlugins/ive/ReadWrite.h b/src/osgPlugins/ive/ReadWrite.h index c15b5ac3e..86445eb52 100644 --- a/src/osgPlugins/ive/ReadWrite.h +++ b/src/osgPlugins/ive/ReadWrite.h @@ -83,6 +83,7 @@ namespace ive { #define IVETEXTURERECTANGLE 0x00001130 #define IVEPOINTSPRITE 0x00001131 #define IVEMULTISAMPLE 0x00001132 +#define IVEFOG 0x00001133 // Drawables #define IVEDRAWABLE 0x00001000 diff --git a/src/osgPlugins/osg/Fog.cpp b/src/osgPlugins/osg/Fog.cpp index 83faa89ee..e61769cf9 100644 --- a/src/osgPlugins/osg/Fog.cpp +++ b/src/osgPlugins/osg/Fog.cpp @@ -135,7 +135,7 @@ const char* Fog_getModeStr(Fog::Mode mode) { switch(mode) { - case(Fog::LINEAR): return "NEVER"; + case(Fog::LINEAR): return "LINEAR"; case(Fog::EXP): return "EXP"; case(Fog::EXP2): return "EXP2"; }