| | 28 | #include <osgUtil/Simplifier> |
| | 29 | |
| | 30 | class StripStateVisitor : public osg::NodeVisitor |
| | 31 | { |
| | 32 | public: |
| | 33 | StripStateVisitor(bool useStateSets, bool useDisplayLists, bool useVBO): |
| | 34 | osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), |
| | 35 | _useStateSets(useStateSets), |
| | 36 | _useDisplayLists(useDisplayLists), |
| | 37 | _useVBO(useVBO) {} |
| | 38 | |
| | 39 | bool _useStateSets; |
| | 40 | bool _useDisplayLists; |
| | 41 | bool _useVBO; |
| | 42 | |
| | 43 | void apply(osg::Node& node) |
| | 44 | { |
| | 45 | if (!_useStateSets && node.getStateSet()) node.setStateSet(0); |
| | 46 | traverse(node); |
| | 47 | } |
| | 48 | |
| | 49 | void apply(osg::Geode& node) |
| | 50 | { |
| | 51 | if (!_useStateSets && node.getStateSet()) node.setStateSet(0); |
| | 52 | for(unsigned int i = 0; i<node.getNumDrawables(); ++i) |
| | 53 | { |
| | 54 | process(*node.getDrawable(i)); |
| | 55 | } |
| | 56 | |
| | 57 | traverse(node); |
| | 58 | } |
| | 59 | |
| | 60 | void process(osg::Drawable& drawable) |
| | 61 | { |
| | 62 | if (!_useStateSets && drawable.getStateSet()) |
| | 63 | { |
| | 64 | drawable.setStateSet(0); |
| | 65 | } |
| | 66 | |
| | 67 | drawable.setUseDisplayList(_useDisplayLists); |
| | 68 | drawable.setUseVertexBufferObjects(_useVBO); |
| | 69 | } |
| | 70 | }; |
| | 105 | |
| | 106 | if (simplificatioRatio < 1.0) |
| | 107 | { |
| | 108 | OSG_NOTICE<<"Running simplifier with simplification ratio="<<simplificatioRatio<<std::endl; |
| | 109 | float maxError = 4.0f; |
| | 110 | osgUtil::Simplifier simplifier(simplificatioRatio, maxError); |
| | 111 | node->accept(simplifier); |
| | 112 | } |
| | 113 | |
| | 114 | if (modifyDrawableSettings || modifyTextureSettings) |
| | 115 | { |
| | 116 | OSG_NOTICE<<"Running StripStateVisitor"<<std::endl; |
| | 117 | StripStateVisitor ssv(true, useDisplayLists, useVBO); |
| | 118 | node->accept(ssv); |
| | 119 | } |
| | 120 | |