diff --git a/src/osgPlugins/ive/BlendEquation.cpp b/src/osgPlugins/ive/BlendEquation.cpp new file mode 100644 index 000000000..394ebb9c7 --- /dev/null +++ b/src/osgPlugins/ive/BlendEquation.cpp @@ -0,0 +1,61 @@ +/********************************************************************** + * + * FILE: BlendEquation.cpp + * + * DESCRIPTION: Read/Write osg::BlendEquation 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 "BlendEquation.h" +#include "Object.h" + +using namespace ive; + +void BlendEquation::write(DataOutputStream* out){ + + // Write BlendEquation's identification. + out->writeInt(IVEBLENDEQUATION); + + // 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("BlendEquation::write(): Could not cast this osg::BlendEquation to an osg::Object."); + // Write BlendEquation's properties. + + // Write source + out->writeInt(getEquation()); +} + +void BlendEquation::read(DataInputStream* in){ + // Peek on BlendEquation's identification. + int id = in->peekInt(); + if(id == IVEBLENDEQUATION){ + // Read BlendEquation'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("BlendEquation::read(): Could not cast this osg::BlendEquation to an osg::Object."); + // Read BlendEquation's properties + + // Read source + setEquation(osg::BlendEquation::Equation(in->readInt())); + + } + else{ + throw Exception("BlendEquation::read(): Expected BlendEquation identification."); + } +} diff --git a/src/osgPlugins/ive/BlendEquation.h b/src/osgPlugins/ive/BlendEquation.h new file mode 100644 index 000000000..d883819d2 --- /dev/null +++ b/src/osgPlugins/ive/BlendEquation.h @@ -0,0 +1,15 @@ +#ifndef IVE_BLENDEQUATION +#define IVE_BLENDEQUATION 1 + +#include +#include "ReadWrite.h" + +namespace ive{ +class BlendEquation : public osg::BlendEquation, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; +} + +#endif diff --git a/src/osgPlugins/ive/CMakeLists.txt b/src/osgPlugins/ive/CMakeLists.txt index 3735c5bf3..5cda86523 100644 --- a/src/osgPlugins/ive/CMakeLists.txt +++ b/src/osgPlugins/ive/CMakeLists.txt @@ -10,6 +10,7 @@ SET(TARGET_SRC AzimSector.cpp Billboard.cpp BlendColor.cpp + BlendEquation.cpp BlendFunc.cpp BlinkSequence.cpp Camera.cpp diff --git a/src/osgPlugins/ive/DataInputStream.cpp b/src/osgPlugins/ive/DataInputStream.cpp index 7ea90555d..1c65bd560 100644 --- a/src/osgPlugins/ive/DataInputStream.cpp +++ b/src/osgPlugins/ive/DataInputStream.cpp @@ -21,6 +21,7 @@ #include "BlendColor.h" #include "Stencil.h" #include "BlendFunc.h" +#include "BlendEquation.h" #include "Depth.h" #include "Material.h" #include "CullFace.h" @@ -1097,6 +1098,10 @@ osg::StateAttribute* DataInputStream::readStateAttribute() attribute = new osg::BlendFunc(); ((ive::BlendFunc*)(attribute))->read(this); } + else if(attributeID == IVEBLENDEQUATION){ + attribute = new osg::BlendEquation(); + ((ive::BlendEquation*)(attribute))->read(this); + } else if(attributeID == IVEDEPTH){ attribute = new osg::Depth(); ((ive::Depth*)(attribute))->read(this); diff --git a/src/osgPlugins/ive/DataOutputStream.cpp b/src/osgPlugins/ive/DataOutputStream.cpp index 61814c10f..011e3d826 100644 --- a/src/osgPlugins/ive/DataOutputStream.cpp +++ b/src/osgPlugins/ive/DataOutputStream.cpp @@ -22,6 +22,7 @@ #include "BlendColor.h" #include "Stencil.h" #include "BlendFunc.h" +#include "BlendEquation.h" #include "Material.h" #include "CullFace.h" #include "ColorMask.h" @@ -723,6 +724,9 @@ void DataOutputStream::writeStateAttribute(const osg::StateAttribute* attribute) else if(dynamic_cast(attribute)){ ((ive::BlendFunc*)(attribute))->write(this); } + else if(dynamic_cast(attribute)){ + ((ive::BlendEquation*)(attribute))->write(this); + } else if(dynamic_cast(attribute)){ ((ive::Depth*)(attribute))->write(this); } diff --git a/src/osgPlugins/ive/ReadWrite.h b/src/osgPlugins/ive/ReadWrite.h index c93db9fbe..b58ace510 100644 --- a/src/osgPlugins/ive/ReadWrite.h +++ b/src/osgPlugins/ive/ReadWrite.h @@ -72,6 +72,7 @@ namespace ive { #define IVESTENCIL 0x00000131 #define IVESTENCILTWOSIDED 0x00000132 #define IVECOLORMASK 0x00000133 +#define IVEBLENDEQUATION 0x00000134 #define IVELIGHTMODEL 0x00001121 #define IVECLIPPLANE 0x00001122 #define IVEFRONTFACE 0x00001123 diff --git a/src/osgPlugins/osg/BlendEquation.cpp b/src/osgPlugins/osg/BlendEquation.cpp new file mode 100644 index 000000000..7cde67972 --- /dev/null +++ b/src/osgPlugins/osg/BlendEquation.cpp @@ -0,0 +1,84 @@ +#include "osg/BlendEquation" + +#include "osgDB/Registry" +#include "osgDB/Input" +#include "osgDB/Output" + +using namespace osg; +using namespace osgDB; + +// forward declare functions to use later. +bool BlendEquation_readLocalData(Object& obj, Input& fr); +bool BlendEquation_writeLocalData(const Object& obj, Output& fw); + +bool BlendEquation_matchModeStr(const char* str,int& mode); +const char* BlendEquation_getModeStr(int value); + +// register the read and write functions with the osgDB::Registry. +RegisterDotOsgWrapperProxy g_BlendEquationProxy +( + new osg::BlendEquation, + "BlendEquation", + "Object StateAttribute BlendEquation", + &BlendEquation_readLocalData, + &BlendEquation_writeLocalData +); + +bool BlendEquation_readLocalData(Object& obj, Input& fr) +{ + bool iteratorAdvanced = false; + + BlendEquation& transparency = static_cast(obj); + + int mode; + if (fr[0].matchWord("equation") && BlendEquation_matchModeStr(fr[1].getStr(),mode)) + { + transparency.setEquation(osg::BlendEquation::Equation(mode)); + fr+=2; + iteratorAdvanced = true; + } + + return iteratorAdvanced; +} + +bool BlendEquation_writeLocalData(const Object& obj, Output& fw) +{ + const BlendEquation& transparency = static_cast(obj); + + fw.indent() << "equation " << BlendEquation_getModeStr(transparency.getEquation()) << std::endl; + + return true; +} + + + +bool BlendEquation_matchModeStr(const char* str,int& mode) +{ + if (strcmp(str,"RGBA_MIN")==0) mode = BlendEquation::RGBA_MIN; + else if (strcmp(str,"RGBA_MAX")==0) mode = BlendEquation::RGBA_MAX; + else if (strcmp(str,"ALPHA_MIN")==0) mode = BlendEquation::ALPHA_MIN; + else if (strcmp(str,"ALPHA_MAX")==0) mode = BlendEquation::ALPHA_MAX; + else if (strcmp(str,"LOGIC_OP")==0) mode = BlendEquation::LOGIC_OP; + else if (strcmp(str,"FUNC_ADD")==0) mode = BlendEquation::FUNC_ADD; + else if (strcmp(str,"FUNC_SUBTRACT")==0) mode = BlendEquation::FUNC_SUBTRACT; + else if (strcmp(str,"FUNC_REVERSE_SUBTRACT")==0) mode = BlendEquation::FUNC_REVERSE_SUBTRACT; + else return false; + return true; + +} +const char* BlendEquation_getModeStr(int value) +{ + switch(value) + { + case(BlendEquation::RGBA_MIN) : return "RGBA_MIN"; + case(BlendEquation::RGBA_MAX) : return "RGBA_MAX"; + case(BlendEquation::ALPHA_MIN) : return "ALPHA_MIN"; + case(BlendEquation::ALPHA_MAX) : return "ALPHA_MAX"; + case(BlendEquation::LOGIC_OP) : return "LOGIC_OP"; + case(BlendEquation::FUNC_ADD) : return "FUNC_ADD"; + case(BlendEquation::FUNC_SUBTRACT) : return "FUNC_SUBTRACT"; + case(BlendEquation::FUNC_REVERSE_SUBTRACT) : return "FUNC_REVERSE_SUBTRACT"; + } + + return NULL; +} diff --git a/src/osgPlugins/osg/CMakeLists.txt b/src/osgPlugins/osg/CMakeLists.txt index 3428fae72..3ff51b4e6 100644 --- a/src/osgPlugins/osg/CMakeLists.txt +++ b/src/osgPlugins/osg/CMakeLists.txt @@ -8,6 +8,7 @@ AutoTransform.cpp Billboard.cpp BlendColor.cpp BlendFunc.cpp +BlendEquation.cpp Camera.cpp CameraView.cpp ClearNode.cpp