diff --git a/include/osg/Image b/include/osg/Image index df3cf2bb2..46662f926 100644 --- a/include/osg/Image +++ b/include/osg/Image @@ -79,6 +79,15 @@ class OSG_EXPORT Image : public Object void setFileName(const std::string& fileName); inline const std::string& getFileName() const { return _fileName; } + enum WriteHint { + NO_PREFERENCE, + STORE_INLINE, + EXTERNAL_FILE + }; + + void setWriteHint(WriteHint writeHint) { _writeHint = writeHint; } + WriteHint getWriteHint() const { return _writeHint; } + enum AllocationMode { NO_DELETE, USE_NEW_DELETE, @@ -307,6 +316,8 @@ class OSG_EXPORT Image : public Object Image& operator = (const Image&) { return *this; } std::string _fileName; + WriteHint _writeHint; + Origin _origin; diff --git a/src/osg/Image.cpp b/src/osg/Image.cpp index 9dc9f61c8..d1600fbf0 100644 --- a/src/osg/Image.cpp +++ b/src/osg/Image.cpp @@ -38,6 +38,7 @@ Image::Image() setDataVariance(STATIC); _fileName = ""; + _writeHint = NO_PREFERENCE; _origin = BOTTOM_LEFT; _s = _t = _r = 0; _internalTextureFormat = 0; @@ -54,6 +55,7 @@ Image::Image() Image::Image(const Image& image,const CopyOp& copyop): Object(image,copyop), _fileName(image._fileName), + _writeHint(image._writeHint), _origin(image._origin), _s(image._s), _t(image._t), _r(image._r), _internalTextureFormat(image._internalTextureFormat), diff --git a/src/osgPlugins/ive/DataOutputStream.cpp b/src/osgPlugins/ive/DataOutputStream.cpp index d835048f6..11d7c9e4f 100644 --- a/src/osgPlugins/ive/DataOutputStream.cpp +++ b/src/osgPlugins/ive/DataOutputStream.cpp @@ -1125,8 +1125,27 @@ void DataOutputStream::writeNode(const osg::Node* node) } } +IncludeImageMode DataOutputStream::getIncludeImageMode(const osg::Image* image) const +{ + if (image) + { + if (image->getWriteHint()==osg::Image::STORE_INLINE) + { + return IMAGE_INCLUDE_DATA; + } + else if (image->getWriteHint()==osg::Image::EXTERNAL_FILE) + { + return IMAGE_REFERENCE_FILE; + } + } + return getIncludeImageMode(); +} + + void DataOutputStream::writeImage(osg::Image *image) { + IncludeImageMode mode = getIncludeImageMode(image); + if ( getVersion() >= VERSION_0029) { osg::ImageSequence* is = dynamic_cast(image); @@ -1137,19 +1156,20 @@ void DataOutputStream::writeImage(osg::Image *image) else { writeInt(IVEIMAGE); - writeChar(getIncludeImageMode()); - writeImage(getIncludeImageMode(),image); + writeChar(mode); + writeImage(mode,image); } } else { - writeChar(getIncludeImageMode()); - writeImage(getIncludeImageMode(),image); + writeChar(mode); + writeImage(mode,image); } } void DataOutputStream::writeImage(IncludeImageMode mode, osg::Image *image) { + osg::notify(osg::NOTICE)<<"DataOutputStream::writeImage("<getFileName()="<getFileName()<writeString(getFileName()); - + + if ( out->getVersion() >= VERSION_0031) + { + out->writeInt((int)getWriteHint()); + } + // Write width, height, depth of image. out->writeInt(s()); out->writeInt(t()); @@ -90,6 +95,11 @@ void Image::read(DataInputStream* in) // Read name setFileName(in->readString()); + + if ( in->getVersion() >= VERSION_0031) + { + setWriteHint((osg::Image::WriteHint)in->readInt()); + } // Read width, height, depth of image. int is=in->readInt(); diff --git a/src/osgPlugins/ive/ImageLayer.cpp b/src/osgPlugins/ive/ImageLayer.cpp index f3c683309..925a28f5c 100644 --- a/src/osgPlugins/ive/ImageLayer.cpp +++ b/src/osgPlugins/ive/ImageLayer.cpp @@ -32,7 +32,7 @@ void ImageLayer::write(DataOutputStream* out) throw Exception("ImageLayer::write(): Could not cast this osgLayer::ImageLayer to an osgTerrain::Layer."); - IncludeImageMode imMode = out->getIncludeImageMode(); + IncludeImageMode imMode = out->getIncludeImageMode(getImage()); if (getFileName().empty() && imMode==IMAGE_REFERENCE_FILE) imMode = IMAGE_INCLUDE_DATA; diff --git a/src/osgPlugins/ive/IveVersion.h b/src/osgPlugins/ive/IveVersion.h index f71481955..1e61b3cdc 100644 --- a/src/osgPlugins/ive/IveVersion.h +++ b/src/osgPlugins/ive/IveVersion.h @@ -40,8 +40,9 @@ #define VERSION_0029 29 #define VERSION_0030 30 #define VERSION_0031 31 +#define VERSION_0032 32 -#define VERSION VERSION_0031 +#define VERSION VERSION_0032 /* The BYTE_SEX tag is used to check the endian of the IVE file being read in. The IVE format diff --git a/src/osgPlugins/ive/ReaderWriterIVE.cpp b/src/osgPlugins/ive/ReaderWriterIVE.cpp index fcdffb328..fa0c33465 100644 --- a/src/osgPlugins/ive/ReaderWriterIVE.cpp +++ b/src/osgPlugins/ive/ReaderWriterIVE.cpp @@ -48,7 +48,8 @@ class ReaderWriterIVE : public ReaderWriter // code for setting up the database path so that internally referenced files are searched for on relative paths. osg::ref_ptr local_opt = options ? static_cast(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; - local_opt->setDatabasePath(osgDB::getFilePath(fileName)); + local_opt->getDatabasePathList().push_front(osgDB::getFilePath(fileName)); + std::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary); return readImage(istream, local_opt.get()); } @@ -63,7 +64,7 @@ class ReaderWriterIVE : public ReaderWriter // code for setting up the database path so that internally referenced file are searched for on relative paths. osg::ref_ptr local_opt = options ? static_cast(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; - local_opt->setDatabasePath(osgDB::getFilePath(fileName)); + local_opt->getDatabasePathList().push_front(osgDB::getFilePath(fileName)); std::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary); return readNode(istream,local_opt.get()); diff --git a/src/osgPlugins/ive/TextureCubeMap.cpp b/src/osgPlugins/ive/TextureCubeMap.cpp index 435c3c759..56b5e427c 100644 --- a/src/osgPlugins/ive/TextureCubeMap.cpp +++ b/src/osgPlugins/ive/TextureCubeMap.cpp @@ -50,7 +50,7 @@ void TextureCubeMap::write(DataOutputStream* out){ else { // Should we include images date in stream - IncludeImageMode includeImg = out->getIncludeImageMode(); + IncludeImageMode includeImg = out->getIncludeImageMode(getImage(osg::TextureCubeMap::POSITIVE_X)); out->writeChar(includeImg); out->writeImage(includeImg,getImage(osg::TextureCubeMap::POSITIVE_X));