From 41863ecbb644cada79738972d8a97a770f4a0ca3 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 19 Mar 2012 09:49:41 +0000 Subject: [PATCH] From Lukasz Izdebski, Added StencilTwoSided support to ive plugin --- src/osgPlugins/ive/CMakeLists.txt | 2 + src/osgPlugins/ive/DataInputStream.cpp | 6 +- src/osgPlugins/ive/DataOutputStream.cpp | 4 ++ src/osgPlugins/ive/StencilTwoSided.cpp | 92 +++++++++++++++++++++++++ src/osgPlugins/ive/StencilTwoSided.h | 15 ++++ 5 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 src/osgPlugins/ive/StencilTwoSided.cpp create mode 100644 src/osgPlugins/ive/StencilTwoSided.h diff --git a/src/osgPlugins/ive/CMakeLists.txt b/src/osgPlugins/ive/CMakeLists.txt index 0912efacc..311103a6e 100644 --- a/src/osgPlugins/ive/CMakeLists.txt +++ b/src/osgPlugins/ive/CMakeLists.txt @@ -99,6 +99,7 @@ SET(TARGET_SRC SpecularHighlights.cpp StateSet.cpp Stencil.cpp + StencilTwoSided.cpp Switch.cpp SwitchLayer.cpp Terrain.cpp @@ -229,6 +230,7 @@ SET(TARGET_H SpecularHighlights.h StateSet.h Stencil.h + StencilTwoSided.h Switch.h SwitchLayer.h Terrain.h diff --git a/src/osgPlugins/ive/DataInputStream.cpp b/src/osgPlugins/ive/DataInputStream.cpp index 14717d5cf..f076a4657 100644 --- a/src/osgPlugins/ive/DataInputStream.cpp +++ b/src/osgPlugins/ive/DataInputStream.cpp @@ -20,6 +20,7 @@ #include "AlphaFunc.h" #include "BlendColor.h" #include "Stencil.h" +#include "StencilTwoSided.h" #include "BlendFunc.h" #include "BlendEquation.h" #include "Depth.h" @@ -59,7 +60,6 @@ #include "Light.h" #include "PolygonStipple.h" - #include "Node.h" #include "Group.h" #include "MatrixTransform.h" @@ -1507,6 +1507,10 @@ osg::StateAttribute* DataInputStream::readStateAttribute() attribute = new osg::Stencil(); ((ive::Stencil*)(attribute.get()))->read(this); } + else if(attributeID == IVESTENCILTWOSIDED){ + attribute = new osg::StencilTwoSided(); + ((ive::StencilTwoSided*)(attribute.get()))->read(this); + } else if(attributeID == IVEFOG){ attribute = new osg::Fog(); ((ive::Fog*)(attribute.get()))->read(this); diff --git a/src/osgPlugins/ive/DataOutputStream.cpp b/src/osgPlugins/ive/DataOutputStream.cpp index fc9d7cd54..ddf18a9c4 100644 --- a/src/osgPlugins/ive/DataOutputStream.cpp +++ b/src/osgPlugins/ive/DataOutputStream.cpp @@ -21,6 +21,7 @@ #include "AlphaFunc.h" #include "BlendColor.h" #include "Stencil.h" +#include "StencilTwoSided.h" #include "BlendFunc.h" #include "BlendEquation.h" #include "Material.h" @@ -1000,6 +1001,9 @@ void DataOutputStream::writeStateAttribute(const osg::StateAttribute* attribute) else if(dynamic_cast(attribute)){ ((ive::Stencil*)(attribute))->write(this); } + else if(dynamic_cast(attribute)){ + ((ive::StencilTwoSided*)(attribute))->write(this); + } else if(dynamic_cast(attribute)){ ((ive::BlendFunc*)(attribute))->write(this); } diff --git a/src/osgPlugins/ive/StencilTwoSided.cpp b/src/osgPlugins/ive/StencilTwoSided.cpp new file mode 100644 index 000000000..8ebccd935 --- /dev/null +++ b/src/osgPlugins/ive/StencilTwoSided.cpp @@ -0,0 +1,92 @@ +/********************************************************************** + * + * 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 "StencilTwoSided.h" +#include "Object.h" + +using namespace ive; + +void StencilTwoSided::write(DataOutputStream* out){ + // Write Stencil's identification. + out->writeInt(IVESTENCILTWOSIDED); + // 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 + out_THROW_EXCEPTION("Stencil::write(): Could not cast this osg::Stencil to an osg::Object."); + // Write Stencil's properties. + + out->writeInt(getFunction(FRONT)); + out->writeInt(getFunctionRef(FRONT)); + out->writeUInt(getFunctionMask(FRONT)); + + out->writeInt(getStencilFailOperation(FRONT)); + out->writeInt(getStencilPassAndDepthFailOperation(FRONT)); + out->writeInt(getStencilPassAndDepthPassOperation(FRONT)); + + out->writeUInt(getWriteMask(FRONT)); + + out->writeInt(getFunction(BACK)); + out->writeInt(getFunctionRef(BACK)); + out->writeUInt(getFunctionMask(BACK)); + + out->writeInt(getStencilFailOperation(BACK)); + out->writeInt(getStencilPassAndDepthFailOperation(BACK)); + out->writeInt(getStencilPassAndDepthPassOperation(BACK)); + + out->writeUInt(getWriteMask(BACK)); +} + +void StencilTwoSided::read(DataInputStream* in){ + // Peek on Stencil's identification. + int id = in->peekInt(); + if(id == IVESTENCILTWOSIDED) + { + // 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 + in_THROW_EXCEPTION("Stencil::read(): Could not cast this osg::Stencil to an osg::Object."); + + setFunction(FRONT, (Function)in->readInt()); + setFunctionRef(FRONT, in->readInt()); + setFunctionMask(FRONT, in->readUInt()); + + setStencilFailOperation(FRONT, (Operation)in->readInt()); + setStencilPassAndDepthFailOperation(FRONT, (Operation)in->readInt()); + setStencilPassAndDepthPassOperation(FRONT, (Operation)in->readInt()); + + setWriteMask(FRONT, in->readUInt()); + + setFunction(BACK, (Function)in->readInt()); + setFunctionRef(BACK, in->readInt()); + setFunctionMask(BACK, in->readUInt()); + + setStencilFailOperation(BACK, (Operation)in->readInt()); + setStencilPassAndDepthFailOperation(BACK, (Operation)in->readInt()); + setStencilPassAndDepthPassOperation(BACK, (Operation)in->readInt()); + + setWriteMask(BACK, in->readUInt()); + } + else{ + in_THROW_EXCEPTION("Stencil::read(): Expected Stencil identification."); + } +} diff --git a/src/osgPlugins/ive/StencilTwoSided.h b/src/osgPlugins/ive/StencilTwoSided.h new file mode 100644 index 000000000..496954471 --- /dev/null +++ b/src/osgPlugins/ive/StencilTwoSided.h @@ -0,0 +1,15 @@ +#ifndef IVE_STENCIL_TWO_SIDED +#define IVE_STENCIL_TWO_SIDED 1 + +#include +#include "ReadWrite.h" + +namespace ive{ +class StencilTwoSided : public osg::StencilTwoSided, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; +} + +#endif