From Pavel Moloshtan, Byte2,3,4 and Short2,3,4 classes and their Array counterparts.

With a few build tweaks and bug fixes by Robert Osfield.
This commit is contained in:
Robert Osfield 2005-07-05 15:57:53 +00:00
parent ba5f3ce99a
commit facb0e2638
27 changed files with 1571 additions and 154 deletions

View File

@ -57,10 +57,10 @@ Ben Discoe <ben@vterrain.org>
Mike Weiblen <mike.weiblen@3dlabs.com> <mew@mew.cx>
- osgGL2, osgshaders example
- win32 binary installer package.
- rot, scale, trans pseudoloader plugins.
- win32 binary installer package.
- rot, scale, trans pseudoloader plugins.
- assistance on visual studio workspace files.
- osg.ico windows icon
- osg.ico windows icon
Randall Hopper <aa8vb@yahoo.com>
- port to FreeBSD.
@ -132,7 +132,8 @@ Pavel Moloshtan <pasha@moloshtan.com>
- Support of GL_ARB_occlusion_query in osg::Drawable.
- Support of GL_ARB_shadow in osg::Texture, osgdepthtexture example.
- Support of GL_ARB_shadow_ambient in osg::Texture.
- Improvement to the ive plugin.
- Speed improvement to the ive plugin.
- Byte2, Byte3, Byte4, Short2, Short3, Short4 vectors, read/write support.
Daniel Sjölie <deepone@acc.umu.se>
- Support for multitextured flt files.
@ -151,7 +152,7 @@ Vladimir Vukicevic <vladimir@pobox.com>
Rune Schmidt Jensen <rune@schmidt-jensen.com>
- dds loader.
- ive plugin.
- ive plugin.
Romano José Magacho da Silva <rmagacho@predialnet.com.br>
- pause/resume in osgGA::AnimationPathManipulator

View File

@ -1000,6 +1000,34 @@ SOURCE=..\..\Include\Osg\UnitTestFramework
# End Source File
# Begin Source File
SOURCE=..\..\Include\Osg\Byte2
# End Source File
# Begin Source File
SOURCE=..\..\Include\Osg\Byte3
# End Source File
# Begin Source File
SOURCE=..\..\Include\Osg\Byte4
# End Source File
# Begin Source File
SOURCE=..\..\Include\Osg\Short2
# End Source File
# Begin Source File
SOURCE=..\..\Include\Osg\Short3
# End Source File
# Begin Source File
SOURCE=..\..\Include\Osg\Short4
# End Source File
# Begin Source File
SOURCE=..\..\Include\Osg\UByte4
# End Source File
# Begin Source File
SOURCE=..\..\Include\Osg\Vec2
# End Source File
# Begin Source File

View File

@ -20,6 +20,13 @@
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/UByte4>
#include <osg/Short2>
#include <osg/Short3>
#include <osg/Short4>
#include <osg/Byte2>
#include <osg/Byte3>
#include <osg/Byte4>
#include <osg/Object>
#include <osg/GL>
@ -50,7 +57,14 @@ class OSG_EXPORT Array : public Object
FloatArrayType = 8,
Vec2ArrayType = 9,
Vec3ArrayType = 10,
Vec4ArrayType = 11
Vec4ArrayType = 11,
Short2ArrayType = 12,
Short3ArrayType = 13,
Short4ArrayType = 14,
Byte2ArrayType = 15,
Byte3ArrayType = 16,
Byte4ArrayType = 17
};
Array(Type arrayType=ArrayType,GLint dataSize=0,GLenum dataType=0):
@ -257,6 +271,14 @@ typedef TemplateArray<Vec2,Array::Vec2ArrayType,2,GL_FLOAT>
typedef TemplateArray<Vec3,Array::Vec3ArrayType,3,GL_FLOAT> Vec3Array;
typedef TemplateArray<Vec4,Array::Vec4ArrayType,4,GL_FLOAT> Vec4Array;
typedef TemplateArray<Short2,Array::Short2ArrayType,2,GL_SHORT> Short2Array;
typedef TemplateArray<Short3,Array::Short3ArrayType,3,GL_SHORT> Short3Array;
typedef TemplateArray<Short4,Array::Short4ArrayType,4,GL_SHORT> Short4Array;
typedef TemplateArray<Byte2,Array::Byte2ArrayType,2,GL_BYTE> Byte2Array;
typedef TemplateArray<Byte3,Array::Byte3ArrayType,3,GL_BYTE> Byte3Array;
typedef TemplateArray<Byte4,Array::Byte4ArrayType,4,GL_BYTE> Byte4Array;
class ArrayVisitor
{
public:
@ -274,6 +296,13 @@ class ArrayVisitor
virtual void apply(Vec2Array&) {}
virtual void apply(Vec3Array&) {}
virtual void apply(Vec4Array&) {}
virtual void apply(Short2Array&) {}
virtual void apply(Short3Array&) {}
virtual void apply(Short4Array&) {}
virtual void apply(Byte2Array&) {}
virtual void apply(Byte3Array&) {}
virtual void apply(Byte4Array&) {}
};
class ConstArrayVisitor
@ -293,6 +322,13 @@ class ConstArrayVisitor
virtual void apply(const Vec2Array&) {}
virtual void apply(const Vec3Array&) {}
virtual void apply(const Vec4Array&) {}
virtual void apply(const Short2Array&) {}
virtual void apply(const Short3Array&) {}
virtual void apply(const Short4Array&) {}
virtual void apply(const Byte2Array&) {}
virtual void apply(const Byte3Array&) {}
virtual void apply(const Byte4Array&) {}
};
@ -312,6 +348,13 @@ class ValueVisitor
virtual void apply(Vec2&) {}
virtual void apply(Vec3&) {}
virtual void apply(Vec4&) {}
virtual void apply(Short2&) {}
virtual void apply(Short3&) {}
virtual void apply(Short4&) {}
virtual void apply(Byte2&) {}
virtual void apply(Byte3&) {}
virtual void apply(Byte4&) {}
};
class ConstValueVisitor
@ -330,6 +373,13 @@ class ConstValueVisitor
virtual void apply(const Vec2&) {}
virtual void apply(const Vec3&) {}
virtual void apply(const Vec4&) {}
virtual void apply(const Short2&) {}
virtual void apply(const Short3&) {}
virtual void apply(const Short4&) {}
virtual void apply(const Byte2&) {}
virtual void apply(const Byte3&) {}
virtual void apply(const Byte4&) {}
};
template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType>

136
include/osg/Byte2 Normal file
View File

@ -0,0 +1,136 @@
/* -*-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_BYTE2
#define OSG_BYTE2 1
namespace osg {
/** General purpose float triple.
* Uses include representation of color coordinates.
* No support yet added for float * Byte2 - is it necessary?
* Need to define a non-member non-friend operator* etc.
* Byte2 * float is okay
*/
class Byte2
{
public:
// Methods are defined here so that they are implicitly inlined
Byte2() { _v[0]=0; _v[1]=0; }
Byte2(char r, char g)
{
_v[0]=r; _v[1]=g;
}
char _v[2];
inline bool operator == (const Byte2& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1]; }
inline bool operator != (const Byte2& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1]; }
inline bool operator < (const Byte2& v) const
{
if (_v[0]<v._v[0]) return true;
else if (_v[0]>v._v[0]) return false;
else return (_v[1]<v._v[1]);
}
inline char* ptr() { return _v; }
inline const char* ptr() const { return _v; }
inline void set(char r, char g)
{
_v[0]=r; _v[1]=g;
}
inline char& operator [] (unsigned int i) { return _v[i]; }
inline char operator [] (unsigned int i) const { return _v[i]; }
inline char& r() { return _v[0]; }
inline char& g() { return _v[1]; }
inline char r() const { return _v[0]; }
inline char g() const { return _v[1]; }
/** Multiply by scalar. */
inline Byte2 operator * (float rhs) const
{
Byte2 col(*this);
col *= rhs;
return col;
}
/** Unary multiply by scalar. */
inline Byte2& operator *= (float rhs)
{
_v[0]=(char)((float)_v[0]*rhs);
_v[1]=(char)((float)_v[1]*rhs);
return *this;
}
/** Divide by scalar. */
inline Byte2 operator / (float rhs) const
{
Byte2 col(*this);
col /= rhs;
return col;
}
/** Unary divide by scalar. */
inline Byte2& operator /= (float rhs)
{
float div = 1.0f/rhs;
*this *= div;
return *this;
}
/** Binary vector add. */
inline Byte2 operator + (const Byte2& rhs) const
{
return Byte2(_v[0]+rhs._v[0], _v[1]+rhs._v[1]);
}
/** Unary vector add. Slightly more efficient because no temporary
* intermediate object.
*/
inline Byte2& operator += (const Byte2& rhs)
{
_v[0] += rhs._v[0];
_v[1] += rhs._v[1];
return *this;
}
/** Binary vector subtract. */
inline Byte2 operator - (const Byte2& rhs) const
{
return Byte2(_v[0]-rhs._v[0], _v[1]-rhs._v[1]);
}
/** Unary vector subtract. */
inline Byte2& operator -= (const Byte2& rhs)
{
_v[0]-=rhs._v[0];
_v[1]-=rhs._v[1];
return *this;
}
}; // end of class Byte2
} // end of namespace osg
#endif

