From e4580f2028663f92cdc508992a19b384aa564a32 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 26 Mar 2005 10:04:31 +0000 Subject: [PATCH] From Farshid Laskari, addiition of FrontFace support to .ive --- VisualStudio/osgPlugins/ive/ive.dsp | 8 ++++ src/osgPlugins/ive/DataInputStream.cpp | 7 ++- src/osgPlugins/ive/DataOutputStream.cpp | 7 ++- src/osgPlugins/ive/FrontFace.cpp | 60 +++++++++++++++++++++++++ src/osgPlugins/ive/FrontFace.h | 16 +++++++ src/osgPlugins/ive/GNUmakefile | 1 + src/osgPlugins/ive/ReadWrite.h | 1 + 7 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 src/osgPlugins/ive/FrontFace.cpp create mode 100644 src/osgPlugins/ive/FrontFace.h diff --git a/VisualStudio/osgPlugins/ive/ive.dsp b/VisualStudio/osgPlugins/ive/ive.dsp index 44c8b75dd..61925c18e 100755 --- a/VisualStudio/osgPlugins/ive/ive.dsp +++ b/VisualStudio/osgPlugins/ive/ive.dsp @@ -216,6 +216,10 @@ SOURCE=..\..\..\src\osgPlugins\ive\FragmentProgram.cpp # End Source File # Begin Source File +SOURCE=..\..\..\src\osgPlugins\ive\FrontFace.cpp +# End Source File +# Begin Source File + SOURCE=..\..\..\src\osgPlugins\ive\Geode.cpp # End Source File # Begin Source File @@ -524,6 +528,10 @@ SOURCE=..\..\..\src\osgPlugins\ive\FragmentProgram.h # End Source File # Begin Source File +SOURCE=..\..\..\src\osgPlugins\ive\FrontFace.h +# End Source File +# Begin Source File + SOURCE=..\..\..\src\osgPlugins\ive\Geode.h # End Source File # Begin Source File diff --git a/src/osgPlugins/ive/DataInputStream.cpp b/src/osgPlugins/ive/DataInputStream.cpp index e509dee95..b7cc67c50 100644 --- a/src/osgPlugins/ive/DataInputStream.cpp +++ b/src/osgPlugins/ive/DataInputStream.cpp @@ -38,6 +38,7 @@ #include "VertexProgram.h" #include "LightModel.h" #include "ProxyNode.h" +#include "FrontFace.h" #include "Group.h" #include "MatrixTransform.h" @@ -745,12 +746,14 @@ osg::StateAttribute* DataInputStream::readStateAttribute() attribute = new osg::VertexProgram(); ((ive::VertexProgram*)(attribute))->read(this); } - else if(attributeID == IVELIGHTMODEL){ attribute = new osg::LightModel(); ((ive::LightModel*)(attribute))->read(this); } - + else if(attributeID == IVEFRONTFACE){ + attribute = new osg::FrontFace(); + ((ive::FrontFace*)(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 ee6d975aa..48ebd857e 100644 --- a/src/osgPlugins/ive/DataOutputStream.cpp +++ b/src/osgPlugins/ive/DataOutputStream.cpp @@ -39,7 +39,7 @@ #include "VertexProgram.h" #include "LightModel.h" #include "ProxyNode.h" - +#include "FrontFace.h" #include "Group.h" #include "MatrixTransform.h" @@ -561,11 +561,14 @@ void DataOutputStream::writeStateAttribute(const osg::StateAttribute* attribute) else if(dynamic_cast(attribute)){ ((ive::VertexProgram*)(attribute))->write(this); } - // This is a LightModel else if(dynamic_cast(attribute)){ ((ive::LightModel*)(attribute))->write(this); } + // This is a FrontFace + else if(dynamic_cast(attribute)){ + ((ive::FrontFace*)(attribute))->write(this); + } else{ std::string className = attribute->className(); diff --git a/src/osgPlugins/ive/FrontFace.cpp b/src/osgPlugins/ive/FrontFace.cpp new file mode 100644 index 000000000..a6fcc52f7 --- /dev/null +++ b/src/osgPlugins/ive/FrontFace.cpp @@ -0,0 +1,60 @@ +/********************************************************************** + * + * FILE: FrontFace.cpp + * + * DESCRIPTION: Read/Write osg::FrontFace 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 "FrontFace.h" +#include "Object.h" + +using namespace ive; + +void FrontFace::write(DataOutputStream* out){ + // Write FrontFace's identification. + out->writeInt(IVEFRONTFACE); + // 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("FrontFace::write(): Could not cast this osg::FrontFace to an osg::Object."); + // Write FrontFace's properties. + + // Write mode + out->writeInt(getMode()); +} + +void FrontFace::read(DataInputStream* in){ + // Peek on FrontFace's identification. + int id = in->peekInt(); + if(id == IVEFRONTFACE){ + // Read FrontFace'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("FrontFace::read(): Could not cast this osg::FrontFace to an osg::Object."); + // Read FrontFace's properties + + // Read mode + setMode((osg::FrontFace::Mode)in->readInt()); + + } + else{ + throw Exception("FrontFace::read(): Expected FrontFace identification."); + } +} + diff --git a/src/osgPlugins/ive/FrontFace.h b/src/osgPlugins/ive/FrontFace.h new file mode 100644 index 000000000..5c99d7ead --- /dev/null +++ b/src/osgPlugins/ive/FrontFace.h @@ -0,0 +1,16 @@ +#ifndef IVE_FRONTFACE +#define IVE_FRONTFACE 1 + +#include +#include "ReadWrite.h" + +namespace ive{ +class FrontFace : public osg::FrontFace, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; +} + +#endif + diff --git a/src/osgPlugins/ive/GNUmakefile b/src/osgPlugins/ive/GNUmakefile index 98c2f8fae..75fb5bd5f 100644 --- a/src/osgPlugins/ive/GNUmakefile +++ b/src/osgPlugins/ive/GNUmakefile @@ -32,6 +32,7 @@ CXXFILES =\ EllipsoidModel.cpp\ Exception.cpp\ FragmentProgram.cpp\ + FrontFace.cpp\ Geode.cpp\ Geometry.cpp\ Group.cpp\ diff --git a/src/osgPlugins/ive/ReadWrite.h b/src/osgPlugins/ive/ReadWrite.h index 635e93119..9acce3f3b 100644 --- a/src/osgPlugins/ive/ReadWrite.h +++ b/src/osgPlugins/ive/ReadWrite.h @@ -63,6 +63,7 @@ namespace ive { #define IVEVERTEXPROGRAM 0x0000012F #define IVELIGHTMODEL 0x00001121 #define IVECLIPPLANE 0x00001122 +#define IVEFRONTFACE 0x00001123 // Drawables #define IVEDRAWABLE 0x00001000