diff --git a/include/osgUtil/Optimizer b/include/osgUtil/Optimizer index 379e01782..317dd2b7e 100644 --- a/include/osgUtil/Optimizer +++ b/include/osgUtil/Optimizer @@ -42,10 +42,12 @@ class OSGUTIL_EXPORT Optimizer REMOVE_REDUNDANT_NODES = 0x2, COMBINE_ADJACENT_LODS = 0x4, SHARE_DUPLICATE_STATE = 0x8, + MERGE_GEOMETRY = 0x10, ALL_OPTIMIZATIONS = FLATTEN_STATIC_TRANSFORMS | REMOVE_REDUNDANT_NODES | COMBINE_ADJACENT_LODS | - SHARE_DUPLICATE_STATE + SHARE_DUPLICATE_STATE | + MERGE_GEOMETRY }; /** traverse the node and its subgraph with a series of optimization diff --git a/src/osg/Geometry.cpp b/src/osg/Geometry.cpp index a16aca250..e13c9904f 100644 --- a/src/osg/Geometry.cpp +++ b/src/osg/Geometry.cpp @@ -123,11 +123,11 @@ public: _extensions->glVertexAttrib4fv( _index, v.ptr() ); } - const Geometry::Extensions *_extensions; - const Array* _attribcoords; - const IndexArray* _indices; - GLboolean _normalized; - unsigned int _index; + unsigned int _index; + GLboolean _normalized; + const Geometry::Extensions* _extensions; + const Array* _attribcoords; + const IndexArray* _indices; }; class DrawTexCoord : public osg::Referenced, public osg::ConstValueVisitor @@ -1681,10 +1681,12 @@ bool Geometry::verifyBindings() const if (_normalArray->getNumElements()!=1) return false; break; case(BIND_PER_PRIMITIVE_SET): - case(BIND_PER_PRIMITIVE): if (!_normalArray.valid()) return false; if (_normalArray->getNumElements()!=_primitives.size()) return false; break; + case(BIND_PER_PRIMITIVE): + if (!_normalArray.valid()) return false; + break; case(BIND_PER_VERTEX): if (_vertexArray.valid()) { @@ -1705,10 +1707,12 @@ bool Geometry::verifyBindings() const if (_colorArray->getNumElements()!=1) return false; break; case(BIND_PER_PRIMITIVE_SET): - case(BIND_PER_PRIMITIVE): if (!_colorArray.valid()) return false; if (_colorArray->getNumElements()!=_primitives.size()) return false; break; + case(BIND_PER_PRIMITIVE): + if (!_colorArray.valid()) return false; + break; case(BIND_PER_VERTEX): if (_vertexArray.valid()) { @@ -1780,7 +1784,6 @@ void Geometry::computeCorrectBindingsAndArraySizes() } break; case(BIND_PER_PRIMITIVE_SET): - case(BIND_PER_PRIMITIVE): if (!_normalArray.valid()) { _normalBinding = BIND_OFF; @@ -1796,6 +1799,8 @@ void Geometry::computeCorrectBindingsAndArraySizes() _normalArray->erase(_normalArray->begin()+_primitives.size(),_normalArray->end()); } break; + case(BIND_PER_PRIMITIVE): + break; case(BIND_PER_VERTEX): if (!_normalArray.valid()) { diff --git a/src/osgUtil/Optimizer.cpp b/src/osgUtil/Optimizer.cpp index 956b215bf..a546b491e 100644 --- a/src/osgUtil/Optimizer.cpp +++ b/src/osgUtil/Optimizer.cpp @@ -94,7 +94,10 @@ void Optimizer::optimize(osg::Node* node, unsigned int options) StateVisitor osv; node->accept(osv); osv.optimize(); - + } + + if (options & MERGE_GEOMETRY) + { MergeGeometryVisitor mgv; node->accept(mgv); } @@ -1068,18 +1071,33 @@ struct LessGeometry if (lhs->getStateSet()getStateSet()) return true; if (rhs->getStateSet()getStateSet()) return false; + if (rhs->getVertexIndices()) { if (!lhs->getVertexIndices()) return true; } + else if (lhs->getVertexIndices()) return false; + if (lhs->getNormalBinding()getNormalBinding()) return true; if (rhs->getNormalBinding()getNormalBinding()) return false; + if (rhs->getNormalIndices()) { if (!lhs->getNormalIndices()) return true; } + else if (lhs->getNormalIndices()) return false; + if (lhs->getColorBinding()getColorBinding()) return true; if (rhs->getColorBinding()getColorBinding()) return false; + if (rhs->getColorIndices()) { if (!lhs->getColorIndices()) return true; } + else if (lhs->getColorIndices()) return false; + if (lhs->getSecondaryColorBinding()getSecondaryColorBinding()) return true; if (rhs->getSecondaryColorBinding()getSecondaryColorBinding()) return false; + if (rhs->getSecondaryColorIndices()) { if (!lhs->getSecondaryColorIndices()) return true; } + else if (lhs->getSecondaryColorIndices()) return false; + if (lhs->getFogCoordBinding()getFogCoordBinding()) return true; if (rhs->getFogCoordBinding()getFogCoordBinding()) return false; + if (rhs->getFogCoordIndices()) { if (!lhs->getFogCoordIndices()) return true; } + else if (lhs->getFogCoordIndices()) return false; + if (lhs->getNumTexCoordArrays()getNumTexCoordArrays()) return true; if (rhs->getNumTexCoordArrays()getNumTexCoordArrays()) return false; @@ -1087,13 +1105,18 @@ struct LessGeometry for(unsigned int i=0;igetNumTexCoordArrays();++i) { - if (rhs->getTexCoordArray(i)) + if (rhs->getTexCoordArray(i)) { if (!lhs->getTexCoordArray(i)) return true; } else if (lhs->getTexCoordArray(i)) return false; + + if (rhs->getTexCoordIndices(i)) { if (!lhs->getTexCoordIndices(i)) return true; } + else if (lhs->getTexCoordIndices(i)) return false; } + + if (lhs->getNormalBinding()==osg::Geometry::BIND_OVERALL) { // assumes that the bindings and arrays are set up correctly, this @@ -1168,7 +1191,7 @@ bool Optimizer::MergeGeometryVisitor::mergeGeode(osg::Geode& geode) osg::Geometry* geom = dynamic_cast(geode.getDrawable(i)); if (geom) { - geom->computeCorrectBindingsAndArraySizes(); + //geom->computeCorrectBindingsAndArraySizes(); if (!geometryContainsSharedArrays(*geom)) {