Fixes to the Optimizer's handling of merging of osg::Geometry

This commit is contained in:
Robert Osfield 2003-05-22 15:29:20 +00:00
parent 23569ac5db
commit efa16a34c5
3 changed files with 42 additions and 12 deletions

View File

@ -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

View File

@ -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())
{

View File

@ -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()<rhs->getStateSet()) return true;
if (rhs->getStateSet()<lhs->getStateSet()) return false;
if (rhs->getVertexIndices()) { if (!lhs->getVertexIndices()) return true; }
else if (lhs->getVertexIndices()) return false;
if (lhs->getNormalBinding()<rhs->getNormalBinding()) return true;
if (rhs->getNormalBinding()<lhs->getNormalBinding()) return false;
if (rhs->getNormalIndices()) { if (!lhs->getNormalIndices()) return true; }
else if (lhs->getNormalIndices()) return false;
if (lhs->getColorBinding()<rhs->getColorBinding()) return true;
if (rhs->getColorBinding()<lhs->getColorBinding()) return false;
if (rhs->getColorIndices()) { if (!lhs->getColorIndices()) return true; }
else if (lhs->getColorIndices()) return false;
if (lhs->getSecondaryColorBinding()<rhs->getSecondaryColorBinding()) return true;
if (rhs->getSecondaryColorBinding()<lhs->getSecondaryColorBinding()) return false;
if (rhs->getSecondaryColorIndices()) { if (!lhs->getSecondaryColorIndices()) return true; }
else if (lhs->getSecondaryColorIndices()) return false;
if (lhs->getFogCoordBinding()<rhs->getFogCoordBinding()) return true;
if (rhs->getFogCoordBinding()<lhs->getFogCoordBinding()) return false;
if (rhs->getFogCoordIndices()) { if (!lhs->getFogCoordIndices()) return true; }
else if (lhs->getFogCoordIndices()) return false;
if (lhs->getNumTexCoordArrays()<rhs->getNumTexCoordArrays()) return true;
if (rhs->getNumTexCoordArrays()<lhs->getNumTexCoordArrays()) return false;
@ -1087,13 +1105,18 @@ struct LessGeometry
for(unsigned int i=0;i<lhs->getNumTexCoordArrays();++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<osg::Geometry*>(geode.getDrawable(i));
if (geom)
{
geom->computeCorrectBindingsAndArraySizes();
//geom->computeCorrectBindingsAndArraySizes();
if (!geometryContainsSharedArrays(*geom))
{