- Timestamp:
- 03/21/12 18:36:20 (15 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgUtil/DrawElementTypeSimplifier.cpp
r12292 r13041 4 4 5 5 template <typename InType, typename OutType> 6 OutType * copy(InType& array) 6 OutType * copy(InType& array) 7 7 { 8 8 unsigned int size = array.size(); 9 9 OutType * newArray = new OutType(array.getMode(), size); 10 10 OutType & na = *newArray; 11 11 12 12 for (unsigned int i = 0; i < size; ++i) na[i] = array[i]; 13 13 14 14 return newArray; 15 15 } 16 16 17 17 template <typename InType> 18 unsigned int getMax(InType& array) 18 unsigned int getMax(InType& array) 19 19 { 20 20 unsigned int max = 0; 21 21 unsigned int size = array.size(); 22 23 for (unsigned int i = 0; i < size; ++i) 22 23 for (unsigned int i = 0; i < size; ++i) 24 24 { 25 25 if (array[i] > max) max = array[i]; … … 36 36 osg::Geometry::PrimitiveSetList & psl = geometry.getPrimitiveSetList(); 37 37 osg::Geometry::PrimitiveSetList::iterator it, end = psl.end(); 38 38 39 39 unsigned int max = 0; 40 40 41 41 for (it = psl.begin(); it!=end; ++it) 42 42 { … … 46 46 { 47 47 osg::DrawElementsUShort & de = *static_cast<osg::DrawElementsUShort*>(it->get()); 48 48 49 49 max = getMax<osg::DrawElementsUShort>(de); 50 50 if (max < 255) *it = copy<osg::DrawElementsUShort, osg::DrawElementsUByte>(de); 51 51 52 52 break; 53 53 } … … 55 55 { 56 56 osg::DrawElementsUInt & de = *static_cast<osg::DrawElementsUInt*>(it->get()); 57 57 58 58 max = getMax<osg::DrawElementsUInt>(de); 59 59 if (max < 256) *it = copy<osg::DrawElementsUInt, osg::DrawElementsUByte>(de); 60 60 else if (max < 65536) *it = copy<osg::DrawElementsUInt, osg::DrawElementsUShort>(de); 61 61 62 62 break; 63 63 } … … 66 66 } 67 67 } 68 68 69 69 void DrawElementTypeSimplifierVisitor::apply(osg::Geode& node) 70 70 { 71 71 DrawElementTypeSimplifier dets; 72 72 73 73 unsigned int numDrawables = node.getNumDrawables(); 74 74 for (unsigned int i = 0; i != numDrawables; ++i) … … 76 76 osg::Geometry * geom = dynamic_cast<osg::Geometry*>(node.getDrawable(i)); 77 77 if (geom) dets.simplify(*geom); 78 } 79 80 osg::NodeVisitor::apply((osg::Node&)node); 78 } 79 80 osg::NodeVisitor::apply((osg::Node&)node); 81 81 } 82 82
