From Pavel Moloshton, addition of AlphaFunc support to .ive.

This commit is contained in:
Robert Osfield
2003-12-01 14:31:56 +00:00
parent 3c9d1e0603
commit bd4a1cd601
8 changed files with 100 additions and 47 deletions

View File

@@ -0,0 +1,61 @@
/**********************************************************************
*
* FILE: AlphaFunc.cpp
*
* DESCRIPTION: Read/Write osg::AlphaFunc in binary format to disk.
*
* CREATED BY: Pavlo Moloshtan
*
* HISTORY: Created 30.11.2003
*
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
#include "AlphaFunc.h"
#include "Object.h"
using namespace ive;
void AlphaFunc::write(DataOutputStream* out){
// write AlphaFunc's identification
out->writeInt(IVEALPHAFUNC);
// 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)
((ive::Object*)(obj))->write(out);
else
throw Exception("AlphaFunc::write(): Could not cast this osg::AlphaFunc to an osg::Object.");
// write AlphaFunc's properties
out->writeInt(getFunction());
out->writeFloat(getReferenceValue());
}
void AlphaFunc::read(DataInputStream* in){
// peek on AlphaFunc's identification
int id = in->peekInt();
if(id == IVEALPHAFUNC)
{
// read AlphaFunc'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<osg::Object*>(this);
if(obj)
((ive::Object*)(obj))->read(in);
else
throw Exception("AlphaFunc::read(): Could not cast this osg::AlphaFunc to an osg::Object.");
// Read AlphaFunc's properties
osg::AlphaFunc::ComparisonFunction comparison_funtion = osg::AlphaFunc::ComparisonFunction(in->readInt());
float reference_value = in->readFloat();
setFunction(comparison_funtion, reference_value);
}
else{
throw Exception("AlphaFunc::read(): Expected AlphaFunc identification.");
}
}

View File

@@ -0,0 +1,15 @@
#ifndef IVE_ALPHAFUNC
#define IVE_ALPHAFUNC 1
#include <osg/AlphaFunc>
#include "ReadWrite.h"
namespace ive{
class AlphaFunc : public osg::AlphaFunc, public ReadWrite {
public:
void write(DataOutputStream* out);
void read(DataInputStream* in);
};
}
#endif

View File

@@ -14,6 +14,7 @@
#include "DataInputStream.h"
#include "StateSet.h"
#include "AlphaFunc.h"
#include "BlendFunc.h"
#include "Material.h"
#include "CullFace.h"
@@ -530,7 +531,11 @@ osg::StateAttribute* DataInputStream::readStateAttribute()
osg::StateAttribute* attribute;
int attributeID = peekInt();
if(attributeID == IVEBLENDFUNC){
if(attributeID == IVEALPHAFUNC){
attribute = new osg::AlphaFunc();
((ive::AlphaFunc*)(attribute))->read(this);
}
else if(attributeID == IVEBLENDFUNC){
attribute = new osg::BlendFunc();
((ive::BlendFunc*)(attribute))->read(this);
}

View File

@@ -16,6 +16,7 @@
#include "Exception.h"
#include "StateSet.h"
#include "AlphaFunc.h"
#include "BlendFunc.h"
#include "Material.h"
#include "CullFace.h"
@@ -403,7 +404,10 @@ void DataOutputStream::writeStateAttribute(const osg::StateAttribute* attribute)
writeInt(id);
// write the stateset.
if(dynamic_cast<const osg::BlendFunc*>(attribute)){
if(dynamic_cast<const osg::AlphaFunc*>(attribute)){
((ive::AlphaFunc*)(attribute))->write(this);
}
else if(dynamic_cast<const osg::BlendFunc*>(attribute)){
((ive::BlendFunc*)(attribute))->write(this);
}
// This is a Material

View File

@@ -2,6 +2,7 @@ TOPDIR = ../../..
include $(TOPDIR)/Make/makedefs
CXXFILES =\
AlphaFunc.cpp\
AnimationPath.cpp\
AnimationPathCallback.cpp\
Billboard.cpp\