diff --git a/include/osg/Endian b/include/osg/Endian new file mode 100644 index 000000000..e6799b9b2 --- /dev/null +++ b/include/osg/Endian @@ -0,0 +1,54 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef OSG_ENDIAN +#define OSG_ENDIAN 1 + +namespace osg { + +enum Endian +{ + BigEndian, + LittleEndian +}; + +inline Endian getCpuByteOrder() +{ + static char big_endian_1[2] = { 0, 1 }; + + if ( (*((short*) big_endian_1)) == 1) + return BigEndian; + else + return LittleEndian; +} + + +template +inline void swapBytes( T& in ) +{ + if( sizeof( T ) == 1 ) return; + + typedef unsigned char * BytePtr; + + T tmp = in; + BytePtr sptr = (BytePtr)∈ + BytePtr tptr = (BytePtr)&tmp + sizeof(T)-1; + + for( unsigned int i = 0; i < sizeof(T); ++i ) + *(sptr++) = *(dptr--); +} + + +} + +#endif diff --git a/src/osgSim/LightPointDrawable.cpp b/src/osgSim/LightPointDrawable.cpp index b5df2d82a..caa3f754e 100644 --- a/src/osgSim/LightPointDrawable.cpp +++ b/src/osgSim/LightPointDrawable.cpp @@ -19,9 +19,11 @@ using namespace osgSim; LightPointDrawable::LightPointDrawable(): osg::Drawable(), + _endian(osg::getCpuByteOrder()), _referenceTime(0.0), _referenceTimeInterval(0.0) { + setSupportsDisplayList(false); _depthOff = new osg::Depth; diff --git a/src/osgSim/LightPointDrawable.h b/src/osgSim/LightPointDrawable.h index 153c36d81..9a9d2b624 100644 --- a/src/osgSim/LightPointDrawable.h +++ b/src/osgSim/LightPointDrawable.h @@ -18,6 +18,7 @@ #include #include #include +#include #include @@ -52,16 +53,7 @@ class OSGSIM_EXPORT LightPointDrawable : public osg::Drawable inline unsigned long asRGBA(const osg::Vec4& color) const { -#if defined(__sgi) || defined (__hpux__) - // big endian. - return color.asABGR(); -#elif defined (sun) - // should probably test at runtime for endianess, assume big endian right now. - return color.asABGR(); -#else - // x86 little endian - return color.asRGBA(); -#endif + return _endian==osg::BigEndian?color.asABGR():color.asRGBA(); } inline void addOpaqueLightPoint(unsigned int pointSize,const osg::Vec3& position,const osg::Vec4& color) @@ -106,9 +98,11 @@ class OSGSIM_EXPORT LightPointDrawable : public osg::Drawable virtual bool computeBound() const; ~LightPointDrawable() {} + + osg::Endian _endian; - double _referenceTime; - double _referenceTimeInterval; + double _referenceTime; + double _referenceTimeInterval; typedef std::vector LightPointList; typedef std::vector SizedLightPointList;