From e7d04408d331b40659d2030be1a8e68247d460f9 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 3 Jul 2006 09:22:11 +0000 Subject: [PATCH] From Michael Platings, added support for blend seperates to .ive and .osg --- src/osgPlugins/ive/BlendFunc.cpp | 24 ++++++++++++++++++++++-- src/osgPlugins/ive/DataInputStream.cpp | 3 ++- src/osgPlugins/ive/ReadWrite.h | 1 + src/osgPlugins/osg/BlendFunc.cpp | 26 +++++++++++++++++++++++++- 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/osgPlugins/ive/BlendFunc.cpp b/src/osgPlugins/ive/BlendFunc.cpp index 73f54fa67..3446fbfca 100644 --- a/src/osgPlugins/ive/BlendFunc.cpp +++ b/src/osgPlugins/ive/BlendFunc.cpp @@ -19,8 +19,11 @@ using namespace ive; void BlendFunc::write(DataOutputStream* out){ + + bool bSeparate = getSource() != getSourceAlpha() || getDestination() != getDestinationAlpha(); + // Write BlendFunc's identification. - out->writeInt(IVEBLENDFUNC); + out->writeInt(bSeparate ? IVEBLENDFUNCSEPARATE : IVEBLENDFUNC); // 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){ @@ -34,12 +37,20 @@ void BlendFunc::write(DataOutputStream* out){ out->writeInt(getSource()); // Write destination out->writeInt(getDestination()); + + if (bSeparate) + { + // Write source alpha + out->writeInt(getSourceAlpha()); + // Write destination alpha + out->writeInt(getDestinationAlpha()); + } } void BlendFunc::read(DataInputStream* in){ // Peek on BlendFunc's identification. int id = in->peekInt(); - if(id == IVEBLENDFUNC){ + if(id == IVEBLENDFUNC || id == IVEBLENDFUNCSEPARATE){ // Read BlendFunc's identification. id = in->readInt(); // If the osg class is inherited by any other class we should also read this from file. @@ -56,6 +67,15 @@ void BlendFunc::read(DataInputStream* in){ // Read destination setDestination((GLenum)in->readInt()); + if (id == IVEBLENDFUNCSEPARATE) + { + // Read source alpha + setSourceAlpha((GLenum)in->readInt()); + + // Read destination alpha + setDestinationAlpha((GLenum)in->readInt()); + } + } else{ throw Exception("BlendFunc::read(): Expected BlendFunc identification."); diff --git a/src/osgPlugins/ive/DataInputStream.cpp b/src/osgPlugins/ive/DataInputStream.cpp index 1f473b11d..29f4dec52 100644 --- a/src/osgPlugins/ive/DataInputStream.cpp +++ b/src/osgPlugins/ive/DataInputStream.cpp @@ -921,7 +921,8 @@ osg::StateAttribute* DataInputStream::readStateAttribute() attribute = new osg::AlphaFunc(); ((ive::AlphaFunc*)(attribute))->read(this); } - else if(attributeID == IVEBLENDFUNC){ + else if(attributeID == IVEBLENDFUNC || + attributeID == IVEBLENDFUNCSEPARATE){ attribute = new osg::BlendFunc(); ((ive::BlendFunc*)(attribute))->read(this); } diff --git a/src/osgPlugins/ive/ReadWrite.h b/src/osgPlugins/ive/ReadWrite.h index 6037ab02d..78860f633 100644 --- a/src/osgPlugins/ive/ReadWrite.h +++ b/src/osgPlugins/ive/ReadWrite.h @@ -47,6 +47,7 @@ namespace ive { #define IVESTATEATTRIBUTE 0x00000100 #define IVEALPHAFUNC 0x00000101 #define IVEBLENDFUNC 0x00000102 +#define IVEBLENDFUNCSEPARATE 0x00000103 #define IVEMATERIAL 0x00000110 #define IVETEXTURE 0x00000120 #define IVETEXTURE1D 0x00000121 diff --git a/src/osgPlugins/osg/BlendFunc.cpp b/src/osgPlugins/osg/BlendFunc.cpp index f0fda1c24..1e90ef190 100644 --- a/src/osgPlugins/osg/BlendFunc.cpp +++ b/src/osgPlugins/osg/BlendFunc.cpp @@ -54,7 +54,21 @@ bool BlendFunc_readLocalData(Object& obj, Input& fr) fr+=2; iteratorAdvanced = true; } - + + if (fr[0].matchWord("sourceAlpha") && BlendFunc_matchModeStr(fr[1].getStr(),mode)) + { + transparency.setSourceAlpha(mode); + fr+=2; + iteratorAdvanced = true; + } + + if (fr[0].matchWord("destinationAlpha") && BlendFunc_matchModeStr(fr[1].getStr(),mode)) + { + transparency.setDestinationAlpha(mode); + fr+=2; + iteratorAdvanced = true; + } + return iteratorAdvanced; } @@ -65,6 +79,16 @@ bool BlendFunc_writeLocalData(const Object& obj, Output& fw) fw.indent() << "source " << BlendFunc_getModeStr(transparency.getSource()) << std::endl; fw.indent() << "destination " << BlendFunc_getModeStr(transparency.getDestination()) << std::endl; + if (transparency.getSource() != transparency.getSourceAlpha()) + { + fw.indent() << "sourceAlpha " << BlendFunc_getModeStr(transparency.getSourceAlpha()) << std::endl; + } + + if (transparency.getDestination() != transparency.getDestinationAlpha()) + { + fw.indent() << "destinationAlpha " << BlendFunc_getModeStr(transparency.getDestinationAlpha()) << std::endl; + } + return true; }