diff --git a/src/osgPlugins/ive/DataInputStream.cpp b/src/osgPlugins/ive/DataInputStream.cpp index 4329518b0..1bf703dce 100644 --- a/src/osgPlugins/ive/DataInputStream.cpp +++ b/src/osgPlugins/ive/DataInputStream.cpp @@ -8,6 +8,7 @@ * CREATED BY: Rune Schmidt Jensen * * HISTORY: Created 11.03.2003 + * Updated for texture1D by Don Burns, 27.1.2004 * * Copyright 2003 VR-C **********************************************************************/ @@ -21,6 +22,7 @@ #include "PolygonOffset.h" #include "ShadeModel.h" #include "Point.h" +#include "Texture1D.h" #include "Texture2D.h" #include "TextureCubeMap.h" #include "TexEnv.h" @@ -629,6 +631,10 @@ osg::StateAttribute* DataInputStream::readStateAttribute() attribute = new osg::Point(); ((ive::Point*)(attribute))->read(this); } + else if(attributeID == IVETEXTURE1D){ + attribute = new osg::Texture1D(); + ((ive::Texture1D*)(attribute))->read(this); + } else if(attributeID == IVETEXTURE2D){ attribute = new osg::Texture2D(); ((ive::Texture2D*)(attribute))->read(this); @@ -654,7 +660,7 @@ osg::StateAttribute* DataInputStream::readStateAttribute() ((ive::TexMat*)(attribute))->read(this); } else{ - throw Exception("Unkown StateAttribute in StateSet::read()"); + throw Exception("Unknown StateAttribute in StateSet::read()"); } // and add it to the stateattribute map, diff --git a/src/osgPlugins/ive/DataOutputStream.cpp b/src/osgPlugins/ive/DataOutputStream.cpp index 17128ff85..8de644cdf 100644 --- a/src/osgPlugins/ive/DataOutputStream.cpp +++ b/src/osgPlugins/ive/DataOutputStream.cpp @@ -8,6 +8,7 @@ * CREATED BY: Rune Schmidt Jensen * * HISTORY: Created 11.03.2003 + * Updated for 1D textures - Don Burns 27.1.2004 * * Copyright 2003 VR-C **********************************************************************/ @@ -23,6 +24,7 @@ #include "PolygonOffset.h" #include "ShadeModel.h" #include "Point.h" +#include "Texture1D.h" #include "Texture2D.h" #include "TextureCubeMap.h" #include "TexEnv.h" @@ -429,6 +431,10 @@ void DataOutputStream::writeStateAttribute(const osg::StateAttribute* attribute) else if(dynamic_cast(attribute)){ ((ive::Point*)(attribute))->write(this); } + // This is a Texture1D + else if(dynamic_cast(attribute)){ + ((ive::Texture1D*)(attribute))->write(this); + } // This is a Texture2D else if(dynamic_cast(attribute)){ ((ive::Texture2D*)(attribute))->write(this); diff --git a/src/osgPlugins/ive/GNUmakefile b/src/osgPlugins/ive/GNUmakefile index c9c5b6c68..b4c8dc1ae 100644 --- a/src/osgPlugins/ive/GNUmakefile +++ b/src/osgPlugins/ive/GNUmakefile @@ -49,6 +49,7 @@ CXXFILES =\ TexGen.cpp\ TexMat.cpp\ Texture.cpp\ + Texture1D.cpp\ Texture2D.cpp\ TextureCubeMap.cpp\ Transform.cpp\ diff --git a/src/osgPlugins/ive/Geometry.cpp b/src/osgPlugins/ive/Geometry.cpp index f99df3d08..796c80279 100644 --- a/src/osgPlugins/ive/Geometry.cpp +++ b/src/osgPlugins/ive/Geometry.cpp @@ -199,7 +199,7 @@ void Geometry::read(DataInputStream* in){ addPrimitiveSet(prim); } else{ - throw Exception("Unkown PrimitiveSet in Geometry::read()"); + throw Exception("Unknown PrimitiveSet in Geometry::read()"); } } diff --git a/src/osgPlugins/ive/StateSet.cpp b/src/osgPlugins/ive/StateSet.cpp index 8d8c7b965..2711777f7 100644 --- a/src/osgPlugins/ive/StateSet.cpp +++ b/src/osgPlugins/ive/StateSet.cpp @@ -20,6 +20,7 @@ #include "CullFace.h" #include "PolygonOffset.h" #include "ShadeModel.h" +#include "Texture1D.h" #include "Texture2D.h" #include "TextureCubeMap.h" #include "TexEnv.h" @@ -131,7 +132,7 @@ void StateSet::read(DataInputStream* in){ case 3: setRenderBinDetails(num, name, osg::StateSet::ENCLOSE_RENDERBIN_DETAILS); break; - default: throw Exception("Unkown RenderBinMode in StateSet::read()"); + default: throw Exception("Unknown RenderBinMode in StateSet::read()"); } // Read stateset modes. diff --git a/src/osgPlugins/ive/Texture1D.cpp b/src/osgPlugins/ive/Texture1D.cpp new file mode 100644 index 000000000..c0b9bf467 --- /dev/null +++ b/src/osgPlugins/ive/Texture1D.cpp @@ -0,0 +1,98 @@ +/********************************************************************** + * + * FILE: Texture2D.cpp + * + * DESCRIPTION: Read/Write osg::Texture2D in binary format to disk. + * + * CREATED BY: Copied from Texture 2D.cpp and edited for Texture 1D + * by Don Burns + * + * HISTORY: Created 27.1.2004 + * + * Copyright 2003 VR-C, OSGPL + **********************************************************************/ + +#include "Exception.h" +#include "Texture1D.h" +#include "Texture.h" +#include "Image.h" + +using namespace ive; + +void Texture1D::write(DataOutputStream* out){ + // Write Texture1D's identification. + out->writeInt(IVETEXTURE1D); + // If the osg class is inherited by any other class we should also write this to file. + osg::Texture* tex = dynamic_cast(this); + if(tex){ + ((ive::Texture*)(tex))->write(out); + } + else + throw Exception("Texture1D::write(): Could not cast this osg::Texture1D to an osg::Texture."); + // Write Texture1D's properties. + // Write image. + + // Should we include images date in stream + bool includeImg = out->getIncludeImageData(); + out->writeBool(includeImg); + + // Include image data in stream + if(includeImg){ + out->writeBool(getImage()!=0); + if(getImage()) + ((ive::Image*)getImage())->write(out); + } + // Only include image name in stream + else{ + if (getImage() && !(getImage()->getFileName().empty())){ + out->writeString(getImage()->getFileName()); + } + else{ + out->writeString(""); + } + } +} + +void Texture1D::read(DataInputStream* in){ + // Read Texture1D's identification. + int id = in->peekInt(); + if(id == IVETEXTURE1D){ + // Code to read Texture1D's properties. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Texture* tex = dynamic_cast(this); + if(tex){ + ((ive::Texture*)(tex))->read(in); + } + else + throw Exception("Texture1D::read(): Could not cast this osg::Texture1D to an osg::Texture."); + // Read image. + + // Should we read image data from stream + bool includeImg = in->readBool(); + + // Read image data from stream + if(includeImg) + { + if(in->readBool()) + { + osg::Image* image = new osg::Image(); + ((ive::Image*)image)->read(in); + setImage(image); + } + } + // Only read image name from stream. + else{ + std::string filename = in->readString(); + if(filename.compare("")!=0){ + osg::Image* image = in->readImage(filename); + if (image){ + setImage(image); + } + } + } + } + else{ + throw Exception("Texture1D::read(): Expected Texture1D identification."); + } +} diff --git a/src/osgPlugins/ive/Texture1D.h b/src/osgPlugins/ive/Texture1D.h new file mode 100644 index 000000000..9de0996fc --- /dev/null +++ b/src/osgPlugins/ive/Texture1D.h @@ -0,0 +1,15 @@ +#ifndef IVE_TEXTURE1D +#define IVE_TEXTURE1D 1 + +#include +#include "ReadWrite.h" + +namespace ive{ +class Texture1D : public osg::Texture1D, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; +} + +#endif