From 7eb172277f255c68c30d367952abcd88e9bdffef Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 20 Aug 2010 10:24:06 +0000 Subject: [PATCH] Fixed bug in handling large osg::Geometry. --- src/osgUtil/SmoothingVisitor.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/osgUtil/SmoothingVisitor.cpp b/src/osgUtil/SmoothingVisitor.cpp index 722ae7a85..ac63638fa 100644 --- a/src/osgUtil/SmoothingVisitor.cpp +++ b/src/osgUtil/SmoothingVisitor.cpp @@ -478,18 +478,23 @@ struct FindSharpEdgesFunctor osg::PrimitiveSet* createPrimitiveSet() { - osg::DrawElementsUShort* elements = new osg::DrawElementsUShort(GL_TRIANGLES); - elements->reserve(_triangles.size()*3); + osg::ref_ptr elements = (_vertices->size()<16384) ? + static_cast(new osg::DrawElementsUShort(GL_TRIANGLES)) : + static_cast(new osg::DrawElementsUInt(GL_TRIANGLES)); + + elements->reserveElements(_triangles.size()*3); + for(Triangles::iterator itr = _triangles.begin(); itr != _triangles.end(); ++itr) { Triangle* tri = itr->get(); - elements->push_back(tri->_p1); - elements->push_back(tri->_p2); - elements->push_back(tri->_p3); + elements->addElement(tri->_p1); + elements->addElement(tri->_p2); + elements->addElement(tri->_p3); } - return elements; + + return elements.release(); } void updateGeometry()