From 73bf2a7de96fe2959072a6f22cdaf18eb223aee2 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 23 Mar 2009 17:08:58 +0000 Subject: [PATCH] From Luc Frauciel, You'll find attached a modification in ive plugin for POLYGONSTIPPLE read/write. --- src/osgPlugins/ive/CMakeLists.txt | 2 + src/osgPlugins/ive/DataInputStream.cpp | 5 +++ src/osgPlugins/ive/DataOutputStream.cpp | 5 +++ src/osgPlugins/ive/PolygonStipple.cpp | 54 +++++++++++++++++++++++++ src/osgPlugins/ive/PolygonStipple.h | 15 +++++++ src/osgPlugins/ive/ReadWrite.h | 1 + 6 files changed, 82 insertions(+) create mode 100644 src/osgPlugins/ive/PolygonStipple.cpp create mode 100644 src/osgPlugins/ive/PolygonStipple.h diff --git a/src/osgPlugins/ive/CMakeLists.txt b/src/osgPlugins/ive/CMakeLists.txt index 871dc2f66..9620df7fa 100644 --- a/src/osgPlugins/ive/CMakeLists.txt +++ b/src/osgPlugins/ive/CMakeLists.txt @@ -78,6 +78,7 @@ SET(TARGET_SRC PointSprite.cpp PolygonMode.cpp PolygonOffset.cpp + PolygonStipple.cpp PositionAttitudeTransform.cpp PrimitiveSet.cpp Program.cpp @@ -194,6 +195,7 @@ SET(TARGET_H PointSprite.h PolygonMode.h PolygonOffset.h + PolygonStipple.h PositionAttitudeTransform.h PrimitiveSet.h Program.h diff --git a/src/osgPlugins/ive/DataInputStream.cpp b/src/osgPlugins/ive/DataInputStream.cpp index 2fbf1080c..43900fd11 100644 --- a/src/osgPlugins/ive/DataInputStream.cpp +++ b/src/osgPlugins/ive/DataInputStream.cpp @@ -56,6 +56,7 @@ #include "Multisample.h" #include "Fog.h" #include "Light.h" +#include "PolygonStipple.h" #include "Group.h" @@ -1411,6 +1412,10 @@ osg::StateAttribute* DataInputStream::readStateAttribute() attribute = new osg::Light(); ((ive::Light*)(attribute))->read(this); } + else if(attributeID == IVEPOLYGONSTIPPLE){ + attribute = new osg::PolygonStipple(); + ((ive::PolygonStipple*)(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 e5047c4bc..cfeddaf6b 100644 --- a/src/osgPlugins/ive/DataOutputStream.cpp +++ b/src/osgPlugins/ive/DataOutputStream.cpp @@ -59,6 +59,7 @@ #include "Multisample.h" #include "Fog.h" #include "Light.h" +#include "PolygonStipple.h" #include "Group.h" #include "MatrixTransform.h" @@ -1089,6 +1090,10 @@ void DataOutputStream::writeStateAttribute(const osg::StateAttribute* attribute) else if(dynamic_cast(attribute)){ ((ive::Light*)(attribute))->write(this); } + // This is a PolygonStipple + else if(dynamic_cast(attribute)){ + ((ive::PolygonStipple*)(attribute))->write(this); + } else{ std::string className = attribute->className(); diff --git a/src/osgPlugins/ive/PolygonStipple.cpp b/src/osgPlugins/ive/PolygonStipple.cpp new file mode 100644 index 000000000..b3d25b0bc --- /dev/null +++ b/src/osgPlugins/ive/PolygonStipple.cpp @@ -0,0 +1,54 @@ +/********************************************************************** + * + * FILE: PolygonStipple.cpp + * + * DESCRIPTION: Read/Write osg::PolygonStipple in binary format to disk. + * + * CREATED BY: Copied from LineStipple + * and modified by Luc Frauciel + * + * HISTORY: Created 21.3.2009 + * + * Copyright 2008 VR-C + **********************************************************************/ + +#include "Exception.h" +#include "PolygonStipple.h" +#include "Object.h" + +using namespace ive; + +void PolygonStipple::write(DataOutputStream* out){ + // Write CullFace's identification. + out->writeInt(IVEPOLYGONSTIPPLE); + // 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("PolygonStipple::write(): Could not cast this osg::PolygonStipple to an osg::Object."); + // Write PolygonStipple's properties. + out->writeUByteArray(new osg::UByteArray(128,const_cast(getMask()))); +} + +void PolygonStipple::read(DataInputStream* in){ + // Peek on LineStipple's identification. + int id = in->peekInt(); + if (id == IVEPOLYGONSTIPPLE) { + // Read PolygonStipple'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("PolygonStipple::read(): Could not cast this osg::PolygonStipple to an osg::Object."); + // Read PolygonStipple's properties + setMask((GLubyte *)in->readUByteArray()->getDataPointer()); + } + else{ + throw Exception("PolygonStipple::read(): Expected PolygonStipple identification."); + } +} diff --git a/src/osgPlugins/ive/PolygonStipple.h b/src/osgPlugins/ive/PolygonStipple.h new file mode 100644 index 000000000..b3badf1e4 --- /dev/null +++ b/src/osgPlugins/ive/PolygonStipple.h @@ -0,0 +1,15 @@ +#ifndef IVE_POLYGONSTIPPLE +#define IVE_POLYGONSTIPPLE 1 + +#include +#include "ReadWrite.h" + +namespace ive{ +class PolygonStipple : public osg::PolygonStipple, 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 799afe06d..44ad38f18 100644 --- a/src/osgPlugins/ive/ReadWrite.h +++ b/src/osgPlugins/ive/ReadWrite.h @@ -87,6 +87,7 @@ namespace ive { #define IVEMULTISAMPLE 0x00001132 #define IVEFOG 0x00001133 #define IVELINESTIPPLE 0x00001134 +#define IVEPOLYGONSTIPPLE 0x00001135 // Drawables #define IVEDRAWABLE 0x00001000