Show
Ignore:
Timestamp:
03/11/10 19:15:20 (5 years ago)
Author:
robert
Message:

From Time Moore, "This submission implements 3 optimizations for meshes. INDEX_MESH turns DrawArrays? style geometry into DrawElements?, uniquifying the vertices in the process. This is useful for certain loaders, like ac3d, which just spit out DrawArrays?. VERTEX_POSTTRANSFORM and VERTEX_PRETRANSFORM optimize mesh triangle and vertex order for the caches on a modern GPU, using Tom Forsyth's algorithm. I describe this and the big difference it makes (38% improvement on a very large mesh) in my blog,
http://shiny-dynamics.blogspot.com/2010/03/vertex-cache-optimization-for-osg.html."

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgUtil/Optimizer.cpp

    r11131 r11204  
    4040#include <osgUtil/Tessellator> 
    4141#include <osgUtil/Statistics> 
     42#include <osgUtil/MeshOptimizers> 
    4243 
    4344#include <typeinfo> 
     
    5556} 
    5657 
    57 static osg::ApplicationUsageProxy Optimizer_e0(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_OPTIMIZER \"<type> [<type>]\"","OFF | DEFAULT | FLATTEN_STATIC_TRANSFORMS | FLATTEN_STATIC_TRANSFORMS_DUPLICATING_SHARED_SUBGRAPHS | REMOVE_REDUNDANT_NODES | COMBINE_ADJACENT_LODS | SHARE_DUPLICATE_STATE | MERGE_GEOMETRY | MERGE_GEODES | SPATIALIZE_GROUPS  | COPY_SHARED_NODES  | TRISTRIP_GEOMETRY | OPTIMIZE_TEXTURE_SETTINGS | REMOVE_LOADED_PROXY_NODES | TESSELLATE_GEOMETRY | CHECK_GEOMETRY |  FLATTEN_BILLBOARDS | TEXTURE_ATLAS_BUILDER | STATIC_OBJECT_DETECTION"); 
     58static osg::ApplicationUsageProxy Optimizer_e0(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_OPTIMIZER \"<type> [<type>]\"","OFF | DEFAULT | FLATTEN_STATIC_TRANSFORMS | FLATTEN_STATIC_TRANSFORMS_DUPLICATING_SHARED_SUBGRAPHS | REMOVE_REDUNDANT_NODES | COMBINE_ADJACENT_LODS | SHARE_DUPLICATE_STATE | MERGE_GEOMETRY | MERGE_GEODES | SPATIALIZE_GROUPS  | COPY_SHARED_NODES  | TRISTRIP_GEOMETRY | OPTIMIZE_TEXTURE_SETTINGS | REMOVE_LOADED_PROXY_NODES | TESSELLATE_GEOMETRY | CHECK_GEOMETRY |  FLATTEN_BILLBOARDS | TEXTURE_ATLAS_BUILDER | STATIC_OBJECT_DETECTION | INDEX_MESH | VERTEX_POSTTRANSFORM | VERTEX_PRETRANSFORM"); 
    5859 
    5960void Optimizer::optimize(osg::Node* node) 
     
    126127        else if(str.find("STATIC_OBJECT_DETECTION")!=std::string::npos) options |= STATIC_OBJECT_DETECTION; 
    127128 
     129        if(str.find("~INDEX_MESH")!=std::string::npos) options ^= INDEX_MESH; 
     130        else if(str.find("INDEX_MESH")!=std::string::npos) options |= INDEX_MESH; 
     131 
     132        if(str.find("~VERTEX_POSTTRANSFORM")!=std::string::npos) options ^= VERTEX_POSTTRANSFORM; 
     133        else if(str.find("VERTEX_POSTTRANSFORM")!=std::string::npos) options |= VERTEX_POSTTRANSFORM; 
     134 
     135        if(str.find("~VERTEX_PRETRANSFORM")!=std::string::npos) options ^= VERTEX_PRETRANSFORM; 
     136        else if(str.find("VERTEX_PRETRANSFORM")!=std::string::npos) options |= VERTEX_PRETRANSFORM; 
     137 
    128138    } 
    129139    else 
     
    346356        node->accept(sv); 
    347357        sv.divide(); 
     358    } 
     359 
     360    if (options & INDEX_MESH) 
     361    { 
     362        OSG_NOTIFY(osg::INFO)<<"Optimizer::optimize() doing INDEX_MESH"<<std::endl; 
     363        IndexMeshVisitor imv(this); 
     364        node->accept(imv); 
     365        imv.makeMesh(); 
     366    } 
     367 
     368    if (options & VERTEX_POSTTRANSFORM) 
     369    { 
     370        OSG_NOTIFY(osg::INFO)<<"Optimizer::optimize() doing VERTEX_POSTTRANSFORM"<<std::endl; 
     371        VertexCacheVisitor vcv; 
     372        node->accept(vcv); 
     373        vcv.optimizeVertices(); 
     374    } 
     375 
     376    if (options & VERTEX_PRETRANSFORM) 
     377    { 
     378        OSG_NOTIFY(osg::INFO)<<"Optimizer::optimize() doing VERTEX_PRETRANSFORM"<<std::endl; 
     379        VertexAccessOrderVisitor vaov; 
     380        node->accept(vaov); 
     381        vaov.optimizeOrder(); 
    348382    } 
    349383