*** empty log message ***

This commit is contained in:
Don BURNS
2003-06-24 15:40:09 +00:00
parent 5a939f5420
commit 15f88f35b2
91 changed files with 2871 additions and 1937 deletions

View File

@@ -1,15 +1,15 @@
/**********************************************************************
*
* FILE: StateSet.cpp
* FILE: StateSet.cpp
*
* DESCRIPTION: Read/Write osg::StateSet in binary format to disk.
* DESCRIPTION: Read/Write osg::StateSet in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 17.3.2003
* HISTORY: Created 17.3.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
@@ -18,6 +18,8 @@
#include "BlendFunc.h"
#include "Material.h"
#include "CullFace.h"
#include "PolygonOffset.h"
#include "ShadeModel.h"
#include "Texture2D.h"
#include "TextureCubeMap.h"
#include "TexEnv.h"
@@ -29,238 +31,148 @@
using namespace ive;
void StateSet::write(DataOutputStream* out){
// Write StateSet's identification.
out->writeInt(IVESTATESET);
// 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("StateSet::write(): Could not cast this osg::StateSet to an osg::Object.");
// Write StateSet's identification.
out->writeInt(IVESTATESET);
// 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("StateSet::write(): Could not cast this osg::StateSet to an osg::Object.");
// Write render bin bin details.
switch(getRenderBinMode()){
case osg::StateSet::INHERIT_RENDERBIN_DETAILS: out->writeChar((char)0);break;
case osg::StateSet::USE_RENDERBIN_DETAILS: out->writeChar((char)1);break;
case osg::StateSet::OVERRIDE_RENDERBIN_DETAILS: out->writeChar((char)2);break;
case osg::StateSet::ENCLOSE_RENDERBIN_DETAILS: out->writeChar((char)3);break;
default: throw Exception("Unknown RenderBinMode in StateSet::write()");
}
out->writeInt(getBinNumber());
out->writeString(getBinName());
// Write render bin bin details.
switch(getRenderBinMode()){
case osg::StateSet::INHERIT_RENDERBIN_DETAILS: out->writeChar((char)0);break;
case osg::StateSet::USE_RENDERBIN_DETAILS: out->writeChar((char)1);break;
case osg::StateSet::OVERRIDE_RENDERBIN_DETAILS: out->writeChar((char)2);break;
case osg::StateSet::ENCLOSE_RENDERBIN_DETAILS: out->writeChar((char)3);break;
default: throw Exception("Unknown RenderBinMode in StateSet::write()");
}
out->writeInt(getBinNumber());
out->writeString(getBinName());
StateSet::ModeList ml = getModeList();
StateSet::AttributeList al = getAttributeList();
StateSet::ModeList ml = getModeList();
StateSet::AttributeList al = getAttributeList();
// Write stateset modes, this could for instance be GL_NORMALIZE, GL_LIGHT, etc.
out->writeInt(ml.size());
for(StateSet::ModeList::const_iterator mitr=ml.begin(); mitr!=ml.end(); ++mitr){
out->writeInt((unsigned int)mitr->first);
out->writeInt((unsigned int)mitr->second);
}
// Write stateset modes, this could for instance be GL_NORMALIZE, GL_LIGHT, etc.
out->writeInt(ml.size());
for(StateSet::ModeList::const_iterator mitr=ml.begin(); mitr!=ml.end(); ++mitr){
out->writeInt((unsigned int)mitr->first);
out->writeInt((unsigned int)mitr->second);
}
// Write stateset attributes, this could for instance be alphafunctions, materials, etc.
out->writeInt(al.size());
for(StateSet::AttributeList::iterator aitr=al.begin(); aitr!=al.end(); ++aitr){
// This is a BlendFunc.
if(dynamic_cast<osg::BlendFunc*>(aitr->second.first.get())){
((ive::BlendFunc*)(aitr->second.first.get()))->write(out);
out->writeInt(aitr->second.second);
}
// This is a Material
else if(dynamic_cast<osg::Material*>(aitr->second.first.get())){
((ive::Material*)(aitr->second.first.get()))->write(out);
out->writeInt(aitr->second.second);
}
// This is a CullFace
else if(dynamic_cast<osg::CullFace*>(aitr->second.first.get())){
((ive::CullFace*)(aitr->second.first.get()))->write(out);
out->writeInt(aitr->second.second);
}
else{
std::string className = (aitr->second.first.get())->className();
throw Exception(std::string("StateSet::write(): Unknown StateAttribute: ").append(className));
}
}
// Write stateset attributes, this could for instance be alphafunctions, materials, etc.
out->writeInt(al.size());
for(StateSet::AttributeList::iterator aitr=al.begin(); aitr!=al.end(); ++aitr){
out->writeStateAttribute(aitr->second.first.get());
out->writeInt(aitr->second.second);
}
StateSet::TextureModeList tml = getTextureModeList();
StateSet::TextureAttributeList tal = getTextureAttributeList();
StateSet::TextureModeList tml = getTextureModeList();
StateSet::TextureAttributeList tal = getTextureAttributeList();
// Write texture stateset modes, this could for instance be TEXGEN ON, TEXTURECUBEMAP ON, etc.
int nUnits = tml.size();
out->writeInt(nUnits);
// Write texture stateset modes, this could for instance be TEXGEN ON, TEXTURECUBEMAP ON, etc.
int nUnits = tml.size();
out->writeInt(nUnits);
int unit;
for(unit=0;unit<nUnits;unit++){
ml = tml[unit];
out->writeInt(ml.size());
for(StateSet::ModeList::const_iterator mitr=ml.begin(); mitr!=ml.end(); ++mitr){
out->writeInt((unsigned int)mitr->first);
out->writeInt((unsigned int)mitr->second);
}
}
for(unit=0;unit<nUnits;unit++){
ml = tml[unit];
out->writeInt(ml.size());
for(StateSet::ModeList::const_iterator mitr=ml.begin(); mitr!=ml.end(); ++mitr){
out->writeInt((unsigned int)mitr->first);
out->writeInt((unsigned int)mitr->second);
}
}
// Write texture attributes, this could for instance texture2D, texturecubemap
nUnits = tal.size();
out->writeInt(nUnits);
for(unit=0;unit<nUnits;unit++){
al = tal[unit];
out->writeInt(al.size());
for(StateSet::AttributeList::iterator aitr=al.begin(); aitr!=al.end(); ++aitr){
// This is a Texture2D
if(dynamic_cast<osg::Texture2D*>(aitr->second.first.get())){
((ive::Texture2D*)(aitr->second.first.get()))->write(out);
out->writeInt(aitr->second.second);
}
// This is a TextureCubeMap
else if(dynamic_cast<osg::TextureCubeMap*>(aitr->second.first.get())){
((ive::TextureCubeMap*)(aitr->second.first.get()))->write(out);
out->writeInt(aitr->second.second);
}
// This is a TexEnv
else if(dynamic_cast<osg::TexEnv*>(aitr->second.first.get())){
((ive::TexEnv*)(aitr->second.first.get()))->write(out);
out->writeInt(aitr->second.second);
}
// This is a TexEnvCombine
else if(dynamic_cast<osg::TexEnvCombine*>(aitr->second.first.get())){
((ive::TexEnvCombine*)(aitr->second.first.get()))->write(out);
out->writeInt(aitr->second.second);
}
// This is a TexGen
else if(dynamic_cast<osg::TexGen*>(aitr->second.first.get())){
((ive::TexGen*)(aitr->second.first.get()))->write(out);
out->writeInt(aitr->second.second);
}
else{
std::string className = (aitr->second.first.get())->className();
throw Exception(std::string("StateSet::write(): Unknown Texture StateAttribute: ").append(className));
}
}
}
// Write texture attributes, this could for instance texture2D, texturecubemap
nUnits = tal.size();
out->writeInt(nUnits);
for(unit=0;unit<nUnits;unit++){
al = tal[unit];
out->writeInt(al.size());
for(StateSet::AttributeList::iterator aitr=al.begin(); aitr!=al.end(); ++aitr){
out->writeStateAttribute(aitr->second.first.get());
out->writeInt(aitr->second.second);
}
}
}
void StateSet::read(DataInputStream* in){
// Read StateSet's identification.
int id = in->peekInt();
if(id == IVESTATESET){
// Code to read StateSet's properties.
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("StateSet::read(): Could not cast this osg::StateSet to an osg::Object.");
// Read StateSet's identification.
int id = in->peekInt();
if(id == IVESTATESET){
// Code to read StateSet's properties.
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("StateSet::read(): Could not cast this osg::StateSet to an osg::Object.");
// Read render bin details.
char c = in->readChar();
int num = in->readInt();
std::string name = in->readString();
switch((int)c){
case 0:
setRenderBinDetails(num, name, osg::StateSet::INHERIT_RENDERBIN_DETAILS);
break;
case 1:
setRenderBinDetails(num, name, osg::StateSet::USE_RENDERBIN_DETAILS);
break;
case 2:
setRenderBinDetails(num, name, osg::StateSet::OVERRIDE_RENDERBIN_DETAILS);
break;
case 3:
setRenderBinDetails(num, name, osg::StateSet::ENCLOSE_RENDERBIN_DETAILS);
break;
default: throw Exception("Unkown RenderBinMode in StateSet::read()");
}
// Read render bin details.
char c = in->readChar();
int num = in->readInt();
std::string name = in->readString();
switch((int)c){
case 0:
setRenderBinDetails(num, name, osg::StateSet::INHERIT_RENDERBIN_DETAILS);
break;
case 1:
setRenderBinDetails(num, name, osg::StateSet::USE_RENDERBIN_DETAILS);
break;
case 2:
setRenderBinDetails(num, name, osg::StateSet::OVERRIDE_RENDERBIN_DETAILS);
break;
case 3:
setRenderBinDetails(num, name, osg::StateSet::ENCLOSE_RENDERBIN_DETAILS);
break;
default: throw Exception("Unkown RenderBinMode in StateSet::read()");
}
// Read stateset modes.
int size = in->readInt();
// Read stateset modes.
int size = in->readInt();
int i;
for(i=0;i<size;i++){
int mode = in->readInt();
int value = in->readInt();
setMode((osg::StateAttribute::GLMode)mode, (osg::StateAttribute::GLModeValue)value);
}
for(i=0;i<size;i++){
int mode = in->readInt();
int value = in->readInt();
setMode((osg::StateAttribute::GLMode)mode, (osg::StateAttribute::GLModeValue)value);
}
// Read state attributes
size = in->readInt();
for(i=0;i<size;i++){
osg::StateAttribute* attribute;
int attributeID = in->peekInt();
if(attributeID == IVEBLENDFUNC){
attribute = new osg::BlendFunc();
((ive::BlendFunc*)(attribute))->read(in);
setAttribute(attribute, (osg::StateAttribute::OverrideValue)in->readInt());
}
else if(attributeID == IVEMATERIAL){
attribute = new osg::Material();
((ive::Material*)(attribute))->read(in);
setAttribute(attribute, (osg::StateAttribute::OverrideValue)in->readInt());
}
else if(attributeID == IVECULLFACE){
attribute = new osg::CullFace();
((ive::CullFace*)(attribute))->read(in);
setAttribute(attribute, (osg::StateAttribute::OverrideValue)in->readInt());
}
else{
throw Exception("Unkown StateAttribute in StateSet::read()");
}
}
// Read texture stateset mode.
int nUnits = in->readInt();
// Read state attributes
size = in->readInt();
for(i=0;i<size;i++){
osg::StateAttribute* attribute = in->readStateAttribute();
setAttribute(attribute, (osg::StateAttribute::OverrideValue)in->readInt());
}
// Read texture stateset mode.
int nUnits = in->readInt();
int unit;
for(unit=0;unit<nUnits;unit++){
size = in->readInt();
for(i=0;i<size;i++){
int mode = in->readInt();
int value = in->readInt();
setTextureMode(unit,(osg::StateAttribute::GLMode)mode, (osg::StateAttribute::GLModeValue)value);
}
}
for(unit=0;unit<nUnits;unit++){
size = in->readInt();
for(i=0;i<size;i++){
int mode = in->readInt();
int value = in->readInt();
setTextureMode(unit,(osg::StateAttribute::GLMode)mode, (osg::StateAttribute::GLModeValue)value);
}
}
// Read texture attributes.
nUnits = in->readInt();
for(unit=0;unit<nUnits;unit++){
size = in->readInt();
for(i=0;i<size;i++){
osg::StateAttribute* attribute;
int attributeID = in->peekInt();
if(attributeID == IVETEXTURE2D){
attribute = new osg::Texture2D();
((ive::Texture2D*)(attribute))->read(in);
setTextureAttribute(unit, attribute, (osg::StateAttribute::OverrideValue)in->readInt());
}
else if(attributeID == IVETEXTURECUBEMAP){
attribute = new osg::TextureCubeMap();
((ive::TextureCubeMap*)(attribute))->read(in);
setTextureAttribute(unit, attribute, (osg::StateAttribute::OverrideValue)in->readInt());
}
else if(attributeID == IVETEXENV){
attribute = new osg::TexEnv();
((ive::TexEnv*)(attribute))->read(in);
setTextureAttribute(unit, attribute, (osg::StateAttribute::OverrideValue)in->readInt());
}
else if(attributeID == IVETEXENVCOMBINE){
attribute = new osg::TexEnvCombine();
((ive::TexEnvCombine*)(attribute))->read(in);
setTextureAttribute(unit, attribute, (osg::StateAttribute::OverrideValue)in->readInt());
}
else if(attributeID == IVETEXGEN){
attribute = new osg::TexGen();
((ive::TexGen*)(attribute))->read(in);
setTextureAttribute(unit, attribute, (osg::StateAttribute::OverrideValue)in->readInt());
}
else{
throw Exception("Unkown Texture StateAttribute in StateSet::read()");
}
}
}
}
else{
throw Exception("StateSet::read(): Expected StateSet identification");
}
// Read texture attributes.
nUnits = in->readInt();
for(unit=0;unit<nUnits;unit++){
size = in->readInt();
for(i=0;i<size;i++){
osg::StateAttribute* attribute = in->readStateAttribute();
setTextureAttribute(unit, attribute, (osg::StateAttribute::OverrideValue)in->readInt());
}
}
}
else{
throw Exception("StateSet::read(): Expected StateSet identification");
}
}