Added Endian test header to the core osg, and add use of the new
getCpuByteOrder test in LightPointDrawable.
This commit is contained in:
54
include/osg/Endian
Normal file
54
include/osg/Endian
Normal file
@@ -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 <class T>
|
||||
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
|
||||
@@ -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;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <osg/BlendFunc>
|
||||
#include <osg/ColorMask>
|
||||
#include <osg/Point>
|
||||
#include <osg/Endian>
|
||||
|
||||
#include <vector>
|
||||
|
||||
@@ -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<ColorPosition> LightPointList;
|
||||
typedef std::vector<LightPointList> SizedLightPointList;
|
||||
|
||||
Reference in New Issue
Block a user