Added explict handling of osg::Image, osg::HeightField, osg::Shader and osg::Node when doing writes to the archive.

This commit is contained in:
Robert Osfield 2012-11-22 09:49:24 +00:00
parent f0b3a47735
commit 56bc0b14bc
2 changed files with 19 additions and 3 deletions

View File

@ -139,7 +139,15 @@ int main( int argc, char **argv )
if (obj.valid()) if (obj.valid())
{ {
std::cout<<" write to archive "<<*itr<<std::endl; std::cout<<" write to archive "<<*itr<<std::endl;
archive->writeObject(*obj, *itr); osg::Image* image = dynamic_cast<osg::Image*>(obj.get());
osg::HeightField* hf = dynamic_cast<osg::HeightField*>(obj.get());
osg::Node* node = dynamic_cast<osg::Node*>(obj.get());
osg::Shader* shader = dynamic_cast<osg::Shader*>(obj.get());
if (image) archive->writeImage(*image, *itr);
else if (hf) archive->writeHeightField(*hf, *itr);
else if (node) archive->writeNode(*node, *itr);
else if (shader) archive->writeShader(*shader, *itr);
else archive->writeObject(*obj, *itr);
} }
} }
} }

View File

@ -753,7 +753,7 @@ struct OSGA_Archive::WriteImageFunctor : public OSGA_Archive::WriteFunctor
_object(object) {} _object(object) {}
const osg::Image& _object; const osg::Image& _object;
virtual ReaderWriter::WriteResult doWrite(ReaderWriter& rw, std::ostream& output) const { return rw.writeImage(_object, output, _options); } virtual ReaderWriter::WriteResult doWrite(ReaderWriter& rw, std::ostream& output) const { OSG_NOTICE<<"doWrite() rw.writeImage(), "<<std::endl; return rw.writeImage(_object, output, _options); }
}; };
struct OSGA_Archive::WriteHeightFieldFunctor : public OSGA_Archive::WriteFunctor struct OSGA_Archive::WriteHeightFieldFunctor : public OSGA_Archive::WriteFunctor
@ -812,7 +812,15 @@ ReaderWriter::WriteResult OSGA_Archive::write(const WriteFunctor& writeFunctor)
pos_type final_position = ARCHIVE_POS( _output.tellp() ); pos_type final_position = ARCHIVE_POS( _output.tellp() );
size_type size = size_type( final_position-position ); size_type size = size_type( final_position-position );
if (result.success()) addFileReference(position, size, writeFunctor._filename); if (result.success())
{
OSG_INFO<<"Adding file "<<writeFunctor._filename<<" reference to archive."<<std::endl;
addFileReference(position, size, writeFunctor._filename);
}
else
{
OSG_INFO<<"writeFunctor unsuccessful."<<std::endl;
}
return result; return result;
} }