diff --git a/VisualStudio/osgPlugins/ive/ive.dsp b/VisualStudio/osgPlugins/ive/ive.dsp index 13d77ef18..3d0bb3020 100755 --- a/VisualStudio/osgPlugins/ive/ive.dsp +++ b/VisualStudio/osgPlugins/ive/ive.dsp @@ -441,6 +441,10 @@ SOURCE=..\..\..\src\osgPlugins\ive\Switch.cpp # End Source File # Begin Source File +SOURCE=..\..\..\src\osgPlugins\ive\Stencil.cpp +# End Source File +# Begin Source File + SOURCE=..\..\..\src\osgPlugins\ive\TexEnv.cpp # End Source File # Begin Source File @@ -801,6 +805,10 @@ SOURCE=..\..\..\src\osgPlugins\ive\StateSet.h # End Source File # Begin Source File +SOURCE=..\..\..\src\osgPlugins\ive\Stencil.h +# End Source File +# Begin Source File + SOURCE=..\..\..\src\osgPlugins\ive\Switch.h # End Source File # Begin Source File diff --git a/examples/osgreflect/osgreflect.cpp b/examples/osgreflect/osgreflect.cpp index 0948f465c..c734db21f 100644 --- a/examples/osgreflect/osgreflect.cpp +++ b/examples/osgreflect/osgreflect.cpp @@ -23,6 +23,8 @@ #include #include +#include + #include #include @@ -359,6 +361,8 @@ int main( int argc, char **argv ) // hint to tell viewer to request stencil buffer when setting up windows osg::DisplaySettings::instance()->setMinimumNumStencilBits(8); + osgDB::writeNodeFile(*rootNode, "test.osg"); + return viewer.run(); } diff --git a/src/osgPlugins/ive/DataInputStream.cpp b/src/osgPlugins/ive/DataInputStream.cpp index 9045e7992..92987c659 100644 --- a/src/osgPlugins/ive/DataInputStream.cpp +++ b/src/osgPlugins/ive/DataInputStream.cpp @@ -19,6 +19,7 @@ #include "StateSet.h" #include "AlphaFunc.h" #include "BlendColor.h" +#include "Stencil.h" #include "BlendFunc.h" #include "Depth.h" #include "Material.h" @@ -1081,6 +1082,10 @@ osg::StateAttribute* DataInputStream::readStateAttribute() attribute = new osg::PointSprite(); ((ive::PointSprite*)(attribute))->read(this); } + else if(attributeID == IVESTENCIL){ + attribute = new osg::Stencil(); + ((ive::Stencil*)(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 b9826dd71..4bb4b8830 100644 --- a/src/osgPlugins/ive/DataOutputStream.cpp +++ b/src/osgPlugins/ive/DataOutputStream.cpp @@ -20,6 +20,7 @@ #include "StateSet.h" #include "AlphaFunc.h" #include "BlendColor.h" +#include "Stencil.h" #include "BlendFunc.h" #include "Material.h" #include "CullFace.h" @@ -658,6 +659,9 @@ void DataOutputStream::writeStateAttribute(const osg::StateAttribute* attribute) else if(dynamic_cast(attribute)){ ((ive::BlendColor*)(attribute))->write(this); } + else if(dynamic_cast(attribute)){ + ((ive::Stencil*)(attribute))->write(this); + } else if(dynamic_cast(attribute)){ ((ive::BlendFunc*)(attribute))->write(this); } diff --git a/src/osgPlugins/ive/GNUmakefile b/src/osgPlugins/ive/GNUmakefile index 393699cc6..2bcc19a78 100644 --- a/src/osgPlugins/ive/GNUmakefile +++ b/src/osgPlugins/ive/GNUmakefile @@ -74,6 +74,7 @@ CXXFILES =\ Shape.cpp\ ShapeDrawable.cpp\ StateSet.cpp\ + Stencil.cpp\ Switch.cpp\ TexEnvCombine.cpp\ TexEnv.cpp\ diff --git a/src/osgPlugins/ive/ReadWrite.h b/src/osgPlugins/ive/ReadWrite.h index 876aefb95..61706dbb6 100644 --- a/src/osgPlugins/ive/ReadWrite.h +++ b/src/osgPlugins/ive/ReadWrite.h @@ -67,6 +67,7 @@ namespace ive { #define IVEFRAGMENTPROGRAM 0x0000012E #define IVEVERTEXPROGRAM 0x0000012F #define IVEDEPTH 0x00000130 +#define IVESTENCIL 0x00000131 #define IVELIGHTMODEL 0x00001121 #define IVECLIPPLANE 0x00001122 #define IVEFRONTFACE 0x00001123 diff --git a/src/osgPlugins/ive/Stencil.cpp b/src/osgPlugins/ive/Stencil.cpp new file mode 100644 index 000000000..34c8afdcd --- /dev/null +++ b/src/osgPlugins/ive/Stencil.cpp @@ -0,0 +1,75 @@ +/********************************************************************** + * + * FILE: Stencil.cpp + * + * DESCRIPTION: Read/Write osg::Stencil in binary format to disk. + * + * CREATED BY: Auto generated by iveGenerated + * and later modified by Rune Schmidt Jensen. + * + * HISTORY: Created 21.3.2003 + * + * Copyright 2003 VR-C + **********************************************************************/ + +#include "Exception.h" +#include "Stencil.h" +#include "Object.h" + +using namespace ive; + +void Stencil::write(DataOutputStream* out){ + // Write Stencil's identification. + out->writeInt(IVESTENCIL); + // 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("Stencil::write(): Could not cast this osg::Stencil to an osg::Object."); + // Write Stencil's properties. + + out->writeInt(getFunction()); + out->writeInt(getFunctionRef()); + out->writeUInt(getFunctionMask()); + + out->writeInt(getStencilFailOperation()); + out->writeInt(getStencilPassAndDepthFailOperation()); + out->writeInt(getStencilPassAndDepthPassOperation()); + + out->writeUInt(getWriteMask()); + + +} + +void Stencil::read(DataInputStream* in){ + // Peek on Stencil's identification. + int id = in->peekInt(); + if(id == IVESTENCIL) + { + // Read Stencil'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("Stencil::read(): Could not cast this osg::Stencil to an osg::Object."); + + setFunction((Function)in->readInt()); + setFunctionRef(in->readInt()); + setFunctionMask(in->readUInt()); + + setStencilFailOperation((Operation)in->readInt()); + setStencilPassAndDepthFailOperation((Operation)in->readInt()); + setStencilPassAndDepthPassOperation((Operation)in->readInt()); + + setWriteMask(in->readUInt()); + + } + else{ + throw Exception("Stencil::read(): Expected Stencil identification."); + } +} diff --git a/src/osgPlugins/ive/Stencil.h b/src/osgPlugins/ive/Stencil.h new file mode 100644 index 000000000..8fec542fd --- /dev/null +++ b/src/osgPlugins/ive/Stencil.h @@ -0,0 +1,15 @@ +#ifndef IVE_STENCIL +#define IVE_STENCIL 1 + +#include +#include "ReadWrite.h" + +namespace ive{ +class Stencil : public osg::Stencil, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; +} + +#endif