145
include/osg/Byte3 Normal file
View File

@ -0,0 +1,145 @@
/* -*-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_BYTE3
#define OSG_BYTE3 1
namespace osg {
/** General purpose float triple.
* Uses include representation of color coordinates.
* No support yet added for float * Byte3 - is it necessary?
* Need to define a non-member non-friend operator* etc.
* Byte3 * float is okay
*/
class Byte3
{
public:
// Methods are defined here so that they are implicitly inlined
Byte3() { _v[0]=0; _v[1]=0; _v[2]=0; }
Byte3(char r, char g, char b)
{
_v[0]=r; _v[1]=g; _v[2]=b;
}
char _v[3];
inline bool operator == (const Byte3& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2]; }
inline bool operator != (const Byte3& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2]; }
inline bool operator < (const Byte3& v) const
{
if (_v[0]<v._v[0]) return true;
else if (_v[0]>v._v[0]) return false;
else if (_v[1]<v._v[1]) return true;
else if (_v[1]>v._v[1]) return false;
else return (_v[2]<v._v[2]);
}
inline char* ptr() { return _v; }
inline const char* ptr() const { return _v; }
inline void set(char r, char g, char b)
{
_v[0]=r; _v[1]=g; _v[2]=b;
}
inline char& operator [] (unsigned int i) { return _v[i]; }
inline char operator [] (unsigned int i) const { return _v[i]; }
inline char& r() { return _v[0]; }
inline char& g() { return _v[1]; }
inline char& b() { return _v[2]; }
inline char r() const { return _v[0]; }
inline char g() const { return _v[1]; }
inline char b() const { return _v[2]; }
/** Multiply by scalar. */
inline Byte3 operator * (float rhs) const
{
Byte3 col(*this);
col *= rhs;
return col;
}
/** Unary multiply by scalar. */
inline Byte3& operator *= (float rhs)
{
_v[0]=(char)((float)_v[0]*rhs);
_v[1]=(char)((float)_v[1]*rhs);
_v[2]=(char)((float)_v[2]*rhs);
return *this;
}
/** Divide by scalar. */
inline Byte3 operator / (float rhs) const
{
Byte3 col(*this);
col /= rhs;
return col;
}
/** Unary divide by scalar. */
inline Byte3& operator /= (float rhs)
{
float div = 1.0f/rhs;
*this *= div;
return *this;
}
/** Binary vector add. */
inline Byte3 operator + (const Byte3& rhs) const
{
return Byte3(_v[0]+rhs._v[0], _v[1]+rhs._v[1],
_v[2]+rhs._v[2]);
}
/** Unary vector add. Slightly more efficient because no temporary
* intermediate object.
*/
inline Byte3& operator += (const Byte3& rhs)
{
_v[0] += rhs._v[0];
_v[1] += rhs._v[1];
_v[2] += rhs._v[2];
return *this;
}
/** Binary vector subtract. */
inline Byte3 operator - (const Byte3& rhs) const
{
return Byte3(_v[0]-rhs._v[0], _v[1]-rhs._v[1],
_v[2]-rhs._v[2]);
}
/** Unary vector subtract. */
inline Byte3& operator -= (const Byte3& rhs)
{
_v[0]-=rhs._v[0];
_v[1]-=rhs._v[1];
_v[2]-=rhs._v[2];
return *this;
}
}; // end of class Byte3
} // end of namespace osg
#endif

152
include/osg/Byte4 Normal file
View File

@ -0,0 +1,152 @@
/* -*-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_BYTE4
#define OSG_BYTE4 1
namespace osg {
/** General purpose float triple.
* Uses include representation of color coordinates.
* No support yet added for float * Byte4 - is it necessary?
* Need to define a non-member non-friend operator* etc.
* Byte4 * float is okay
*/
class Byte4
{
public:
// Methods are defined here so that they are implicitly inlined
Byte4() { _v[0]=0; _v[1]=0; _v[2]=0; _v[3]=0; }
Byte4(char r, char g, char b, char a)
{
_v[0]=r; _v[1]=g; _v[2]=b; _v[3]=a;
}
char _v[4];
inline bool operator == (const Byte4& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2] && _v[3]==v._v[3]; }
inline bool operator != (const Byte4& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2] || _v[3]!=v._v[3]; }
inline bool operator < (const Byte4& v) const
{
if (_v[0]<v._v[0]) return true;
else if (_v[0]>v._v[0]) return false;
else if (_v[1]<v._v[1]) return true;
else if (_v[1]>v._v[1]) return false;
else if (_v[2]<v._v[2]) return true;
else if (_v[2]>v._v[2]) return false;
else return (_v[3]<v._v[3]);
}
inline char* ptr() { return _v; }
inline const char* ptr() const { return _v; }
inline void set(char r, char g, char b, char a)
{
_v[0]=r; _v[1]=g; _v[2]=b; _v[3]=a;
}
inline char& operator [] (unsigned int i) { return _v[i]; }
inline char operator [] (unsigned int i) const { return _v[i]; }
inline char& r() { return _v[0]; }
inline char& g() { return _v[1]; }
inline char& b() { return _v[2]; }
inline char& a() { return _v[3]; }
inline char r() const { return _v[0]; }
inline char g() const { return _v[1]; }
inline char b() const { return _v[2]; }
inline char a() const { return _v[3]; }
/** Multiply by scalar. */
inline Byte4 operator * (float rhs) const
{
Byte4 col(*this);
col *= rhs;
return col;
}
/** Unary multiply by scalar. */
inline Byte4& operator *= (float rhs)
{
_v[0]=(char)((float)_v[0]*rhs);
_v[1]=(char)((float)_v[1]*rhs);
_v[2]=(char)((float)_v[2]*rhs);
_v[3]=(char)((float)_v[3]*rhs);
return *this;
}
/** Divide by scalar. */
inline Byte4 operator / (float rhs) const
{
Byte4 col(*this);
col /= rhs;
return col;
}
/** Unary divide by scalar. */
inline Byte4& operator /= (float rhs)
{
float div = 1.0f/rhs;
*this *= div;
return *this;
}
/** Binary vector add. */
inline Byte4 operator + (const Byte4& rhs) const
{
return Byte4(_v[0]+rhs._v[0], _v[1]+rhs._v[1],
_v[2]+rhs._v[2], _v[3]+rhs._v[3]);
}
/** Unary vector add. Slightly more efficient because no temporary
* intermediate object.
*/
inline Byte4& operator += (const Byte4& rhs)
{
_v[0] += rhs._v[0];
_v[1] += rhs._v[1];
_v[2] += rhs._v[2];
_v[3] += rhs._v[3];
return *this;
}
/** Binary vector subtract. */
inline Byte4 operator - (const Byte4& rhs) const
{
return Byte4(_v[0]-rhs._v[0], _v[1]-rhs._v[1],
_v[2]-rhs._v[2], _v[3]-rhs._v[3]);
}
/** Unary vector subtract. */
inline Byte4& operator -= (const Byte4& rhs)
{
_v[0]-=rhs._v[0];
_v[1]-=rhs._v[1];
_v[2]-=rhs._v[2];
_v[3]-=rhs._v[3];
return *this;
}
}; // end of class Byte4
} // end of namespace osg
#endif

View File

