diff --git a/include/osg/Geometry b/include/osg/Geometry index ea54f515b..63871ecf1 100644 --- a/include/osg/Geometry +++ b/include/osg/Geometry @@ -51,107 +51,230 @@ class SG_EXPORT Geometry : public Drawable BIND_PER_VERTEX }; - template - struct AttributeData +// template +// struct AttributeData +// { +// AttributeData(): +// binding(BIND_OFF), +// normalize(GL_FALSE), +// offset(0) {} +// +// AttributeData(T* a, AttributeBinding b, GLboolean n = GL_FALSE): +// array(a), +// indices(0), +// binding(b), +// normalize(n), +// offset(0) {} +// +// AttributeData(T* a, IndexArray* i, AttributeBinding b, GLboolean n = GL_FALSE): +// array(a), +// indices(i), +// binding(b), +// normalize(n), +// offset(0) {} +// +// // AttributeData(const AttributeData& rhs, const CopyOp& copyop=CopyOp::SHADLLOW_COPY): +// // array(dynamic_cast(copyop(rhs.array)), +// // indices(dynamic_cast(copyop(rhs.indices)), +// // binding(ths,binding), +// // normalize(GL_FALSE), +// // offset(rhs.offset) {} +// +// AttributeData& operator = (const AttributeData& rhs) +// { +// array = rhs.array; +// indices = rhs.indices; +// binding = rhs.binding; +// normalize = rhs.normalize; +// offset = rhs.offset; +// return *this; +// } +// +// ref_ptr array; +// ref_ptr indices; +// AttributeBinding binding; +// GLboolean normalize; +// mutable unsigned int offset; +// }; + +// typedef AttributeData ArrayData; + struct ArrayData { - AttributeData(): - _normalize(GL_FALSE), - _binding(BIND_OFF), - _offset(0) {} - - ref_ptr _array; - ref_ptr _indices; - AttributeBinding _binding; - - // only used in vertex attributes - GLboolean _normalize; - - unsigned int _offset; - }; - - - void setVertexArray(Array* array) { _vertexArray = array; dirtyDisplayList(); dirtyBound(); } - Array* getVertexArray() { return _vertexArray.get(); } - const Array* getVertexArray() const { return _vertexArray.get(); } - - void setVertexIndices(IndexArray* array) { _vertexIndices = array; computeFastPathsUsed(); dirtyDisplayList(); dirtyBound(); } - IndexArray* getVertexIndices() { return _vertexIndices.get(); } - const IndexArray* getVertexIndices() const { return _vertexIndices.get(); } - - - void setNormalBinding(AttributeBinding ab) { _normalBinding = ab; dirtyDisplayList(); computeFastPathsUsed(); } - AttributeBinding getNormalBinding() const { return _normalBinding; } - - void setNormalArray(Vec3Array* array) { _normalArray = array; if (!_normalArray.valid()) _normalBinding=BIND_OFF; computeFastPathsUsed(); dirtyDisplayList(); } - Vec3Array* getNormalArray() { return _normalArray.get(); } - const Vec3Array* getNormalArray() const { return _normalArray.get(); } - - void setNormalIndices(IndexArray* array) { _normalIndices = array; computeFastPathsUsed(); dirtyDisplayList(); } - IndexArray* getNormalIndices() { return _normalIndices.get(); } - const IndexArray* getNormalIndices() const { return _normalIndices.get(); } - - - void setColorBinding(AttributeBinding ab) { _colorBinding = ab; computeFastPathsUsed();} - AttributeBinding getColorBinding() const { return _colorBinding; } - - void setColorArray(Array* array) { _colorArray = array; if (!_colorArray.valid()) _colorBinding=BIND_OFF; computeFastPathsUsed(); dirtyDisplayList(); } - Array* getColorArray() { return _colorArray.get(); } - const Array* getColorArray() const { return _colorArray.get(); } - - void setColorIndices(IndexArray* array) { _colorIndices = array; computeFastPathsUsed(); dirtyDisplayList(); } - IndexArray* getColorIndices() { return _colorIndices.get(); } - const IndexArray* getColorIndices() const { return _colorIndices.get(); } - - - void setSecondaryColorBinding(AttributeBinding ab) { _secondaryColorBinding = ab; computeFastPathsUsed();} - AttributeBinding getSecondaryColorBinding() const { return _secondaryColorBinding; } - - void setSecondaryColorArray(Array* array) { _secondaryColorArray = array; if (!_secondaryColorArray.valid()) _secondaryColorBinding=BIND_OFF; computeFastPathsUsed(); dirtyDisplayList(); } - Array* getSecondaryColorArray() { return _secondaryColorArray.get(); } - const Array* getSecondaryColorArray() const { return _secondaryColorArray.get(); } - - void setSecondaryColorIndices(IndexArray* array) { _secondaryColorIndices = array; computeFastPathsUsed(); dirtyDisplayList(); } - IndexArray* getSecondaryColorIndices() { return _secondaryColorIndices.get(); } - const IndexArray* getSecondaryColorIndices() const { return _secondaryColorIndices.get(); } - - - void setFogCoordBinding(AttributeBinding ab) { _fogCoordBinding = ab; computeFastPathsUsed();} - AttributeBinding getFogCoordBinding() const { return _fogCoordBinding; } - - void setFogCoordArray(Array* array) { _fogCoordArray = array; if (!_fogCoordArray.valid()) _fogCoordBinding=BIND_OFF; dirtyDisplayList(); } - Array* getFogCoordArray() { return _fogCoordArray.get(); } - const Array* getFogCoordArray() const { return _fogCoordArray.get(); } - - - void setFogCoordIndices(IndexArray* array) { _fogCoordIndices = array; dirtyDisplayList(); } - IndexArray* getFogCoordIndices() { return _fogCoordIndices.get(); } - const IndexArray* getFogCoordIndices() const { return _fogCoordIndices.get(); } - - - struct ArrayPair - { - ArrayPair(): + ArrayData(): + binding(BIND_OFF), + normalize(GL_FALSE), offset(0) {} - ArrayPair(const ArrayPair& rhs): - first(rhs.first), - second(rhs.second), - offset(rhs.offset) {} + ArrayData(Array* a, AttributeBinding b, GLboolean n = GL_FALSE): + array(a), + indices(0), + binding(b), + normalize(n), + offset(0) {} - ArrayPair& operator = (const ArrayPair& rhs) + ArrayData(Array* a, IndexArray* i, AttributeBinding b, GLboolean n = GL_FALSE): + array(a), + indices(i), + binding(b), + normalize(n), + offset(0) {} + +// ArrayData(const ArrayData& rhs, const CopyOp& copyop=CopyOp::SHADLLOW_COPY): +// array(dynamic_cast(copyop(rhs.array)), +// indices(dynamic_cast(copyop(rhs.indices)), +// binding(ths,binding), +// normalize(GL_FALSE), +// offset(rhs.offset) {} + + ArrayData& operator = (const ArrayData& rhs) { - first = rhs.first; - second = rhs.second; + array = rhs.array; + indices = rhs.indices; + binding = rhs.binding; + normalize = rhs.normalize; offset = rhs.offset; return *this; } - ref_ptr first; - ref_ptr second; + ref_ptr array; + ref_ptr indices; + AttributeBinding binding; + GLboolean normalize; mutable unsigned int offset; }; - typedef std::vector< ArrayPair > TexCoordArrayList; + + struct Vec3ArrayData + { + Vec3ArrayData(): + binding(BIND_OFF), + normalize(GL_FALSE), + offset(0) {} + + Vec3ArrayData(Vec3Array* a, AttributeBinding b, GLboolean n = GL_FALSE): + array(a), + indices(0), + binding(b), + normalize(n), + offset(0) {} + Vec3ArrayData(Vec3Array* a, IndexArray* i, AttributeBinding b, GLboolean n = GL_FALSE): + array(a), + indices(i), + binding(b), + normalize(n), + offset(0) {} + +// Vec3ArrayData(const Vec3ArrayData& rhs, const CopyOp& copyop=CopyOp::SHADLLOW_COPY): +// array(dynamic_cast(copyop(rhs.array)), +// indices(dynamic_cast(copyop(rhs.indices)), +// binding(ths,binding), +// normalize(GL_FALSE), +// offset(rhs.offset) {} + + Vec3ArrayData& operator = (const Vec3ArrayData& rhs) + { + array = rhs.array; + indices = rhs.indices; + binding = rhs.binding; + normalize = rhs.normalize; + offset = rhs.offset; + return *this; + } + + ref_ptr array; + ref_ptr indices; + AttributeBinding binding; + GLboolean normalize; + mutable unsigned int offset; + }; + +// typedef AttributeData Vec3ArrayData; + + /** static ArrayData which is returned get getTexCoordData(i) const and getVertexAttribData(i) const + * when i is out of range.*/ + static const ArrayData s_InvalidArrayData; + + typedef std::vector< ArrayData > ArrayList; + + + void setVertexArray(Array* array) { _vertexData.array = array; dirtyDisplayList(); dirtyBound(); } + Array* getVertexArray() { return _vertexData.array.get(); } + const Array* getVertexArray() const { return _vertexData.array.get(); } + + void setVertexIndices(IndexArray* array) { _vertexData.indices = array; computeFastPathsUsed(); dirtyDisplayList(); dirtyBound(); } + IndexArray* getVertexIndices() { return _vertexData.indices.get(); } + const IndexArray* getVertexIndices() const { return _vertexData.indices.get(); } + + void setVertexData(const ArrayData& arrayData) { _vertexData = arrayData; } + ArrayData& getVertexData() { return _vertexData; } + const ArrayData& getVertexData() const { return _vertexData; } + + + 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 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 setColorBinding(AttributeBinding ab) { _colorData.binding = ab; computeFastPathsUsed();} + AttributeBinding getColorBinding() const { return _colorData.binding; } + + void setColorArray(Array* array) { _colorData.array = array; if (!_colorData.array.valid()) _colorData.binding=BIND_OFF; computeFastPathsUsed(); dirtyDisplayList(); } + Array* getColorArray() { return _colorData.array.get(); } + const Array* getColorArray() const { return _colorData.array.get(); } + + void setColorIndices(IndexArray* array) { _colorData.indices = array; computeFastPathsUsed(); dirtyDisplayList(); } + IndexArray* getColorIndices() { return _colorData.indices.get(); } + const IndexArray* getColorIndices() const { return _colorData.indices.get(); } + + void setColorData(const ArrayData& arrayData) { _colorData = arrayData; } + ArrayData& getColorData() { return _colorData; } + const ArrayData& getColorData() const { return _colorData; } + + + void setSecondaryColorBinding(AttributeBinding ab) { _secondaryColorData.binding = ab; computeFastPathsUsed();} + AttributeBinding getSecondaryColorBinding() const { return _secondaryColorData.binding; } + + void setSecondaryColorArray(Array* array) { _secondaryColorData.array = array; if (!_secondaryColorData.array.valid()) _secondaryColorData.binding=BIND_OFF; computeFastPathsUsed(); dirtyDisplayList(); } + Array* getSecondaryColorArray() { return _secondaryColorData.array.get(); } + const Array* getSecondaryColorArray() const { return _secondaryColorData.array.get(); } + + void setSecondaryColorIndices(IndexArray* array) { _secondaryColorData.indices = array; computeFastPathsUsed(); dirtyDisplayList(); } + IndexArray* getSecondaryColorIndices() { return _secondaryColorData.indices.get(); } + const IndexArray* getSecondaryColorIndices() const { return _secondaryColorData.indices.get(); } + + void setSecondaryColorData(const ArrayData& arrayData) { _secondaryColorData = arrayData; } + ArrayData& getSecondaryColorData() { return _secondaryColorData; } + const ArrayData& getSecondaryColorData() const { return _secondaryColorData; } + + + void setFogCoordBinding(AttributeBinding ab) { _fogCoordData.binding = ab; computeFastPathsUsed();} + AttributeBinding getFogCoordBinding() const { return _fogCoordData.binding; } + + void setFogCoordArray(Array* array) { _fogCoordData.array = array; if (!_fogCoordData.array.valid()) _fogCoordData.binding=BIND_OFF; dirtyDisplayList(); } + Array* getFogCoordArray() { return _fogCoordData.array.get(); } + const Array* getFogCoordArray() const { return _fogCoordData.array.get(); } + + void setFogCoordIndices(IndexArray* array) { _fogCoordData.indices = array; dirtyDisplayList(); } + IndexArray* getFogCoordIndices() { return _fogCoordData.indices.get(); } + const IndexArray* getFogCoordIndices() const { return _fogCoordData.indices.get(); } + + void setFogCoordData(const ArrayData& arrayData) { _fogCoordData = arrayData; } + ArrayData& setFogCoordData() { return _fogCoordData; } + const ArrayData& setFogCoordData() const { return _fogCoordData; } + + void setTexCoordArray(unsigned int unit,Array*); Array* getTexCoordArray(unsigned int unit); @@ -161,62 +284,37 @@ class SG_EXPORT Geometry : public Drawable IndexArray* getTexCoordIndices(unsigned int unit); const IndexArray* getTexCoordIndices(unsigned int unit) const; + void setTexCoordData(unsigned int index,const ArrayData& arrayData); + ArrayData& getTexCoordData(unsigned int index); + const ArrayData& getTexCoordData(unsigned int index) const; + unsigned int getNumTexCoordArrays() const { return _texCoordList.size(); } - TexCoordArrayList& getTexCoordArrayList() { return _texCoordList; } - const TexCoordArrayList& getTexCoordArrayList() const { return _texCoordList; } + ArrayList& getTexCoordArrayList() { return _texCoordList; } + const ArrayList& getTexCoordArrayList() const { return _texCoordList; } -#ifdef COMPILE_POSSIBLE_NEW_ARRAY_METHODS - void setArray(AttributeType type, Array* array); - Array* getArray(AttributeType type); - const Array* getArray(AttributeType type) const; - - void setIndices(AttributeType type, IndexArray* indices); - IndexArray* getIndices(AttributeType type); - const IndexArray* getIndices(AttributeType type) const; - - void setNormalize(AttributeType type, GLboolean normalize); - GLboolean getNormalize(AttributeType type) const; - - void setBinding(AttributeType type,AttributeBinding binding); - AttributeBinding getBinding(AttributeType type) const; - - - unsigned int getNumArrays() const { return _attributeList.size(); } - - AttributeData& getAttributeData(unsigned int type) { return _attributeList[type]; } - - const AttributeData& getAttributeData(unsigned int type) const { return _attributeList[type]; } - - typedef std::vector AttributeList; - - void setAttributeList(AttributeList& al) { _attributeList = al; } - - AttributeList& getAttributeList() { return _attributeList; } - - const AttributeList& getAttributeList() const { return _attributeList; } - -#endif - - typedef std::pair< GLboolean, ArrayPair > VertexAttribNormArrayPair; - typedef std::vector< VertexAttribNormArrayPair > VertexAttribArrayList; - typedef std::vector< AttributeBinding > VertexAttribBindingList; - - void setVertexAttribArray(unsigned int index,GLboolean normalize,Array* array,AttributeBinding ab=BIND_OFF); + void setVertexAttribArray(unsigned int index,Array* array); Array *getVertexAttribArray(unsigned int index); const Array *getVertexAttribArray(unsigned int index) const; - bool getVertexAttribNormalize(unsigned int index, GLboolean &ret) const; - bool getVertexAttribBinding(unsigned int index, AttributeBinding& ab) const; - void setVertexAttribIndices(unsigned int index,IndexArray* array); IndexArray* getVertexAttribIndices(unsigned int index); const IndexArray* getVertexAttribIndices(unsigned int index) const; + void setVertexAttribBinding(unsigned int index,AttributeBinding ab); + AttributeBinding getVertexAttribBinding(unsigned int index) const; + + void setVertexAttribNormalize(unsigned int index,GLboolean norm); + GLboolean getVertexAttribNormalize(unsigned int index) const; + + void setVertexAttribData(unsigned int index,const ArrayData& arrayData); + ArrayData& getVertexAttribData(unsigned int index); + const ArrayData& getVertexAttribData(unsigned int index) const; + unsigned int getNumVertexAttribArrays() const { return _vertexAttribList.size(); } - VertexAttribArrayList& getVertexAttribArrayList() { return _vertexAttribList; } - const VertexAttribArrayList& getVertexAttribArrayList() const { return _vertexAttribList; } + ArrayList& getVertexAttribArrayList() { return _vertexAttribList; } + const ArrayList& getVertexAttribArrayList() const { return _vertexAttribList; } @@ -315,38 +413,21 @@ class SG_EXPORT Geometry : public Drawable virtual ~Geometry(); PrimitiveSetList _primitives; - -#ifdef COMPILE_POSSIBLE_NEW_ARRAY_METHODS - AttributeList _attributeList; -#endif - ref_ptr _vertexArray; - ref_ptr _vertexIndices; - mutable unsigned int _vertexOffset; - mutable AttributeBinding _normalBinding; - ref_ptr _normalArray; - ref_ptr _normalIndices; - mutable unsigned int _normalOffset; - - mutable AttributeBinding _colorBinding; - ref_ptr _colorArray; - ref_ptr _colorIndices; - mutable unsigned int _colorOffset; - - mutable AttributeBinding _secondaryColorBinding; - ref_ptr _secondaryColorArray; - ref_ptr _secondaryColorIndices; - mutable unsigned int _secondaryColorOffset; + ArrayData _vertexData; - mutable AttributeBinding _fogCoordBinding; - ref_ptr _fogCoordArray; - ref_ptr _fogCoordIndices; - mutable unsigned int _fogCoordOffset; + Vec3ArrayData _normalData; + + ArrayData _colorData; + + ArrayData _secondaryColorData; + + ArrayData _fogCoordData; - TexCoordArrayList _texCoordList; + ArrayList _texCoordList; - VertexAttribArrayList _vertexAttribList; - mutable VertexAttribBindingList _vertexAttribBindingList; + ArrayList _vertexAttribList; + mutable bool _fastPath; diff --git a/src/osg/Geometry.cpp b/src/osg/Geometry.cpp index 9f170f683..aa410ec3c 100644 --- a/src/osg/Geometry.cpp +++ b/src/osg/Geometry.cpp @@ -15,6 +15,8 @@ using namespace osg; +const Geometry::ArrayData Geometry::s_InvalidArrayData; + #if 1 class DrawVertex { @@ -355,35 +357,17 @@ class DrawFogCoord : public osg::ConstValueVisitor Geometry::Geometry() { - _normalBinding = BIND_OFF; - _colorBinding = BIND_OFF; - _secondaryColorBinding = BIND_OFF; - _fogCoordBinding = BIND_OFF; - _fastPath = false; - _fastPathHint = true; } Geometry::Geometry(const Geometry& geometry,const CopyOp& copyop): Drawable(geometry,copyop), -#ifdef COMPILE_POSSIBLE_NEW_ARRAY_METHODS - _attributeList(geometry._attributeList), -#endif - _vertexArray((copyop(geometry._vertexArray.get()))), - _vertexIndices(dynamic_cast(copyop(geometry._vertexIndices.get()))), - _normalBinding(geometry._normalBinding), - _normalArray(dynamic_cast(copyop(geometry._normalArray.get()))), - _normalIndices(dynamic_cast(copyop(geometry._normalIndices.get()))), - _colorBinding(geometry._colorBinding), - _colorArray(copyop(geometry._colorArray.get())), - _colorIndices(dynamic_cast(copyop(geometry._colorIndices.get()))), - _secondaryColorBinding(geometry._secondaryColorBinding), - _secondaryColorArray(copyop(geometry._secondaryColorArray.get())), - _secondaryColorIndices(dynamic_cast(copyop(geometry._secondaryColorIndices.get()))), - _fogCoordBinding(geometry._fogCoordBinding), - _fogCoordArray(dynamic_cast(copyop(geometry._fogCoordArray.get()))), - _fogCoordIndices(dynamic_cast(copyop(geometry._fogCoordIndices.get()))), + _vertexData(geometry._vertexData), + _normalData(geometry._normalData), + _colorData(geometry._colorData), + _secondaryColorData(geometry._secondaryColorData), + _fogCoordData(geometry._fogCoordData), _fastPath(geometry._fastPath), _fastPathHint(geometry._fastPathHint) { @@ -395,14 +379,14 @@ Geometry::Geometry(const Geometry& geometry,const CopyOp& copyop): if (primitive) _primitives.push_back(primitive); } - for(TexCoordArrayList::const_iterator titr=geometry._texCoordList.begin(); + for(ArrayList::const_iterator titr=geometry._texCoordList.begin(); titr!=geometry._texCoordList.end(); ++titr) { _texCoordList.push_back(*titr); } - for(VertexAttribArrayList::const_iterator vitr=geometry._vertexAttribList.begin(); + for(ArrayList::const_iterator vitr=geometry._vertexAttribList.begin(); vitr!=geometry._vertexAttribList.end(); ++vitr) { @@ -415,153 +399,90 @@ Geometry::~Geometry() // no need to delete, all automatically handled by ref_ptr :-) } -void Geometry::setTexCoordArray(unsigned int unit,Array* array) +Geometry::ArrayData& Geometry::getTexCoordData(unsigned int unit) { if (_texCoordList.size()<=unit) _texCoordList.resize(unit+1); - _texCoordList[unit].first = array; + return _texCoordList[unit]; +} +const Geometry::ArrayData& Geometry::getTexCoordData(unsigned int unit) const +{ + if (_texCoordList.size()<=unit) + return s_InvalidArrayData; + + return _texCoordList[unit]; +} + +void Geometry::setTexCoordArray(unsigned int unit,Array* array) +{ + getTexCoordData(unit).array = array; + + computeFastPathsUsed(); dirtyDisplayList(); } Array* Geometry::getTexCoordArray(unsigned int unit) { - if (unit<_texCoordList.size()) return _texCoordList[unit].first.get(); + if (unit<_texCoordList.size()) return _texCoordList[unit].array.get(); else return 0; } const Array* Geometry::getTexCoordArray(unsigned int unit) const { - if (unit<_texCoordList.size()) return _texCoordList[unit].first.get(); + if (unit<_texCoordList.size()) return _texCoordList[unit].array.get(); else return 0; } void Geometry::setTexCoordIndices(unsigned int unit,IndexArray* array) { - if (_texCoordList.size()<=unit) - _texCoordList.resize(unit+1); - - _texCoordList[unit].second = array; + getTexCoordData(unit).indices = array; + computeFastPathsUsed(); dirtyDisplayList(); } IndexArray* Geometry::getTexCoordIndices(unsigned int unit) { - if (unit<_texCoordList.size()) return _texCoordList[unit].second.get(); + if (unit<_texCoordList.size()) return _texCoordList[unit].indices.get(); else return 0; } const IndexArray* Geometry::getTexCoordIndices(unsigned int unit) const { - if (unit<_texCoordList.size()) return _texCoordList[unit].second.get(); + if (unit<_texCoordList.size()) return _texCoordList[unit].indices.get(); else return 0; } -#ifdef COMPILE_POSSIBLE_NEW_ARRAY_METHODS - -void Geometry::setArray(AttributeType type,Array* array) -{ - if (_attributeList.size()<=type) - _attributeList.resize(type+1); - - _attributeList[type]._array = array; - - dirtyDisplayList(); -} - -Array* Geometry::getArray(AttributeType type) -{ - if (type<_attributeList.size()) return _attributeList[type]._array.get(); - else return 0; -} - -const Array* Geometry::getArray(AttributeType type) const -{ - if (type<_attributeList.size()) return _attributeList[type]._array.get(); - else return 0; -} - - -void Geometry::setIndices(AttributeType type,IndexArray* array) -{ - if (_attributeList.size()<=type) - _attributeList.resize(type+1); - - _attributeList[type]._indices = array; - - dirtyDisplayList(); -} - -IndexArray* Geometry::getIndices(AttributeType type) -{ - if (type<_attributeList.size()) return _attributeList[type]._indices.get(); - else return 0; -} - -const IndexArray* Geometry::getIndices(AttributeType type) const -{ - if (type<_attributeList.size()) return _attributeList[type]._indices.get(); - else return 0; -} - - -void Geometry::setNormalize(AttributeType type,GLboolean normalize) -{ - if (_attributeList.size()<=type) - _attributeList.resize(type+1); - - _attributeList[type]._normalize = normalize; - - dirtyDisplayList(); -} - -GLboolean Geometry::getNormalize(AttributeType type) const -{ - if (type<_attributeList.size()) return _attributeList[type]._normalize; - else return GL_FALSE; -} - -void Geometry::setBinding(AttributeType type,AttributeBinding binding) -{ - if (_attributeList.size()<=type) - _attributeList.resize(type+1); - - _attributeList[type]._binding = binding; - - dirtyDisplayList(); -} - -Geometry::AttributeBinding Geometry::getBinding(AttributeType type) const -{ - if (type<_attributeList.size()) return _attributeList[type]._binding; - else return BIND_OFF; -} - -#endif - -void Geometry::setVertexAttribArray(unsigned int index,GLboolean normalize,Array* array,AttributeBinding ab) +void Geometry::setVertexAttribData(unsigned int index, const Geometry::ArrayData& attrData) { if (_vertexAttribList.size()<=index) - { _vertexAttribList.resize(index+1); - _vertexAttribBindingList.resize(index+1); - } + + _vertexAttribList[index] = attrData; +} - _vertexAttribList[index].first = normalize; - _vertexAttribList[index].second.first = array; +Geometry::ArrayData& Geometry::getVertexAttribData(unsigned int index) +{ + if (_vertexAttribList.size()<=index) + _vertexAttribList.resize(index+1); + + return _vertexAttribList[index]; +} - if( index == 0 ) - { - // Force bind per vertex - _vertexAttribBindingList[index] = BIND_PER_VERTEX; - } - else - { - _vertexAttribBindingList[index] = ab; - } +const Geometry::ArrayData& Geometry::getVertexAttribData(unsigned int index) const +{ + if (_vertexAttribList.size()<=_vertexAttribList.size()) + return s_InvalidArrayData; + + return _vertexAttribList[index]; +} + +void Geometry::setVertexAttribArray(unsigned int index, Array* array) +{ + getVertexAttribData(index).array = array; computeFastPathsUsed(); dirtyDisplayList(); @@ -569,70 +490,63 @@ void Geometry::setVertexAttribArray(unsigned int index,GLboolean normalize,Array Array *Geometry::getVertexAttribArray(unsigned int index) { - if (index<_vertexAttribList.size()) return _vertexAttribList[index].second.first.get(); + if (index<_vertexAttribList.size()) return _vertexAttribList[index].array.get(); else return 0; } const Array *Geometry::getVertexAttribArray(unsigned int index) const { - if (index<_vertexAttribList.size()) return _vertexAttribList[index].second.first.get(); + if (index<_vertexAttribList.size()) return _vertexAttribList[index].array.get(); else return 0; } -bool Geometry::getVertexAttribBinding(unsigned int index, AttributeBinding& ab) const -{ - // AttributeBinding value goes in ab - // return true if index is valid, false otherwise - - if (index<_vertexAttribBindingList.size()) - { - ab = _vertexAttribBindingList[index]; - return true; - } - else - { - return false; - } -} - -bool Geometry::getVertexAttribNormalize(unsigned int index, GLboolean &ret) const -{ - // normalized value goes in ret - // return true if index is valid, false otherwise - - if (index<_vertexAttribList.size()) - { - ret = _vertexAttribList[index].first; - return true; - } - else - { - return false; - } -} - void Geometry::setVertexAttribIndices(unsigned int index,IndexArray* array) { - if (_vertexAttribList.size()<=index) - _vertexAttribList.resize(index+1); - - _vertexAttribList[index].second.second = array; + getVertexAttribData(index).indices = array; + computeFastPathsUsed(); dirtyDisplayList(); } IndexArray* Geometry::getVertexAttribIndices(unsigned int index) { - if (index<_vertexAttribList.size()) return _vertexAttribList[index].second.second.get(); + if (index<_vertexAttribList.size()) return _vertexAttribList[index].indices.get(); else return 0; } const IndexArray* Geometry::getVertexAttribIndices(unsigned int index) const { - if (index<_vertexAttribList.size()) return _vertexAttribList[index].second.second.get(); + if (index<_vertexAttribList.size()) return _vertexAttribList[index].indices.get(); else return 0; } +void Geometry::setVertexAttribBinding(unsigned int index,AttributeBinding ab) +{ + getVertexAttribData(index).binding = ab; + + computeFastPathsUsed(); + dirtyDisplayList(); +} + +Geometry::AttributeBinding Geometry::getVertexAttribBinding(unsigned int index) const +{ + if (index<_vertexAttribList.size()) return _vertexAttribList[index].binding; + else return BIND_OFF; +} + +void Geometry::setVertexAttribNormalize(unsigned int index,GLboolean norm) +{ + getVertexAttribData(index).normalize = norm; + + dirtyDisplayList(); +} + +GLboolean Geometry::getVertexAttribNormalize(unsigned int index) const +{ + if (index<_vertexAttribList.size()) return _vertexAttribList[index].normalize; + else return GL_FALSE; +} + bool Geometry::addPrimitiveSet(PrimitiveSet* primitiveset) { if (primitiveset) @@ -721,12 +635,12 @@ bool Geometry::computeFastPathsUsed() // // set up normals if required. // - if (!_normalArray.valid() || - _normalArray->empty() || - (_normalIndices.valid() && _normalIndices->getNumElements()==0) ) + if (!_normalData.array.valid() || + _normalData.array->empty() || + (_normalData.indices.valid() && _normalData.indices->getNumElements()==0) ) { // switch off if not supported or have a valid data. - _normalBinding = BIND_OFF; + _normalData.binding = BIND_OFF; } @@ -734,12 +648,12 @@ bool Geometry::computeFastPathsUsed() // // set up colours.. // - if (!_colorArray.valid() || - _colorArray->getNumElements()==0 || - (_colorIndices.valid() && _colorIndices->getNumElements()==0) ) + if (!_colorData.array.valid() || + _colorData.array->getNumElements()==0 || + (_colorData.indices.valid() && _colorData.indices->getNumElements()==0) ) { // switch off if not supported or have a valid data. - _colorBinding = BIND_OFF; + _colorData.binding = BIND_OFF; } @@ -748,12 +662,12 @@ bool Geometry::computeFastPathsUsed() // // Set up secondary color if required. // - if (!_secondaryColorArray.valid() || - _secondaryColorArray->getNumElements()==0 || - (_secondaryColorIndices.valid() && _secondaryColorIndices->getNumElements()==0) ) + if (!_secondaryColorData.array.valid() || + _secondaryColorData.array->getNumElements()==0 || + (_secondaryColorData.indices.valid() && _secondaryColorData.indices->getNumElements()==0) ) { // switch off if not supported or have a valid data. - _secondaryColorBinding = BIND_OFF; + _secondaryColorData.binding = BIND_OFF; } @@ -761,12 +675,12 @@ bool Geometry::computeFastPathsUsed() // // Set up fog coord if required. // - if (!_fogCoordArray.valid() || - _fogCoordArray->getNumElements()==0 || - (_fogCoordIndices.valid() && _fogCoordIndices->getNumElements()==0) ) + if (!_fogCoordData.array.valid() || + _fogCoordData.array->getNumElements()==0 || + (_fogCoordData.indices.valid() && _fogCoordData.indices->getNumElements()==0) ) { // switch off if not supported or have a valid data. - _fogCoordBinding = BIND_OFF; + _fogCoordData.binding = BIND_OFF; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -792,26 +706,26 @@ bool Geometry::computeFastPathsUsed() // check to see if fast path can be used. // _fastPath = true; - if (_vertexIndices.valid()) _fastPath = false; - else if (_normalBinding==BIND_PER_PRIMITIVE || (_normalBinding==BIND_PER_VERTEX && _normalIndices.valid())) _fastPath = false; - else if (_colorBinding==BIND_PER_PRIMITIVE || (_colorBinding==BIND_PER_VERTEX && _colorIndices.valid())) _fastPath = false; - else if (_secondaryColorBinding==BIND_PER_PRIMITIVE || (_secondaryColorBinding==BIND_PER_VERTEX && _secondaryColorIndices.valid())) _fastPath = false; - else if (_fogCoordBinding==BIND_PER_PRIMITIVE || (_fogCoordBinding==BIND_PER_VERTEX && _fogCoordIndices.valid())) _fastPath = false; + if (_vertexData.indices.valid()) _fastPath = false; + else if (_normalData.binding==BIND_PER_PRIMITIVE || (_normalData.binding==BIND_PER_VERTEX && _normalData.indices.valid())) _fastPath = false; + else if (_colorData.binding==BIND_PER_PRIMITIVE || (_colorData.binding==BIND_PER_VERTEX && _colorData.indices.valid())) _fastPath = false; + else if (_secondaryColorData.binding==BIND_PER_PRIMITIVE || (_secondaryColorData.binding==BIND_PER_VERTEX && _secondaryColorData.indices.valid())) _fastPath = false; + else if (_fogCoordData.binding==BIND_PER_PRIMITIVE || (_fogCoordData.binding==BIND_PER_VERTEX && _fogCoordData.indices.valid())) _fastPath = false; else { - for( unsigned int va = 0; va < _vertexAttribBindingList.size(); ++va ) + for( unsigned int va = 0; va < _vertexAttribList.size(); ++va ) { - if (_vertexAttribBindingList[va]==BIND_PER_PRIMITIVE) + if (_vertexAttribList[va].binding==BIND_PER_PRIMITIVE) { _fastPath = false; break; } else { - const Array * array = _vertexAttribList[va].second.first.get(); - const IndexArray * idxArray = _vertexAttribList[va].second.second.get(); + const Array * array = _vertexAttribList[va].array.get(); + const IndexArray * idxArray = _vertexAttribList[va].indices.get(); - if( _vertexAttribBindingList[va]==BIND_PER_VERTEX && + if( _vertexAttribList[va].binding==BIND_PER_VERTEX && array && array->getNumElements()>0 && idxArray && idxArray->getNumElements()>0 ) { @@ -828,12 +742,12 @@ bool Geometry::computeFastPathsUsed() // for(unsigned int unit=0;unit!=_texCoordList.size();++unit) { - const ArrayPair& texcoordPair = _texCoordList[unit]; - if (texcoordPair.first.valid() && texcoordPair.first->getNumElements()>0) + const ArrayData& texcoordData = _texCoordList[unit]; + if (texcoordData.array.valid() && texcoordData.array->getNumElements()>0) { - if (texcoordPair.second.valid()) + if (texcoordData.indices.valid()) { - if (texcoordPair.second->getNumElements()>0) + if (texcoordData.indices->getNumElements()>0) { _fastPath = false; break; @@ -860,34 +774,34 @@ void Geometry::drawImplementation(State& state) const const Extensions* extensions = getExtensions(state.getContextID(),true); - if( !( ( _vertexArray.valid() && _vertexArray->getNumElements() != 0 ) || + if( !( ( _vertexData.array.valid() && _vertexData.array->getNumElements() != 0 ) || ( _vertexAttribList.size() > 0 && - _vertexAttribList[0].second.first.valid() && - _vertexAttribList[0].second.first->getNumElements() != 0 ) ) ) + _vertexAttribList[0].array.valid() && + _vertexAttribList[0].array->getNumElements() != 0 ) ) ) { return; } - if( ( _vertexIndices.valid() && _vertexIndices->getNumElements() == 0 ) || + if( ( _vertexData.indices.valid() && _vertexData.indices->getNumElements() == 0 ) || ( _vertexAttribList.size() > 0 && - _vertexAttribList[0].second.second.valid() && - _vertexAttribList[0].second.second->getNumElements() == 0 ) ) + _vertexAttribList[0].indices.valid() && + _vertexAttribList[0].indices->getNumElements() == 0 ) ) { return; } - DrawNormal drawNormal(_normalArray.get(),_normalIndices.get()); - DrawColor drawColor(_colorArray.get(),_colorIndices.get()); - DrawSecondaryColor drawSecondaryColor(_secondaryColorArray.get(),_secondaryColorIndices.get(),extensions); + DrawNormal drawNormal(_normalData.array.get(),_normalData.indices.get()); + DrawColor drawColor(_colorData.array.get(),_colorData.indices.get()); + DrawSecondaryColor drawSecondaryColor(_secondaryColorData.array.get(),_secondaryColorData.indices.get(),extensions); - DrawFogCoord drawFogCoord(_fogCoordArray.get(),_fogCoordIndices.get(),extensions); + DrawFogCoord drawFogCoord(_fogCoordData.array.get(),_fogCoordData.indices.get(),extensions); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Set up secondary color if required. // - AttributeBinding secondaryColorBinding = _secondaryColorBinding; + AttributeBinding secondaryColorBinding = _secondaryColorData.binding; if (secondaryColorBinding!=BIND_OFF && !extensions->isSecondaryColorSupported()) { // switch off if not supported or have a valid data. @@ -899,28 +813,13 @@ void Geometry::drawImplementation(State& state) const // // Set up fog coord if required. // - AttributeBinding fogCoordBinding = _fogCoordBinding; + AttributeBinding fogCoordBinding = _fogCoordData.binding; if (fogCoordBinding!=BIND_OFF && !extensions->isFogCoordSupported()) { // switch off if not supported or have a valid data. fogCoordBinding = BIND_OFF; } - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // Set up vertex attrib if required. - // - if(!extensions->isVertexProgramSupported()) - { - for( unsigned int va = 0; va < _vertexAttribBindingList.size(); ++va ) - { - if (_vertexAttribBindingList[va]!=BIND_OFF) - { - _vertexAttribBindingList[va] = BIND_OFF; - } - } - } - unsigned int normalIndex = 0; unsigned int colorIndex = 0; unsigned int secondaryColorIndex = 0; @@ -929,11 +828,11 @@ void Geometry::drawImplementation(State& state) const #if USE_DEFAULT_NORMAL // if no values are defined for normal and color provide some defaults... - if (_normalBinding==BIND_OFF) glNormal3f(0.0f,0.0f,1.0f); + if (_normalData.binding==BIND_OFF) glNormal3f(0.0f,0.0f,1.0f); #endif #if USE_DEFAULT_COLOUR - if (_colorBinding==BIND_OFF) glColor4f(1.0f,1.0f,1.0f,1.0f); + if (_colorData.binding==BIND_OFF) glColor4f(1.0f,1.0f,1.0f,1.0f); #endif typedef std::vector< ref_ptr > DrawVertexAttribList; @@ -971,27 +870,27 @@ void Geometry::drawImplementation(State& state) const // compute total size and offsets required. unsigned int totalSize = 0; - _vertexOffset = 0; - if (_vertexArray.valid()) totalSize += _vertexArray->getTotalDataSize(); + _vertexData.offset = 0; + if (_vertexData.array.valid()) totalSize += _vertexData.array->getTotalDataSize(); - _normalOffset = totalSize; - if (_normalArray.valid()) totalSize += _normalArray->getTotalDataSize(); + _normalData.offset = totalSize; + if (_normalData.array.valid()) totalSize += _normalData.array->getTotalDataSize(); - _colorOffset = totalSize; - if (_colorArray.valid()) totalSize += _colorArray->getTotalDataSize(); + _colorData.offset = totalSize; + if (_colorData.array.valid()) totalSize += _colorData.array->getTotalDataSize(); - _secondaryColorOffset = totalSize; - if (_secondaryColorArray.valid()) totalSize += _secondaryColorArray->getTotalDataSize(); + _secondaryColorData.offset = totalSize; + if (_secondaryColorData.array.valid()) totalSize += _secondaryColorData.array->getTotalDataSize(); - _fogCoordOffset = totalSize; - if (_fogCoordArray.valid()) totalSize += _fogCoordArray->getTotalDataSize(); + _fogCoordData.offset = totalSize; + if (_fogCoordData.array.valid()) totalSize += _fogCoordData.array->getTotalDataSize(); unsigned int unit; for(unit=0;unit<_texCoordList.size();++unit) { _texCoordList[unit].offset = totalSize; - const Array* array = _texCoordList[unit].first.get(); + const Array* array = _texCoordList[unit].array.get(); if (array) totalSize += array->getTotalDataSize(); @@ -1003,11 +902,11 @@ void Geometry::drawImplementation(State& state) const for( index = 0; index < _vertexAttribList.size(); ++index ) { _texCoordList[unit].offset = totalSize; - const Array* array = _vertexAttribList[index].second.first.get(); - const AttributeBinding ab = _vertexAttribBindingList[index]; + const Array* array = _vertexAttribList[index].array.get(); + const AttributeBinding ab = _vertexAttribList[index].binding; if( ab == BIND_PER_VERTEX && array ) { - totalSize += array->getTotalDataSize(); + totalSize += array->getTotalDataSize(); } } } @@ -1020,24 +919,24 @@ void Geometry::drawImplementation(State& state) const // // copy the data // - if( _vertexArray.valid() ) - extensions->glBufferSubData(GL_ARRAY_BUFFER_ARB, _vertexOffset, _vertexArray->getTotalDataSize(),_vertexArray->getDataPointer()); + if( _vertexData.array.valid() ) + extensions->glBufferSubData(GL_ARRAY_BUFFER_ARB, _vertexData.offset, _vertexData.array->getTotalDataSize(),_vertexData.array->getDataPointer()); - if (_normalBinding==BIND_PER_VERTEX) - extensions->glBufferSubData(GL_ARRAY_BUFFER_ARB, _normalOffset, _normalArray->getTotalDataSize(),_normalArray->getDataPointer()); + if (_normalData.binding==BIND_PER_VERTEX) + extensions->glBufferSubData(GL_ARRAY_BUFFER_ARB, _normalData.offset, _normalData.array->getTotalDataSize(),_normalData.array->getDataPointer()); - if (_colorBinding==BIND_PER_VERTEX) - extensions->glBufferSubData(GL_ARRAY_BUFFER_ARB, _colorOffset, _colorArray->getTotalDataSize(),_colorArray->getDataPointer()); + if (_colorData.binding==BIND_PER_VERTEX) + extensions->glBufferSubData(GL_ARRAY_BUFFER_ARB, _colorData.offset, _colorData.array->getTotalDataSize(),_colorData.array->getDataPointer()); if (secondaryColorBinding==BIND_PER_VERTEX) - extensions->glBufferSubData(GL_ARRAY_BUFFER_ARB, _secondaryColorOffset, _secondaryColorArray->getTotalDataSize(),_secondaryColorArray->getDataPointer()); + extensions->glBufferSubData(GL_ARRAY_BUFFER_ARB, _secondaryColorData.offset, _secondaryColorData.array->getTotalDataSize(),_secondaryColorData.array->getDataPointer()); if (fogCoordBinding==BIND_PER_VERTEX) - extensions->glBufferSubData(GL_ARRAY_BUFFER_ARB, _fogCoordOffset, _fogCoordArray->getTotalDataSize(),_fogCoordArray->getDataPointer()); + extensions->glBufferSubData(GL_ARRAY_BUFFER_ARB, _fogCoordData.offset, _fogCoordData.array->getTotalDataSize(),_fogCoordData.array->getDataPointer()); for(unit=0;unit<_texCoordList.size();++unit) { - const Array* array = _texCoordList[unit].first.get(); + const Array* array = _texCoordList[unit].array.get(); if (array) extensions->glBufferSubData(GL_ARRAY_BUFFER_ARB, _texCoordList[unit].offset, array->getTotalDataSize(), array->getDataPointer()); } @@ -1047,12 +946,12 @@ void Geometry::drawImplementation(State& state) const unsigned int index; for( index = 0; index < _vertexAttribList.size(); ++index ) { - const Array* array = _vertexAttribList[index].second.first.get(); - const AttributeBinding ab = _vertexAttribBindingList[index]; + const Array* array = _vertexAttribList[index].array.get(); + const AttributeBinding ab = _vertexAttribList[index].binding; if( ab == BIND_PER_VERTEX && array ) { - extensions->glBufferSubData(GL_ARRAY_BUFFER_ARB, _vertexAttribList[index].second.offset, array->getTotalDataSize(), array->getDataPointer()); + extensions->glBufferSubData(GL_ARRAY_BUFFER_ARB, _vertexAttribList[index].offset, array->getTotalDataSize(), array->getDataPointer()); } } } @@ -1064,35 +963,35 @@ void Geometry::drawImplementation(State& state) const extensions->glBindBuffer(GL_ARRAY_BUFFER_ARB,buffer); - if( _vertexArray.valid() ) - state.setVertexPointer(_vertexArray->getDataSize(),_vertexArray->getDataType(),0,(const GLvoid*)_vertexOffset); + if( _vertexData.array.valid() ) + state.setVertexPointer(_vertexData.array->getDataSize(),_vertexData.array->getDataType(),0,(const GLvoid*)_vertexData.offset); else state.disableVertexPointer(); - if (_normalBinding==BIND_PER_VERTEX) - state.setNormalPointer(GL_FLOAT,0,(const GLvoid*)_normalOffset); + if (_normalData.binding==BIND_PER_VERTEX) + state.setNormalPointer(GL_FLOAT,0,(const GLvoid*)_normalData.offset); else state.disableNormalPointer(); - if (_colorBinding==BIND_PER_VERTEX) - state.setColorPointer(_colorArray->getDataSize(),_colorArray->getDataType(),0,(const GLvoid*)_colorOffset); + if (_colorData.binding==BIND_PER_VERTEX) + state.setColorPointer(_colorData.array->getDataSize(),_colorData.array->getDataType(),0,(const GLvoid*)_colorData.offset); else state.disableColorPointer(); if (secondaryColorBinding==BIND_PER_VERTEX) - state.setSecondaryColorPointer(_secondaryColorArray->getDataSize(),_secondaryColorArray->getDataType(),0,(const GLvoid*)_secondaryColorOffset); + state.setSecondaryColorPointer(_secondaryColorData.array->getDataSize(),_secondaryColorData.array->getDataType(),0,(const GLvoid*)_secondaryColorData.offset); else state.disableSecondaryColorPointer(); if (fogCoordBinding==BIND_PER_VERTEX) - state.setFogCoordPointer(GL_FLOAT,0,(const GLvoid*)_fogCoordOffset); + state.setFogCoordPointer(GL_FLOAT,0,(const GLvoid*)_fogCoordData.offset); else state.disableFogCoordPointer(); unsigned int unit; for(unit=0;unit<_texCoordList.size();++unit) { - const Array* array = _texCoordList[unit].first.get(); + const Array* array = _texCoordList[unit].array.get(); if (array) state.setTexCoordPointer(unit,array->getDataSize(),array->getDataType(),0,(const GLvoid*)_texCoordList[unit].offset); else @@ -1105,29 +1004,29 @@ void Geometry::drawImplementation(State& state) const unsigned int index; for( index = 0; index < _vertexAttribList.size(); ++index ) { - const Array* array = _vertexAttribList[index].second.first.get(); - const AttributeBinding ab = _vertexAttribBindingList[index]; + const Array* array = _vertexAttribList[index].array.get(); + const AttributeBinding ab = _vertexAttribList[index].binding; if( ab == BIND_PER_VERTEX && array ) { state.setVertexAttribPointer( index, array->getDataSize(), array->getDataType(), - _vertexAttribList[index].first, 0, (const GLvoid*)_vertexAttribList[index].second.offset ); + _vertexAttribList[index].normalize, 0, (const GLvoid*)_vertexAttribList[index].offset ); } else { if( array ) { - const IndexArray* indexArray = _vertexAttribList[index].second.second.get(); + const IndexArray* indexArray = _vertexAttribList[index].indices.get(); if( indexArray && indexArray->getNumElements() > 0 ) { drawVertexAttribMap[ab].push_back( - new DrawVertexAttrib(extensions,index,_vertexAttribList[index].first,array,indexArray) ); + new DrawVertexAttrib(extensions,index,_vertexAttribList[index].normalize,array,indexArray) ); } else { drawVertexAttribMap[ab].push_back( - new DrawVertexAttrib(extensions,index,_vertexAttribList[index].first,array,0) ); + new DrawVertexAttrib(extensions,index,_vertexAttribList[index].normalize,array,0) ); } } @@ -1151,35 +1050,35 @@ void Geometry::drawImplementation(State& state) const // // None Vertex Buffer Object path for defining vertex arrays. // - if( _vertexArray.valid() ) - state.setVertexPointer(_vertexArray->getDataSize(),_vertexArray->getDataType(),0,_vertexArray->getDataPointer()); + if( _vertexData.array.valid() ) + state.setVertexPointer(_vertexData.array->getDataSize(),_vertexData.array->getDataType(),0,_vertexData.array->getDataPointer()); else state.disableVertexPointer(); - if (_normalBinding==BIND_PER_VERTEX) - state.setNormalPointer(GL_FLOAT,0,_normalArray->getDataPointer()); + if (_normalData.binding==BIND_PER_VERTEX) + state.setNormalPointer(GL_FLOAT,0,_normalData.array->getDataPointer()); else state.disableNormalPointer(); - if (_colorBinding==BIND_PER_VERTEX) - state.setColorPointer(_colorArray->getDataSize(),_colorArray->getDataType(),0,_colorArray->getDataPointer()); + if (_colorData.binding==BIND_PER_VERTEX) + state.setColorPointer(_colorData.array->getDataSize(),_colorData.array->getDataType(),0,_colorData.array->getDataPointer()); else state.disableColorPointer(); if (secondaryColorBinding==BIND_PER_VERTEX) - state.setSecondaryColorPointer(_secondaryColorArray->getDataSize(),_secondaryColorArray->getDataType(),0,_secondaryColorArray->getDataPointer()); + state.setSecondaryColorPointer(_secondaryColorData.array->getDataSize(),_secondaryColorData.array->getDataType(),0,_secondaryColorData.array->getDataPointer()); else state.disableSecondaryColorPointer(); if (fogCoordBinding==BIND_PER_VERTEX) - state.setFogCoordPointer(GL_FLOAT,0,_fogCoordArray->getDataPointer()); + state.setFogCoordPointer(GL_FLOAT,0,_fogCoordData.array->getDataPointer()); else state.disableFogCoordPointer(); unsigned int unit; for(unit=0;unit<_texCoordList.size();++unit) { - const Array* array = _texCoordList[unit].first.get(); + const Array* array = _texCoordList[unit].array.get(); if (array) state.setTexCoordPointer(unit,array->getDataSize(),array->getDataType(),0,array->getDataPointer()); else @@ -1192,29 +1091,29 @@ void Geometry::drawImplementation(State& state) const unsigned int index; for( index = 0; index < _vertexAttribList.size(); ++index ) { - const Array* array = _vertexAttribList[index].second.first.get(); - const AttributeBinding ab = _vertexAttribBindingList[index]; + const Array* array = _vertexAttribList[index].array.get(); + const AttributeBinding ab = _vertexAttribList[index].binding; if( ab == BIND_PER_VERTEX && array ) { state.setVertexAttribPointer( index, array->getDataSize(), array->getDataType(), - _vertexAttribList[index].first, 0, array->getDataPointer() ); + _vertexAttribList[index].normalize, 0, array->getDataPointer() ); } else { if( array ) { - const IndexArray* indexArray = _vertexAttribList[index].second.second.get(); + const IndexArray* indexArray = _vertexAttribList[index].indices.get(); if( indexArray && indexArray->getNumElements() > 0 ) { drawVertexAttribMap[ab].push_back( - new DrawVertexAttrib(extensions,index,_vertexAttribList[index].first,array,indexArray) ); + new DrawVertexAttrib(extensions,index,_vertexAttribList[index].normalize,array,indexArray) ); } else { drawVertexAttribMap[ab].push_back( - new DrawVertexAttrib(extensions,index,_vertexAttribList[index].first,array,0) ); + new DrawVertexAttrib(extensions,index,_vertexAttribList[index].normalize,array,0) ); } } @@ -1234,8 +1133,8 @@ void Geometry::drawImplementation(State& state) const // // pass the overall binding values onto OpenGL. // - if (_normalBinding==BIND_OVERALL) drawNormal(normalIndex++); - if (_colorBinding==BIND_OVERALL) drawColor(colorIndex++); + if (_normalData.binding==BIND_OVERALL) drawNormal(normalIndex++); + if (_colorData.binding==BIND_OVERALL) drawColor(colorIndex++); if (secondaryColorBinding==BIND_OVERALL) drawSecondaryColor(secondaryColorIndex++); if (fogCoordBinding==BIND_OVERALL) drawFogCoord(fogCoordIndex++); if (handleVertexAttributes) @@ -1257,8 +1156,8 @@ void Geometry::drawImplementation(State& state) const ++itr) { - if (_normalBinding==BIND_PER_PRIMITIVE_SET) drawNormal(normalIndex++); - if (_colorBinding==BIND_PER_PRIMITIVE_SET) drawColor(colorIndex++); + if (_normalData.binding==BIND_PER_PRIMITIVE_SET) drawNormal(normalIndex++); + if (_colorData.binding==BIND_PER_PRIMITIVE_SET) drawColor(colorIndex++); if (secondaryColorBinding==BIND_PER_PRIMITIVE_SET) drawSecondaryColor(secondaryColorIndex++); if (fogCoordBinding==BIND_PER_PRIMITIVE_SET) drawFogCoord(fogCoordIndex++); if (handleVertexAttributes) @@ -1297,26 +1196,22 @@ void Geometry::drawImplementation(State& state) const // fallback if multitexturing not supported. ref_ptr drawTextCoord; - if (extensions->isMultiTexSupported()) + if (extensions->isMultiTexSupported() && _texCoordList.size()>1) { // multitexture supported.. for(unsigned int unit=0;unit!=_texCoordList.size();++unit) { - const ArrayPair& texcoordPair = _texCoordList[unit]; - if (texcoordPair.first.valid() && texcoordPair.first->getNumElements()>0) + const ArrayData& texcoordData = _texCoordList[unit]; + if (texcoordData.array.valid() && texcoordData.array->getNumElements()>0) { - if (texcoordPair.second.valid()) + if (texcoordData.indices.valid() && texcoordData.indices->getNumElements()>0) { - if (texcoordPair.second->getNumElements()>0) - { - drawTexCoordList.push_back(new DrawMultiTexCoord(GL_TEXTURE0+unit,texcoordPair.first.get(),texcoordPair.second.get(), - extensions)); - - } + drawTexCoordList.push_back(new DrawMultiTexCoord(GL_TEXTURE0+unit,texcoordData.array.get(),texcoordData.indices.get(), + extensions)); } else { - drawTexCoordList.push_back(new DrawMultiTexCoord(GL_TEXTURE0+unit,texcoordPair.first.get(),0, + drawTexCoordList.push_back(new DrawMultiTexCoord(GL_TEXTURE0+unit,texcoordData.array.get(),0, extensions)); } } @@ -1326,22 +1221,21 @@ void Geometry::drawImplementation(State& state) const { if (!_texCoordList.empty()) { - const ArrayPair& texcoordPair = _texCoordList[0]; - if (texcoordPair.first.valid() && texcoordPair.first->getNumElements()>0) + const ArrayData& texcoordData = _texCoordList[0]; + if (texcoordData.array.valid() && texcoordData.array->getNumElements()>0) { - if (texcoordPair.second.valid()) + if (texcoordData.indices.valid()) { - if (texcoordPair.second->getNumElements()>0) + if (texcoordData.indices->getNumElements()>0) { - drawTextCoord = new DrawTexCoord(texcoordPair.first.get(),texcoordPair.second.get()); + drawTextCoord = new DrawTexCoord(texcoordData.array.get(),texcoordData.indices.get()); } } else { - drawTextCoord = new DrawTexCoord(texcoordPair.first.get(),0); + drawTextCoord = new DrawTexCoord(texcoordData.array.get(),0); } } - } } @@ -1350,21 +1244,19 @@ void Geometry::drawImplementation(State& state) const unsigned int index; for( index = 1; index < _vertexAttribList.size(); ++index ) { - const Array* array = _vertexAttribList[index].second.first.get(); - - if( array && array->getNumElements() > 0 ) + const ArrayData& vertAttribData = _vertexAttribList[index]; + + if( vertAttribData.array.valid() && vertAttribData.array->getNumElements() > 0 ) { - const IndexArray* indexArray = _vertexAttribList[index].second.second.get(); - - if( indexArray && indexArray->getNumElements() > 0 ) + if( vertAttribData.indices.valid() && vertAttribData.indices->getNumElements() > 0 ) { - drawVertexAttribMap[_vertexAttribBindingList[index]].push_back( - new DrawVertexAttrib(extensions,index,_vertexAttribList[index].first,array,indexArray) ); + drawVertexAttribMap[vertAttribData.binding].push_back( + new DrawVertexAttrib(extensions,index,vertAttribData.normalize,vertAttribData.array.get(),vertAttribData.indices.get() )); } else { - drawVertexAttribMap[_vertexAttribBindingList[index]].push_back( - new DrawVertexAttrib(extensions,index,_vertexAttribList[index].first,array,0) ); + drawVertexAttribMap[vertAttribData.binding].push_back( + new DrawVertexAttrib(extensions,index,vertAttribData.normalize,vertAttribData.array.get(),0) ); } } } @@ -1379,8 +1271,8 @@ void Geometry::drawImplementation(State& state) const // // pass the overall binding values onto OpenGL. // - if (_normalBinding==BIND_OVERALL) drawNormal(normalIndex++); - if (_colorBinding==BIND_OVERALL) drawColor(colorIndex++); + if (_normalData.binding==BIND_OVERALL) drawNormal(normalIndex++); + if (_colorData.binding==BIND_OVERALL) drawColor(colorIndex++); if (secondaryColorBinding==BIND_OVERALL) drawSecondaryColor(secondaryColorIndex++); if (fogCoordBinding==BIND_OVERALL) drawFogCoord(fogCoordIndex++); if (handleVertexAttributes) @@ -1394,18 +1286,18 @@ void Geometry::drawImplementation(State& state) const } // set up vertex functor. - DrawVertex drawVertex(_vertexArray.get(),_vertexIndices.get()); + DrawVertex drawVertex(_vertexData.array.get(),_vertexData.indices.get()); bool useVertexAttrib = _vertexAttribList.size() > 0 && - _vertexAttribList[0].second.first.valid() && - _vertexAttribList[0].second.first->getNumElements(); + _vertexAttribList[0].array.valid() && + _vertexAttribList[0].indices->getNumElements(); ref_ptr drawVertexAttribZero; if( useVertexAttrib ) { drawVertexAttribZero = new DrawVertexAttrib(extensions,0, - _vertexAttribList[0].first,_vertexAttribList[0].second.first.get(), - _vertexAttribList[0].second.second.get()); + _vertexAttribList[0].normalize,_vertexAttribList[0].array.get(), + _vertexAttribList[0].indices.get()); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1416,8 +1308,8 @@ void Geometry::drawImplementation(State& state) const itr!=_primitives.end(); ++itr) { - if (_normalBinding==BIND_PER_PRIMITIVE_SET) drawNormal(normalIndex++); - if (_colorBinding==BIND_PER_PRIMITIVE_SET) drawColor(colorIndex++); + if (_normalData.binding==BIND_PER_PRIMITIVE_SET) drawNormal(normalIndex++); + if (_colorData.binding==BIND_PER_PRIMITIVE_SET) drawColor(colorIndex++); if (secondaryColorBinding==BIND_PER_PRIMITIVE_SET) drawSecondaryColor(secondaryColorIndex++); if (fogCoordBinding==BIND_PER_PRIMITIVE_SET) drawFogCoord(fogCoordIndex++); if (handleVertexAttributes) @@ -1464,8 +1356,8 @@ void Geometry::drawImplementation(State& state) const if ((primCount%primLength)==0) { - if (_normalBinding==BIND_PER_PRIMITIVE) drawNormal(normalIndex++); - if (_colorBinding==BIND_PER_PRIMITIVE) drawColor(colorIndex++); + if (_normalData.binding==BIND_PER_PRIMITIVE) drawNormal(normalIndex++); + if (_colorData.binding==BIND_PER_PRIMITIVE) drawColor(colorIndex++); if (secondaryColorBinding==BIND_PER_PRIMITIVE) drawSecondaryColor(secondaryColorIndex++); if (fogCoordBinding==BIND_PER_PRIMITIVE) drawFogCoord(fogCoordIndex++); if (handleVertexAttributes) @@ -1479,8 +1371,8 @@ void Geometry::drawImplementation(State& state) const } } - if (_normalBinding==BIND_PER_VERTEX) drawNormal(vindex); - if (_colorBinding==BIND_PER_VERTEX) drawColor(vindex); + if (_normalData.binding==BIND_PER_VERTEX) drawNormal(vindex); + if (_colorData.binding==BIND_PER_VERTEX) drawColor(vindex); if (secondaryColorBinding==BIND_PER_VERTEX) drawSecondaryColor(vindex); if (fogCoordBinding==BIND_PER_VERTEX) drawFogCoord(vindex); if (handleVertexAttributes) @@ -1533,8 +1425,8 @@ void Geometry::drawImplementation(State& state) const { if ((primCount%localPrimLength)==0) { - if (_normalBinding==BIND_PER_PRIMITIVE) drawNormal(normalIndex++); - if (_colorBinding==BIND_PER_PRIMITIVE) drawColor(colorIndex++); + if (_normalData.binding==BIND_PER_PRIMITIVE) drawNormal(normalIndex++); + if (_colorData.binding==BIND_PER_PRIMITIVE) drawColor(colorIndex++); if (secondaryColorBinding==BIND_PER_PRIMITIVE) drawSecondaryColor(secondaryColorIndex++); if (fogCoordBinding==BIND_PER_PRIMITIVE) drawFogCoord(fogCoordIndex++); if (handleVertexAttributes) @@ -1548,8 +1440,8 @@ void Geometry::drawImplementation(State& state) const } } - if (_normalBinding==BIND_PER_VERTEX) drawNormal(vindex); - if (_colorBinding==BIND_PER_VERTEX) drawColor(vindex); + if (_normalData.binding==BIND_PER_VERTEX) drawNormal(vindex); + if (_colorData.binding==BIND_PER_VERTEX) drawColor(vindex); if (secondaryColorBinding==BIND_PER_VERTEX) drawSecondaryColor(vindex); if (fogCoordBinding==BIND_PER_VERTEX) drawFogCoord(vindex); if (handleVertexAttributes) @@ -1601,8 +1493,8 @@ void Geometry::drawImplementation(State& state) const if ((primCount%primLength)==0) { - if (_normalBinding==BIND_PER_PRIMITIVE) drawNormal(normalIndex++); - if (_colorBinding==BIND_PER_PRIMITIVE) drawColor(colorIndex++); + if (_normalData.binding==BIND_PER_PRIMITIVE) drawNormal(normalIndex++); + if (_colorData.binding==BIND_PER_PRIMITIVE) drawColor(colorIndex++); if (secondaryColorBinding==BIND_PER_PRIMITIVE) drawSecondaryColor(secondaryColorIndex++); if (fogCoordBinding==BIND_PER_PRIMITIVE) drawFogCoord(fogCoordIndex++); if (handleVertexAttributes) @@ -1618,8 +1510,8 @@ void Geometry::drawImplementation(State& state) const unsigned int vindex=*primItr; - if (_normalBinding==BIND_PER_VERTEX) drawNormal(vindex); - if (_colorBinding==BIND_PER_VERTEX) drawColor(vindex); + if (_normalData.binding==BIND_PER_VERTEX) drawNormal(vindex); + if (_colorData.binding==BIND_PER_VERTEX) drawColor(vindex); if (secondaryColorBinding==BIND_PER_VERTEX) drawSecondaryColor(vindex); if (fogCoordBinding==BIND_PER_VERTEX) drawFogCoord(vindex); if ( extensions->isVertexProgramSupported() ) @@ -1668,8 +1560,8 @@ void Geometry::drawImplementation(State& state) const if ((primCount%primLength)==0) { - if (_normalBinding==BIND_PER_PRIMITIVE) drawNormal(normalIndex++); - if (_colorBinding==BIND_PER_PRIMITIVE) drawColor(colorIndex++); + if (_normalData.binding==BIND_PER_PRIMITIVE) drawNormal(normalIndex++); + if (_colorData.binding==BIND_PER_PRIMITIVE) drawColor(colorIndex++); if (secondaryColorBinding==BIND_PER_PRIMITIVE) drawSecondaryColor(secondaryColorIndex++); if (fogCoordBinding==BIND_PER_PRIMITIVE) drawFogCoord(fogCoordIndex++); if (handleVertexAttributes) @@ -1685,8 +1577,8 @@ void Geometry::drawImplementation(State& state) const unsigned int vindex=*primItr; - if (_normalBinding==BIND_PER_VERTEX) drawNormal(vindex); - if (_colorBinding==BIND_PER_VERTEX) drawColor(vindex); + if (_normalData.binding==BIND_PER_VERTEX) drawNormal(vindex); + if (_colorData.binding==BIND_PER_VERTEX) drawColor(vindex); if (secondaryColorBinding==BIND_PER_VERTEX) drawSecondaryColor(vindex); if (fogCoordBinding==BIND_PER_VERTEX) drawFogCoord(vindex); if (handleVertexAttributes) @@ -1735,8 +1627,8 @@ void Geometry::drawImplementation(State& state) const if ((primCount%primLength)==0) { - if (_normalBinding==BIND_PER_PRIMITIVE) drawNormal(normalIndex++); - if (_colorBinding==BIND_PER_PRIMITIVE) drawColor(colorIndex++); + if (_normalData.binding==BIND_PER_PRIMITIVE) drawNormal(normalIndex++); + if (_colorData.binding==BIND_PER_PRIMITIVE) drawColor(colorIndex++); if (secondaryColorBinding==BIND_PER_PRIMITIVE) drawSecondaryColor(secondaryColorIndex++); if (fogCoordBinding==BIND_PER_PRIMITIVE) drawFogCoord(fogCoordIndex++); if ( extensions->isVertexProgramSupported() ) @@ -1752,8 +1644,8 @@ void Geometry::drawImplementation(State& state) const unsigned int vindex=*primItr; - if (_normalBinding==BIND_PER_VERTEX) drawNormal(vindex); - if (_colorBinding==BIND_PER_VERTEX) drawColor(vindex); + if (_normalData.binding==BIND_PER_VERTEX) drawNormal(vindex); + if (_colorData.binding==BIND_PER_VERTEX) drawColor(vindex); if (secondaryColorBinding==BIND_PER_VERTEX) drawSecondaryColor(vindex); if (fogCoordBinding==BIND_PER_VERTEX) drawFogCoord(vindex); if ( extensions->isVertexProgramSupported() ) @@ -1836,13 +1728,13 @@ void Geometry::accept(AttributeFunctor& af) { AttrbuteFunctorArrayVisitor afav(af); - afav.applyArray(VERTICES,_vertexArray.get()); - afav.applyArray(NORMALS,_normalArray.get()); - afav.applyArray(COLORS,_colorArray.get()); + afav.applyArray(VERTICES,_vertexData.array.get()); + afav.applyArray(NORMALS,_normalData.array.get()); + afav.applyArray(COLORS,_colorData.array.get()); for(unsigned unit=0;unit<_texCoordList.size();++unit) { - afav.applyArray((AttributeType)(TEXTURE_COORDS_0+unit),_texCoordList[unit].first.get()); + afav.applyArray((AttributeType)(TEXTURE_COORDS_0+unit),_texCoordList[unit].array.get()); } } @@ -1885,35 +1777,35 @@ void Geometry::accept(ConstAttributeFunctor& af) const { ConstAttrbuteFunctorArrayVisitor afav(af); - afav.applyArray(VERTICES,_vertexArray.get()); - afav.applyArray(NORMALS,_normalArray.get()); - afav.applyArray(COLORS,_colorArray.get()); + afav.applyArray(VERTICES,_vertexData.array.get()); + afav.applyArray(NORMALS,_normalData.array.get()); + afav.applyArray(COLORS,_colorData.array.get()); for(unsigned unit=0;unit<_texCoordList.size();++unit) { - afav.applyArray((AttributeType)(TEXTURE_COORDS_0+unit),_texCoordList[unit].first.get()); + afav.applyArray((AttributeType)(TEXTURE_COORDS_0+unit),_texCoordList[unit].array.get()); } } void Geometry::accept(PrimitiveFunctor& functor) const { - if (!_vertexArray.valid() || _vertexArray->getNumElements()==0) return; + if (!_vertexData.array.valid() || _vertexData.array->getNumElements()==0) return; - if (!_vertexIndices.valid()) + if (!_vertexData.indices.valid()) { - switch(_vertexArray->getType()) + switch(_vertexData.array->getType()) { case(Array::Vec2ArrayType): - functor.setVertexArray(_vertexArray->getNumElements(),static_cast(_vertexArray->getDataPointer())); + functor.setVertexArray(_vertexData.array->getNumElements(),static_cast(_vertexData.array->getDataPointer())); break; case(Array::Vec3ArrayType): - functor.setVertexArray(_vertexArray->getNumElements(),static_cast(_vertexArray->getDataPointer())); + functor.setVertexArray(_vertexData.array->getNumElements(),static_cast(_vertexData.array->getDataPointer())); break; case(Array::Vec4ArrayType): - functor.setVertexArray(_vertexArray->getNumElements(),static_cast(_vertexArray->getDataPointer())); + functor.setVertexArray(_vertexData.array->getNumElements(),static_cast(_vertexData.array->getDataPointer())); break; default: - notify(WARN)<<"Warning: Geometry::accept(PrimtiveFunctor&) cannot handle Vertex Array type"<<_vertexArray->getType()<getType()<getType(); + Array::Type type = _vertexData.array->getType(); switch(type) { case(Array::Vec2ArrayType): - vec2Array = static_cast(_vertexArray.get()); + vec2Array = static_cast(_vertexData.array.get()); break; case(Array::Vec3ArrayType): - vec3Array = static_cast(_vertexArray.get()); + vec3Array = static_cast(_vertexData.array.get()); break; case(Array::Vec4ArrayType): - vec4Array = static_cast(_vertexArray.get()); + vec4Array = static_cast(_vertexData.array.get()); break; default: - notify(WARN)<<"Warning: Geometry::accept(PrimtiveFunctor&) cannot handle Vertex Array type"<<_vertexArray->getType()<getType()<index(vindex)]); + functor.vertex((*vec2Array)[_vertexData.indices->index(vindex)]); break; case(Array::Vec3ArrayType): - functor.vertex((*vec3Array)[_vertexIndices->index(vindex)]); + functor.vertex((*vec3Array)[_vertexData.indices->index(vindex)]); break; case(Array::Vec4ArrayType): - functor.vertex((*vec4Array)[_vertexIndices->index(vindex)]); + functor.vertex((*vec4Array)[_vertexData.indices->index(vindex)]); break; default: break; @@ -2002,13 +1894,13 @@ void Geometry::accept(PrimitiveFunctor& functor) const switch(type) { case(Array::Vec2ArrayType): - functor.vertex((*vec2Array)[_vertexIndices->index(vindex)]); + functor.vertex((*vec2Array)[_vertexData.indices->index(vindex)]); break; case(Array::Vec3ArrayType): - functor.vertex((*vec3Array)[_vertexIndices->index(vindex)]); + functor.vertex((*vec3Array)[_vertexData.indices->index(vindex)]); break; case(Array::Vec4ArrayType): - functor.vertex((*vec4Array)[_vertexIndices->index(vindex)]); + functor.vertex((*vec4Array)[_vertexData.indices->index(vindex)]); break; default: break; @@ -2035,13 +1927,13 @@ void Geometry::accept(PrimitiveFunctor& functor) const switch(type) { case(Array::Vec2ArrayType): - functor.vertex((*vec2Array)[_vertexIndices->index(vindex)]); + functor.vertex((*vec2Array)[_vertexData.indices->index(vindex)]); break; case(Array::Vec3ArrayType): - functor.vertex((*vec3Array)[_vertexIndices->index(vindex)]); + functor.vertex((*vec3Array)[_vertexData.indices->index(vindex)]); break; case(Array::Vec4ArrayType): - functor.vertex((*vec4Array)[_vertexIndices->index(vindex)]); + functor.vertex((*vec4Array)[_vertexData.indices->index(vindex)]); break; default: break; @@ -2064,13 +1956,13 @@ void Geometry::accept(PrimitiveFunctor& functor) const switch(type) { case(Array::Vec2ArrayType): - functor.vertex((*vec2Array)[_vertexIndices->index(vindex)]); + functor.vertex((*vec2Array)[_vertexData.indices->index(vindex)]); break; case(Array::Vec3ArrayType): - functor.vertex((*vec3Array)[_vertexIndices->index(vindex)]); + functor.vertex((*vec3Array)[_vertexData.indices->index(vindex)]); break; case(Array::Vec4ArrayType): - functor.vertex((*vec4Array)[_vertexIndices->index(vindex)]); + functor.vertex((*vec4Array)[_vertexData.indices->index(vindex)]); break; default: break; @@ -2093,13 +1985,13 @@ void Geometry::accept(PrimitiveFunctor& functor) const switch(type) { case(Array::Vec2ArrayType): - functor.vertex((*vec2Array)[_vertexIndices->index(vindex)]); + functor.vertex((*vec2Array)[_vertexData.indices->index(vindex)]); break; case(Array::Vec3ArrayType): - functor.vertex((*vec3Array)[_vertexIndices->index(vindex)]); + functor.vertex((*vec3Array)[_vertexData.indices->index(vindex)]); break; case(Array::Vec4ArrayType): - functor.vertex((*vec4Array)[_vertexIndices->index(vindex)]); + functor.vertex((*vec4Array)[_vertexData.indices->index(vindex)]); break; default: break; @@ -2121,66 +2013,66 @@ void Geometry::accept(PrimitiveFunctor& functor) const bool Geometry::verifyBindings() const { - switch(_normalBinding) + switch(_normalData.binding) { case(BIND_OFF): - if (_normalArray.valid() && _normalArray->getNumElements()>0) return false; + if (_normalData.array.valid() && _normalData.array->getNumElements()>0) return false; break; case(BIND_OVERALL): - if (!_normalArray.valid()) return false; - if (_normalArray->getNumElements()!=1) return false; + if (!_normalData.array.valid()) return false; + if (_normalData.array->getNumElements()!=1) return false; break; case(BIND_PER_PRIMITIVE_SET): - if (!_normalArray.valid()) return false; - if (_normalArray->getNumElements()!=_primitives.size()) return false; + if (!_normalData.array.valid()) return false; + if (_normalData.array->getNumElements()!=_primitives.size()) return false; break; case(BIND_PER_PRIMITIVE): - if (!_normalArray.valid()) return false; + if (!_normalData.array.valid()) return false; break; case(BIND_PER_VERTEX): - if (_vertexArray.valid()) + if (_vertexData.array.valid()) { - if (!_normalArray.valid()) return false; - if (_normalArray->getNumElements()!=_vertexArray->getNumElements()) return false; + if (!_normalData.array.valid()) return false; + if (_normalData.array->getNumElements()!=_vertexData.array->getNumElements()) return false; } - else if (_normalArray.valid() && _normalArray->getNumElements()==0) return false; + else if (_normalData.array.valid() && _normalData.array->getNumElements()==0) return false; break; } - switch(_colorBinding) + switch(_colorData.binding) { case(BIND_OFF): - if (_colorArray.valid() && _colorArray->getNumElements()>0) return false; + if (_colorData.array.valid() && _colorData.array->getNumElements()>0) return false; break; case(BIND_OVERALL): - if (!_colorArray.valid()) return false; - if (_colorArray->getNumElements()!=1) return false; + if (!_colorData.array.valid()) return false; + if (_colorData.array->getNumElements()!=1) return false; break; case(BIND_PER_PRIMITIVE_SET): - if (!_colorArray.valid()) return false; - if (_colorArray->getNumElements()!=_primitives.size()) return false; + if (!_colorData.array.valid()) return false; + if (_colorData.array->getNumElements()!=_primitives.size()) return false; break; case(BIND_PER_PRIMITIVE): - if (!_colorArray.valid()) return false; + if (!_colorData.array.valid()) return false; break; case(BIND_PER_VERTEX): - if (_vertexArray.valid()) + if (_vertexData.array.valid()) { - if (!_colorArray.valid()) return false; - if (_colorArray->getNumElements()!=_vertexArray->getNumElements()) return false; + if (!_colorData.array.valid()) return false; + if (_colorData.array->getNumElements()!=_vertexData.array->getNumElements()) return false; } - else if (_colorArray.valid() && _colorArray->getNumElements()==0) return false; + else if (_colorData.array.valid() && _colorData.array->getNumElements()==0) return false; break; } - for(TexCoordArrayList::const_iterator itr=_texCoordList.begin(); + for(ArrayList::const_iterator itr=_texCoordList.begin(); itr!=_texCoordList.end(); ++itr) { - const Array* array = itr->first.get(); - if (_vertexArray.valid()) + const Array* array = itr->array.get(); + if (_vertexData.array.valid()) { - if (array && array->getNumElements()!=_vertexArray->getNumElements()) return false; + if (array && array->getNumElements()!=_vertexData.array->getNumElements()) return false; } else if (array && array->getNumElements()==0) return false; } @@ -2192,17 +2084,17 @@ void Geometry::computeCorrectBindingsAndArraySizes() { if (verifyBindings()) return; - if (!_vertexArray.valid() || _vertexArray->getNumElements()==0) + if (!_vertexData.array.valid() || _vertexData.array->getNumElements()==0) { // no vertex array so switch everything off. - _vertexArray = 0; + _vertexData.array = 0; - _colorArray = 0; - _colorBinding = BIND_OFF; + _colorData.array = 0; + _colorData.binding = BIND_OFF; - _normalArray = 0; - _normalBinding = BIND_OFF; + _normalData.array = 0; + _normalData.binding = BIND_OFF; _texCoordList.clear(); @@ -2212,59 +2104,59 @@ void Geometry::computeCorrectBindingsAndArraySizes() } - switch(_normalBinding) + switch(_normalData.binding) { case(BIND_OFF): - if (_normalArray.valid()) _normalArray = 0; + if (_normalData.array.valid()) _normalData.array = 0; break; case(BIND_OVERALL): - if (!_normalArray.valid()) + if (!_normalData.array.valid()) { - _normalBinding = BIND_OFF; + _normalData.binding = BIND_OFF; } - else if (_normalArray->getNumElements()==0) + else if (_normalData.array->getNumElements()==0) { - _normalArray = 0; - _normalBinding = BIND_OFF; + _normalData.array = 0; + _normalData.binding = BIND_OFF; } - else if (_normalArray->getNumElements()>1) + else if (_normalData.array->getNumElements()>1) { // trim the array down to 1 element long. - _normalArray->erase(_normalArray->begin()+1,_normalArray->end()); + _normalData.array->erase(_normalData.array->begin()+1,_normalData.array->end()); } break; case(BIND_PER_PRIMITIVE_SET): - if (!_normalArray.valid()) + if (!_normalData.array.valid()) { - _normalBinding = BIND_OFF; + _normalData.binding = BIND_OFF; } - else if (_normalArray->getNumElements()<_primitives.size()) + else if (_normalData.array->getNumElements()<_primitives.size()) { - _normalArray = 0; - _normalBinding = BIND_OFF; + _normalData.array = 0; + _normalData.binding = BIND_OFF; } - else if (_normalArray->getNumElements()>_primitives.size()) + else if (_normalData.array->getNumElements()>_primitives.size()) { // trim the array down to size of the number of primitives. - _normalArray->erase(_normalArray->begin()+_primitives.size(),_normalArray->end()); + _normalData.array->erase(_normalData.array->begin()+_primitives.size(),_normalData.array->end()); } break; case(BIND_PER_PRIMITIVE): break; case(BIND_PER_VERTEX): - if (!_normalArray.valid()) + if (!_normalData.array.valid()) { - _normalBinding = BIND_OFF; + _normalData.binding = BIND_OFF; } - else if (_normalArray->getNumElements()<_vertexArray->getNumElements()) + else if (_normalData.array->getNumElements()<_vertexData.array->getNumElements()) { - _normalArray = 0; - _normalBinding = BIND_OFF; + _normalData.array = 0; + _normalData.binding = BIND_OFF; } - else if (_normalArray->getNumElements()>_vertexArray->getNumElements()) + else if (_normalData.array->getNumElements()>_vertexData.array->getNumElements()) { // trim the array down to size of the number of primitives. - _normalArray->erase(_normalArray->begin()+_vertexArray->getNumElements(),_normalArray->end()); + _normalData.array->erase(_normalData.array->begin()+_vertexData.array->getNumElements(),_normalData.array->end()); } break; } @@ -2460,24 +2352,18 @@ void Geometry::copyToAndOptimize(Geometry& target) } } - for(unsigned int vi=0;viaccept(eia); - getVertexAttribNormalize(vi,normalize); - target.setVertexAttribArray(vi,normalize,eia._targetArray,vab); - target.setVertexAttribIndices(vi,0); + ExpandIndexedArray eia(*arrayData.indices,target.getVertexAttribArray(vi)); + arrayData.array->accept(eia); + target.setVertexAttribData(vi,ArrayData(eia._targetArray, 0, arrayData.binding, arrayData.normalize)); } - else if (getVertexAttribArray(vi)) + else if (arrayData.array.valid()) { - GLboolean normalize; - getVertexAttribNormalize(vi,normalize); - target.setVertexAttribArray(vi,normalize,getVertexAttribArray(vi),vab); + target.setVertexAttribData(vi,arrayData); } } } diff --git a/src/osgFX/BumpMapping.cpp b/src/osgFX/BumpMapping.cpp index 007bd33cb..369e99a2f 100644 --- a/src/osgFX/BumpMapping.cpp +++ b/src/osgFX/BumpMapping.cpp @@ -586,11 +586,11 @@ void BumpMapping::prepareGeometry(osg::Geometry *geo) osg::ref_ptr tsg = new osgUtil::TangentSpaceGenerator; tsg->generate(geo, normalunit_); if (!geo->getVertexAttribArray(6)) - geo->setVertexAttribArray(6, false, tsg->getTangentArray(), osg::Geometry::BIND_PER_VERTEX); + geo->setVertexAttribData(6, osg::Geometry::ArrayData(tsg->getTangentArray(), osg::Geometry::BIND_PER_VERTEX,GL_TRUE)); if (!geo->getVertexAttribArray(7)) - geo->setVertexAttribArray(7, false, tsg->getBinormalArray(), osg::Geometry::BIND_PER_VERTEX); + geo->setVertexAttribData(7, osg::Geometry::ArrayData(tsg->getBinormalArray(), osg::Geometry::BIND_PER_VERTEX, GL_TRUE)); if (!geo->getVertexAttribArray(15)) - geo->setVertexAttribArray(15, false, tsg->getNormalArray(), osg::Geometry::BIND_PER_VERTEX); + geo->setVertexAttribData(15, osg::Geometry::ArrayData(tsg->getNormalArray(), osg::Geometry::BIND_PER_VERTEX, GL_TRUE)); } void BumpMapping::prepareNode(osg::Node *node) diff --git a/src/osgPlugins/dw/ReaderWriterDW.cpp b/src/osgPlugins/dw/ReaderWriterDW.cpp index c05193cf9..91271e666 100644 --- a/src/osgPlugins/dw/ReaderWriterDW.cpp +++ b/src/osgPlugins/dw/ReaderWriterDW.cpp @@ -642,9 +642,8 @@ public: nverts++; return nverts-1; } - void settmat(const Matrix *mx) { - tmat= new Matrix; - *tmat=*mx; + void settmat(const Matrix& mx) { + tmat= new Matrix(mx); } void makeuv(Vec2 &uv, const double pos[]) { Vec3 p; @@ -923,12 +922,16 @@ class ReaderWriterDW : public osgDB::ReaderWriter //nrecs=0; // a numVerts is followed by nv vetex postiions if (nexpected>0) obj.readOpenings(fp, nexpected); } else if( strncmp(buff,"UVW:",4)==0) { // texture application matrix - Matrix mx; - sscanf(buff+4,"%f %f %f%f %f %f%f %f %f", - &mx(0,0), &mx(0,1), &mx(0,2), - &mx(1,0), &mx(1,1), &mx(1,2), - &mx(2,0), &mx(2,1), &mx(2,2)); - obj.settmat(&mx); + double mx[3][2]; + sscanf(buff+4,"%lf %lf %lf %lf %lf %lf %lf %lf %lf", + &mx[0][0], &mx[0][1], &mx[0][2], + &mx[1][0], &mx[1][1], &mx[1][2], + &mx[2][0], &mx[2][1], &mx[2][2]); + + obj.settmat(Matrix(mx[0][0],mx[0][1],mx[0][2],0.0, + mx[1][0],mx[1][1],mx[1][2],0.0, + mx[2][0],mx[2][1],mx[2][2],0.0, + 0.0 ,0.0 ,0.0 ,1.0)); } } diff --git a/src/osgPlugins/ive/DataOutputStream.cpp b/src/osgPlugins/ive/DataOutputStream.cpp index d6f99590f..db8402a5c 100644 --- a/src/osgPlugins/ive/DataOutputStream.cpp +++ b/src/osgPlugins/ive/DataOutputStream.cpp @@ -92,12 +92,12 @@ void DataOutputStream::writeDouble(double d){ _ostream->write((char*)&d, DOUBLESIZE); } -void DataOutputStream::writeString(std::string s){ +void DataOutputStream::writeString(const std::string& s){ writeInt(s.size()); _ostream->write(s.c_str(), s.size()); } -void DataOutputStream::writeCharArray(char* data, int size){ +void DataOutputStream::writeCharArray(const char* data, int size){ _ostream->write(data, size); } @@ -144,50 +144,51 @@ void DataOutputStream::writeBinding(osg::Geometry::AttributeBinding b){ } } -void DataOutputStream::writeArray(osg::Array* a){ +void DataOutputStream::writeArray(const osg::Array* a){ switch(a->getType()){ case osg::Array::IntArrayType: writeChar((char)0); - writeIntArray(static_cast(a)); + writeIntArray(static_cast(a)); break; case osg::Array::UByteArrayType: writeChar((char)1); - writeUByteArray(static_cast(a)); + writeUByteArray(static_cast(a)); break; case osg::Array::UShortArrayType: writeChar((char)2); - writeUShortArray(static_cast(a)); + writeUShortArray(static_cast(a)); break; case osg::Array::UIntArrayType: writeChar((char)3); - writeUIntArray(static_cast(a)); + writeUIntArray(static_cast(a)); break; case osg::Array::UByte4ArrayType: writeChar((char)4); - writeUByte4Array(static_cast(a)); + writeUByte4Array(static_cast(a)); break; case osg::Array::FloatArrayType: writeChar((char)5); - writeFloatArray(static_cast(a)); + writeFloatArray(static_cast(a)); break; case osg::Array::Vec2ArrayType: writeChar((char)6); - writeVec2Array(static_cast(a)); + writeVec2Array(static_cast(a)); break; case osg::Array::Vec3ArrayType: writeChar((char)7); - writeVec3Array(static_cast(a)); + writeVec3Array(static_cast(a)); break; case osg::Array::Vec4ArrayType: writeChar((char)8); - writeVec4Array(static_cast(a)); + writeVec4Array(static_cast(a)); break; default: throw Exception("Unknown array type in DataOutputStream::writeArray()"); } } -void DataOutputStream::writeIntArray(osg::IntArray* a){ +void DataOutputStream::writeIntArray(const osg::IntArray* a) +{ int size = a->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; isize(); writeInt(size); for(int i=0;isize(); writeInt(size); for(int i = 0; i < size; i++){ @@ -252,7 +260,8 @@ void DataOutputStream::writeVec3Array(osg::Vec3Array* a){ } } -void DataOutputStream::writeVec4Array(osg::Vec4Array* a){ +void DataOutputStream::writeVec4Array(const osg::Vec4Array* a) +{ int size = a->size(); writeInt(size); for(int i=0;i(attribute)){ + if(dynamic_cast(attribute)){ ((ive::BlendFunc*)(attribute))->write(this); } // This is a Material - else if(dynamic_cast(attribute)){ + else if(dynamic_cast(attribute)){ ((ive::Material*)(attribute))->write(this); } // This is a CullFace - else if(dynamic_cast(attribute)){ + else if(dynamic_cast(attribute)){ ((ive::CullFace*)(attribute))->write(this); } // This is a PolygonOffset - else if(dynamic_cast(attribute)){ + else if(dynamic_cast(attribute)){ ((ive::PolygonOffset*)(attribute))->write(this); } - else if(dynamic_cast(attribute)){ + else if(dynamic_cast(attribute)){ ((ive::ShadeModel*)(attribute))->write(this); } - else if(dynamic_cast(attribute)){ + else if(dynamic_cast(attribute)){ ((ive::Point*)(attribute))->write(this); } // This is a Texture2D - else if(dynamic_cast(attribute)){ + else if(dynamic_cast(attribute)){ ((ive::Texture2D*)(attribute))->write(this); } // This is a TextureCubeMap - else if(dynamic_cast(attribute)){ + else if(dynamic_cast(attribute)){ ((ive::TextureCubeMap*)(attribute))->write(this); } // This is a TexEnv - else if(dynamic_cast(attribute)){ + else if(dynamic_cast(attribute)){ ((ive::TexEnv*)(attribute))->write(this); } // This is a TexEnvCombine - else if(dynamic_cast(attribute)){ + else if(dynamic_cast(attribute)){ ((ive::TexEnvCombine*)(attribute))->write(this); } // This is a TexGen - else if(dynamic_cast(attribute)){ + else if(dynamic_cast(attribute)){ ((ive::TexGen*)(attribute))->write(this); } else{ @@ -364,7 +373,7 @@ void DataOutputStream::writeStateAttribute(osg::StateAttribute* attribute) } } -void DataOutputStream::writeDrawable(osg::Drawable* drawable) +void DataOutputStream::writeDrawable(const osg::Drawable* drawable) { DrawableMap::iterator itr = _drawableMap.find(drawable); if (itr!=_drawableMap.end()) @@ -383,7 +392,7 @@ void DataOutputStream::writeDrawable(osg::Drawable* drawable) // write the id. writeInt(id); - if(dynamic_cast(drawable)) + if(dynamic_cast(drawable)) ((ive::Geometry*)(drawable))->write(this); else{ throw Exception("Unknown drawable in DataOutputStream::writeDrawable()"); @@ -391,7 +400,7 @@ void DataOutputStream::writeDrawable(osg::Drawable* drawable) } } -void DataOutputStream::writeNode(osg::Node* node) +void DataOutputStream::writeNode(const osg::Node* node) { NodeMap::iterator itr = _nodeMap.find(node); if (itr!=_nodeMap.end()) @@ -410,46 +419,48 @@ void DataOutputStream::writeNode(osg::Node* node) // write the id. writeInt(id); - if(dynamic_cast(node)){ + // this follow code *really* should use a NodeVisitor... Robert Osfield August 2003. + + if(dynamic_cast(node)){ ((ive::MatrixTransform*)(node))->write(this); } // else if(dynamic_cast(node)){ // ((ive::ViewPoint*)(node))->write(this); // } - else if(dynamic_cast(node)){ + else if(dynamic_cast(node)){ ((ive::PositionAttitudeTransform*)(node))->write(this); } - else if(dynamic_cast(node)){ + else if(dynamic_cast(node)){ ((ive::LightSource*)(node))->write(this); } - else if(dynamic_cast(node)){ + else if(dynamic_cast(node)){ ((ive::Sequence*)(node))->write(this); } - else if(dynamic_cast(node)){ + else if(dynamic_cast(node)){ ((ive::Impostor*)(node))->write(this); } - else if(dynamic_cast(node)){ + else if(dynamic_cast(node)){ ((ive::PagedLOD*)(node))->write(this); } - else if(dynamic_cast(node)){ + else if(dynamic_cast(node)){ ((ive::LOD*)(node))->write(this); } - else if(dynamic_cast(node)){ + else if(dynamic_cast(node)){ ((ive::Switch*)(node))->write(this); } - else if(dynamic_cast(node)){ + else if(dynamic_cast(node)){ ((ive::OccluderNode*)(node))->write(this); } - else if(dynamic_cast(node)){ + else if(dynamic_cast(node)){ ((ive::Transform*)(node))->write(this); } - else if(dynamic_cast(node)){ + else if(dynamic_cast(node)){ ((ive::Group*)(node))->write(this); } - else if(dynamic_cast(node)){ + else if(dynamic_cast(node)){ ((ive::Billboard*)(node))->write(this); } - else if(dynamic_cast(node)){ + else if(dynamic_cast(node)){ ((ive::Geode*)(node))->write(this); } else diff --git a/src/osgPlugins/ive/DataOutputStream.h b/src/osgPlugins/ive/DataOutputStream.h index e0ee5486c..67212608e 100644 --- a/src/osgPlugins/ive/DataOutputStream.h +++ b/src/osgPlugins/ive/DataOutputStream.h @@ -34,30 +34,30 @@ public: void writeFloat(float f); void writeLong(long l); void writeDouble(double d); - void writeString(std::string s); - void writeCharArray(char* data, int size); + 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 writeUByte4(const osg::UByte4& v); void writeQuat(const osg::Quat& q); void writeBinding(osg::Geometry::AttributeBinding b); - void writeArray(osg::Array* a); - void writeIntArray(osg::IntArray* a); - void writeUByteArray(osg::UByteArray* a); - void writeUShortArray(osg::UShortArray* a); - void writeUIntArray(osg::UIntArray* a); - void writeUByte4Array(osg::UByte4Array* a); - void writeFloatArray(osg::FloatArray* a); - void writeVec2Array(osg::Vec2Array* a); - void writeVec3Array(osg::Vec3Array* a); - void writeVec4Array(osg::Vec4Array* a); + 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 writeMatrix(const osg::Matrix& mat); - void writeStateSet(osg::StateSet* stateset); - void writeStateAttribute(osg::StateAttribute* sa); - void writeDrawable(osg::Drawable* sa); - void writeNode(osg::Node* sa); + void writeStateSet(const osg::StateSet* stateset); + void writeStateAttribute(const osg::StateAttribute* sa); + void writeDrawable(const osg::Drawable* sa); + void writeNode(const osg::Node* sa); // Set and get include image data in stream void setIncludeImageData(bool b) {_includeImageData=b;}; @@ -67,10 +67,10 @@ private: std::ostream* _ostream; // Container to map stateset uniques to their respective stateset. - typedef std::map StateSetMap; - typedef std::map StateAttributeMap; - typedef std::map DrawableMap; - typedef std::map NodeMap; + typedef std::map StateSetMap; + typedef std::map StateAttributeMap; + typedef std::map DrawableMap; + typedef std::map NodeMap; StateSetMap _stateSetMap; StateAttributeMap _stateAttributeMap; diff --git a/src/osgPlugins/ive/Geometry.cpp b/src/osgPlugins/ive/Geometry.cpp index 595386e94..c199f8944 100644 --- a/src/osgPlugins/ive/Geometry.cpp +++ b/src/osgPlugins/ive/Geometry.cpp @@ -109,18 +109,40 @@ void Geometry::write(DataOutputStream* out){ out->writeArray(getFogCoordIndices()); } // Write texture coord arrays - Geometry::TexCoordArrayList& tcal = getTexCoordArrayList(); + Geometry::ArrayList& tcal = getTexCoordArrayList(); out->writeInt(tcal.size()); - for(unsigned int j=0;jwriteBool(tcal[j].first.valid()); - if (tcal[j].first.valid()){ - out->writeArray(tcal[j].first.get()); + out->writeBool(tcal[j].array.valid()); + if (tcal[j].array.valid()){ + out->writeArray(tcal[j].array.get()); } // Write indices if valid - out->writeBool(tcal[j].second.valid()); - if (tcal[j].second.valid()){ - out->writeArray(tcal[j].second.get()); + out->writeBool(tcal[j].indices.valid()); + if (tcal[j].indices.valid()){ + out->writeArray(tcal[j].indices.get()); + } + } + + // Write vertex attributes + Geometry::ArrayList& vaal = getVertexAttribArrayList(); + out->writeInt(vaal.size()); + for(j=0;jwriteBinding(arrayData.binding); + out->writeBool(arrayData.normalize==GL_TRUE); + out->writeBool(arrayData.array.valid()); + if (arrayData.array.valid()){ + out->writeArray(arrayData.array.get()); + } + // Write indices if valid + out->writeBool(arrayData.indices.valid()); + if (arrayData.indices.valid()){ + out->writeArray(arrayData.indices.get()); } } } @@ -223,7 +245,8 @@ void Geometry::read(DataInputStream* in){ } // Read texture coord arrays size = in->readInt(); - for(i =0;ireadBool(); if(coords_valid) @@ -233,6 +256,25 @@ void Geometry::read(DataInputStream* in){ if(indices_valid) setTexCoordIndices(i, static_cast(in->readArray())); } + + // Read vertex attrib arrays + size = in->readInt(); + for(i =0;ireadBinding()); + setVertexAttribNormalize(i,in->readBool()?GL_TRUE:GL_FALSE); + + // Read coords if valid + bool coords_valid = in->readBool(); + if(coords_valid) + setVertexAttribArray(i, in->readArray()); + + // Read Indices if valid + bool indices_valid = in->readBool(); + if(indices_valid) + setVertexAttribIndices(i, static_cast(in->readArray())); + } + } else{ throw Exception("Geometry::read(): Expected Geometry identification."); diff --git a/src/osgPlugins/osg/Geometry.cpp b/src/osgPlugins/osg/Geometry.cpp index 06f962a9d..a13765447 100644 --- a/src/osgPlugins/osg/Geometry.cpp +++ b/src/osgPlugins/osg/Geometry.cpp @@ -313,6 +313,59 @@ bool Geometry_readLocalData(Object& obj, Input& fr) iteratorAdvanced = true; } + Geometry::AttributeBinding vertexAttribBinding=Geometry::BIND_OFF; + if (fr.matchSequence("VertexAttribBinding %i %s") && Geometry_matchBindingTypeStr(fr[2].getStr(),vertexAttribBinding)) + { + int unit=0; + fr[1].getInt(unit); + geom.setVertexAttribBinding(unit,vertexAttribBinding); + fr+=3; + iteratorAdvanced = true; + } + + if (fr.matchSequence("VertexAttribNormalize %i %s")) + { + int unit=0; + fr[1].getInt(unit); + + if (fr[2].matchString("TRUE")) + geom.setVertexAttribNormalize(unit,GL_TRUE); + else + geom.setVertexAttribNormalize(unit,GL_FALSE); + + fr+=3; + iteratorAdvanced = true; + } + + if (fr.matchSequence("VertexAttribArray %i")) + { + int unit=0; + fr[1].getInt(unit); + + fr+=2; + Array* vertexattrib = Array_readLocalData(fr); + if (vertexattrib) + { + geom.setVertexAttribArray(unit,vertexattrib); + } + iteratorAdvanced = true; + + } + + if (fr.matchSequence("VertexAttribIndices %i")) + { + int unit=0; + fr[1].getInt(unit); + + fr+=2; + IndexArray* indices = dynamic_cast(Array_readLocalData(fr)); + if (indices) + { + geom.setVertexAttribIndices(unit,indices); + } + iteratorAdvanced = true; + } + return iteratorAdvanced; } @@ -969,21 +1022,45 @@ bool Geometry_writeLocalData(const Object& obj, Output& fw) Array_writeLocalData(*geom.getFogCoordIndices(),fw); } - const Geometry::TexCoordArrayList& tcal=geom.getTexCoordArrayList(); - for(unsigned int i=0;i normal_tex = static_cast(fr.readObjectOfType(osgDB::type_wrapper())); if (normal_tex.valid()) { - myobj.setOverrideDiffuseTexture(normal_tex.get()); + myobj.setOverrideNormalMapTexture(normal_tex.get()); itAdvanced = true; } diff --git a/src/osgUtil/Tesselator.cpp b/src/osgUtil/Tesselator.cpp index 1b4e6fe11..06ecedfc1 100644 --- a/src/osgUtil/Tesselator.cpp +++ b/src/osgUtil/Tesselator.cpp @@ -265,14 +265,14 @@ void Tesselator::retesselatePolygons(osg::Geometry& geom) arrays.push_back(geom.getFogCoordArray()); } - osg::Geometry::TexCoordArrayList& tcal = geom.getTexCoordArrayList(); - for(osg::Geometry::TexCoordArrayList::iterator tcalItr=tcal.begin(); + osg::Geometry::ArrayList& tcal = geom.getTexCoordArrayList(); + for(osg::Geometry::ArrayList::iterator tcalItr=tcal.begin(); tcalItr!=tcal.end(); ++tcalItr) { - if (tcalItr->first.valid()) + if (tcalItr->array.valid()) { - arrays.push_back(tcalItr->first.get()); + arrays.push_back(tcalItr->array.get()); } }