diff --git a/AUTHORS.txt b/AUTHORS.txt index 249ccb534..d51c8a7d1 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -57,10 +57,10 @@ Ben Discoe Mike Weiblen - 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 - port to FreeBSD. @@ -132,7 +132,8 @@ Pavel Moloshtan - 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 - Support for multitextured flt files. @@ -151,7 +152,7 @@ Vladimir Vukicevic Rune Schmidt Jensen - dds loader. - - ive plugin. + - ive plugin. Romano José Magacho da Silva - pause/resume in osgGA::AnimationPathManipulator diff --git a/VisualStudio/osg/osg.dsp b/VisualStudio/osg/osg.dsp index 87427642c..44bde1dc5 100755 --- a/VisualStudio/osg/osg.dsp +++ b/VisualStudio/osg/osg.dsp @@ -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 diff --git a/include/osg/Array b/include/osg/Array index eda6c6f08..28352dc33 100644 --- a/include/osg/Array +++ b/include/osg/Array @@ -20,6 +20,13 @@ #include #include #include +#include +#include +#include +#include +#include +#include + #include #include @@ -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 typedef TemplateArray Vec3Array; typedef TemplateArray Vec4Array; +typedef TemplateArray Short2Array; +typedef TemplateArray Short3Array; +typedef TemplateArray Short4Array; +typedef TemplateArray Byte2Array; +typedef TemplateArray Byte3Array; +typedef TemplateArray 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 diff --git a/include/osg/Byte2 b/include/osg/Byte2 new file mode 100644 index 000000000..3db014992 --- /dev/null +++ b/include/osg/Byte2 @@ -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 false; + else return (_v[1]v._v[0]) return false; + else if (_v[1]v._v[1]) return false; + else return (_v[2]v._v[0]) return false; + else if (_v[1]v._v[1]) return false; + else if (_v[2]v._v[2]) return false; + else return (_v[3]v._v[0]) return false; + else return (_v[1]v._v[0]) return false; + else if (_v[1]v._v[1]) return false; + else return (_v[2]v._v[0]) return false; + else if (_v[1]v._v[1]) return false; + else if (_v[2]v._v[2]) return false; + else return (_v[3] #include +#include +#include +#include +#include +#include +#include #include #include #include @@ -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 ) diff --git a/src/osg/Array.cpp b/src/osg/Array.cpp index afa307d7d..51fb14638 100644 --- a/src/osg/Array.cpp +++ b/src/osg/Array.cpp @@ -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"; diff --git a/src/osg/Drawable.cpp b/src/osg/Drawable.cpp index 3a18f9d6f..d2ea9a2cf 100644 --- a/src/osg/Drawable.cpp +++ b/src/osg/Drawable.cpp @@ -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"<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 diff --git a/src/osg/Geometry.cpp b/src/osg/Geometry.cpp index 837b501d0..abfaeabfb 100644 --- a/src/osg/Geometry.cpp +++ b/src/osg/Geometry.cpp @@ -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(_normals); + if (_indices) glNormal3fv(normals[_indices->index(pos)].ptr()); + else glNormal3fv(normals[pos].ptr()); + } + break; + case (Array::Short3ArrayType): + { + const Short3Array& normals = *static_cast(_normals); + if (_indices) glNormal3sv(normals[_indices->index(pos)].ptr()); + else glNormal3sv(normals[pos].ptr()); + } + break; + case (Array::Short4ArrayType): + { + const Short4Array& normals = *static_cast(_normals); + if (_indices) glNormal3sv(normals[_indices->index(pos)].ptr()); + else glNormal3sv(normals[pos].ptr()); + } + break; + case (Array::Byte3ArrayType): + { + const Byte3Array& normals = *static_cast(_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(_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(); diff --git a/src/osgPlugins/ac3d/ac3d.cpp b/src/osgPlugins/ac3d/ac3d.cpp index f221c2f85..787952dce 100644 --- a/src/osgPlugins/ac3d/ac3d.cpp +++ b/src/osgPlugins/ac3d/ac3d.cpp @@ -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(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; igetNormalArray(); + osg::Vec3Array* normals = dynamic_cast(geom->getNormalArray()); if (normals) { if (_normal_binding==osg::Geometry::BIND_PER_VERTEX || _normal_binding==osg::Geometry::BIND_PER_PRIMITIVE) diff --git a/src/osgPlugins/ive/DataInputStream.cpp b/src/osgPlugins/ive/DataInputStream.cpp index ec44afc52..8c6906477 100644 --- a/src/osgPlugins/ive/DataInputStream.cpp +++ b/src/osgPlugins/ive/DataInputStream.cpp @@ -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() ["<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() ["<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() ["<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() ["<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() ["<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() ["<write((char*)&s, SHORTSIZE); + + if (_verboseOutput) std::cout<<"read/writeShort() ["<write((char*)&s, INTSIZE); @@ -264,6 +270,30 @@ void DataOutputStream::writeUByte4(const osg::UByte4& v){ if (_verboseOutput) std::cout<<"read/writeUByte4() ["<(a)); break; + case osg::Array::Short2ArrayType: + writeChar((char)9); + writeShort2Array(static_cast(a)); + break; + case osg::Array::Short3ArrayType: + writeChar((char)10); + writeShort3Array(static_cast(a)); + break; + case osg::Array::Short4ArrayType: + writeChar((char)11); + writeShort4Array(static_cast(a)); + break; + case osg::Array::Byte2ArrayType: + writeChar((char)12); + writeByte2Array(static_cast(a)); + break; + case osg::Array::Byte3ArrayType: + writeChar((char)13); + writeByte3Array(static_cast(a)); + break; + case osg::Array::Byte4ArrayType: + writeChar((char)14); + writeByte4Array(static_cast(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() ["<getNumElements(); + writeInt(size); + for(int i =0; igetNumElements(); + writeInt(size); + for(int i =0; igetNumElements(); + writeInt(size); + for(int i =0; igetNumElements(); + writeInt(size); + for(int i =0; igetNumElements(); + writeInt(size); + for(int i =0; igetNumElements(); + writeInt(size); + for(int i =0; i // for ofstream +#include // for ofstream #include #include #include @@ -23,106 +23,116 @@ #include #include -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 StateSetMap; - typedef std::map StateAttributeMap; - typedef std::map UniformMap; - typedef std::map ShaderMap; - typedef std::map DrawableMap; - typedef std::map ShapeMap; - typedef std::map NodeMap; + // Container to map stateset uniques to their respective stateset. + typedef std::map StateSetMap; + typedef std::map StateAttributeMap; + typedef std::map UniformMap; + typedef std::map ShaderMap; + typedef std::map DrawableMap; + typedef std::map ShapeMap; + typedef std::map 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 _options; + bool _includeImageData; + bool _includeExternalReferences; + bool _writeExternalReferenceFiles; + bool _useOriginalExternalReferences; + + osg::ref_ptr _options; }; } diff --git a/src/osgPlugins/ive/Geometry.cpp b/src/osgPlugins/ive/Geometry.cpp index 796c80279..fd189a444 100644 --- a/src/osgPlugins/ive/Geometry.cpp +++ b/src/osgPlugins/ive/Geometry.cpp @@ -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(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(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){ diff --git a/src/osgPlugins/ive/IveVersion.h b/src/osgPlugins/ive/IveVersion.h index 799ea6090..0e481cd0b 100644 --- a/src/osgPlugins/ive/IveVersion.h +++ b/src/osgPlugins/ive/IveVersion.h @@ -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 diff --git a/src/osgPlugins/osg/Geometry.cpp b/src/osgPlugins/osg/Geometry.cpp index 855b66862..ef304de5c 100644 --- a/src/osgPlugins/osg/Geometry.cpp +++ b/src/osgPlugins/osg/Geometry.cpp @@ -173,7 +173,7 @@ bool Geometry_readLocalData(Object& obj, Input& fr) { // post 0.9.3 releases. ++fr; - Vec3Array* normals = dynamic_cast(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(array); + fw<(array); + fw<(array); + fw<(array); + fw<(array); + fw<(array); + fw<getNormalArray(); + n = dynamic_cast(geometry->getNormalArray()); if (n.valid() && n->size()!=numVertices) n->resize(numVertices); #endif // now apply the normals computed through equalization diff --git a/src/osgUtil/Optimizer.cpp b/src/osgUtil/Optimizer.cpp index 89814f35e..37fc51f4d 100644 --- a/src/osgUtil/Optimizer.cpp +++ b/src/osgUtil/Optimizer.cpp @@ -214,6 +214,7 @@ void Optimizer::optimize(osg::Node* node, unsigned int options) osg::notify(osg::INFO)<<"Optimizer::optimize() doing MERGE_GEOMETRY"<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_normalgetNormalArray(); + const osg::Array* rhs_normalArray = rhs->getNormalArray(); + if (lhs_normalArray->getType()getType()) return true; + if (rhs_normalArray->getType()getType()) return false; + switch(lhs_normalArray->getType()) + { + case(osg::Array::Byte3ArrayType): + if ((*static_cast(lhs_normalArray))[0]<(*static_cast(rhs_normalArray))[0]) return true; + if ((*static_cast(rhs_normalArray))[0]<(*static_cast(lhs_normalArray))[0]) return false; + break; + case(osg::Array::Short3ArrayType): + if ((*static_cast(lhs_normalArray))[0]<(*static_cast(rhs_normalArray))[0]) return true; + if ((*static_cast(rhs_normalArray))[0]<(*static_cast(lhs_normalArray))[0]) return false; + break; + case(osg::Array::Vec3ArrayType): + if ((*static_cast(lhs_normalArray))[0]<(*static_cast(rhs_normalArray))[0]) return true; + if ((*static_cast(rhs_normalArray))[0]<(*static_cast(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) diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index b01d79533..a08897c4c 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -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()<getCollectedOccluderSet().size()<getOccluderList().clear(); std::copy(_collectOccludersVisistor->getCollectedOccluderSet().begin(),_collectOccludersVisistor->getCollectedOccluderSet().end(), std::back_insert_iterator(cullVisitor->getOccluderList())); diff --git a/src/osgUtil/Tesselator.cpp b/src/osgUtil/Tesselator.cpp index 9f809dad7..40e25b7b9 100644 --- a/src/osgUtil/Tesselator.cpp +++ b/src/osgUtil/Tesselator.cpp @@ -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(geom.getNormalArray()); } typedef std::vector 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(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