@ -161,19 +161,20 @@ class OSG_EXPORT Geometry : public Drawable
void setNormalBinding(AttributeBinding ab) { _normalData.binding = ab; dirtyDisplayList(); computeFastPathsUsed(); }
AttributeBinding getNormalBinding() const { return _normalData.binding; }
void setNormalArray(Vec3Array* array) { _normalData.array = array; if (!_normalData.array.valid()) _normalData.binding=BIND_OFF; computeFastPathsUsed(); dirtyDisplayList(); }
Vec3Array* getNormalArray() { return _normalData.array.get(); }
const Vec3Array* getNormalArray() const { return _normalData.array.get(); }
void setNormalArray(Array* array) { _normalData.array = array; if (!_normalData.array.valid()) _normalData.binding=BIND_OFF; computeFastPathsUsed(); dirtyDisplayList(); }
Array* getNormalArray() { return _normalData.array.get(); }
const Array* getNormalArray() const { return _normalData.array.get(); }
Array* getNormalArrayEx() { return _normalData.array.get(); }
const Array* getNormalArrayEx() const { return _normalData.array.get(); }
void setNormalIndices(IndexArray* array) { _normalData.indices = array; computeFastPathsUsed(); dirtyDisplayList(); }
IndexArray* getNormalIndices() { return _normalData.indices.get(); }
const IndexArray* getNormalIndices() const { return _normalData.indices.get(); }
void setNormalData(const Vec3ArrayData& arrayData) { _normalData = arrayData; }
Vec3ArrayData& getNormalData() { return _normalData; }
const Vec3ArrayData& getNormalData() const { return _normalData; }
void setNormalData(const ArrayData& arrayData) { _normalData = arrayData; }
ArrayData& getNormalData() { return _normalData; }
const ArrayData& getNormalData() const { return _normalData; }
void setColorBinding(AttributeBinding ab) { _colorData.binding = ab; computeFastPathsUsed();}
AttributeBinding getColorBinding() const { return _colorData.binding; }
@ -380,7 +381,7 @@ class OSG_EXPORT Geometry : public Drawable
PrimitiveSetList _primitives;
ArrayData _vertexData;
Vec3ArrayData _normalData;
ArrayData _normalData;
ArrayData _colorData;
ArrayData _secondaryColorData;
ArrayData _fogCoordData;

85
include/osg/Short2 Normal file
View File

