Hi! My starting point was, that I wanted to use the osg-archive in conjunction with ".osgb.gz" and ".dds.gz" files and it took me a surprisingly quite long round-trip to get everything to work. I had to do several fixes, that I describe below. Maybe they are not appropriate for you, but maybe they are are helpful to find a better solution?
Regards, --Alex 1. osgarchive.cpp osgDB::readObject() was used for reading all kind of input files (textures, nodes, etc.). At least with the ".osgb" format a node file can not be read by readObject, since readObject expects the InputStream::READ_OBJECT token at the beginning of the file, while readNode expects InputStream::READ_SCENE. I changed the code to try to read a file as node, and if not successful as image, heightfield and finally as object. It's not an optimal solution, it would be better if the program could conclude the proper file type by its name. Additionally I had to set the "ForceReadingImage" option, to not loose texture file names, if they are not already present. 2. osgDB/ReaderWriter, ReaderWriterGZ.cpp When reading/writing a file to an osgDB::Archive, the stream variants of the readXXX writeXXX methods are used. This methods don't get the filename, but ReaderWriterGZ needs it to get the right plugin, depending on the file extension. I added readXXX writeXXX methods that get a stream and a filename. 3. osgDB/Registry, osgDB/Registry.cpp When a file is read from an archive in Registry::read(), it was tried to read that file with readObject(), instead of using the readFunctor, that reads as node, image, object, etc. I changed to use the readFunctor and modified the functor to be able to give it a different file name and options. The next problem was, that my osgb files don't reference the other osgb and texture image files by their full path name. Their names start with the archives filename and the archive file is stored in the archive cache with it's full name, hence the archive could not be resolved from the cache for the subsequent reads. An additional issue was, that a newly opened archive is added to the archive cache not until, the master file was completely read, so when the master file in turn reads some textures, the archive will not yet be found in the cache. To circumvent that, I moved the adding to the archive cache from Registry::openArchiveImplementation() to ReaderWriterOSGA and in Registry::openArchiveImplementation() I added a resolution to the full path name for a queried archive by osgDB::findDataFile. 4. OSGA_Archive.cpp Here the functor's now use the readXXX writeXXX methods, to provide the filename, that is needed by the ReaderWriterGZ to resolve the plugin depending on the file extension. Next trouble was made by the proxy_streambuf. Reading a osgb file from the archive caused a recursion to OSGA_Archive::read() again for reading the texture images, that are referenced in the osgb file. The first call changed the "rdbuf" of the input stream _input to mystreambuf, what is restored after the reading has finished. But through the recursive read of the texture image, from the same OSGA_Archive, the mystreambuf for the texture gets the mystreambuf from the osgb file as first parameter, instead of the original "rdbuf" from the _input stream. That lead the texture reading to fail. The recursive proxy_streambuf problem can be repaired, by having an input stream as local variable, giving it the mystreambuf without touching the original input stream. That worked for me, but at the end I was not sure why this complicated proxy_streambuf class is used at all and I doubt, that it has optimal performance, since every read character leads to an underflow with every single character beeing read by sbumpc from the original input buffer. Here I found it better to read the complete file with a single read operation into memory and give it to the reader plugin as strstream. 5. ReaderWriterOSGA.cpp As already described under 3. I added the adding of the archive to the cache to openArchive(), so that is can be found in the cache also for the subsequent reads of a file read. The archive is now registered in the cache always by it's real path name. ------------------ Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=33719#33719 Attachments: http://forum.openscenegraph.org//files/osg_archive_fixes_162.zip _______________________________________________ osg-submissions mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org
