From f90e4ff5f88af2add3f7709adf3be7c29c7d9c70 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 2 Sep 2003 17:16:17 +0000 Subject: [PATCH] Converted eroneous writeLong/readInt boolean entries used writeBool/readBool. --- src/osgPlugins/ive/Geometry.cpp | 356 +++++++++++++------------- src/osgPlugins/ive/Image.cpp | 8 +- src/osgPlugins/ive/LightSource.cpp | 97 +++---- src/osgPlugins/ive/Node.cpp | 147 +++++------ src/osgPlugins/ive/Texture2D.cpp | 148 +++++------ src/osgPlugins/ive/TextureCubeMap.cpp | 24 +- 6 files changed, 393 insertions(+), 387 deletions(-) diff --git a/src/osgPlugins/ive/Geometry.cpp b/src/osgPlugins/ive/Geometry.cpp index f0d1a4d64..595386e94 100644 --- a/src/osgPlugins/ive/Geometry.cpp +++ b/src/osgPlugins/ive/Geometry.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: Geometry.cpp + * FILE: Geometry.cpp * - * DESCRIPTION: Read/Write osg::Geometry in binary format to disk. + * DESCRIPTION: Read/Write osg::Geometry 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 18.3.2003 + * HISTORY: Created 18.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -23,218 +23,218 @@ using namespace ive; void Geometry::write(DataOutputStream* out){ - // Write Geometry's identification. - out->writeInt(IVEGEOMETRY); + // Write Geometry's identification. + out->writeInt(IVEGEOMETRY); - // If the osg class is inherited by any other class we should also write this to file. - osg::Drawable* drawable = dynamic_cast(this); - if(drawable){ - ((ive::Drawable*)(drawable))->write(out); - } - else - throw Exception("Geometry::write(): Could not cast this osg::Geometry to an osg::Drawable."); + // If the osg class is inherited by any other class we should also write this to file. + osg::Drawable* drawable = dynamic_cast(this); + if(drawable){ + ((ive::Drawable*)(drawable))->write(out); + } + else + throw Exception("Geometry::write(): Could not cast this osg::Geometry to an osg::Drawable."); - // Write Geometry's properties. + // Write Geometry's properties. - // Write primitiveset list. - int size = getNumPrimitiveSets(); - out->writeInt(size); - for(int i=0;i(getPrimitiveSet(i))) - ((ive::DrawArrays*)(getPrimitiveSet(i)))->write(out); - else if(dynamic_cast(getPrimitiveSet(i))) - ((ive::DrawArrayLengths*)(getPrimitiveSet(i)))->write(out); - else if(dynamic_cast(getPrimitiveSet(i))) - ((ive::DrawElementsUShort*)(getPrimitiveSet(i)))->write(out); - else if(dynamic_cast(getPrimitiveSet(i))) - ((ive::DrawElementsUInt*)(getPrimitiveSet(i)))->write(out); - else - throw Exception("Unknown PrimitivSet in Geometry::write()"); - } + // Write primitiveset list. + int size = getNumPrimitiveSets(); + out->writeInt(size); + for(int i=0;i(getPrimitiveSet(i))) + ((ive::DrawArrays*)(getPrimitiveSet(i)))->write(out); + else if(dynamic_cast(getPrimitiveSet(i))) + ((ive::DrawArrayLengths*)(getPrimitiveSet(i)))->write(out); + else if(dynamic_cast(getPrimitiveSet(i))) + ((ive::DrawElementsUShort*)(getPrimitiveSet(i)))->write(out); + else if(dynamic_cast(getPrimitiveSet(i))) + ((ive::DrawElementsUInt*)(getPrimitiveSet(i)))->write(out); + else + throw Exception("Unknown PrimitivSet in Geometry::write()"); + } - // Write vertex array if any - out->writeLong((long)getVertexArray()); + // Write vertex array if any + out->writeBool(getVertexArray()!=0); if (getVertexArray()) { - out->writeArray(getVertexArray()); + out->writeArray(getVertexArray()); } - // Write vertex indices if any - out->writeLong((long)getVertexIndices()); + // Write vertex indices if any + out->writeBool(getVertexIndices()!=0); if (getVertexIndices()){ out->writeArray(getVertexIndices()); } - // Write normal array if any - out->writeLong((long)getNormalArray()); - if (getNormalArray()){ - out->writeBinding(getNormalBinding()); - out->writeVec3Array(getNormalArray()); + // Write normal array if any + out->writeBool(getNormalArray()!=0); + if (getNormalArray()){ + out->writeBinding(getNormalBinding()); + out->writeVec3Array(getNormalArray()); } - // Write normal indices if any - out->writeLong((long)getNormalIndices()); + // Write normal indices if any + out->writeBool(getNormalIndices()!=0); if (getNormalIndices()){ out->writeArray(getNormalIndices()); } - // Write color array if any. - out->writeLong((long)getColorArray()); + // Write color array if any. + out->writeBool(getColorArray()!=0); if (getColorArray()){ - out->writeBinding(getColorBinding()); - out->writeArray(getColorArray()); + out->writeBinding(getColorBinding()); + out->writeArray(getColorArray()); } - // Write color indices if any - out->writeLong((long)getColorIndices()); + // Write color indices if any + out->writeBool(getColorIndices()!=0); if (getColorIndices()){ out->writeArray(getColorIndices()); } - // Write secondary color array if any - out->writeLong((long)getSecondaryColorArray()); + // Write secondary color array if any + out->writeBool(getSecondaryColorArray()!=0); if (getSecondaryColorArray()){ out->writeBinding(getSecondaryColorBinding()); out->writeArray(getSecondaryColorArray()); } - // Write second color indices if any - out->writeLong((long)getSecondaryColorIndices()); + // Write second color indices if any + out->writeBool(getSecondaryColorIndices()!=0); if (getSecondaryColorIndices()){ - out->writeArray(getSecondaryColorIndices()); + out->writeArray(getSecondaryColorIndices()); } - // Write fog coord array if any - out->writeLong((long)getFogCoordArray()); - if (getFogCoordArray()){ - out->writeBinding(getFogCoordBinding()); - out->writeArray(getFogCoordArray()); + // Write fog coord array if any + out->writeBool(getFogCoordArray()!=0); + if (getFogCoordArray()){ + out->writeBinding(getFogCoordBinding()); + out->writeArray(getFogCoordArray()); } - // Write fog coord indices if any - out->writeLong((long)getFogCoordIndices()); + // Write fog coord indices if any + out->writeBool(getFogCoordIndices()!=0); if (getFogCoordIndices()){ - out->writeArray(getFogCoordIndices()); + out->writeArray(getFogCoordIndices()); } - // Write texture coord arrays + // Write texture coord arrays Geometry::TexCoordArrayList& tcal = getTexCoordArrayList(); - out->writeInt(tcal.size()); + out->writeInt(tcal.size()); for(unsigned int j=0;jwriteBool(tcal[j].first.valid()); + // Write coords if valid + out->writeBool(tcal[j].first.valid()); if (tcal[j].first.valid()){ - out->writeArray(tcal[j].first.get()); + out->writeArray(tcal[j].first.get()); } - // Write indices if valid - out->writeBool(tcal[j].second.valid()); + // Write indices if valid + out->writeBool(tcal[j].second.valid()); if (tcal[j].second.valid()){ - out->writeArray(tcal[j].second.get()); + out->writeArray(tcal[j].second.get()); } } } void Geometry::read(DataInputStream* in){ - // Read Geometry's identification. - int id = in->peekInt(); - if(id == IVEGEOMETRY){ - // Code to read Geometry's properties. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Drawable* drawable = dynamic_cast(this); - if(drawable){ - ((ive::Drawable*)(drawable))->read(in); - } - else - throw Exception("Geometry::read(): Could not cast this osg::Geometry to an osg::Drawable."); + // Read Geometry's identification. + int id = in->peekInt(); + if(id == IVEGEOMETRY){ + // Code to read Geometry's properties. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Drawable* drawable = dynamic_cast(this); + if(drawable){ + ((ive::Drawable*)(drawable))->read(in); + } + else + throw Exception("Geometry::read(): Could not cast this osg::Geometry to an osg::Drawable."); - // Read geoemtry properties + // Read geoemtry properties - // Read primitiveset list. - int size = in->readInt(); - int i; - for(i=0;ipeekInt(); - if(primID==IVEDRAWARRAYS){ - prim = new osg::DrawArrays(); - ((ive::DrawArrays*)(prim))->read(in); - addPrimitiveSet(prim); - } - else if(primID==IVEDRAWARRAYLENGTHS){ - prim = new osg::DrawArrayLengths(); - ((ive::DrawArrayLengths*)(prim))->read(in); - addPrimitiveSet(prim); - } - else if(primID==IVEDRAWELEMENTSUSHORT){ - prim = new osg::DrawElementsUShort(); - ((ive::DrawElementsUShort*)(prim))->read(in); - addPrimitiveSet(prim); - } - else if(primID==IVEDRAWELEMENTSUINT){ - prim = new osg::DrawElementsUInt(); - ((ive::DrawElementsUInt*)(prim))->read(in); - addPrimitiveSet(prim); - } - else{ - throw Exception("Unkown PrimitiveSet in Geometry::read()"); - } - } - - // Read vertex array if any - int va=in->readInt(); - if (va){ - setVertexArray(in->readArray()); - } - // Read vertex indices if any - int vi = in->readInt(); - if (vi){ - setVertexIndices(static_cast(in->readArray())); - } - // Read normal array if any - int na =in->readInt(); - if(na){ - setNormalBinding(in->readBinding()); - setNormalArray(in->readVec3Array()); - } - // Read normal indices if any - int ni = in->readInt(); - if(ni){ - setNormalIndices(static_cast(in->readArray())); - } - // Read color array if any. - if(in->readInt()){ - setColorBinding(in->readBinding()); - setColorArray(in->readArray()); - } - // Read color indices if any - if(in->readInt()){ - setColorIndices(static_cast(in->readArray())); - } - // Read secondary color array if any - if(in->readInt()){ - setSecondaryColorBinding(in->readBinding()); - setSecondaryColorArray(in->readArray()); - } - // Read second color indices if any - if(in->readInt()){ - setSecondaryColorIndices(static_cast(in->readArray())); - } - // Read fog coord array if any - if(in->readInt()){ - setFogCoordBinding(in->readBinding()); - setFogCoordArray(in->readArray()); - } - // Read fog coord indices if any - if(in->readInt()){ - setFogCoordIndices(static_cast(in->readArray())); - } - // Read texture coord arrays - size = in->readInt(); - for(i =0;ireadBool(); - if(coords_valid) - setTexCoordArray(i, in->readArray()); - // Read Indices if valid - bool indices_valid = in->readBool(); - if(indices_valid) - setTexCoordIndices(i, static_cast(in->readArray())); - } - } - else{ - throw Exception("Geometry::read(): Expected Geometry identification."); - } + // Read primitiveset list. + int size = in->readInt(); + int i; + for(i=0;ipeekInt(); + if(primID==IVEDRAWARRAYS){ + prim = new osg::DrawArrays(); + ((ive::DrawArrays*)(prim))->read(in); + addPrimitiveSet(prim); + } + else if(primID==IVEDRAWARRAYLENGTHS){ + prim = new osg::DrawArrayLengths(); + ((ive::DrawArrayLengths*)(prim))->read(in); + addPrimitiveSet(prim); + } + else if(primID==IVEDRAWELEMENTSUSHORT){ + prim = new osg::DrawElementsUShort(); + ((ive::DrawElementsUShort*)(prim))->read(in); + addPrimitiveSet(prim); + } + else if(primID==IVEDRAWELEMENTSUINT){ + prim = new osg::DrawElementsUInt(); + ((ive::DrawElementsUInt*)(prim))->read(in); + addPrimitiveSet(prim); + } + else{ + throw Exception("Unkown PrimitiveSet in Geometry::read()"); + } + } + + // Read vertex array if any + bool va=in->readBool(); + if (va){ + setVertexArray(in->readArray()); + } + // Read vertex indices if any + bool vi = in->readBool(); + if (vi){ + setVertexIndices(static_cast(in->readArray())); + } + // Read normal array if any + bool na =in->readBool(); + if(na){ + setNormalBinding(in->readBinding()); + setNormalArray(in->readVec3Array()); + } + // Read normal indices if any + bool ni = in->readBool(); + if(ni){ + setNormalIndices(static_cast(in->readArray())); + } + // Read color array if any. + if(in->readBool()){ + setColorBinding(in->readBinding()); + setColorArray(in->readArray()); + } + // Read color indices if any + if(in->readBool()){ + setColorIndices(static_cast(in->readArray())); + } + // Read secondary color array if any + if(in->readBool()){ + setSecondaryColorBinding(in->readBinding()); + setSecondaryColorArray(in->readArray()); + } + // Read second color indices if any + if(in->readBool()){ + setSecondaryColorIndices(static_cast(in->readArray())); + } + // Read fog coord array if any + if(in->readBool()){ + setFogCoordBinding(in->readBinding()); + setFogCoordArray(in->readArray()); + } + // Read fog coord indices if any + if(in->readBool()){ + setFogCoordIndices(static_cast(in->readArray())); + } + // Read texture coord arrays + size = in->readInt(); + for(i =0;ireadBool(); + if(coords_valid) + setTexCoordArray(i, in->readArray()); + // Read Indices if valid + bool indices_valid = in->readBool(); + if(indices_valid) + setTexCoordIndices(i, static_cast(in->readArray())); + } + } + else{ + throw Exception("Geometry::read(): Expected Geometry identification."); + } } diff --git a/src/osgPlugins/ive/Image.cpp b/src/osgPlugins/ive/Image.cpp index 73c2eb4a4..765e91f60 100644 --- a/src/osgPlugins/ive/Image.cpp +++ b/src/osgPlugins/ive/Image.cpp @@ -58,8 +58,9 @@ void Image::write(DataOutputStream* out) out->writeInt(_mipmapData[i]); // Write image data if any - out->writeLong((long)data()); - if(data()){ + out->writeBool(data()!=0); + if(data()) + { // Compute the size of image data and write this. unsigned int size = getTotalSizeInBytesIncludingMipmaps(); out->writeInt(size); @@ -117,7 +118,8 @@ void Image::read(DataInputStream* in) // Read image data if any - if(in->readInt()){ + if(in->readBool()) + { unsigned int dataSize = (unsigned int)in->readInt(); //static int totalSize = 0; diff --git a/src/osgPlugins/ive/LightSource.cpp b/src/osgPlugins/ive/LightSource.cpp index 6885d97ea..23a85a0b1 100644 --- a/src/osgPlugins/ive/LightSource.cpp +++ b/src/osgPlugins/ive/LightSource.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: LightSource.cpp + * FILE: LightSource.cpp * - * DESCRIPTION: Read/Write osg::LightSource in binary format to disk. + * DESCRIPTION: Read/Write osg::LightSource 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 21.3.2003 + * HISTORY: Created 21.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -20,53 +20,54 @@ using namespace ive; void LightSource::write(DataOutputStream* out){ - // Write LightSource's identification. - out->writeInt(IVELIGHTSOURCE); - // If the osg class is inherited by any other class we should also write this to file. - osg::Group* group = dynamic_cast(this); - if(group){ - ((ive::Group*)(group))->write(out); - } - else - throw Exception("LightSource::write(): Could not cast this osg::LightSource to an osg::Group."); - // Write LightSource's properties. + // Write LightSource's identification. + out->writeInt(IVELIGHTSOURCE); + // If the osg class is inherited by any other class we should also write this to file. + osg::Group* group = dynamic_cast(this); + if(group){ + ((ive::Group*)(group))->write(out); + } + else + throw Exception("LightSource::write(): Could not cast this osg::LightSource to an osg::Group."); + // Write LightSource's properties. - // Write out light - out->writeLong((long)getLight()); - if(getLight()){ - ((ive::Light*)(getLight()))->write(out); - } + // Write out light + out->writeBool(getLight()!=0); + if(getLight()) + { + ((ive::Light*)(getLight()))->write(out); + } - // Write reference frame - out->writeInt((int)getReferenceFrame()); + // Write reference frame + out->writeInt((int)getReferenceFrame()); } void LightSource::read(DataInputStream* in){ - // Peek on LightSource's identification. - int id = in->peekInt(); - if(id == IVELIGHTSOURCE){ - // Read LightSource's identification. - id = in->readInt(); - // If the osg class is inherited by any other class we should also read this from file. - osg::Group* group = dynamic_cast(this); - if(group){ - ((ive::Group*)(group))->read(in); - } - else - throw Exception("LightSource::read(): Could not cast this osg::LightSource to an osg::Object."); - // Read LightSource's properties + // Peek on LightSource's identification. + int id = in->peekInt(); + if(id == IVELIGHTSOURCE){ + // Read LightSource's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Group* group = dynamic_cast(this); + if(group){ + ((ive::Group*)(group))->read(in); + } + else + throw Exception("LightSource::read(): Could not cast this osg::LightSource to an osg::Object."); + // Read LightSource's properties - // Read light - if(in->readInt()){ - osg::Light* light = new osg::Light(); - ((ive::Light*)(light))->read(in); - setLight(light); - } + // Read light + if(in->readBool()){ + osg::Light* light = new osg::Light(); + ((ive::Light*)(light))->read(in); + setLight(light); + } - // Read reference frame - setReferenceFrame((osg::LightSource::ReferenceFrame) in->readInt()); - } - else{ - throw Exception("LightSource::read(): Expected LightSource identification."); - } + // Read reference frame + setReferenceFrame((osg::LightSource::ReferenceFrame) in->readInt()); + } + else{ + throw Exception("LightSource::read(): Expected LightSource identification."); + } } diff --git a/src/osgPlugins/ive/Node.cpp b/src/osgPlugins/ive/Node.cpp index e1b9d96f6..38b827805 100644 --- a/src/osgPlugins/ive/Node.cpp +++ b/src/osgPlugins/ive/Node.cpp @@ -1,14 +1,14 @@ /********************************************************************** * - * FILE: Node.cpp + * FILE: Node.cpp * - * DESCRIPTION: Read/Write osg::Node in binary format to disk. + * DESCRIPTION: Read/Write osg::Node in binary format to disk. * - * CREATED BY: Rune Schmidt Jensen + * CREATED BY: Rune Schmidt Jensen * - * HISTORY: Created 10.03.2003 + * HISTORY: Created 10.03.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -24,83 +24,84 @@ using namespace ive; void Node::write(DataOutputStream* out){ - // Write node identification. - out->writeInt(IVENODE); + // Write node identification. + out->writeInt(IVENODE); - // Write out any inherited classes. - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->write(out); - } - else - throw Exception("Node::write(): Could not cast this osg::Node to an osg::Object."); + // Write out any inherited classes. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->write(out); + } + else + throw Exception("Node::write(): Could not cast this osg::Node to an osg::Object."); - // Write osg::node properties. + // Write osg::node properties. - // Write Name - out->writeString(getName()); - // Write culling active - out->writeBool( getCullingActive()); - // Write Descriptions - int nDesc = getDescriptions().size(); - out->writeInt(nDesc); - if(nDesc!=0){ - std::vector desc = getDescriptions(); - for(int i=0;iwriteString(desc[i]); - } - // Write Stateset if any - out->writeLong((long) getStateSet()); - if(getStateSet()) - out->writeStateSet(getStateSet()); + // Write Name + out->writeString(getName()); + // Write culling active + out->writeBool( getCullingActive()); + // Write Descriptions + int nDesc = getDescriptions().size(); + out->writeInt(nDesc); + if(nDesc!=0){ + std::vector desc = getDescriptions(); + for(int i=0;iwriteString(desc[i]); + } + // Write Stateset if any + out->writeBool( getStateSet()!=0); + if(getStateSet()) + out->writeStateSet(getStateSet()); - // Write UpdateCallback if any - osg::NodeCallback* nc = getUpdateCallback(); - if(nc && dynamic_cast(nc)){ - out->writeLong((long)nc); - ((ive::AnimationPathCallback*)(nc))->write(out); - } - else - out->writeInt(0x0); + // Write UpdateCallback if any + osg::AnimationPathCallback* nc = dynamic_cast(getUpdateCallback()); + out->writeBool(nc!=0); + if(nc) + { + ((ive::AnimationPathCallback*)(nc))->write(out); + } } void Node::read(DataInputStream* in){ - // Peak on the identification id. - int id = in->peekInt(); + // Peak on the identification id. + int id = in->peekInt(); - if(id == IVENODE){ - id = in->readInt(); - osg::Object* obj = dynamic_cast(this); - if(obj){ - ((ive::Object*)(obj))->read(in); - } - else - throw Exception("Node::read(): Could not cast this osg::Node to an osg::Object."); - // Read name - setName(in->readString()); - // Read Culling active - setCullingActive(in->readBool()); - // Read descriptions - int nDesc = in->readInt(); - if(nDesc!=0){ - for(int i=0;ireadString()); - } - // Read StateSet if any - if(in->readInt()){ - setStateSet(in->readStateSet()); - } - // Read UpdateCallback if any - if(in->readInt()){ - osg::AnimationPathCallback* nc = new osg::AnimationPathCallback(); - ((ive::AnimationPathCallback*)(nc))->read(in); - setUpdateCallback(nc); - } - } - else{ - throw Exception("Node::read(): Expected Node identification"); - } + if(id == IVENODE){ + id = in->readInt(); + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->read(in); + } + else + throw Exception("Node::read(): Could not cast this osg::Node to an osg::Object."); + // Read name + setName(in->readString()); + // Read Culling active + setCullingActive(in->readBool()); + // Read descriptions + int nDesc = in->readInt(); + if(nDesc!=0){ + for(int i=0;ireadString()); + } + // Read StateSet if any + if(in->readBool()) + { + setStateSet(in->readStateSet()); + } + // Read UpdateCallback if any + if(in->readBool()) + { + osg::AnimationPathCallback* nc = new osg::AnimationPathCallback(); + ((ive::AnimationPathCallback*)(nc))->read(in); + setUpdateCallback(nc); + } + } + else{ + throw Exception("Node::read(): Expected Node identification"); + } } diff --git a/src/osgPlugins/ive/Texture2D.cpp b/src/osgPlugins/ive/Texture2D.cpp index 7d3a2be35..65f903659 100644 --- a/src/osgPlugins/ive/Texture2D.cpp +++ b/src/osgPlugins/ive/Texture2D.cpp @@ -1,15 +1,15 @@ /********************************************************************** * - * FILE: Texture2D.cpp + * FILE: Texture2D.cpp * - * DESCRIPTION: Read/Write osg::Texture2D in binary format to disk. + * DESCRIPTION: Read/Write osg::Texture2D 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 20.3.2003 + * HISTORY: Created 20.3.2003 * - * Copyright 2003 VR-C + * Copyright 2003 VR-C **********************************************************************/ #include "Exception.h" @@ -20,78 +20,80 @@ using namespace ive; void Texture2D::write(DataOutputStream* out){ - // Write Texture2D's identification. - out->writeInt(IVETEXTURE2D); - // 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("Texture2D::write(): Could not cast this osg::Texture2D to an osg::Texture."); - // Write Texture2D's properties. - // Write image. + // Write Texture2D's identification. + out->writeInt(IVETEXTURE2D); + // 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("Texture2D::write(): Could not cast this osg::Texture2D to an osg::Texture."); + // Write Texture2D's properties. + // Write image. - // Should we include images date in stream - bool includeImg = out->getIncludeImageData(); - out->writeBool(includeImg); + // Should we include images date in stream + bool includeImg = out->getIncludeImageData(); + out->writeBool(includeImg); - // Include image data in stream - if(includeImg){ - out->writeLong((long)getImage()); - 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(""); - } - } + // 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 Texture2D::read(DataInputStream* in){ - // Read Texture2D's identification. - int id = in->peekInt(); - if(id == IVETEXTURE2D){ - // Code to read Texture2D'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("Texture2D::read(): Could not cast this osg::Texture2D to an osg::Texture."); - // Read image. - - // Should we read image data from stream - bool includeImg = in->readBool(); + // Read Texture2D's identification. + int id = in->peekInt(); + if(id == IVETEXTURE2D){ + // Code to read Texture2D'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("Texture2D::read(): Could not cast this osg::Texture2D 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->readInt()){ - 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("Texture2D::read(): Expected Texture2D identification."); - } + // 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("Texture2D::read(): Expected Texture2D identification."); + } } diff --git a/src/osgPlugins/ive/TextureCubeMap.cpp b/src/osgPlugins/ive/TextureCubeMap.cpp index 8e21589b4..b3cb2057d 100644 --- a/src/osgPlugins/ive/TextureCubeMap.cpp +++ b/src/osgPlugins/ive/TextureCubeMap.cpp @@ -41,27 +41,27 @@ void TextureCubeMap::write(DataOutputStream* out){ out->writeInt(getNumMipmapLevels()); // Write images if any - out->writeLong((long)getImage(osg::TextureCubeMap::POSITIVE_X)); + out->writeBool(getImage(osg::TextureCubeMap::POSITIVE_X)!=0); if(getImage(osg::TextureCubeMap::POSITIVE_X)) ((ive::Image*)(getImage(osg::TextureCubeMap::POSITIVE_X)))->write(out); - out->writeLong((long)getImage(osg::TextureCubeMap::NEGATIVE_X)); + out->writeBool(getImage(osg::TextureCubeMap::NEGATIVE_X)!=0); if(getImage(osg::TextureCubeMap::NEGATIVE_X)) ((ive::Image*)(getImage(osg::TextureCubeMap::NEGATIVE_X)))->write(out); - out->writeLong((long)getImage(osg::TextureCubeMap::POSITIVE_Y)); + out->writeBool(getImage(osg::TextureCubeMap::POSITIVE_Y)!=0); if(getImage(osg::TextureCubeMap::POSITIVE_Y)) ((ive::Image*)(getImage(osg::TextureCubeMap::POSITIVE_Y)))->write(out); - out->writeLong((long)getImage(osg::TextureCubeMap::NEGATIVE_Y)); + out->writeBool(getImage(osg::TextureCubeMap::NEGATIVE_Y)!=0); if(getImage(osg::TextureCubeMap::NEGATIVE_Y)) ((ive::Image*)(getImage(osg::TextureCubeMap::NEGATIVE_Y)))->write(out); - out->writeLong((long)getImage(osg::TextureCubeMap::POSITIVE_Z)); + out->writeBool(getImage(osg::TextureCubeMap::POSITIVE_Z)!=0); if(getImage(osg::TextureCubeMap::POSITIVE_Z)) ((ive::Image*)(getImage(osg::TextureCubeMap::POSITIVE_Z)))->write(out); - out->writeLong((long)getImage(osg::TextureCubeMap::NEGATIVE_Z)); + out->writeBool(getImage(osg::TextureCubeMap::NEGATIVE_Z)!=0); if(getImage(osg::TextureCubeMap::NEGATIVE_Z)) ((ive::Image*)(getImage(osg::TextureCubeMap::NEGATIVE_Z)))->write(out); @@ -91,32 +91,32 @@ void TextureCubeMap::read(DataInputStream* in){ setNumMipmapLevels((unsigned int)in->readInt()); // Read images if any - if(in->readInt()){ + if(in->readBool()){ osg::Image* image = new osg::Image(); ((ive::Image*)(image))->read(in); setImage(osg::TextureCubeMap::POSITIVE_X, image); } - if(in->readInt()){ + if(in->readBool()){ osg::Image* image = new osg::Image(); ((ive::Image*)(image))->read(in); setImage(osg::TextureCubeMap::NEGATIVE_X, image); } - if(in->readInt()){ + if(in->readBool()){ osg::Image* image = new osg::Image(); ((ive::Image*)(image))->read(in); setImage(osg::TextureCubeMap::POSITIVE_Y, image); } - if(in->readInt()){ + if(in->readBool()){ osg::Image* image = new osg::Image(); ((ive::Image*)(image))->read(in); setImage(osg::TextureCubeMap::NEGATIVE_Y, image); } - if(in->readInt()){ + if(in->readBool()){ osg::Image* image = new osg::Image(); ((ive::Image*)(image))->read(in); setImage(osg::TextureCubeMap::POSITIVE_Z, image); } - if(in->readInt()){ + if(in->readBool()){ osg::Image* image = new osg::Image(); ((ive::Image*)(image))->read(in); setImage(osg::TextureCubeMap::NEGATIVE_Z, image);