@ -0,0 +1,85 @@
/* -*-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_SHORT_2
#define OSG_SHORT_2 1
namespace osg {
class Short2
{
public:
typedef short value_type;
union
{
struct {value_type x,y;};
value_type _v[2];
};
Short2() {}
Short2(value_type xx, value_type yy)
{ x = xx; y = yy; }
inline value_type* ptr() { return _v; }
inline const value_type* ptr() const { return _v; }
inline bool operator == (const Short2& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1]; }
inline bool operator != (const Short2& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1]; }
inline bool operator < (const Short2& v) const
{
if (_v[0]<v._v[0]) return true;
else if (_v[0]>v._v[0]) return false;
else return (_v[1]<v._v[1]);
}
inline Short2 operator * (value_type rhs) const
{
return Short2(_v[0]*rhs, _v[1]*rhs);
}
inline Short2 operator / (value_type rhs) const
{
return Short2(_v[0]/rhs, _v[1]/rhs);
}
inline Short2 operator + (value_type rhs) const
{
return Short2(_v[0]+rhs, _v[1]+rhs);
}
inline Short2 operator - (value_type rhs) const
{
return Short2(_v[0]-rhs, _v[1]-rhs);
}
inline Short2 operator + (const Short2& rhs) const
{
return Short2(_v[0]+rhs._v[0], _v[1]+rhs._v[1]);
}
inline Short2 operator - (const Short2& rhs) const
{
return Short2(_v[0]-rhs._v[0], _v[1]-rhs._v[1]);
}
inline Short2 operator * (const Short2& rhs) const
{
return Short2(_v[0]*rhs._v[0], _v[1]*rhs._v[1]);
}
};
}
#endif

87
include/osg/Short3 Normal file
View File

@ -0,0 +1,87 @@
/* -*-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_SHORT_3
#define OSG_SHORT_3 1
namespace osg {
class Short3
{
public:
typedef short value_type;
union
{
struct {value_type x,y,z;};
value_type _v[3];
};
Short3 (){}
Short3 (value_type xx, value_type yy, value_type zz)
{ x = xx; y = yy; z = zz;}
inline value_type* ptr() { return _v; }
inline const value_type* ptr() const { return _v; }
inline bool operator == (const Short3& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2]; }
inline bool operator != (const Short3& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2]; }
inline bool operator < (const Short3& v) const
{
if (_v[0]<v._v[0]) return true;
else if (_v[0]>v._v[0]) return false;
else if (_v[1]<v._v[1]) return true;
else if (_v[1]>v._v[1]) return false;
else return (_v[2]<v._v[2]);
}
inline Short3 operator * (value_type rhs) const
{
return Short3(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs);
}
inline Short3 operator / (value_type rhs) const
{
return Short3(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs);
}
inline Short3 operator + (value_type rhs) const
{
return Short3(_v[0]+rhs, _v[1]+rhs, _v[2]+rhs);
}
inline Short3 operator - (value_type rhs) const
{
return Short3(_v[0]-rhs, _v[1]-rhs, _v[2]-rhs);
}
inline Short3 operator + (const Short3& rhs) const
{
return Short3(_v[0]+rhs._v[0], _v[1]+rhs._v[1], _v[2]+rhs._v[2]);
}
inline Short3 operator - (const Short3& rhs) const
{
return Short3(_v[0]-rhs._v[0], _v[1]-rhs._v[1], _v[2]-rhs._v[2]);
}
inline Short3 operator * (const Short3& rhs) const
{
return Short3(_v[0]*rhs._v[0], _v[1]*rhs._v[1], _v[2]*rhs._v[2]);
}
};
};
#endif

89
include/osg/Short4 Normal file
View File

@ -0,0 +1,89 @@
/* -*-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_SHORT_4
#define OSG_SHORT_4 1
namespace osg {
class Short4
{
public:
typedef short value_type;
union
{
struct {value_type x,y,z,w;};
value_type _v[4];
};
Short4 (){}
Short4 (value_type xx, value_type yy, value_type zz, value_type ww)
{x = xx; y = yy; z = zz; w = ww;}
inline value_type* ptr() { return _v; }
inline const value_type* ptr() const { return _v; }
inline bool operator == (const Short4& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2] && _v[3]==v._v[3]; }
inline bool operator != (const Short4& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2] || _v[3]!=v._v[3]; }
inline bool operator < (const Short4& v) const
{
if (_v[0]<v._v[0]) return true;
else if (_v[0]>v._v[0]) return false;
else if (_v[1]<v._v[1]) return true;
else if (_v[1]>v._v[1]) return false;
else if (_v[2]<v._v[2]) return true;
else if (_v[2]>v._v[2]) return false;
else return (_v[3]<v._v[3]);
}
inline Short4 operator * (value_type rhs) const
{
return Short4(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs, _v[3]*rhs);
}
inline Short4 operator / (value_type rhs) const
{
return Short4(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs, _v[3]/rhs);
}
inline Short4 operator + (value_type rhs) const
{
return Short4(_v[0]+rhs, _v[1]+rhs, _v[2]+rhs, _v[3]+rhs);
}
inline Short4 operator - (value_type rhs) const
{
return Short4(_v[0]-rhs, _v[1]-rhs, _v[2]-rhs, _v[3]-rhs);
}
inline Short4 operator + (const Short4& rhs) const
{
return Short4(_v[0]+rhs._v[0], _v[1]+rhs._v[1], _v[2]+rhs._v[2], _v[3]+rhs._v[3]);
}
inline Short4 operator - (const Short4& rhs) const
{
return Short4(_v[0]-rhs._v[0], _v[1]-rhs._v[1], _v[2]-rhs._v[2], _v[3]-rhs._v[3]);
}
inline Short4 operator * (const Short4& rhs) const
{
return Short4(_v[0]*rhs._v[0], _v[1]*rhs._v[1], _v[2]*rhs._v[2], _v[3]*rhs._v[3]);
}
};
};
#endif

View File

@ -19,6 +19,12 @@
#include <osg/Vec4d>
#include <osg/UByte4>
#include <osg/Byte2>
#include <osg/Byte3>
#include <osg/Byte4>
#include <osg/Short2>
#include <osg/Short3>
#include <osg/Short4>
#include <osg/Matrixf>
#include <osg/Matrixd>
#include <osg/Plane>
@ -124,6 +130,104 @@ inline std::istream& operator >> (std::istream& input, Vec4d& vec)
}
//////////////////////////////////////////////////////////////////////////
// Byte2 steaming operators.
inline std::ostream& operator << (std::ostream& output, const Byte2& vec)
{
output << (int)vec._v[0] << " "
<< (int)vec._v[1];
return output; // to enable cascading
}
inline std::istream& operator >> (std::istream& input, Byte2& vec)
{
input >> vec._v[0] >> vec._v[1];
return input;
}
//////////////////////////////////////////////////////////////////////////
// Byte3 steaming operators.
inline std::ostream& operator << (std::ostream& output, const Byte3& vec)
{
output << (int)vec._v[0] << " "
<< (int)vec._v[1] << " "
<< (int)vec._v[2];
return output; // to enable cascading
}
inline std::istream& operator >> (std::istream& input, Byte3& vec)
{
input >> vec._v[0] >> vec._v[1] >> vec._v[2];
return input;
}
//////////////////////////////////////////////////////////////////////////
// Byte4 steaming operators.
inline std::ostream& operator << (std::ostream& output, const Byte4& vec)
{
output << (int)vec._v[0] << " "
<< (int)vec._v[1] << " "
<< (int)vec._v[2] << " "
<< (int)vec._v[3];
return output; // to enable cascading
}
inline std::istream& operator >> (std::istream& input, Byte4& vec)
{
input >> vec._v[0] >> vec._v[1] >> vec._v[2] >> vec._v[3];
return input;
}
//////////////////////////////////////////////////////////////////////////
// Short2 steaming operators.
inline std::ostream& operator << (std::ostream& output, const Short2& vec)
{
output << (int)vec._v[0] << " "
<< (int)vec._v[1];
return output; // to enable cascading
}
inline std::istream& operator >> (std::istream& input, Short2& vec)
{
input >> vec._v[0] >> vec._v[1];
return input;
}
//////////////////////////////////////////////////////////////////////////
// Short3 steaming operators.
inline std::ostream& operator << (std::ostream& output, const Short3& vec)
{
output << (int)vec._v[0] << " "
<< (int)vec._v[1] << " "
<< (int)vec._v[2];
return output; // to enable cascading
}
inline std::istream& operator >> (std::istream& input, Short3& vec)
{
input >> vec._v[0] >> vec._v[1] >> vec._v[2];
return input;
}
//////////////////////////////////////////////////////////////////////////
// Short4 steaming operators.
inline std::ostream& operator << (std::ostream& output, const Short4& vec)
{
output << (int)vec._v[0] << " "
<< (int)vec._v[1] << " "
<< (int)vec._v[2] << " "
<< (int)vec._v[3];
return output; // to enable cascading
}
inline std::istream& operator >> (std::istream& input, Short4& vec)
{
input >> vec._v[0] >> vec._v[1] >> vec._v[2] >> vec._v[3];
return input;
}
//////////////////////////////////////////////////////////////////////////
// Matrxf steaming operators.
inline std::ostream& operator<< (std::ostream& os, const Matrixf& m )

View File

@ -30,11 +30,19 @@ static char* s_ArrayNames[] =
"Vec2Array", // 9
"Vec3Array", // 10
"Vec4Array", // 11
"Short2Array", // 12
"Short3Array", // 13
"Short4Array", // 14
"Byte2Array", // 15
"Byte3Array", // 16
"Byte4Array", // 17
};
const char* Array::className() const
{
if (_arrayType>=ArrayType && _arrayType<=Vec4ArrayType)
if (_arrayType>=ArrayType && _arrayType<=Byte4ArrayType)
return s_ArrayNames[_arrayType];
else
return "UnkownArray";

View File

@ -653,19 +653,15 @@ void Drawable::setEventCallback(EventCallback* ac)
struct ComputeBound : public PrimitiveFunctor
{
ComputeBound():_vertices(0) {}
virtual void setVertexArray(unsigned int,const Vec2*)
ComputeBound() { _vertices = 0; _vertices4 = 0;}
virtual void setVertexArray(unsigned int,const Vec2*)
{
notify(WARN)<<"ComputeBound does not support Vec2* vertex arrays"<<std::endl;
}
virtual void setVertexArray(unsigned int,const Vec3* vertices) { _vertices = vertices; }
virtual void setVertexArray(unsigned int,const Vec4*)
{
notify(WARN)<<"ComputeBound does not support Vec4* vertex arrays"<<std::endl;
}
virtual void setVertexArray(unsigned int,const Vec3* vertices) { _vertices = vertices; }
virtual void setVertexArray(unsigned int,const Vec4* vertices) { _vertices4 = vertices; }
virtual void drawArrays(GLenum,GLint first,GLsizei count)
{
@ -677,6 +673,15 @@ struct ComputeBound : public PrimitiveFunctor
_bb.expandBy(*vert);
}
}
if (_vertices4)
{
const osg::Vec4* vert = _vertices4+first;
for(;count>0;--count,++vert)
{
_bb.expandBy(*((Vec3*) vert));
}
}
}
virtual void drawElements(GLenum,GLsizei count,const GLubyte* indices)
@ -688,6 +693,14 @@ struct ComputeBound : public PrimitiveFunctor
_bb.expandBy(_vertices[*indices]);
}
}
if (_vertices4)
{
for(;count>0;--count,++indices)
{
_bb.expandBy(*((Vec3*)&_vertices4[*indices]));
}
}
}
virtual void drawElements(GLenum,GLsizei count,const GLushort* indices)
@ -699,6 +712,14 @@ struct ComputeBound : public PrimitiveFunctor
_bb.expandBy(_vertices[*indices]);
}
}
if (_vertices4)
{
for(;count>0;--count,++indices)
{
_bb.expandBy(*((Vec3*)&_vertices4[*indices]));
}
}
}
virtual void drawElements(GLenum,GLsizei count,const GLuint* indices)
@ -710,19 +731,28 @@ struct ComputeBound : public PrimitiveFunctor
_bb.expandBy(_vertices[*indices]);
}
}
if (_vertices4)
{
for(;count>0;--count,++indices)
{
_bb.expandBy(*((Vec3*)&_vertices4[*indices]));
}
}
}
virtual void begin(GLenum) {}
virtual void vertex(const Vec2& vert) { _bb.expandBy(osg::Vec3(vert[0],vert[1],0.0f)); }
virtual void vertex(const Vec3& vert) { _bb.expandBy(vert); }
virtual void vertex(const Vec4& vert) { if (vert[3]!=0.0f) _bb.expandBy(osg::Vec3(vert[0],vert[1],vert[2])/vert[3]); }
virtual void vertex(float x,float y) { _bb.expandBy(x,y,1.0f); }
virtual void vertex(float x,float y) { _bb.expandBy(x,y,1.0f); }
virtual void vertex(float x,float y,float z) { _bb.expandBy(x,y,z); }
virtual void vertex(float x,float y,float z,float w) { if (w!=0.0f) _bb.expandBy(x/w,y/w,z/w); }
virtual void end() {}
const Vec3* _vertices;
BoundingBox _bb;
const Vec4* _vertices4;
BoundingBox _bb;
};
BoundingBox Drawable::computeBound() const

View File

@ -102,18 +102,61 @@ class DrawNormal
{
public:
DrawNormal(const Vec3Array* normals,const IndexArray* indices):
DrawNormal(const Array* normals,const IndexArray* indices):
_normals(normals),
_indices(indices) {}
_indices(indices)
{
_normalsType = normals?normals->getType():Array::ArrayType;
}
void operator () (unsigned int pos)
{
if (_indices) glNormal3fv((*_normals)[_indices->index(pos)].ptr());
else glNormal3fv((*_normals)[pos].ptr());
switch(_normalsType)
{
case (Array::Vec3ArrayType):
{
const Vec3Array& normals = *static_cast<const Vec3Array*>(_normals);
if (_indices) glNormal3fv(normals[_indices->index(pos)].ptr());
else glNormal3fv(normals[pos].ptr());
}
break;
case (Array::Short3ArrayType):
{
const Short3Array& normals = *static_cast<const Short3Array*>(_normals);
if (_indices) glNormal3sv(normals[_indices->index(pos)].ptr());
else glNormal3sv(normals[pos].ptr());
}
break;
case (Array::Short4ArrayType):
{
const Short4Array& normals = *static_cast<const Short4Array*>(_normals);
if (_indices) glNormal3sv(normals[_indices->index(pos)].ptr());
else glNormal3sv(normals[pos].ptr());
}
break;
case (Array::Byte3ArrayType):
{
const Byte3Array& normals = *static_cast<const Byte3Array*>(_normals);
if (_indices) glNormal3bv((const GLbyte*)normals[_indices->index(pos)].ptr());
else glNormal3bv((const GLbyte*)normals[pos].ptr());
}
break;
case (Array::Byte4ArrayType):
{
const Byte4Array& normals = *static_cast<const Byte4Array*>(_normals);
if (_indices) glNormal3bv((const GLbyte*)normals[_indices->index(pos)].ptr());
else glNormal3bv((const GLbyte*)normals[pos].ptr());
}
break;
default:
break;
}
}
const Vec3Array* _normals;
const Array* _normals;
const IndexArray* _indices;
Array::Type _normalsType;
};
#if 1
@ -1084,7 +1127,7 @@ void Geometry::drawImplementation(State& state) const
state.disableVertexPointer();
if (_normalData.binding==BIND_PER_VERTEX)
state.setNormalPointer(GL_FLOAT,0,_normalData.array->getDataPointer());
state.setNormalPointer(_normalData.array->getDataType(),0,_normalData.array->getDataPointer());
else
state.disableNormalPointer();

View File

@ -795,25 +795,28 @@ osg::Group *ac_load_object(std::istream &f,const ACObject *parent,const osgDB::R
ia.push_back(app.get());
}
osg::Vec3Array* normals = geom->getNormalArray();
/** calc surface normal **/
if (asurf.num_vertref >= 3)
osg::Vec3Array* normals = dynamic_cast<osg::Vec3Array*>(geom->getNormalArray());
if (normals)
{
osg::Vec3 norm;
unsigned short i1=(*nusidx)[0];
unsigned short i2=(*nusidx)[1];
unsigned short i3=(*nusidx)[2];
osgtri_calc_normal((*vertpool)[i1],
(*vertpool)[i2],
(*vertpool)[i3], norm);
normals->push_back(norm);
// fprintf(stdout,"New %x are %d nrms\n",normals,normals->size());
}
else
{
// Generate a dummy normal
osg::Vec3 norm(0, 1, 0);
normals->push_back(norm);
/** calc surface normal **/
if (asurf.num_vertref >= 3)
{
osg::Vec3 norm;
unsigned short i1=(*nusidx)[0];
unsigned short i2=(*nusidx)[1];
unsigned short i3=(*nusidx)[2];
osgtri_calc_normal((*vertpool)[i1],
(*vertpool)[i2],
(*vertpool)[i3], norm);
normals->push_back(norm);
// fprintf(stdout,"New %x are %d nrms\n",normals,normals->size());
}
else
{
// Generate a dummy normal
osg::Vec3 norm(0, 1, 0);
normals->push_back(norm);
}
}
int nstart=(*vgeom).size();
for (i=0; i<asurf.num_vertref; i++)

