Hi Colin and Rui,
I have implemented the detection of the need for byte swapping into
the osg plugin, using Rui's suggestion for checking for byte swapping
of the OSG_HEADER_LOW and OSG_HEADER_HIGH values. The changes are
listed below and checked into svn/trunk.
These changes are far less extensive than Colin's original changes
that forced a particular endian on the files which makes me feel
rather more comfortable about them. Colin could you check that these
changes actually work for your systems, I only have systems with the
same endian here so I can't test the byte swapping.
Cheers,
Robert.
OpenSceneGraph$ svn diff src/osgPlugins/osg
Index: src/osgPlugins/osg/BinaryStreamOperator.h
===================================================================
--- src/osgPlugins/osg/BinaryStreamOperator.h (revision 12975)
+++ src/osgPlugins/osg/BinaryStreamOperator.h (working copy)
@@ -73,7 +73,7 @@
class BinaryInputIterator : public osgDB::InputIterator
{
public:
- BinaryInputIterator( std::istream* istream ) : _byteSwap(0) { _in
= istream; }
+ BinaryInputIterator( std::istream* istream, bool byteSwap ) :
_byteSwap(byteSwap) { _in = istream; }
virtual ~BinaryInputIterator() {}
virtual bool isBinary() const { return true; }
@@ -188,7 +188,7 @@
{ readString( str ); }
protected:
- int _byteSwap;
+ bool _byteSwap;
};
#endif
Index: src/osgPlugins/osg/ReaderWriterOSG2.cpp
===================================================================
--- src/osgPlugins/osg/ReaderWriterOSG2.cpp (revision 12975)
+++ src/osgPlugins/osg/ReaderWriterOSG2.cpp (working copy)
@@ -26,6 +26,8 @@
#define CATCH_EXCEPTION(s) \
if (s.getException()) return (s.getException()->getError() + " At
" + s.getException()->getField());
+#define OSG_REVERSE(value) ( ((value & 0x000000ff)<<24) | ((value &
0x0000ff00)<<8) | ((value & 0x00ff0000)>>8) | ((value &
0xff000000)>>24) )
+
InputIterator* readInputIterator( std::istream& fin, const Options* options )
{
bool extensionIsAscii = false, extensionIsXML = false;
@@ -43,8 +45,15 @@
fin.read( (char*)&headerHigh, INT_SIZE );
if ( headerLow==OSG_HEADER_LOW && headerHigh==OSG_HEADER_HIGH )
{
- return new BinaryInputIterator(&fin);
+ OSG_INFO<<"Reading OpenSceneGraph binary file with the
same endian as this computer."<<std::endl;
+ return new BinaryInputIterator(&fin, false); // endian
the same so no byte swap required
}
+ else if ( headerLow==OSG_REVERSE(OSG_HEADER_LOW) &&
headerHigh==OSG_REVERSE(OSG_HEADER_HIGH) )
+ {
+ OSG_INFO<<"Reading OpenSceneGraph binary file with the
different endian to this computer, doing byte swap."<<std::endl;
+ return new BinaryInputIterator(&fin, true); // endian
different so byte swap required
+ }
+
fin.seekg( 0, std::ios::beg );
}
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org