From 2812c503298ae2efd88de7df2d1d6f85e4574718 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 24 Sep 2003 15:54:22 +0000 Subject: [PATCH] Improved the Geometry::verifyBinding() and computeCorrectBindingsAndArraySizes() methods to check all atributes and to report warnigns when errors are detected. Added a CheckGeomtryVisitor to osgUtil::Optimizer to detect eroneous Geometry before rendering. --- include/osg/Geometry | 72 +- include/osgUtil/Optimizer | 16 +- src/osg/Geometry.cpp | 1501 +++++++++++++++++++------------------ src/osgUtil/Optimizer.cpp | 20 +- 4 files changed, 822 insertions(+), 787 deletions(-) diff --git a/include/osg/Geometry b/include/osg/Geometry index 63871ecf1..99b547651 100644 --- a/include/osg/Geometry +++ b/include/osg/Geometry @@ -51,53 +51,6 @@ class SG_EXPORT Geometry : public Drawable BIND_PER_VERTEX }; -// 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 { ArrayData(): @@ -119,13 +72,6 @@ class SG_EXPORT Geometry : public Drawable 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) { array = rhs.array; @@ -164,13 +110,6 @@ class SG_EXPORT Geometry : public Drawable 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; @@ -188,8 +127,6 @@ class SG_EXPORT Geometry : public Drawable 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; @@ -360,8 +297,8 @@ class SG_EXPORT Geometry : public Drawable bool computeFastPathsUsed(); - bool verifyBindings() const; + void computeCorrectBindingsAndArraySizes(); @@ -412,6 +349,13 @@ class SG_EXPORT Geometry : public Drawable virtual ~Geometry(); + bool verifyBindings(const ArrayData& arrayData) const; + bool verifyBindings(const Vec3ArrayData& arrayData) const; + + void computeCorrectBindingsAndArraySizes(ArrayData& arrayData,const char* arrayName); + void computeCorrectBindingsAndArraySizes(Vec3ArrayData& arrayData,const char* arrayName); + + PrimitiveSetList _primitives; ArrayData _vertexData; diff --git a/include/osgUtil/Optimizer b/include/osgUtil/Optimizer index 317dd2b7e..1f67f1673 100644 --- a/include/osgUtil/Optimizer +++ b/include/osgUtil/Optimizer @@ -43,11 +43,13 @@ class OSGUTIL_EXPORT Optimizer COMBINE_ADJACENT_LODS = 0x4, SHARE_DUPLICATE_STATE = 0x8, MERGE_GEOMETRY = 0x10, + CHECK_GEOMETRY = 0x20, ALL_OPTIMIZATIONS = FLATTEN_STATIC_TRANSFORMS | REMOVE_REDUNDANT_NODES | COMBINE_ADJACENT_LODS | SHARE_DUPLICATE_STATE | - MERGE_GEOMETRY + MERGE_GEOMETRY | + CHECK_GEOMETRY }; /** traverse the node and its subgraph with a series of optimization @@ -175,6 +177,18 @@ class OSGUTIL_EXPORT Optimizer }; + class OSGUTIL_EXPORT CheckGeometryVisitor : public osg::NodeVisitor + { + public: + + /// default to traversing all children. + CheckGeometryVisitor() : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN) {} + + virtual void apply(osg::Geode& geode) { checkGeode(geode); } + + static void checkGeode(osg::Geode& geode); + + }; class OSGUTIL_EXPORT MergeGeometryVisitor : public osg::NodeVisitor { diff --git a/src/osg/Geometry.cpp b/src/osg/Geometry.cpp index aa410ec3c..54f6f08f8 100644 --- a/src/osg/Geometry.cpp +++ b/src/osg/Geometry.cpp @@ -417,6 +417,7 @@ const Geometry::ArrayData& Geometry::getTexCoordData(unsigned int unit) const void Geometry::setTexCoordArray(unsigned int unit,Array* array) { + getTexCoordData(unit).binding = BIND_PER_VERTEX; getTexCoordData(unit).array = array; computeFastPathsUsed(); @@ -629,78 +630,6 @@ unsigned int Geometry::getPrimitiveSetIndex(const PrimitiveSet* primitiveset) co bool Geometry::computeFastPathsUsed() { - -/* - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // set up normals if required. - // - if (!_normalData.array.valid() || - _normalData.array->empty() || - (_normalData.indices.valid() && _normalData.indices->getNumElements()==0) ) - { - // switch off if not supported or have a valid data. - _normalData.binding = BIND_OFF; - } - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // set up colours.. - // - 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. - _colorData.binding = BIND_OFF; - } - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // Set up secondary color if required. - // - 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. - _secondaryColorData.binding = BIND_OFF; - } - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // Set up fog coord if required. - // - 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. - _fogCoordData.binding = BIND_OFF; - } - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // Set up vertex attrib if required. - // - for( unsigned int va = 0; va < _vertexAttribList.size(); ++va ) - { - const Array * array = _vertexAttribList[va].second.first.get(); - const IndexArray * idxArray = _vertexAttribList[va].second.second.get(); - - if (!array || - array->getNumElements()==0 || - (idxArray && idxArray->getNumElements()==0) ) - { - // switch off if not supported or have a valid data. - _vertexAttribBindingList[va] = BIND_OFF; - } - } -*/ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // check to see if fast path can be used. @@ -2011,70 +1940,261 @@ void Geometry::accept(PrimitiveFunctor& functor) const return; } -bool Geometry::verifyBindings() const -{ - switch(_normalData.binding) - { - case(BIND_OFF): - if (_normalData.array.valid() && _normalData.array->getNumElements()>0) return false; - break; - case(BIND_OVERALL): - if (!_normalData.array.valid()) return false; - if (_normalData.array->getNumElements()!=1) return false; - break; - case(BIND_PER_PRIMITIVE_SET): - if (!_normalData.array.valid()) return false; - if (_normalData.array->getNumElements()!=_primitives.size()) return false; - break; - case(BIND_PER_PRIMITIVE): - if (!_normalData.array.valid()) return false; - break; - case(BIND_PER_VERTEX): - if (_vertexData.array.valid()) - { - if (!_normalData.array.valid()) return false; - if (_normalData.array->getNumElements()!=_vertexData.array->getNumElements()) return false; - } - else if (_normalData.array.valid() && _normalData.array->getNumElements()==0) return false; - break; - } - - switch(_colorData.binding) - { - case(BIND_OFF): - if (_colorData.array.valid() && _colorData.array->getNumElements()>0) return false; - break; - case(BIND_OVERALL): - if (!_colorData.array.valid()) return false; - if (_colorData.array->getNumElements()!=1) return false; - break; - case(BIND_PER_PRIMITIVE_SET): - if (!_colorData.array.valid()) return false; - if (_colorData.array->getNumElements()!=_primitives.size()) return false; - break; - case(BIND_PER_PRIMITIVE): - if (!_colorData.array.valid()) return false; - break; - case(BIND_PER_VERTEX): - if (_vertexData.array.valid()) - { - if (!_colorData.array.valid()) return false; - if (_colorData.array->getNumElements()!=_vertexData.array->getNumElements()) return false; - } - else if (_colorData.array.valid() && _colorData.array->getNumElements()==0) return false; - break; - } - for(ArrayList::const_iterator itr=_texCoordList.begin(); - itr!=_texCoordList.end(); +unsigned int _computeNumberOfPrimtives(const osg::Geometry& geom) +{ + + unsigned int totalNumberOfPrimitives = 0; + + for(Geometry::PrimitiveSetList::const_iterator itr=geom.getPrimitiveSetList().begin(); + itr!=geom.getPrimitiveSetList().end(); ++itr) { - const Array* array = itr->array.get(); - if (_vertexData.array.valid()) + const PrimitiveSet* primitiveset = itr->get(); + GLenum mode=primitiveset->getMode(); + + unsigned int primLength; + switch(mode) { - if (array && array->getNumElements()!=_vertexData.array->getNumElements()) return false; + case(GL_POINTS): primLength=1; break; + case(GL_LINES): primLength=2; break; + case(GL_TRIANGLES): primLength=3; break; + case(GL_QUADS): primLength=4; break; + default: primLength=0; break; // compute later when =0. } - else if (array && array->getNumElements()==0) return false; + + // draw primtives by the more flexible "slow" path, + // sending OpenGL glBegin/glVertex.../glEnd(). + switch(primitiveset->getType()) + { + case(PrimitiveSet::DrawArrayLengthsPrimitiveType): + { + + const DrawArrayLengths* drawArrayLengths = static_cast(primitiveset); + for(DrawArrayLengths::const_iterator primItr=drawArrayLengths->begin(); + primItr!=drawArrayLengths->end(); + ++primItr) + { + if (primLength==0) totalNumberOfPrimitives += 1; + else totalNumberOfPrimitives = *primItr/primLength; + } + break; + } + default: + { + if (primLength==0) totalNumberOfPrimitives += 1; + else totalNumberOfPrimitives = primitiveset->getNumIndices()/primLength; + + } + } + } + + return totalNumberOfPrimitives; +} + +template +bool _verifyBindings(const osg::Geometry& geom, const A& arrayData) +{ + switch(arrayData.binding) + { + case(osg::Geometry::BIND_OFF): + if (arrayData.array.valid() && arrayData.array->getNumElements()>0) return false; + break; + case(osg::Geometry::BIND_OVERALL): + if (!arrayData.array.valid()) return false; + if (arrayData.array->getNumElements()!=1) return false; + break; + case(osg::Geometry::BIND_PER_PRIMITIVE_SET): + if (!arrayData.array.valid()) return false; + if (arrayData.array->getNumElements()!=geom.getPrimitiveSetList().size()) return false; + break; + case(osg::Geometry::BIND_PER_PRIMITIVE): + if (!arrayData.array.valid()) return false; + if (arrayData.array->getNumElements()!=_computeNumberOfPrimtives(geom)) return false; + break; + case(osg::Geometry::BIND_PER_VERTEX): + if (geom.getVertexArray()) + { + if (!arrayData.array.valid()) return false; + if (arrayData.array->getNumElements()!=geom.getVertexArray()->getNumElements()) return false; + } + else if (arrayData.array.valid() && arrayData.array->getNumElements()==0) return false; + break; + } + return true; +} + +template +bool _computeCorrectBindingsAndArraySizes(const osg::Geometry& geom, A& arrayData, const char* arrayName) +{ + if (!geom.getVertexArray() || geom.getVertexArray()==0) + { + if (arrayData.array.valid() || arrayData.array.valid() || arrayData.binding!=osg::Geometry::BIND_OFF) + { + arrayData.array = 0; + arrayData.indices = 0; + arrayData.binding = osg::Geometry::BIND_OFF; + notify(WARN)<<"Warning: in osg::Geometry::computeCorrectBindingsAndArraySizes() vertex array is empty but "<getNumElements()==0) + { + arrayData.array = 0; + arrayData.binding = osg::Geometry::BIND_OFF; + notify(WARN)<<"Warning: in osg::Geometry::computeCorrectBindingsAndArraySizes() "<getNumElements()>1) + { + notify(WARN)<<"Warning: in osg::Geometry::computeCorrectBindingsAndArraySizes() "<getNumElements()getNumElements()>geom.getPrimitiveSetList().size()) + { + notify(WARN)<<"Warning: in osg::Geometry::computeCorrectBindingsAndArraySizes() "<getNumElements()getNumElements()>numPrimitives) + { + notify(WARN)<<"Warning: in osg::Geometry::computeCorrectBindingsAndArraySizes() "<getNumElements()getNumElements()) + { + arrayData.array = 0; + arrayData.binding = osg::Geometry::BIND_OFF; + notify(WARN)<<"Warning: in osg::Geometry::computeCorrectBindingsAndArraySizes()"<getNumElements()>geom.getVertexArray()->getNumElements()) + { + notify(WARN)<<"Warning: in osg::Geometry::computeCorrectBindingsAndArraySizes() "<getNumElements()==0) + for(ArrayList::iterator titr=_texCoordList.begin(); + titr!=_texCoordList.end(); + ++titr) { - // no vertex array so switch everything off. - - _vertexData.array = 0; - - _colorData.array = 0; - _colorData.binding = BIND_OFF; - - _normalData.array = 0; - _normalData.binding = BIND_OFF; - - _texCoordList.clear(); - - notify(INFO)<<"Info: remove redundent attribute arrays from empty osg::Geometry"<getNumElements()==0) - { - _normalData.array = 0; - _normalData.binding = BIND_OFF; - } - else if (_normalData.array->getNumElements()>1) - { - // trim the array down to 1 element long. - _normalData.array->erase(_normalData.array->begin()+1,_normalData.array->end()); - } - break; - case(BIND_PER_PRIMITIVE_SET): - if (!_normalData.array.valid()) - { - _normalData.binding = BIND_OFF; - } - else if (_normalData.array->getNumElements()<_primitives.size()) - { - _normalData.array = 0; - _normalData.binding = BIND_OFF; - } - else if (_normalData.array->getNumElements()>_primitives.size()) - { - // trim the array down to size of the number of primitives. - _normalData.array->erase(_normalData.array->begin()+_primitives.size(),_normalData.array->end()); - } - break; - case(BIND_PER_PRIMITIVE): - break; - case(BIND_PER_VERTEX): - if (!_normalData.array.valid()) - { - _normalData.binding = BIND_OFF; - } - else if (_normalData.array->getNumElements()<_vertexData.array->getNumElements()) - { - _normalData.array = 0; - _normalData.binding = BIND_OFF; - } - else if (_normalData.array->getNumElements()>_vertexData.array->getNumElements()) - { - // trim the array down to size of the number of primitives. - _normalData.array->erase(_normalData.array->begin()+_vertexData.array->getNumElements(),_normalData.array->end()); - } - break; - } - - // TODO colours and tex coords. - + computeCorrectBindingsAndArraySizes(*vitr,"_vertAttribList[]"); + } } class ExpandIndexedArray : public osg::ConstArrayVisitor @@ -2430,601 +2489,601 @@ Geometry* osg::createTexturedQuadGeometry(const osg::Vec3& corner,const osg::Vec // Robert Osfield, August 2003. #if 0 -struct DrawAttributeArrays -{ - virtual bool valid() const = 0; - virtual void set(osg::Geometry* geometry) = 0; - virtual unsigned int draw(unsigned int index, unsigned int count) const = 0; -}; - -struct V3 -{ - V3():_array(0) {} - - bool valid() const { return _array!=0; } - - void set(osg::Geometry* geometry) + struct DrawAttributeArrays { - _array = 0; - osg::Array* array = geometry->getVertexArray(); - if (array && array->getType()==osg::Array::Vec3ArrayType) + virtual bool valid() const = 0; + virtual void set(osg::Geometry* geometry) = 0; + virtual unsigned int draw(unsigned int index, unsigned int count) const = 0; + }; + + struct V3 + { + V3():_array(0) {} + + bool valid() const { return _array!=0; } + + void set(osg::Geometry* geometry) { - osg::Vec3Array* vec3array = static_cast(array); - if (!vec3array->empty()) _array = &(vec3array->front()); - } - } - - inline void draw(unsigned int index) const - { - glVertex3fv(_array[index].ptr()); - } - - osg::Vec3* _array; -}; - -struct V3USI -{ - V3USI():_array(0),_indices(0) {} - - bool valid() const { return _array!=0 && _indices!=0; } - - void set(osg::Geometry* geometry) - { - _array = 0; - osg::Array* array = geometry->getVertexArray(); - if (array && array->getType()==osg::Array::Vec3ArrayType) - { - osg::Vec3Array* vec3array = static_cast(array); - if (!vec3array->empty()) _array = &(vec3array->front()); + _array = 0; + osg::Array* array = geometry->getVertexArray(); + if (array && array->getType()==osg::Array::Vec3ArrayType) + { + osg::Vec3Array* vec3array = static_cast(array); + if (!vec3array->empty()) _array = &(vec3array->front()); + } } - _indices = 0; - osg::IndexArray* indices = geometry->getVertexIndices(); - if (indices && indices->getType()==osg::Array::UShortArrayType) + inline void draw(unsigned int index) const { - osg::UShortArray* ushort3array = static_cast(array); - if (!ushort3array->empty()) _indices = &(ushort3array->front()); - } - } - - inline void draw(unsigned int index) const - { - glVertex3fv(_array[_indices[index]].ptr()); - } - - osg::Vec3* _array; - unsigned short* _indices; -}; - -////////////////////////////// - -struct N3 -{ - N3():_array(0) {} - - bool valid() const { return _array!=0; } - - void set(osg::Geometry* geometry) - { - _array = 0; - osg::Array* array = geometry->getVertexArray(); - if (array && array->getType()==osg::Array::Vec3ArrayType) - { - osg::Vec3Array* vec3array = static_cast(array); - if (!vec3array->empty()) _array = &(vec3array->front()); - } - } - - inline void draw(unsigned int index) const - { - glNormal3fv(_array[index].ptr()); - } - - osg::Vec3* _array; -}; - -struct N3USI -{ - N3USI():_array(0),_indices(0) {} - - bool valid() const { return _array!=0 && _indices!=0; } - - void set(osg::Geometry* geometry) - { - _array = 0; - osg::Array* array = geometry->getVertexArray(); - if (array && array->getType()==osg::Array::Vec3ArrayType) - { - osg::Vec3Array* vec3array = static_cast(array); - if (!vec3array->empty()) _array = &(vec3array->front()); + glVertex3fv(_array[index].ptr()); } - _indices = 0; - osg::IndexArray* indices = geometry->getVertexIndices(); - if (indices && indices->getType()==osg::Array::UShortArrayType) + osg::Vec3* _array; + }; + + struct V3USI + { + V3USI():_array(0),_indices(0) {} + + bool valid() const { return _array!=0 && _indices!=0; } + + void set(osg::Geometry* geometry) { - osg::UShortArray* ushortarray = static_cast(array); - if (!ushortarray->empty()) _indices = &(ushortarray->front()); - } - } - - inline void draw(unsigned int index) const - { - glNormal3fv(_array[_indices[index]].ptr()); - } - - osg::Vec3* _array; - unsigned short* _indices; -}; + _array = 0; + osg::Array* array = geometry->getVertexArray(); + if (array && array->getType()==osg::Array::Vec3ArrayType) + { + osg::Vec3Array* vec3array = static_cast(array); + if (!vec3array->empty()) _array = &(vec3array->front()); + } -////////////////////////////// - -struct C4 -{ - C4():_array(0) {} - - bool valid() const { return _array!=0; } - - void set(osg::Geometry* geometry) - { - _array = 0; - osg::Array* array = geometry->getColorArray(); - if (array && array->getType()==osg::Array::Vec4ArrayType) - { - osg::Vec4Array* vec4array = static_cast(array); - if (!vec4array->empty()) _array = &(vec4array->front()); - } - } - - inline void draw(unsigned int index) const - { - glVertex3fv(_array[index].ptr()); - } - - osg::Vec4* _array; -}; - -struct C4USI -{ - C4USI():_array(0),_indices(0) {} - - bool valid() const { return _array!=0 && _indices!=0; } - - void set(osg::Geometry* geometry) - { - _array = 0; - osg::Array* array = geometry->getColorArray(); - if (array && array->getType()==osg::Array::Vec4ArrayType) - { - osg::Vec4Array* vec4array = static_cast(array); - if (!vec4array->empty()) _array = &(vec4array->front()); + _indices = 0; + osg::IndexArray* indices = geometry->getVertexIndices(); + if (indices && indices->getType()==osg::Array::UShortArrayType) + { + osg::UShortArray* ushort3array = static_cast(array); + if (!ushort3array->empty()) _indices = &(ushort3array->front()); + } } - _indices = 0; - osg::IndexArray* indices = geometry->getColorIndices(); - if (indices && indices->getType()==osg::Array::UShortArrayType) + inline void draw(unsigned int index) const { - osg::UShortArray* ushortarray = static_cast(array); - if (!ushortarray->empty()) _indices = &(ushortarray->front()); - } - } - - inline void draw(unsigned int index) const - { - glColor4fv(_array[_indices[index]].ptr()); - } - - osg::Vec4* _array; - unsigned short* _indices; -}; - -////////////////////////////// - -struct T2 -{ - T2():_array(0) {} - - bool valid() const { return _array!=0; } - - void set(osg::Geometry* geometry) - { - _array = 0; - osg::Array* array = geometry->getTexCoordArray(0); - if (array && array->getType()==osg::Array::Vec2ArrayType) - { - osg::Vec2Array* vec2array = static_cast(array); - if (!vec2array->empty()) _array = &(vec2array->front()); - } - } - - inline void draw(unsigned int index) const - { - glTexCoord2fv(_array[index].ptr()); - } - - osg::Vec2* _array; -}; - -struct T2USI -{ - T2USI():_array(0),_indices(0) {} - - bool valid() const { return _array!=0 && _indices!=0; } - - void set(osg::Geometry* geometry) - { - _array = 0; - osg::Array* array = geometry->getTexCoordArray(0); - if (array && array->getType()==osg::Array::Vec2ArrayType) - { - osg::Vec2Array* vec2array = static_cast(array); - if (!vec2array->empty()) _array = &(vec2array->front()); + glVertex3fv(_array[_indices[index]].ptr()); } - _indices = 0; - osg::IndexArray* indices = geometry->getTexCoordIndices(0); - if (indices && indices->getType()==osg::Array::UShortArrayType) + osg::Vec3* _array; + unsigned short* _indices; + }; + + ////////////////////////////// + + struct N3 + { + N3():_array(0) {} + + bool valid() const { return _array!=0; } + + void set(osg::Geometry* geometry) { - osg::UShortArray* ushortarray = static_cast(array); - if (!ushortarray->empty()) _indices = &(ushortarray->front()); + _array = 0; + osg::Array* array = geometry->getVertexArray(); + if (array && array->getType()==osg::Array::Vec3ArrayType) + { + osg::Vec3Array* vec3array = static_cast(array); + if (!vec3array->empty()) _array = &(vec3array->front()); + } } - } - - inline void draw(unsigned int index) const - { - glTexCoord2fv(_array[_indices[index]].ptr()); - } - - osg::Vec2* _array; - unsigned short* _indices; -}; - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -template < class T1 > -struct DrawAttributeArrays_T : public DrawAttributeArrays -{ - DrawAttributeArrays_T(osg::Geometry* geometry) - { - - } - - virtual bool valid() const { return _t1.valid(); } - - virtual void set(osg::Geometry* geometry) - { - _t1.set(geometry); - } - - virtual unsigned int draw(unsigned int index, unsigned int count) const - { - for(unsigned int i=0;i -struct DrawAttributeArrays_TT : public DrawAttributeArrays -{ - DrawAttributeArrays_TT() - { - } - - virtual bool valid() const { return _t1.valid() && _t2.valid(); } + osg::Vec3* _array; + }; - virtual void set(osg::Geometry* geometry) + struct N3USI { - _t1.set(geometry); - _t2.set(geometry); - } - - virtual unsigned int draw(unsigned int index, unsigned int count) const - { - for(unsigned int i=0;igetVertexArray(); + if (array && array->getType()==osg::Array::Vec3ArrayType) + { + osg::Vec3Array* vec3array = static_cast(array); + if (!vec3array->empty()) _array = &(vec3array->front()); + } + + _indices = 0; + osg::IndexArray* indices = geometry->getVertexIndices(); + if (indices && indices->getType()==osg::Array::UShortArrayType) + { + osg::UShortArray* ushortarray = static_cast(array); + if (!ushortarray->empty()) _indices = &(ushortarray->front()); + } } - return index; - } - - T1 _t1; - T1 _t2; -}; -template < class T1, class T2, class T3 > -struct DrawAttributeArrays_TTT : public DrawAttributeArrays -{ - DrawAttributeArrays_TTT() - { - } - - virtual bool valid() const { return _t1.valid() && _t2.valid() && _t3.valid(); } - - virtual void set(osg::Geometry* geometry) - { - _t1.set(geometry); - _t2.set(geometry); - _t3.set(geometry); - } - - virtual unsigned int draw(unsigned int index, unsigned int count) const - { - for(unsigned int i=0;i -struct DrawAttributeArrays_TTTT : public DrawAttributeArrays -{ - DrawAttributeArrays_TTTT() - { - } - - virtual bool valid() const { return _t1.valid() && _t2.valid() && _t3.valid() && _t4.valid(); } + osg::Vec3* _array; + unsigned short* _indices; + }; - virtual void set(osg::Geometry* geometry) + ////////////////////////////// + + struct C4 { - _t1.set(geometry); - _t2.set(geometry); - _t3.set(geometry); - _t4.set(geometry); - } - - virtual unsigned int draw(unsigned int index, unsigned int count) const - { - for(unsigned int i=0;igetColorArray(); + if (array && array->getType()==osg::Array::Vec4ArrayType) + { + osg::Vec4Array* vec4array = static_cast(array); + if (!vec4array->empty()) _array = &(vec4array->front()); + } } - return index; - } - - T1 _t1; - T2 _t2; - T3 _t3; - T4 _t4; -}; -template < class T1, class T2 > -struct DrawAttributeArrays_TT_USI : public DrawAttributeArrays -{ - DrawAttributeArrays_TT_USI() - { - } - - virtual bool valid() const { return _t1.valid() && _t2.valid() && _indices!=0; } - - virtual void set(osg::Geometry* geometry) - { - _t1.set(geometry); - _t2.set(geometry); - - _indices = 0; - osg::IndexArray* indices = geometry->getVertexIndices(); - if (indices && indices->getType()==osg::Array::UShortArrayType) + inline void draw(unsigned int index) const { - osg::UShortArray* ushort3array = static_cast(array); - if (!ushort3array->empty()) _indices = &(ushort3array->front()); + glVertex3fv(_array[index].ptr()); } - } - - virtual unsigned int draw(unsigned int index, unsigned int count) const + + osg::Vec4* _array; + }; + + struct C4USI { - for(unsigned int i=0;igetColorArray(); + if (array && array->getType()==osg::Array::Vec4ArrayType) + { + osg::Vec4Array* vec4array = static_cast(array); + if (!vec4array->empty()) _array = &(vec4array->front()); + } + + _indices = 0; + osg::IndexArray* indices = geometry->getColorIndices(); + if (indices && indices->getType()==osg::Array::UShortArrayType) + { + osg::UShortArray* ushortarray = static_cast(array); + if (!ushortarray->empty()) _indices = &(ushortarray->front()); + } } - return index; - } - - T1 _t1; - T2 _t2; -}; -template < class T1, class T2, class T3 > -struct DrawAttributeArrays_TTT_USI : public DrawAttributeArrays -{ - DrawAttributeArrays_TTT_USI() - { - } - - virtual bool valid() const { return _t1.valid() && _t2.valid() && _t3.valid() && _indices!=0; } - - virtual void set(osg::Geometry* geometry) - { - _t1.set(geometry); - _t2.set(geometry); - _t3.set(geometry); - - _indices = 0; - osg::IndexArray* indices = geometry->getVertexIndices(); - if (indices && indices->getType()==osg::Array::UShortArrayType) + inline void draw(unsigned int index) const { - osg::UShortArray* ushort3array = static_cast(array); - if (!ushort3array->empty()) _indices = &(ushort3array->front()); + glColor4fv(_array[_indices[index]].ptr()); } - } - - virtual unsigned int draw(unsigned int index, unsigned int count) const + + osg::Vec4* _array; + unsigned short* _indices; + }; + + ////////////////////////////// + + struct T2 { - for(unsigned int i=0;igetTexCoordArray(0); + if (array && array->getType()==osg::Array::Vec2ArrayType) + { + osg::Vec2Array* vec2array = static_cast(array); + if (!vec2array->empty()) _array = &(vec2array->front()); + } } - return index; - } - - T1 _t1; - T2 _t2; - T3 _t3; -}; -template < class T1, class T2, class T3, class T4 > -struct DrawAttributeArrays_TTTT_USI : public DrawAttributeArrays -{ - DrawAttributeArrays_TTTT_USI() - { - } - - virtual bool valid() const { return _t1.valid() && _t2.valid() && _t3.valid() && _t4.valid() && _indices!=0; } - - virtual void set(osg::Geometry* geometry) - { - _t1.set(geometry); - _t2.set(geometry); - _t3.set(geometry); - _t4.set(geometry); - - _indices = 0; - osg::IndexArray* indices = geometry->getVertexIndices(); - if (indices && indices->getType()==osg::Array::UShortArrayType) + inline void draw(unsigned int index) const { - osg::UShortArray* ushort3array = static_cast(array); - if (!ushort3array->empty()) _indices = &(ushort3array->front()); + glTexCoord2fv(_array[index].ptr()); } - } - - virtual unsigned int draw(unsigned int index, unsigned int count) const + + osg::Vec2* _array; + }; + + struct T2USI { - for(unsigned int i=0;igetTexCoordArray(0); + if (array && array->getType()==osg::Array::Vec2ArrayType) + { + osg::Vec2Array* vec2array = static_cast(array); + if (!vec2array->empty()) _array = &(vec2array->front()); + } + + _indices = 0; + osg::IndexArray* indices = geometry->getTexCoordIndices(0); + if (indices && indices->getType()==osg::Array::UShortArrayType) + { + osg::UShortArray* ushortarray = static_cast(array); + if (!ushortarray->empty()) _indices = &(ushortarray->front()); + } } - return index; - } - - T1 _t1; - T2 _t2; - T3 _t3; - T4 _t4; -}; -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + inline void draw(unsigned int index) const + { + glTexCoord2fv(_array[_indices[index]].ptr()); + } + + osg::Vec2* _array; + unsigned short* _indices; + }; -// One attribute x 2 + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -typedef DrawAttributeArrays_T DrawAttributeArrays_V3; -typedef DrawAttributeArrays_T DrawAttributeArrays_V3i; + template < class T1 > + struct DrawAttributeArrays_T : public DrawAttributeArrays + { + DrawAttributeArrays_T(osg::Geometry* geometry) + { -// Two attributes x 15 + } -typedef DrawAttributeArrays_TT DrawAttributeArrays_N3V3; -typedef DrawAttributeArrays_TT DrawAttributeArrays_N3iV3; -typedef DrawAttributeArrays_TT DrawAttributeArrays_N3V3i; -typedef DrawAttributeArrays_TT DrawAttributeArrays_N3iV3i; + virtual bool valid() const { return _t1.valid(); } -typedef DrawAttributeArrays_TT_USI DrawAttributeArrays_N3V3_i; + virtual void set(osg::Geometry* geometry) + { + _t1.set(geometry); + } -typedef DrawAttributeArrays_TT DrawAttributeArrays_C4V3; -typedef DrawAttributeArrays_TT DrawAttributeArrays_C4iV3; -typedef DrawAttributeArrays_TT DrawAttributeArrays_C4V3i; -typedef DrawAttributeArrays_TT DrawAttributeArrays_C4iV3i; + virtual unsigned int draw(unsigned int index, unsigned int count) const + { + for(unsigned int i=0;i DrawAttributeArrays_C4V3_i; + T1 _t1; + }; -typedef DrawAttributeArrays_TT DrawAttributeArrays_T2V3; -typedef DrawAttributeArrays_TT DrawAttributeArrays_T2iV3; -typedef DrawAttributeArrays_TT DrawAttributeArrays_T2V3i; -typedef DrawAttributeArrays_TT DrawAttributeArrays_T2iV3i; + template < class T1, class T2 > + struct DrawAttributeArrays_TT : public DrawAttributeArrays + { + DrawAttributeArrays_TT() + { + } -typedef DrawAttributeArrays_TT_USI DrawAttributeArrays_T2V3_i; + virtual bool valid() const { return _t1.valid() && _t2.valid(); } -// Three attributes x 27 + virtual void set(osg::Geometry* geometry) + { + _t1.set(geometry); + _t2.set(geometry); + } -typedef DrawAttributeArrays_TTT DrawAttributeArrays_C4N3V3; -typedef DrawAttributeArrays_TTT DrawAttributeArrays_C4iN3V3; -typedef DrawAttributeArrays_TTT DrawAttributeArrays_C4N3iV3; -typedef DrawAttributeArrays_TTT DrawAttributeArrays_C4iN3iV3; + virtual unsigned int draw(unsigned int index, unsigned int count) const + { + for(unsigned int i=0;i DrawAttributeArrays_C4N3V3i; -typedef DrawAttributeArrays_TTT DrawAttributeArrays_C4iN3V3i; -typedef DrawAttributeArrays_TTT DrawAttributeArrays_C4N3iV3i; -typedef DrawAttributeArrays_TTT DrawAttributeArrays_C4iN3iV3i; + T1 _t1; + T1 _t2; + }; -typedef DrawAttributeArrays_TTT_USI DrawAttributeArrays_C4N3V3_i; + template < class T1, class T2, class T3 > + struct DrawAttributeArrays_TTT : public DrawAttributeArrays + { + DrawAttributeArrays_TTT() + { + } + + virtual bool valid() const { return _t1.valid() && _t2.valid() && _t3.valid(); } + + virtual void set(osg::Geometry* geometry) + { + _t1.set(geometry); + _t2.set(geometry); + _t3.set(geometry); + } + + virtual unsigned int draw(unsigned int index, unsigned int count) const + { + for(unsigned int i=0;i + struct DrawAttributeArrays_TTTT : public DrawAttributeArrays + { + DrawAttributeArrays_TTTT() + { + } + + virtual bool valid() const { return _t1.valid() && _t2.valid() && _t3.valid() && _t4.valid(); } + + virtual void set(osg::Geometry* geometry) + { + _t1.set(geometry); + _t2.set(geometry); + _t3.set(geometry); + _t4.set(geometry); + } + + virtual unsigned int draw(unsigned int index, unsigned int count) const + { + for(unsigned int i=0;i + struct DrawAttributeArrays_TT_USI : public DrawAttributeArrays + { + DrawAttributeArrays_TT_USI() + { + } + + virtual bool valid() const { return _t1.valid() && _t2.valid() && _indices!=0; } + + virtual void set(osg::Geometry* geometry) + { + _t1.set(geometry); + _t2.set(geometry); + + _indices = 0; + osg::IndexArray* indices = geometry->getVertexIndices(); + if (indices && indices->getType()==osg::Array::UShortArrayType) + { + osg::UShortArray* ushort3array = static_cast(array); + if (!ushort3array->empty()) _indices = &(ushort3array->front()); + } + } + + virtual unsigned int draw(unsigned int index, unsigned int count) const + { + for(unsigned int i=0;i + struct DrawAttributeArrays_TTT_USI : public DrawAttributeArrays + { + DrawAttributeArrays_TTT_USI() + { + } + + virtual bool valid() const { return _t1.valid() && _t2.valid() && _t3.valid() && _indices!=0; } + + virtual void set(osg::Geometry* geometry) + { + _t1.set(geometry); + _t2.set(geometry); + _t3.set(geometry); + + _indices = 0; + osg::IndexArray* indices = geometry->getVertexIndices(); + if (indices && indices->getType()==osg::Array::UShortArrayType) + { + osg::UShortArray* ushort3array = static_cast(array); + if (!ushort3array->empty()) _indices = &(ushort3array->front()); + } + } + + virtual unsigned int draw(unsigned int index, unsigned int count) const + { + for(unsigned int i=0;i + struct DrawAttributeArrays_TTTT_USI : public DrawAttributeArrays + { + DrawAttributeArrays_TTTT_USI() + { + } + + virtual bool valid() const { return _t1.valid() && _t2.valid() && _t3.valid() && _t4.valid() && _indices!=0; } + + virtual void set(osg::Geometry* geometry) + { + _t1.set(geometry); + _t2.set(geometry); + _t3.set(geometry); + _t4.set(geometry); + + _indices = 0; + osg::IndexArray* indices = geometry->getVertexIndices(); + if (indices && indices->getType()==osg::Array::UShortArrayType) + { + osg::UShortArray* ushort3array = static_cast(array); + if (!ushort3array->empty()) _indices = &(ushort3array->front()); + } + } + + virtual unsigned int draw(unsigned int index, unsigned int count) const + { + for(unsigned int i=0;i DrawAttributeArrays_T2N3V3; -typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2iN3V3; -typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2iN3iV3; -typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2N3iV3; + // One attribute x 2 -typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2N3V3i; -typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2iN3V3i; -typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2iN3iV3i; -typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2N3iV3i; + typedef DrawAttributeArrays_T DrawAttributeArrays_V3; + typedef DrawAttributeArrays_T DrawAttributeArrays_V3i; -typedef DrawAttributeArrays_TTT_USI DrawAttributeArrays_T2N3V3_i; + // Two attributes x 15 + + typedef DrawAttributeArrays_TT DrawAttributeArrays_N3V3; + typedef DrawAttributeArrays_TT DrawAttributeArrays_N3iV3; + typedef DrawAttributeArrays_TT DrawAttributeArrays_N3V3i; + typedef DrawAttributeArrays_TT DrawAttributeArrays_N3iV3i; + + typedef DrawAttributeArrays_TT_USI DrawAttributeArrays_N3V3_i; + + typedef DrawAttributeArrays_TT DrawAttributeArrays_C4V3; + typedef DrawAttributeArrays_TT DrawAttributeArrays_C4iV3; + typedef DrawAttributeArrays_TT DrawAttributeArrays_C4V3i; + typedef DrawAttributeArrays_TT DrawAttributeArrays_C4iV3i; + + typedef DrawAttributeArrays_TT_USI DrawAttributeArrays_C4V3_i; + + typedef DrawAttributeArrays_TT DrawAttributeArrays_T2V3; + typedef DrawAttributeArrays_TT DrawAttributeArrays_T2iV3; + typedef DrawAttributeArrays_TT DrawAttributeArrays_T2V3i; + typedef DrawAttributeArrays_TT DrawAttributeArrays_T2iV3i; + + typedef DrawAttributeArrays_TT_USI DrawAttributeArrays_T2V3_i; + + // Three attributes x 27 + + typedef DrawAttributeArrays_TTT DrawAttributeArrays_C4N3V3; + typedef DrawAttributeArrays_TTT DrawAttributeArrays_C4iN3V3; + typedef DrawAttributeArrays_TTT DrawAttributeArrays_C4N3iV3; + typedef DrawAttributeArrays_TTT DrawAttributeArrays_C4iN3iV3; + + typedef DrawAttributeArrays_TTT DrawAttributeArrays_C4N3V3i; + typedef DrawAttributeArrays_TTT DrawAttributeArrays_C4iN3V3i; + typedef DrawAttributeArrays_TTT DrawAttributeArrays_C4N3iV3i; + typedef DrawAttributeArrays_TTT DrawAttributeArrays_C4iN3iV3i; + + typedef DrawAttributeArrays_TTT_USI DrawAttributeArrays_C4N3V3_i; -typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2C4V3; -typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2iC4V3; -typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2C4iV3; -typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2iC4iV3; + typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2N3V3; + typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2iN3V3; + typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2iN3iV3; + typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2N3iV3; -typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2C4V3i; -typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2iC4V3i; -typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2C4iV3i; -typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2iC4iV3i; + typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2N3V3i; + typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2iN3V3i; + typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2iN3iV3i; + typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2N3iV3i; -typedef DrawAttributeArrays_TTT_USI DrawAttributeArrays_T2C4V3_t; + typedef DrawAttributeArrays_TTT_USI DrawAttributeArrays_T2N3V3_i; -// Four attributes x 17 + typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2C4V3; + typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2iC4V3; + typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2C4iV3; + typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2iC4iV3; -typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2C4N3V3; -typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2iC4N3V3; -typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2C4iN3V3; -typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2iC4iN3V3; + typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2C4V3i; + typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2iC4V3i; + typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2C4iV3i; + typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2iC4iV3i; -typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2C4N3iV3; -typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2iC4N3iV3; -typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2C4iN3iV3; -typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2iC4iN3iV3; + typedef DrawAttributeArrays_TTT_USI DrawAttributeArrays_T2C4V3_t; -typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2C4N3V3i; -typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2iC4N3V3i; -typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2C4iN3V3i; -typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2iC4iN3V3i; -typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2C4N3iV3i; -typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2iC4N3iV3i; -typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2C4iN3iV3i; -typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2iC4iN3iV3i; + // Four attributes x 17 -typedef DrawAttributeArrays_TTTT_USI DrawAttributeArrays_T2C4N3V3_i; + typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2C4N3V3; + typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2iC4N3V3; + typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2C4iN3V3; + typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2iC4iN3V3; -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2C4N3iV3; + typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2iC4N3iV3; + typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2C4iN3iV3; + typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2iC4iN3iV3; + + typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2C4N3V3i; + typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2iC4N3V3i; + typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2C4iN3V3i; + typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2iC4iN3V3i; + + typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2C4N3iV3i; + typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2iC4N3iV3i; + typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2C4iN3iV3i; + typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2iC4iN3iV3i; + + typedef DrawAttributeArrays_TTTT_USI DrawAttributeArrays_T2C4N3V3_i; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #endif diff --git a/src/osgUtil/Optimizer.cpp b/src/osgUtil/Optimizer.cpp index 54d1fcba0..b6d3850ca 100644 --- a/src/osgUtil/Optimizer.cpp +++ b/src/osgUtil/Optimizer.cpp @@ -98,6 +98,12 @@ void Optimizer::optimize(osg::Node* node, unsigned int options) osv.optimize(); } + if (options & CHECK_GEOMETRY) + { + CheckGeometryVisitor mgv; + node->accept(mgv); + } + if (options & MERGE_GEOMETRY) { MergeGeometryVisitor mgv; @@ -1138,6 +1144,18 @@ struct LessGeometryPrimitiveType } }; +void Optimizer::CheckGeometryVisitor::checkGeode(osg::Geode& geode) +{ + for(unsigned int i=0;iasGeometry(); + if (geom) + { + geom->computeCorrectBindingsAndArraySizes(); + } + } +} + bool Optimizer::MergeGeometryVisitor::mergeGeode(osg::Geode& geode) { if (geode.getNumDrawables()>=2) @@ -1151,7 +1169,7 @@ bool Optimizer::MergeGeometryVisitor::mergeGeode(osg::Geode& geode) unsigned int i; for(i=0;i(geode.getDrawable(i)); + osg::Geometry* geom = geode.getDrawable(i)->asGeometry(); if (geom) { //geom->computeCorrectBindingsAndArraySizes();