From Michael Platings, added support for blend seperates to .ive and .osg

This commit is contained in:
Robert Osfield 2006-07-03 09:22:11 +00:00
parent 8b445af79b
commit e7d04408d3
4 changed files with 50 additions and 4 deletions

View File

@ -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<osg::Object*>(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.");

View File

@ -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);
}

View File

@ -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

View File

@ -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;
}