From 4adb68c802e0beaf8bed2d1c0cf00a8bebe874b7 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 18 Aug 2008 14:49:16 +0000 Subject: [PATCH] Added BlendEquation .osg support --- src/osgPlugins/osg/BlendEquation.cpp | 84 ++++++++++++++++++++++++++++ src/osgPlugins/osg/CMakeLists.txt | 1 + 2 files changed, 85 insertions(+) create mode 100644 src/osgPlugins/osg/BlendEquation.cpp 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