Changeset 268

Show
Ignore:
Timestamp:
10/09/06 18:43:13 (2 years ago)
Author:
dirk
Message:

Some OCC cleanup and additions

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/Dirk_RenderTraversalWork/Source/System/Action/RenderTraversal/OSGOcclusionCullingTreeBuilder.cpp

    r267 r268  
    5353#include "OSGBaseFunctions.h" 
    5454#include "OSGRenderPartition.h" 
     55#include "OSGRenderTraversalAction.h" 
    5556 
    5657//#define OSG_DUMP_SORTING 
     
    6465OcclusionCullingTreeBuilder OcclusionCullingTreeBuilder::Proto; 
    6566 
    66 UInt32 OcclusionCullingTreeBuilder::_extGL_SAMPLES_PASSED_ARB= Window::invalidExtensionID; 
    67 UInt32 OcclusionCullingTreeBuilder::_extGL_QUERY_RESULT_AVAILABLE_ARB= Window::invalidExtensionID; 
    68 UInt32 OcclusionCullingTreeBuilder::_extGL_QUERY_RESULT_ARB= Window::invalidExtensionID; 
     67UInt32 OcclusionCullingTreeBuilder::_extOcclusionQuery= Window::invalidExtensionID; 
    6968UInt32 OcclusionCullingTreeBuilder::_funcGenQueriesARB= Window::invalidFunctionID; 
    70 UInt32 OcclusionCullingTreeBuilder::_funcGetQueryObjectivARB= Window::invalidFunctionID; 
    7169UInt32 OcclusionCullingTreeBuilder::_funcGetQueryObjectuivARB= Window::invalidFunctionID; 
    7270UInt32 OcclusionCullingTreeBuilder::_funcBeginQueryARB= Window::invalidFunctionID; 
    7371UInt32 OcclusionCullingTreeBuilder::_funcEndQueryARB= Window::invalidFunctionID; 
     72 
     73StatElemDesc<StatIntElem> OcclusionCullingTreeBuilder::statNOccTests( 
     74    "OC-Tests",  
     75    "number of occlusion tests"); 
     76StatElemDesc<StatIntElem> OcclusionCullingTreeBuilder::statNOccInvisible( 
     77    "OC-Invisible",  
     78    "number of nodes found invisible through occlusion"); 
     79 
     80// Some typedefs to clean up OpenGL extension handling 
     81 
     82typedef void (OSG_APIENTRY *GenQueryT)(GLuint n, GLuint* ids); 
     83typedef void (OSG_APIENTRY *GetQueryObjectuivT)(GLuint id, GLenum pname,  
     84                                               GLuint* param);  
     85typedef void (OSG_APIENTRY *BeginQueryT)(GLenum target, GLuint id); 
     86typedef void (OSG_APIENTRY *EndQueryT)(GLenum target);  
     87 
     88 
    7489/*-------------------------------------------------------------------------*/ 
    7590/*                            Constructors                                 */ 
     
    7994: uNumNodes (0) 
    8095{ 
    81     _extGL_SAMPLES_PASSED_ARB = Window::registerExtension("GL_SAMPLES_PASSED_ARB"); 
    82     _extGL_QUERY_RESULT_AVAILABLE_ARB = Window::registerExtension("GL_QUERY_RESULT_AVAILABLE"); 
    83     _extGL_QUERY_RESULT_ARB = Window::registerExtension("GL_QUERY_RESULT_ARB"); 
    84     _funcGenQueriesARB          = Window::registerFunction (OSG_DLSYM_UNDERSCORE"glGenQueriesARB"); 
    85     _funcBeginQueryARB          = Window::registerFunction (OSG_DLSYM_UNDERSCORE"glBeginQueryARB"); 
    86     _funcEndQueryARB            = Window::registerFunction (OSG_DLSYM_UNDERSCORE"glEndQueryARB"); 
    87     _funcGetQueryObjectuivARB   = Window::registerFunction (OSG_DLSYM_UNDERSCORE"glGetQueryObjectuivARB"); 
    88     _funcGetQueryObjectivARB   = Window::registerFunction (OSG_DLSYM_UNDERSCORE"glGetQueryObjectivARB"); 
     96    _extOcclusionQuery = Window::registerExtension("GL_ARB_occlusion_query"); 
     97     
     98    _funcGenQueriesARB = Window::registerFunction 
     99            (OSG_DLSYM_UNDERSCORE"glGenQueriesARB",        _extOcclusionQuery); 
     100    _funcBeginQueryARB = Window::registerFunction    
     101            (OSG_DLSYM_UNDERSCORE"glBeginQueryARB",        _extOcclusionQuery); 
     102    _funcEndQueryARB = Window::registerFunction 
     103            (OSG_DLSYM_UNDERSCORE"glEndQueryARB",          _extOcclusionQuery); 
     104    _funcGetQueryObjectuivARB = Window::registerFunction 
     105            (OSG_DLSYM_UNDERSCORE"glGetQueryObjectuivARB", _extOcclusionQuery); 
    89106} 
    90107 
     
    102119void OcclusionCullingTreeBuilder::draw(DrawEnv &denv, RenderPartition *part) 
    103120{ 
     121    Window* win = denv.getWindow(); 
     122     
     123    if(!win->hasExtension(_extOcclusionQuery)) 
     124    { 
     125        // Don't have it, just draw the whole tree. 
     126        TreeBuilderBase::draw(denv,part); 
     127        return; 
     128    } 
     129     
    104130    _uiActiveMatrix = 0; 
    105131    Real32 screen_covered_percentage = 0.f; 
    106     UInt32 current_node =0
     132    UInt32 current_node = 1
    107133    GLuint queries[uNumNodes]; 
    108134    std::cout << "Submitting " << uNumNodes << " queries" << std::endl; 
    109135 
    110     void (OSG_APIENTRY *genquer)(GLuint n, GLuint* ids) =  
    111     (void (OSG_APIENTRY*)(GLuint n, GLuint* ids))denv.getWindow()->getFunction(_funcGenQueriesARB); 
     136    GenQueryT genquer = (GenQueryT)win->getFunction(_funcGenQueriesARB); 
    112137    genquer(uNumNodes, queries); 
    113138     
    114139    //glGenQueriesARB(uNumNodes, queries); 
    115     drawNode(_pRoot, denv, part, screen_covered_percentage,current_node, queries); 
     140    drawNode(_pRoot, denv, part, screen_covered_percentage, current_node, queries); 
    116141    std::cout << "Calc Pixels" << std::endl; 
    117142 
    118     void (OSG_APIENTRY *getqiv)(GLuint a, GLenum b, GLint* ids) =  
    119     (void (OSG_APIENTRY*)(GLuint a, GLenum b, GLint* ids))denv.getWindow()->getFunction(_funcGetQueryObjectivARB); 
    120  
    121     void (OSG_APIENTRY *getquiv)(GLuint a, GLenum b, GLuint* ids) =  
    122     (void (OSG_APIENTRY*)(GLuint a, GLenum b, GLuint* ids))denv.getWindow()->getFunction(_funcGetQueryObjectuivARB); 
    123  
    124     for(UInt32 i = 0; i<uNumNodes; i++) 
    125     { 
    126        GLint available = 0; 
    127        getqiv(queries[i], GL_QUERY_RESULT_AVAILABLE_ARB, &available); 
    128        while (!available) 
    129        { 
     143    GetQueryObjectuivT getquiv =  
     144        (GetQueryObjectuivT)win->getFunction(_funcGetQueryObjectuivARB); 
     145  
     146    StatCollector *sc = denv.getRTAction()->getStatistics(); 
     147    sc->getElem(statNOccTests    )->set(uNumNodes); 
     148    sc->getElem(statNOccInvisible)->set(0); // Just create it 
     149     
     150    for(UInt32 i = 1; i<uNumNodes; i++) 
     151    { 
     152        GLuint available = 0; 
     153        getquiv(queries[i], GL_QUERY_RESULT_AVAILABLE_ARB, &available); 
     154        while (!available) 
     155        { 
    130156         std::cout << "Waiting on " << i << "th query" << std::endl; 
    131          getqiv(queries[i], GL_QUERY_RESULT_AVAILABLE_ARB, &available); 
     157         getquiv(queries[i], GL_QUERY_RESULT_AVAILABLE_ARB, &available); 
    132158         //glGetQueryObjectivARB(queries[i], GL_QUERY_RESULT_AVAILABLE_ARB, &available); 
    133        } 
    134        GLuint sampleCount = 0; 
    135        getquiv(queries[i], GL_QUERY_RESULT_ARB, &sampleCount); 
    136        //glGetQueryObjectuivARB(queries[i], GL_QUERY_RESULT_ARB, &sampleCount); 
    137        std::cout << "Pixels covered: " << sampleCount << std::endl; 
    138     } 
     159        } 
     160        GLuint sampleCount = 0; 
     161        getquiv(queries[i], GL_QUERY_RESULT_ARB, &sampleCount); 
     162        //glGetQueryObjectuivARB(queries[i], GL_QUERY_RESULT_ARB, &sampleCount); 
     163        std::cout << i << ":" << sampleCount << " "; 
     164         
     165        if(sampleCount == 0) 
     166            sc->getElem(statNOccInvisible)->inc(); 
     167    } 
     168    std::cout << std::endl; 
    139169 
    140170   // screen_covered_percentage = 1.0; 
     
    194224        denv.activateState(pNewState, pNewStateOverride); 
    195225 
    196     void (OSG_APIENTRY *beginq)(GLenum a, GLuint b) =  
    197     (void (OSG_APIENTRY*)(GLenum a, GLuint b))denv.getWindow()->getFunction(_funcBeginQueryARB); 
    198  
     226        Window* win = denv.getWindow(); 
     227         
     228        BeginQueryT beginq = (BeginQueryT) win->getFunction(_funcBeginQueryARB); 
    199229        beginq(GL_SAMPLES_PASSED_ARB, queries[cur_node]); 
    200230        //glBeginQueryARB(GL_SAMPLES_PASSED_ARB, queries[cur_node]); 
     
    202232        if(pNode->hasFunctor() == true) 
    203233            pNode->getFunctor()(&denv); 
    204  
    205     void (OSG_APIENTRY *endq)(GLenum a) =  
    206     (void (OSG_APIENTRY*)(GLenum a))denv.getWindow()->getFunction(_funcEndQueryARB); 
    207         
    208234         
     235        EndQueryT endq = (EndQueryT) win->getFunction(_funcEndQueryARB);                
    209236        endq(GL_SAMPLES_PASSED_ARB); 
    210237        //glEndQueryARB(GL_SAMPLES_PASSED_ARB); 
  • branches/Dirk_RenderTraversalWork/Source/System/Action/RenderTraversal/OSGOcclusionCullingTreeBuilder.h

    r267 r268  
    172172    UInt32 uNumNodes; 
    173173 
    174     static UInt32 _extGL_SAMPLES_PASSED_ARB; 
    175     static UInt32 _extGL_QUERY_RESULT_AVAILABLE_ARB; 
    176     static UInt32 _extGL_QUERY_RESULT_ARB; 
     174    static UInt32 _extOcclusionQuery; 
    177175 
    178176    static UInt32 _funcGenQueriesARB; 
    179     static UInt32 _funcGetQueryObjectivARB; 
    180177    static UInt32 _funcGetQueryObjectuivARB; 
    181178    static UInt32 _funcBeginQueryARB; 
    182179    static UInt32 _funcEndQueryARB; 
    183180 
     181    static StatElemDesc<StatIntElem> statNOccTests; 
     182    static StatElemDesc<StatIntElem> statNOccInvisible; 
     183     
    184184 
    185185    //----------------------------------------------------------------------- 
  • branches/Dirk_RenderTraversalWork/Source/System/Action/RenderTraversal/OSGRenderPartition.cpp

    r267 r268  
    495495    else if( 1==1) 
    496496    { 
    497         BuildKeyMapIt mapIt = _mTransMatRoots.lower_bound(iSortKey); 
    498          
    499         if(mapIt == _mTransMatRoots.end() || mapIt->first != iSortKey) 
     497        BuildKeyMapIt mapIt = _mMatRoots.lower_bound(iSortKey); 
     498         
     499        if(mapIt == _mMatRoots.end() || mapIt->first != iSortKey) 
    500500        { 
    501501            TreeBuilderBase *pBuilder = 
     
    504504            pBuilder->setNodePool(_pNodePool); 
    505505             
    506             mapIt = _mTransMatRoots.insert(mapIt,  
     506            mapIt = _mMatRoots.insert(mapIt,  
    507507                                           std::make_pair(iSortKey, pBuilder)); 
    508508        }