View File

@ -154,7 +154,7 @@ void DynGeoSet::addToGeometry(osg::Geometry* geom)
if (!_normalList.empty())
{
osg::Vec3Array* normals = geom->getNormalArray();
osg::Vec3Array* normals = dynamic_cast<osg::Vec3Array*>(geom->getNormalArray());
if (normals)
{
if (_normal_binding==osg::Geometry::BIND_PER_VERTEX || _normal_binding==osg::Geometry::BIND_PER_PRIMITIVE)

View File

@ -438,6 +438,12 @@ osg::Array* DataInputStream::readArray(){
case 6: return readVec2Array();
case 7: return readVec3Array();
case 8: return readVec4Array();
case 9: return readShort2Array();
case 10: return readShort3Array();
case 11: return readShort4Array();
case 12: return readByte2Array();
case 13: return readByte3Array();
case 14: return readByte4Array();
default: throw Exception("Unknown array type in DataInputStream::readArray()");
}
}
@ -612,6 +618,96 @@ osg::Vec4Array* DataInputStream::readVec4Array(){
return a;
}
osg::Byte2Array* DataInputStream::readByte2Array()
{
int size = readInt();
osg::Byte2Array* a = new osg::Byte2Array(size);
_istream->read((char*)&((*a)[0]), CHARSIZE * 2 * size);
if (_istream->rdstate() & _istream->failbit)
throw Exception("DataInputStream::readByte2Array(): Failed to read Byte2 array.");
if (_verboseOutput) std::cout<<"read/writeByte2Array() ["<<size<<"]"<<std::endl;
return a;
}
osg::Byte3Array* DataInputStream::readByte3Array()
{
int size = readInt();
osg::Byte3Array* a = new osg::Byte3Array(size);
_istream->read((char*)&((*a)[0]), CHARSIZE * 3 * size);
if (_istream->rdstate() & _istream->failbit)
throw Exception("DataInputStream::readByte3Array(): Failed to read Byte3 array.");
if (_verboseOutput) std::cout<<"read/writeByte3Array() ["<<size<<"]"<<std::endl;
return a;
}
osg::Byte4Array* DataInputStream::readByte4Array()
{
int size = readInt();
osg::Byte4Array* a = new osg::Byte4Array(size);
_istream->read((char*)&((*a)[0]), CHARSIZE * 4 * size);
if (_istream->rdstate() & _istream->failbit)
throw Exception("DataInputStream::readByte4Array(): Failed to read Byte4 array.");
if (_verboseOutput) std::cout<<"read/writeByte4Array() ["<<size<<"]"<<std::endl;
return a;
}
osg::Short2Array* DataInputStream::readShort2Array()
{
int size = readInt();
osg::Short2Array* a = new osg::Short2Array(size);
_istream->read((char*)&((*a)[0]), SHORTSIZE * 2 * size);
if (_istream->rdstate() & _istream->failbit)
throw Exception("DataInputStream::readShort2Array(): Failed to read Short2 array.");
if (_verboseOutput) std::cout<<"read/writeShort2Array() ["<<size<<"]"<<std::endl;
return a;
}
osg::Short3Array* DataInputStream::readShort3Array()
{
int size = readInt();
osg::Short3Array* a = new osg::Short3Array(size);
_istream->read((char*)&((*a)[0]), SHORTSIZE * 3 * size);
if (_istream->rdstate() & _istream->failbit)
throw Exception("DataInputStream::readShort3Array(): Failed to read Short3 array.");
if (_verboseOutput) std::cout<<"read/writeShort3Array() ["<<size<<"]"<<std::endl;
return a;
}
osg::Short4Array* DataInputStream::readShort4Array()
{
int size = readInt();
osg::Short4Array* a = new osg::Short4Array(size);
_istream->read((char*)&((*a)[0]), SHORTSIZE * 4 * size);
if (_istream->rdstate() & _istream->failbit)
throw Exception("DataInputStream::readShort4Array(): Failed to read Short4 array.");
if (_verboseOutput) std::cout<<"read/writeShort4Array() ["<<size<<"]"<<std::endl;
return a;
}
osg::Matrixf DataInputStream::readMatrixf()
{
osg::Matrixf mat;

View File

@ -77,6 +77,12 @@ public:
osg::Vec2Array* readVec2Array();
osg::Vec3Array* readVec3Array();
osg::Vec4Array* readVec4Array();
osg::Byte2Array* readByte2Array();
osg::Byte3Array* readByte3Array();
osg::Byte4Array* readByte4Array();
osg::Short2Array* readShort2Array();
osg::Short3Array* readShort3Array();
osg::Short4Array* readShort4Array();
osg::Image* readImage(std::string s);
osg::StateSet* readStateSet();

View File

@ -148,6 +148,12 @@ void DataOutputStream::writeUShort(unsigned short s){
if (_verboseOutput) std::cout<<"read/writeUShort() ["<<s<<"]"<<std::endl;
}
void DataOutputStream::writeShort(short s){
_ostream->write((char*)&s, SHORTSIZE);
if (_verboseOutput) std::cout<<"read/writeShort() ["<<s<<"]"<<std::endl;
}
void DataOutputStream::writeUInt(unsigned int s){
_ostream->write((char*)&s, INTSIZE);
@ -264,6 +270,30 @@ void DataOutputStream::writeUByte4(const osg::UByte4& v){
if (_verboseOutput) std::cout<<"read/writeUByte4() ["<<v<<"]"<<std::endl;
}
void DataOutputStream::writeByte2(const osg::Byte2& v){
writeChar(v.r());
writeChar(v.g());
if (_verboseOutput) std::cout<<"read/writeByte2() ["<<v<<"]"<<std::endl;
}
void DataOutputStream::writeByte3(const osg::Byte3& v){
writeChar(v.r());
writeChar(v.g());
writeChar(v.b());
if (_verboseOutput) std::cout<<"read/writeByte3() ["<<v<<"]"<<std::endl;
}
void DataOutputStream::writeByte4(const osg::Byte4& v){
writeChar(v.r());
writeChar(v.g());
writeChar(v.b());
writeChar(v.a());
if (_verboseOutput) std::cout<<"read/writeByte4() ["<<v<<"]"<<std::endl;
}
void DataOutputStream::writeQuat(const osg::Quat& q){
writeFloat(q.x());
writeFloat(q.y());
@ -324,6 +354,30 @@ void DataOutputStream::writeArray(const osg::Array* a){
writeChar((char)8);
writeVec4Array(static_cast<const osg::Vec4Array*>(a));
break;
case osg::Array::Short2ArrayType:
writeChar((char)9);
writeShort2Array(static_cast<const osg::Short2Array*>(a));
break;
case osg::Array::Short3ArrayType:
writeChar((char)10);
writeShort3Array(static_cast<const osg::Short3Array*>(a));
break;
case osg::Array::Short4ArrayType:
writeChar((char)11);
writeShort4Array(static_cast<const osg::Short4Array*>(a));
break;
case osg::Array::Byte2ArrayType:
writeChar((char)12);
writeByte2Array(static_cast<const osg::Byte2Array*>(a));
break;
case osg::Array::Byte3ArrayType:
writeChar((char)13);
writeByte3Array(static_cast<const osg::Byte3Array*>(a));
break;
case osg::Array::Byte4ArrayType:
writeChar((char)14);
writeByte4Array(static_cast<const osg::Byte4Array*>(a));
break;
default: throw Exception("Unknown array type in DataOutputStream::writeArray()");
}
}
@ -429,6 +483,78 @@ void DataOutputStream::writeVec4Array(const osg::Vec4Array* a)
if (_verboseOutput) std::cout<<"read/writeVec4Array() ["<<size<<"]"<<std::endl;
}
void DataOutputStream::writeShort2Array(const osg::Short2Array* a)
{
int size = a->getNumElements();
writeInt(size);
for(int i =0; i<size ;i++){
writeShort((*a)[i].x);
writeShort((*a)[i].y);
}
if (_verboseOutput) std::cout<<"read/writeShort2Array() ["<<size<<"]"<<std::endl;
}
void DataOutputStream::writeShort3Array(const osg::Short3Array* a)
{
int size = a->getNumElements();
writeInt(size);
for(int i =0; i<size ;i++){
writeShort((*a)[i].x);
writeShort((*a)[i].y);
writeShort((*a)[i].z);
}
if (_verboseOutput) std::cout<<"read/writeShort3Array() ["<<size<<"]"<<std::endl;
}
void DataOutputStream::writeShort4Array(const osg::Short4Array* a)
{
int size = a->getNumElements();
writeInt(size);
for(int i =0; i<size ;i++){
writeShort((*a)[i].x);
writeShort((*a)[i].y);
writeShort((*a)[i].z);
writeShort((*a)[i].w);
}
if (_verboseOutput) std::cout<<"read/writeShort4Array() ["<<size<<"]"<<std::endl;
}
void DataOutputStream::writeByte2Array(const osg::Byte2Array* a)
{
int size = a->getNumElements();
writeInt(size);
for(int i =0; i<size ;i++){
writeByte2((*a)[i]);
}
if (_verboseOutput) std::cout<<"read/writeByte2Array() ["<<size<<"]"<<std::endl;
}
void DataOutputStream::writeByte3Array(const osg::Byte3Array* a)
{
int size = a->getNumElements();
writeInt(size);
for(int i =0; i<size ;i++){
writeByte3((*a)[i]);
}
if (_verboseOutput) std::cout<<"read/writeByte3Array() ["<<size<<"]"<<std::endl;
}
void DataOutputStream::writeByte4Array(const osg::Byte4Array* a)
{
int size = a->getNumElements();
writeInt(size);
for(int i =0; i<size ;i++){
writeByte4((*a)[i]);
}
if (_verboseOutput) std::cout<<"read/writeByte4Array() ["<<size<<"]"<<std::endl;
}
void DataOutputStream::writeMatrixf(const osg::Matrixf& mat)
{
for(int r=0;r<4;r++)

View File

@ -3,7 +3,7 @@
#include <iostream> // for ofstream
#include <iostream> // for ofstream
#include <string>
#include <osg/Vec2>
#include <osg/Vec3>
@ -23,106 +23,116 @@
#include <osg/StateSet>
#include <osg/ref_ptr>
namespace ive {
namespace ive {
class DataOutputStream{
public:
DataOutputStream(std::ostream* ostream);
~DataOutputStream();
DataOutputStream(std::ostream* ostream);
~DataOutputStream();
void setOptions(const osgDB::ReaderWriter::Options* options);
const osgDB::ReaderWriter::Options* getOptions() const { return _options.get(); }
void setOptions(const osgDB::ReaderWriter::Options* options);
const osgDB::ReaderWriter::Options* getOptions() const { return _options.get(); }
unsigned int getVersion() { return VERSION; }
unsigned int getVersion() { return VERSION; }
void writeBool(bool b);
void writeChar(char c);
void writeUChar(unsigned char c);
void writeUShort(unsigned short s);
void writeUInt(unsigned int s);
void writeInt(int i);
void writeFloat(float f);
void writeLong(long l);
void writeULong(unsigned long l);
void writeDouble(double d);
void writeString(const std::string& s);
void writeCharArray(const char* data, int size);
void writeVec2(const osg::Vec2& v);
void writeVec3(const osg::Vec3& v);
void writeVec4(const osg::Vec4& v);
void writeVec2d(const osg::Vec2d& v);
void writeVec3d(const osg::Vec3d& v);
void writeVec4d(const osg::Vec4d& v);
void writePlane(const osg::Plane& v);
void writeUByte4(const osg::UByte4& v);
void writeQuat(const osg::Quat& q);
void writeBinding(osg::Geometry::AttributeBinding b);
void writeArray(const osg::Array* a);
void writeIntArray(const osg::IntArray* a);
void writeUByteArray(const osg::UByteArray* a);
void writeUShortArray(const osg::UShortArray* a);
void writeUIntArray(const osg::UIntArray* a);
void writeUByte4Array(const osg::UByte4Array* a);
void writeFloatArray(const osg::FloatArray* a);
void writeVec2Array(const osg::Vec2Array* a);
void writeVec3Array(const osg::Vec3Array* a);
void writeVec4Array(const osg::Vec4Array* a);
void writeMatrixf(const osg::Matrixf& mat);
void writeMatrixd(const osg::Matrixd& mat);
void writeBool(bool b);
void writeChar(char c);
void writeUChar(unsigned char c);
void writeUShort(unsigned short s);
void writeShort(short s);
void writeUInt(unsigned int s);
void writeInt(int i);
void writeFloat(float f);
void writeLong(long l);
void writeULong(unsigned long l);
void writeDouble(double d);
void writeString(const std::string& s);
void writeCharArray(const char* data, int size);
void writeVec2(const osg::Vec2& v);
void writeVec3(const osg::Vec3& v);
void writeVec4(const osg::Vec4& v);
void writeVec2d(const osg::Vec2d& v);
void writeVec3d(const osg::Vec3d& v);
void writeVec4d(const osg::Vec4d& v);
void writePlane(const osg::Plane& v);
void writeUByte4(const osg::UByte4& v);
void writeQuat(const osg::Quat& q);
void writeBinding(osg::Geometry::AttributeBinding b);
void writeArray(const osg::Array* a);
void writeIntArray(const osg::IntArray* a);
void writeUByteArray(const osg::UByteArray* a);
void writeUShortArray(const osg::UShortArray* a);
void writeUIntArray(const osg::UIntArray* a);
void writeUByte4Array(const osg::UByte4Array* a);
void writeByte2(const osg::Byte2& v);
void writeByte3(const osg::Byte3& v);
void writeByte4(const osg::Byte4& v);
void writeFloatArray(const osg::FloatArray* a);
void writeVec2Array(const osg::Vec2Array* a);
void writeVec3Array(const osg::Vec3Array* a);
void writeVec4Array(const osg::Vec4Array* a);
void writeShort2Array(const osg::Short2Array* a);
void writeShort3Array(const osg::Short3Array* a);
void writeShort4Array(const osg::Short4Array* a);
void writeByte2Array(const osg::Byte2Array* a);
void writeByte3Array(const osg::Byte3Array* a);
void writeByte4Array(const osg::Byte4Array* a);
void writeMatrixf(const osg::Matrixf& mat);
void writeMatrixd(const osg::Matrixd& mat);
void writeStateSet(const osg::StateSet* stateset);
void writeStateAttribute(const osg::StateAttribute* sa);
void writeUniform(const osg::Uniform* uniform);
void writeShader(const osg::Shader* shader);
void writeDrawable(const osg::Drawable* sa);
void writeShape(const osg::Shape* sa);
void writeNode(const osg::Node* sa);
void writeStateSet(const osg::StateSet* stateset);
void writeStateAttribute(const osg::StateAttribute* sa);
void writeUniform(const osg::Uniform* uniform);
void writeShader(const osg::Shader* shader);
void writeDrawable(const osg::Drawable* sa);
void writeShape(const osg::Shape* sa);
void writeNode(const osg::Node* sa);
// Set and get include image data in stream
void setIncludeImageData(bool b) {_includeImageData=b;};
bool getIncludeImageData() {return _includeImageData;};
// Set and get include image data in stream
void setIncludeImageData(bool b) {_includeImageData=b;};
bool getIncludeImageData() {return _includeImageData;};
// Set and get include external references in stream
void setIncludeExternalReferences(bool b) {_includeExternalReferences=b;};
bool getIncludeExternalReferences() {return _includeExternalReferences;};
// Set and get include external references in stream
void setIncludeExternalReferences(bool b) {_includeExternalReferences=b;};
bool getIncludeExternalReferences() {return _includeExternalReferences;};
// Set and get if must be generated external reference ive files
void setWriteExternalReferenceFiles(bool b) {_writeExternalReferenceFiles=b;};
bool getWriteExternalReferenceFiles() {return _writeExternalReferenceFiles;};
// Set and get if must be generated external reference ive files
void setWriteExternalReferenceFiles(bool b) {_writeExternalReferenceFiles=b;};
bool getWriteExternalReferenceFiles() {return _writeExternalReferenceFiles;};
// Set and get if must be used original external reference files
void setUseOriginalExternalReferences(bool b) {_useOriginalExternalReferences=b;};
bool getUseOriginalExternalReferences() {return _useOriginalExternalReferences;};
// Set and get if must be used original external reference files
void setUseOriginalExternalReferences(bool b) {_useOriginalExternalReferences=b;};
bool getUseOriginalExternalReferences() {return _useOriginalExternalReferences;};
bool _verboseOutput;
bool _verboseOutput;
private:
std::ostream* _ostream;
std::ostream* _ostream;
// Container to map stateset uniques to their respective stateset.
typedef std::map<const osg::StateSet*,int> StateSetMap;
typedef std::map<const osg::StateAttribute*,int> StateAttributeMap;
typedef std::map<const osg::Uniform*,int> UniformMap;
typedef std::map<const osg::Shader*,int> ShaderMap;
typedef std::map<const osg::Drawable*,int> DrawableMap;
typedef std::map<const osg::Shape*,int> ShapeMap;
typedef std::map<const osg::Node*,int> NodeMap;
// Container to map stateset uniques to their respective stateset.
typedef std::map<const osg::StateSet*,int> StateSetMap;
typedef std::map<const osg::StateAttribute*,int> StateAttributeMap;
typedef std::map<const osg::Uniform*,int> UniformMap;
typedef std::map<const osg::Shader*,int> ShaderMap;
typedef std::map<const osg::Drawable*,int> DrawableMap;
typedef std::map<const osg::Shape*,int> ShapeMap;
typedef std::map<const osg::Node*,int> NodeMap;
StateSetMap _stateSetMap;
StateAttributeMap _stateAttributeMap;
UniformMap _uniformMap;
ShaderMap _shaderMap;
DrawableMap _drawableMap;
ShapeMap _shapeMap;
NodeMap _nodeMap;
StateSetMap _stateSetMap;
StateAttributeMap _stateAttributeMap;
UniformMap _uniformMap;
ShaderMap _shaderMap;
DrawableMap _drawableMap;
ShapeMap _shapeMap;
NodeMap _nodeMap;
bool _includeImageData;
bool _includeExternalReferences;
bool _writeExternalReferenceFiles;
bool _useOriginalExternalReferences;
osg::ref_ptr<const osgDB::ReaderWriter::Options> _options;
bool _includeImageData;
bool _includeExternalReferences;
bool _writeExternalReferenceFiles;
bool _useOriginalExternalReferences;
osg::ref_ptr<const osgDB::ReaderWriter::Options> _options;
};
}

View File

@ -67,12 +67,28 @@ void Geometry::write(DataOutputStream* out){
if (getVertexIndices()){
out->writeArray(getVertexIndices());
}
// Write normal array if any
out->writeBool(getNormalArray()!=0);
if (getNormalArray()){
out->writeBinding(getNormalBinding());
out->writeVec3Array(getNormalArray());
if ( out->getVersion() < VERSION_0013 )
{
osg::Vec3Array* normals = dynamic_cast<osg::Vec3Array*>(getNormalArray());
out->writeBool(normals!=0);
if (normals)
{
out->writeBinding(getNormalBinding());
out->writeVec3Array(normals);
}
}
else
{
out->writeBool(getNormalArray()!=0);
if (getNormalArray()!=0)
{
out->writeBinding(getNormalBinding());
out->writeArray(getNormalArray());
}
}
// Write normal indices if any
out->writeBool(getNormalIndices()!=0);
if (getNormalIndices()){
@ -213,12 +229,25 @@ void Geometry::read(DataInputStream* in){
if (vi){
setVertexIndices(static_cast<osg::IndexArray*>(in->readArray()));
}
// Read normal array if any
bool na =in->readBool();
if(na){
setNormalBinding(in->readBinding());
setNormalArray(in->readVec3Array());
if ( in->getVersion() < VERSION_0013 )
{
bool na =in->readBool();
if(na){
setNormalBinding(in->readBinding());
setNormalArray(in->readVec3Array());
}
}
else
{
bool na =in->readBool();
if(na){
setNormalBinding(in->readBinding());
setNormalArray(in->readArray());
}
}
// Read normal indices if any
bool ni = in->readBool();
if(ni){

View File

@ -21,8 +21,9 @@
#define VERSION_0010 10
#define VERSION_0011 11
#define VERSION_0012 12
#define VERSION_0013 13
#define VERSION VERSION_0012
#define VERSION VERSION_0013
/* The BYTE_SEX tag is used to check the endian

View File

@ -173,7 +173,7 @@ bool Geometry_readLocalData(Object& obj, Input& fr)
{
// post 0.9.3 releases.
++fr;
Vec3Array* normals = dynamic_cast<Vec3Array*>(Array_readLocalData(fr));
Array* normals = Array_readLocalData(fr);
if (normals)
{
geom.setNormalArray(normals);
@ -601,6 +601,120 @@ Array* Array_readLocalData(Input& fr)
++fr;
return_array = array;
}
else if (strcmp(arrayName,"Byte2Array")==0)
{
Byte2Array* array = new Byte2Array;
array->reserve(capacity);
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
{
unsigned int r,g;
if (fr[0].getUInt(r) &&
fr[1].getUInt(g))
{
fr+=2;
array->push_back(osg::Byte2(r,g));
}
else ++fr;
}
++fr;
return_array = array;
}
else if (strcmp(arrayName,"Byte3Array")==0)
{
Byte3Array* array = new Byte3Array;
array->reserve(capacity);
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
{
unsigned int r,g,b;
if (fr[0].getUInt(r) &&
fr[1].getUInt(g) &&
fr[2].getUInt(b))
{
fr+=3;
array->push_back(osg::Byte3(r,g,b));
}
else ++fr;
}
++fr;
return_array = array;
}
else if (strcmp(arrayName,"Byte4Array")==0)
{
Byte4Array* array = new Byte4Array;
array->reserve(capacity);
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
{
unsigned int r,g,b,a;
if (fr[0].getUInt(r) &&
fr[1].getUInt(g) &&
fr[2].getUInt(b) &&
fr[3].getUInt(a))
{
fr+=4;
array->push_back(osg::Byte4(r,g,b,a));
}
else ++fr;
}
++fr;
return_array = array;
}
else if (strcmp(arrayName,"Short2Array")==0)
{
Short2Array* array = new Short2Array;
array->reserve(capacity);
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
{
unsigned int r,g;
if (fr[0].getUInt(r) &&
fr[1].getUInt(g))
{
fr+=2;
array->push_back(osg::Short2(r,g));
}
else ++fr;
}
++fr;
return_array = array;
}
else if (strcmp(arrayName,"Short3Array")==0)
{
Short3Array* array = new Short3Array;
array->reserve(capacity);
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
{
unsigned int r,g,b;
if (fr[0].getUInt(r) &&
fr[1].getUInt(g) &&
fr[2].getUInt(b))
{
fr+=3;
array->push_back(osg::Short3(r,g,b));
}
else ++fr;
}
++fr;
return_array = array;
}
else if (strcmp(arrayName,"Short4Array")==0)
{
Short4Array* array = new Short4Array;
array->reserve(capacity);
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
{
unsigned int r,g,b,a;
if (fr[0].getUInt(r) &&
fr[1].getUInt(g) &&
fr[2].getUInt(b) &&
fr[3].getUInt(a))
{
fr+=4;
array->push_back(osg::Short4(r,g,b,a));
}
else ++fr;
}
++fr;
return_array = array;
}
if (return_array)
{
@ -721,6 +835,54 @@ bool Array_writeLocalData(const Array& array,Output& fw)
return true;
}
break;
case(Array::Short2ArrayType):
{
const Short2Array& carray = static_cast<const Short2Array&>(array);
fw<<array.className()<<" "<<carray.size()<<std::endl;
writeArray(fw,carray.begin(),carray.end(), 3);
return true;
}
break;
case(Array::Short3ArrayType):
{
const Short3Array& carray = static_cast<const Short3Array&>(array);
fw<<array.className()<<" "<<carray.size()<<std::endl;
writeArray(fw,carray.begin(),carray.end(), 2);
return true;
}
break;
case(Array::Short4ArrayType):
{
const Short4Array& carray = static_cast<const Short4Array&>(array);
fw<<array.className()<<" "<<carray.size()<<std::endl;
writeArray(fw,carray.begin(),carray.end(), 1);
return true;
}
break;
case(Array::Byte2ArrayType):
{
const Byte2Array& carray = static_cast<const Byte2Array&>(array);
fw<<array.className()<<" "<<carray.size()<<" ";
writeArray(fw,carray.begin(),carray.end(),1);
return true;
}
break;
case(Array::Byte3ArrayType):
{
const Byte3Array& carray = static_cast<const Byte3Array&>(array);
fw<<array.className()<<" "<<carray.size()<<" ";
writeArray(fw,carray.begin(),carray.end(),1);
return true;
}
break;
case(Array::Byte4ArrayType):
{
const Byte4Array& carray = static_cast<const Byte4Array&>(array);
fw<<array.className()<<" "<<carray.size()<<" ";
writeArray(fw,carray.begin(),carray.end(),1);
return true;
}
break;
case(Array::ArrayType):
default:
return false;

View File

@ -2727,7 +2727,7 @@ osg::Node* DataSet::DestinationTile::createPolygonal()
sv.smooth(*geometry); // this will replace the normal vector with a new one
// now we have to reassign the normals back to the orignal pointer.
n = geometry->getNormalArray();
n = dynamic_cast<osg::Vec3Array*>(geometry->getNormalArray());
if (n.valid() && n->size()!=numVertices) n->resize(numVertices);
#endif
// now apply the normals computed through equalization

View File

@ -214,6 +214,7 @@ void Optimizer::optimize(osg::Node* node, unsigned int options)
osg::notify(osg::INFO)<<"Optimizer::optimize() doing MERGE_GEOMETRY"<<std::endl;
MergeGeometryVisitor mgv(this);
mgv.setTargetMaximumNumberOfVertices(10000);
node->accept(mgv);
}
@ -1561,10 +1562,27 @@ struct LessGeometry
{
// assumes that the bindings and arrays are set up correctly, this
// should be the case after running computeCorrectBindingsAndArraySizes();
const osg::Vec3& lhs_normal = (*(lhs->getNormalArray()))[0];
const osg::Vec3& rhs_normal = (*(rhs->getNormalArray()))[0];
if (lhs_normal<rhs_normal) return true;
if (rhs_normal<lhs_normal) return false;
const osg::Array* lhs_normalArray = lhs->getNormalArray();
const osg::Array* rhs_normalArray = rhs->getNormalArray();
if (lhs_normalArray->getType()<rhs_normalArray->getType()) return true;
if (rhs_normalArray->getType()<lhs_normalArray->getType()) return false;
switch(lhs_normalArray->getType())
{
case(osg::Array::Byte3ArrayType):
if ((*static_cast<const osg::Byte3Array*>(lhs_normalArray))[0]<(*static_cast<const osg::Byte3Array*>(rhs_normalArray))[0]) return true;
if ((*static_cast<const osg::Byte3Array*>(rhs_normalArray))[0]<(*static_cast<const osg::Byte3Array*>(lhs_normalArray))[0]) return false;
break;
case(osg::Array::Short3ArrayType):
if ((*static_cast<const osg::Short3Array*>(lhs_normalArray))[0]<(*static_cast<const osg::Short3Array*>(rhs_normalArray))[0]) return true;
if ((*static_cast<const osg::Short3Array*>(rhs_normalArray))[0]<(*static_cast<const osg::Short3Array*>(lhs_normalArray))[0]) return false;
break;
case(osg::Array::Vec3ArrayType):
if ((*static_cast<const osg::Vec3Array*>(lhs_normalArray))[0]<(*static_cast<const osg::Vec3Array*>(rhs_normalArray))[0]) return true;
if ((*static_cast<const osg::Vec3Array*>(rhs_normalArray))[0]<(*static_cast<const osg::Vec3Array*>(lhs_normalArray))[0]) return false;
break;
default:
break;
}
}
if (lhs->getColorBinding()==osg::Geometry::BIND_OVERALL)
@ -1888,6 +1906,13 @@ class MergeArrayVisitor : public osg::ArrayVisitor
virtual void apply(osg::Vec2Array& rhs) { _merge(rhs); }
virtual void apply(osg::Vec3Array& rhs) { _merge(rhs); }
virtual void apply(osg::Vec4Array& rhs) { _merge(rhs); }
virtual void apply(osg::Byte2Array& rhs) { _merge(rhs); }
virtual void apply(osg::Byte3Array& rhs) { _merge(rhs); }
virtual void apply(osg::Byte4Array& rhs) { _merge(rhs); }
virtual void apply(osg::Short2Array& rhs) { _merge(rhs); }
virtual void apply(osg::Short3Array& rhs) { _merge(rhs); }
virtual void apply(osg::Short4Array& rhs) { _merge(rhs); }
};
bool Optimizer::MergeGeometryVisitor::mergeGeometry(osg::Geometry& lhs,osg::Geometry& rhs)

View File

@ -534,7 +534,7 @@ void SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& mod
_collectOccludersVisistor->removeOccludedOccluders();
osg::notify(osg::INFO) << "finished searching for occluder - found "<<_collectOccludersVisistor->getCollectedOccluderSet().size()<<std::endl;
osg::notify(osg::DEBUG_INFO) << "finished searching for occluder - found "<<_collectOccludersVisistor->getCollectedOccluderSet().size()<<std::endl;
cullVisitor->getOccluderList().clear();
std::copy(_collectOccludersVisistor->getCollectedOccluderSet().begin(),_collectOccludersVisistor->getCollectedOccluderSet().end(), std::back_insert_iterator<CullStack::OccluderList>(cullVisitor->getOccluderList()));

View File

@ -425,7 +425,7 @@ void Tesselator::handleNewVertices(osg::Geometry& geom,VertexPtrToIndexMap &vert
osg::Vec3Array* normals = NULL;
if (geom.getNormalBinding()==osg::Geometry::BIND_PER_VERTEX)
{
normals = geom.getNormalArray();
normals = dynamic_cast<osg::Vec3Array*>(geom.getNormalArray());
}
typedef std::vector<osg::Array*> ArrayList;
@ -668,7 +668,7 @@ void Tesselator::collectTesselation(osg::Geometry &geom)
if (geom.getNormalBinding()==osg::Geometry::BIND_PER_PRIMITIVE ||
geom.getNormalBinding()==osg::Geometry::BIND_PER_PRIMITIVE_SET)
{
normals = geom.getNormalArray(); // GWM Sep 2002
normals = dynamic_cast<osg::Vec3Array*>(geom.getNormalArray()); // GWM Sep 2002
}
// GWM Dec 2003 - needed to add colours for extra facets
osg::Vec4Array* cols4 = NULL; // GWM Dec 2003 colours are vec4