- Timestamp:
- 01/15/11 19:12:19 (2 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osganalysis/osganalysis.cpp
r12035 r12091 80 80 }; 81 81 82 class OptimizeImageVisitor : public osg::NodeVisitor 83 { 84 public: 85 OptimizeImageVisitor(osgDB::ImageProcessor* imageProcessor, bool compressImages, bool generateMipmaps): 86 osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), 87 _imageProcessor(imageProcessor), 88 _compressImages(compressImages), 89 _generateMipmaps(generateMipmaps) {} 90 91 osg::ref_ptr<osgDB::ImageProcessor> _imageProcessor; 92 bool _compressImages; 93 bool _generateMipmaps; 94 95 void apply(osg::Node& node) 96 { 97 processStateSet(node.getStateSet()); 98 traverse(node); 99 } 100 101 void apply(osg::Geode& node) 102 { 103 processStateSet(node.getStateSet()); 104 for(unsigned int i = 0; i<node.getNumDrawables(); ++i) 105 { 106 processStateSet(node.getDrawable(i)->getStateSet()); 107 } 108 109 traverse(node); 110 } 111 112 void processStateSet(osg::StateSet* stateset) 113 { 114 if (!stateset) return; 115 116 for(unsigned int i=0; i<stateset->getNumTextureAttributeLists(); ++i) 117 { 118 osg::StateAttribute* sa = stateset->getTextureAttribute(i, osg::StateAttribute::TEXTURE); 119 osg::Texture* texture = dynamic_cast<osg::Texture*>(sa); 120 if (texture) 121 { 122 for(unsigned int i=0; i<texture->getNumImages(); ++i) 123 { 124 proccessImage(texture->getImage(i)); 125 } 126 } 127 }; 128 } 129 130 131 void proccessImage(osg::Image* image) 132 { 133 if (!image) return; 134 135 if (_imageProcessor.valid()) 136 { 137 OSG_NOTICE<<"Will be using ImageProcessor to proces image "<<image->getFileName()<<std::endl; 138 } 139 else 140 { 141 OSG_NOTICE<<"No ImageProcessor to proces image "<<image->getFileName()<<std::endl; 142 } 143 OSG_NOTICE<<" compressImage "<<_compressImages<<std::endl; 144 OSG_NOTICE<<" generateMipmaps "<<_generateMipmaps<<std::endl; 145 } 146 147 }; 148 149 82 150 class SwapArrayVisitor : public osg::ArrayVisitor 83 151 { … … 352 420 while (arguments.read("--reallocate") || arguments.read("--ra") ) { reallocateMemory = true; } 353 421 354 355 422 OSG_NOTICE<<"simplificatioRatio="<<simplificatioRatio<<std::endl; 356 423 } … … 376 443 } 377 444 445 446 if (modifyTextureSettings) 447 { 448 OptimizeImageVisitor oiv(osgDB::Registry::instance()->getImageProcessor(), compressImages, buildImageMipmaps); 449 node->accept(oiv); 450 } 451 452 378 453 if (removeDuplicateVertices) 379 454 { … … 400 475 } 401 476 402 if (modifyDrawableSettings || modifyTextureSettings)477 if (modifyDrawableSettings) 403 478 { 404 479 OSG_NOTICE<<"Running StripStateVisitor"<<std::endl; … … 512 587 if (_incrementalCompileOperation.valid()) 513 588 { 589 OSG_NOTICE<<"Registering with ICO "<<_outputFilename<<std::endl; 590 514 591 osg::ref_ptr<osgUtil::IncrementalCompileOperation::CompileSet> compileSet = 515 592 new osgUtil::IncrementalCompileOperation::CompileSet(_loadedModel.get()); … … 686 763 databasePagingThread->startThread(); 687 764 765 766 osg::ref_ptr<osg::Group> group = new osg::Group; 767 viewer.setSceneData(group.get()); 768 769 viewer.realize(); 770 688 771 std::string filename = fileNames[modelIndex++]; 689 772 std::string outputFilename = outputPostfix.empty() ? std::string() : osgDB::getStrippedName(filename)+outputPostfix; … … 697 780 databasePagingThread->add(databasePagingOperation.get()); 698 781 699 osg::ref_ptr<osg::Group> group = new osg::Group;700 viewer.setSceneData(group.get());701 702 viewer.realize();703 782 704 783 double timeOfLastMerge = viewer.getFrameStamp()->getReferenceTime(); … … 728 807 if (databasePagingOperation.get() && databasePagingOperation->_modelReadyToMerge) 729 808 { 809 OSG_NOTICE<<"Merging subgraph"<<std::endl; 810 730 811 timeOfLastMerge = currentTime; 731 812
