Changeset 345

Show
Ignore:
Timestamp:
10/21/06 14:04:13 (2 years ago)
Author:
dshipton
Message:

Use a FIFO queue for the queries to help mix rendering, testing, and rendering results for decreased latency.

Files:

Legend:

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

    r342 r345  
    125125: uNumNodes (0), 
    126126  _isOccSetup(false), 
    127   _currSample(0) 
     127  _currSample(0), 
     128  _numTestSamples(1000) 
    128129{ 
    129130    _extOcclusionQuery = Window::registerExtension("GL_ARB_occlusion_query"); 
     
    221222void OcclusionCullingTreeBuilder::draw(DrawEnv &denv, RenderPartition *part) 
    222223{ 
     224    //std::cout << "Frame Start" << std::endl; 
    223225    Window* win = denv.getWindow(); 
    224226 
     
    248250    if(!_isOccSetup) 
    249251    { 
    250         _testSamples = new GLuint[uNumNodes]; 
     252        //_numTestSamples = (uNumNodes / 5) + 2; 
     253        std::cout << "Buf size: " << _numTestSamples << std::endl; 
     254        _testSamples = new GLuint[_numTestSamples]; 
    251255        //std::cout << "Performing OCC on " << uNumNodes << " nodes." << std::endl; 
    252256 
    253257        GenQueryT genquer = (GenQueryT)win->getFunction(_funcGenQueriesARB); 
    254         genquer(uNumNodes, _testSamples); 
     258        genquer(_numTestSamples, _testSamples); 
    255259        _isOccSetup = true; 
    256260    } 
     
    283287    //std::cout << "Calculated Pixels" << std::endl; 
    284288 
    285  
     289     
    286290    Viewport* vp = denv.getViewport(); 
    287291    _vpWidth = vp->getPixelWidth(); 
     
    316320    leaveTesting(denv, part); 
    317321         
    318 //RESULTS / RE-DRAW    
    319     drawTestResults(_pRoot, denv, part); 
     322//RESULTS / RE-DRAW 
     323    while( !_testPendingNodes.empty() ) 
     324    { 
     325        drawTestResults(denv, part); 
     326    } 
    320327 
    321328    //std::cout << "Calc Pixels" << std::endl; 
     
    323330 
    324331  
    325     sc->getElem(statNOccTests    )->add(_currSample); 
    326     sc->getElem(statNOccInvisible)->add(uNumNodes); 
    327332    Real32 percentage = (Real32)sc->getElem(statNOccInvisible)->get() / (Real32)sc->getElem(statNOccTests)->get(); 
    328333    sc->getElem(statNOccSuccessTestPer)->set(percentage); 
     
    330335     
    331336    //std::cout << "Real pixels " << std::endl; 
    332     //std::cout << " Next" << std::endl; 
    333337    //std::cout << std::endl; 
    334338 
     
    337341    uNumNodes=0; 
    338342    _currSample = 0; 
    339  
    340 
     343    //std::cout << "Frame End" << std::endl; 
     344
     345 
    341346void OcclusionCullingTreeBuilder::testNode(RenderTreeNode *pNode, DrawEnv &denv, RenderPartition *part, Real32 &scr_percent) 
    342347{ 
     
    420425 
    421426//Make decision 
    422         if(pNode->hasFunctor() == false) 
     427 
     428         
     429        if(pNode->hasFunctor() == false) //Nothing to do 
    423430        { 
    424431            //renderNode 
     
    429436            //make decision 
    430437            //if(0 > 1) 
    431             if(cbb > scr_percent) 
     438            if(cbb > scr_percent) // Rendering major occluders 
    432439            { 
    433440                drawNode(pNode, denv, part); 
     
    436443            else 
    437444            { 
     445                         
    438446                Real32 pcov; 
    439447                pcov = sqrt(scr_percent) - sqrt(cbb); 
     
    441449                //std::cout << "cbb:" << cbb << " scr_percent:" << scr_percent <<" pcov:" << pcov << std::endl; 
    442450                //if(scr_percent - pcov > 0.001) 
    443                 if(pcov > _coveredProbThreshold || cbb < 0.001) 
     451                if(pcov > _coveredProbThreshold || cbb < 0.001) // If within threshold or reall small 
    444452                { 
    445453                    if(cbb * _vpWidth * _vpHeight <= _minFeatureSize) //small feature culling 
     
    447455                        pNode->setIsRendered(true); 
    448456                    } 
     457                    else if(_testPendingNodes.size() == _numTestSamples - 1) // Make sure we have room to draw a test 
     458                    { 
     459                        drawTestResults(denv, part); 
     460                        if(_testPendingNodes.size() == _numTestSamples - 1) // If we are waiting on a result, draw a node 
     461                        { 
     462                            drawNode(pNode, denv, part); 
     463                        } 
     464                        else 
     465                        { 
     466                            drawTestNode(pNode, denv, part); // Made room, go ahead and draw a test node 
     467                        } 
     468                    } 
    449469                    else 
    450470                    { 
    451                         drawTestNode(pNode, denv, part); 
     471                        drawTestNode(pNode, denv, part); //Plenty of room in buffer to draw a test node 
    452472                    } 
    453473                } 
    454474                else 
    455475                { 
    456                     drawNode(pNode, denv, part); 
     476                    drawNode(pNode, denv, part); // Probably not being covered up...draw the real node 
    457477                    //scr_percent+=cbb; 
    458478                } 
     
    518538    v[1][2] = v[2][2] = v[5][2] = v[6][2] = max[2]; 
    519539 
    520     //glColor3f(0.3,0.4,0.6); 
    521      
     540    //std::cout << "Front: " << _currSample << " Back: " << _currSampleBack << std::endl; 
     541    while(_testPendingNodes.size() == _numTestSamples - 1) 
     542    { 
     543        drawTestResults(denv, part); 
     544        //std::cout << "NOW:  Front: " << _currSample << " Back: " << _currSampleBack << std::endl; 
     545    } 
     546 
     547    if(_currSample == _numTestSamples - 1) 
     548    { 
     549        _currSample = 0; 
     550    } 
     551    _currSample++; 
     552 
    522553    enterTesting(denv, part); 
     554    StatCollector *sc = _rt->getStatistics(); 
     555    sc->getElem(statNOccTests    )->inc(); 
    523556 
    524557    BeginQueryT beginq = (BeginQueryT) win->getFunction(_funcBeginQueryARB); 
    525     _currSample++
     558    //std::cout << "Push: " << _currSample << std::endl
    526559    pNode->setResultNum(_currSample); 
    527560    beginq(GL_SAMPLES_PASSED_ARB, _testSamples[_currSample]); 
     
    539572    } 
    540573    glEnd(); 
    541     //glLoadMatrixf(m); 
    542     //glMatrixMode(GL_MODELVIEW); 
    543     //glPopMatrix(); 
    544574 
    545575    EndQueryT endq = (EndQueryT) win->getFunction(_funcEndQueryARB);                
    546576    endq(GL_SAMPLES_PASSED_ARB); 
    547     //glEndQueryARB(GL_SAMPLES_PASSED_ARB); 
     577    _testPendingNodes.push(pNode); 
    548578} 
    549579 
     
    594624} 
    595625 
    596 void OcclusionCullingTreeBuilder::drawTestResults(RenderTreeNode *pNode, DrawEnv &denv, RenderPartition *part) 
    597 
    598     while (pNode != NULL) 
    599     { 
     626void OcclusionCullingTreeBuilder::drawTestResults(DrawEnv &denv, RenderPartition *part) 
     627
     628    RenderTreeNode* pNode; 
     629    while (!_testPendingNodes.empty()) 
     630    { 
     631        pNode = _testPendingNodes.front(); 
    600632        //DRAW DRAW DRAW 
    601633        if(pNode->hasFunctor() == true && !pNode->getIsRendered()) 
     
    606638            GLuint available = 0; 
    607639            getquiv(_testSamples[pNode->getResultNum()], GL_QUERY_RESULT_AVAILABLE_ARB, &available); 
    608             //if (!available) 
    609             //{ 
    610             //    std::cout << std::endl << "Waiting on " << pNode->getResultNum() << "th query"; 
    611             //}  
     640            if (!available) 
     641            { 
     642                //std::cout << "Waiting on " << pNode->getResultNum() << " buf size:" << _testPendingNodes.size() << std::endl; 
     643                return; 
     644            }  
    612645            GLuint sampleCount = 100;  //XXX: Set to what it should be from calc above. 
    613             if(available) 
    614             { 
    615                 //std::cout << "."; 
    616                 //getquiv(_testSamples[pNode->getResultNum()], GL_QUERY_RESULT_AVAILABLE_ARB, &available); 
    617                 getquiv(_testSamples[pNode->getResultNum()], GL_QUERY_RESULT_ARB, &sampleCount); 
    618                 //glGetQueryObjectivARB(queries[i], GL_QUERY_RESULT_AVAILABLE_ARB, &available); 
    619                 //if(available) 
    620                 //{ 
    621                 //    std::cout << std::endl; 
    622                 //} 
    623             } 
     646            getquiv(_testSamples[pNode->getResultNum()], GL_QUERY_RESULT_ARB, &sampleCount); 
    624647             
    625             //glGetQueryObjectuivARB(queries[i], GL_QUERY_RESULT_ARB, &sampleCount); 
    626             //std::cout << i << ":" << sampleCount << " "; 
    627648            if(sampleCount > _visPixelThreshold) 
    628649            { 
     650                leaveTesting(denv, part); 
    629651                //MATRIX SETUP 
    630652                UInt32 uiNextMatrix = pNode->getMatrixStore().first; 
     
    633655                { 
    634656                    glLoadMatrixf(pNode->getMatrixStore().second.getValues()); 
    635  
    636657                    _uiActiveMatrix = uiNextMatrix; 
    637  
    638658                    _currMatrix.second = pNode->getMatrixStore().second; 
    639  
    640659                    updateTopMatrix(denv); 
    641  
    642660                    denv.setObjectToWorld(_accMatrix); 
    643  
    644661                    ++part->_uiNumMatrixChanges; 
    645662                } 
     
    673690            else 
    674691            { 
    675                 uNumNodes++; 
     692                StatCollector *sc = _rt->getStatistics(); 
     693                sc->getElem(statNOccInvisible)->inc(); 
    676694 
    677695                GeoStatsAttachmentPtr st = 
     
    692710            } 
    693711        } 
    694          
    695  
    696  
    697 //DRAW CHILDREN OR GO TO TOP AND DO IT AGAIN 
    698         if(pNode->getFirstChild() != NULL) 
    699         { 
    700             drawTestResults(pNode->getFirstChild(), denv, part); 
    701         } 
    702          
    703         pNode = pNode->getBrother(); 
     712        //std::cout << "Popped: " << pNode->getResultNum() << " buf size now: " << _testPendingNodes.size() - 1 <<  std::endl; 
     713        _testPendingNodes.pop(); 
    704714    } 
    705715} 
  • branches/Dirk_RenderTraversalWork/Source/System/Action/RenderTraversal/OSGOcclusionCullingTreeBuilder.h

    r342 r345  
    4848 
    4949#include <map> 
     50#include <queue> 
    5051 
    5152#include "OSGHashSorter.h" 
     
    176177    void drawNode(RenderTreeNode *pNode, DrawEnv &denv, RenderPartition *part); 
    177178    void drawTestNode(RenderTreeNode *pNode, DrawEnv &denv, RenderPartition *part); 
    178     void drawTestResults(RenderTreeNode *pNode, DrawEnv &denv, RenderPartition *part); 
     179    void drawTestResults(DrawEnv &denv, RenderPartition *part); 
    179180 
    180181    inline void enterTesting(DrawEnv &denv, RenderPartition *part); 
     
    213214 
    214215    GLuint* _testSamples; 
     216    UInt32  _numTestSamples; 
    215217    bool    _isOccSetup; 
    216218    UInt32  _currSample; //!< Last current sample test number 
     219    //UInt32  _currSampleBack; //!< Last number we can test to 
     220    UInt32  _testedNodes; //!< Number of OC tested nodes 
    217221    bool    _inTesting;  //!< Whether in testing mode or not 
    218222     
     
    227231    
    228232    std::vector<RenderTreeNode*> _testNodes; //!< Nodes currently being tested 
     233    std::queue<RenderTreeNode*> _testPendingNodes; //!< Nodes with tests pending 
    229234 
    230235    //----------------------------------------------------------------------- 
     
    239244    UInt32                 _visPixelThreshold; 
    240245    Real32                 _coveredProbThreshold; 
     246    //Real32                 _screenPercent; 
    241247 
    242248    //-----------------------------------------------------------------------