Changeset 345
- Timestamp:
- 10/21/06 14:04:13 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/Dirk_RenderTraversalWork/Source/System/Action/RenderTraversal/OSGOcclusionCullingTreeBuilder.cpp
r342 r345 125 125 : uNumNodes (0), 126 126 _isOccSetup(false), 127 _currSample(0) 127 _currSample(0), 128 _numTestSamples(1000) 128 129 { 129 130 _extOcclusionQuery = Window::registerExtension("GL_ARB_occlusion_query"); … … 221 222 void OcclusionCullingTreeBuilder::draw(DrawEnv &denv, RenderPartition *part) 222 223 { 224 //std::cout << "Frame Start" << std::endl; 223 225 Window* win = denv.getWindow(); 224 226 … … 248 250 if(!_isOccSetup) 249 251 { 250 _testSamples = new GLuint[uNumNodes]; 252 //_numTestSamples = (uNumNodes / 5) + 2; 253 std::cout << "Buf size: " << _numTestSamples << std::endl; 254 _testSamples = new GLuint[_numTestSamples]; 251 255 //std::cout << "Performing OCC on " << uNumNodes << " nodes." << std::endl; 252 256 253 257 GenQueryT genquer = (GenQueryT)win->getFunction(_funcGenQueriesARB); 254 genquer( uNumNodes, _testSamples);258 genquer(_numTestSamples, _testSamples); 255 259 _isOccSetup = true; 256 260 } … … 283 287 //std::cout << "Calculated Pixels" << std::endl; 284 288 285 289 286 290 Viewport* vp = denv.getViewport(); 287 291 _vpWidth = vp->getPixelWidth(); … … 316 320 leaveTesting(denv, part); 317 321 318 //RESULTS / RE-DRAW 319 drawTestResults(_pRoot, denv, part); 322 //RESULTS / RE-DRAW 323 while( !_testPendingNodes.empty() ) 324 { 325 drawTestResults(denv, part); 326 } 320 327 321 328 //std::cout << "Calc Pixels" << std::endl; … … 323 330 324 331 325 sc->getElem(statNOccTests )->add(_currSample);326 sc->getElem(statNOccInvisible)->add(uNumNodes);327 332 Real32 percentage = (Real32)sc->getElem(statNOccInvisible)->get() / (Real32)sc->getElem(statNOccTests)->get(); 328 333 sc->getElem(statNOccSuccessTestPer)->set(percentage); … … 330 335 331 336 //std::cout << "Real pixels " << std::endl; 332 //std::cout << " Next" << std::endl;333 337 //std::cout << std::endl; 334 338 … … 337 341 uNumNodes=0; 338 342 _currSample = 0; 339 340 } 343 //std::cout << "Frame End" << std::endl; 344 } 345 341 346 void OcclusionCullingTreeBuilder::testNode(RenderTreeNode *pNode, DrawEnv &denv, RenderPartition *part, Real32 &scr_percent) 342 347 { … … 420 425 421 426 //Make decision 422 if(pNode->hasFunctor() == false) 427 428 429 if(pNode->hasFunctor() == false) //Nothing to do 423 430 { 424 431 //renderNode … … 429 436 //make decision 430 437 //if(0 > 1) 431 if(cbb > scr_percent) 438 if(cbb > scr_percent) // Rendering major occluders 432 439 { 433 440 drawNode(pNode, denv, part); … … 436 443 else 437 444 { 445 438 446 Real32 pcov; 439 447 pcov = sqrt(scr_percent) - sqrt(cbb); … … 441 449 //std::cout << "cbb:" << cbb << " scr_percent:" << scr_percent <<" pcov:" << pcov << std::endl; 442 450 //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 444 452 { 445 453 if(cbb * _vpWidth * _vpHeight <= _minFeatureSize) //small feature culling … … 447 455 pNode->setIsRendered(true); 448 456 } 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 } 449 469 else 450 470 { 451 drawTestNode(pNode, denv, part); 471 drawTestNode(pNode, denv, part); //Plenty of room in buffer to draw a test node 452 472 } 453 473 } 454 474 else 455 475 { 456 drawNode(pNode, denv, part); 476 drawNode(pNode, denv, part); // Probably not being covered up...draw the real node 457 477 //scr_percent+=cbb; 458 478 } … … 518 538 v[1][2] = v[2][2] = v[5][2] = v[6][2] = max[2]; 519 539 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 522 553 enterTesting(denv, part); 554 StatCollector *sc = _rt->getStatistics(); 555 sc->getElem(statNOccTests )->inc(); 523 556 524 557 BeginQueryT beginq = (BeginQueryT) win->getFunction(_funcBeginQueryARB); 525 _currSample++;558 //std::cout << "Push: " << _currSample << std::endl; 526 559 pNode->setResultNum(_currSample); 527 560 beginq(GL_SAMPLES_PASSED_ARB, _testSamples[_currSample]); … … 539 572 } 540 573 glEnd(); 541 //glLoadMatrixf(m);542 //glMatrixMode(GL_MODELVIEW);543 //glPopMatrix();544 574 545 575 EndQueryT endq = (EndQueryT) win->getFunction(_funcEndQueryARB); 546 576 endq(GL_SAMPLES_PASSED_ARB); 547 //glEndQueryARB(GL_SAMPLES_PASSED_ARB);577 _testPendingNodes.push(pNode); 548 578 } 549 579 … … 594 624 } 595 625 596 void OcclusionCullingTreeBuilder::drawTestResults(RenderTreeNode *pNode, DrawEnv &denv, RenderPartition *part) 597 { 598 while (pNode != NULL) 599 { 626 void OcclusionCullingTreeBuilder::drawTestResults(DrawEnv &denv, RenderPartition *part) 627 { 628 RenderTreeNode* pNode; 629 while (!_testPendingNodes.empty()) 630 { 631 pNode = _testPendingNodes.front(); 600 632 //DRAW DRAW DRAW 601 633 if(pNode->hasFunctor() == true && !pNode->getIsRendered()) … … 606 638 GLuint available = 0; 607 639 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 } 612 645 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); 624 647 625 //glGetQueryObjectuivARB(queries[i], GL_QUERY_RESULT_ARB, &sampleCount);626 //std::cout << i << ":" << sampleCount << " ";627 648 if(sampleCount > _visPixelThreshold) 628 649 { 650 leaveTesting(denv, part); 629 651 //MATRIX SETUP 630 652 UInt32 uiNextMatrix = pNode->getMatrixStore().first; … … 633 655 { 634 656 glLoadMatrixf(pNode->getMatrixStore().second.getValues()); 635 636 657 _uiActiveMatrix = uiNextMatrix; 637 638 658 _currMatrix.second = pNode->getMatrixStore().second; 639 640 659 updateTopMatrix(denv); 641 642 660 denv.setObjectToWorld(_accMatrix); 643 644 661 ++part->_uiNumMatrixChanges; 645 662 } … … 673 690 else 674 691 { 675 uNumNodes++; 692 StatCollector *sc = _rt->getStatistics(); 693 sc->getElem(statNOccInvisible)->inc(); 676 694 677 695 GeoStatsAttachmentPtr st = … … 692 710 } 693 711 } 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(); 704 714 } 705 715 } branches/Dirk_RenderTraversalWork/Source/System/Action/RenderTraversal/OSGOcclusionCullingTreeBuilder.h
r342 r345 48 48 49 49 #include <map> 50 #include <queue> 50 51 51 52 #include "OSGHashSorter.h" … … 176 177 void drawNode(RenderTreeNode *pNode, DrawEnv &denv, RenderPartition *part); 177 178 void drawTestNode(RenderTreeNode *pNode, DrawEnv &denv, RenderPartition *part); 178 void drawTestResults( RenderTreeNode *pNode,DrawEnv &denv, RenderPartition *part);179 void drawTestResults(DrawEnv &denv, RenderPartition *part); 179 180 180 181 inline void enterTesting(DrawEnv &denv, RenderPartition *part); … … 213 214 214 215 GLuint* _testSamples; 216 UInt32 _numTestSamples; 215 217 bool _isOccSetup; 216 218 UInt32 _currSample; //!< Last current sample test number 219 //UInt32 _currSampleBack; //!< Last number we can test to 220 UInt32 _testedNodes; //!< Number of OC tested nodes 217 221 bool _inTesting; //!< Whether in testing mode or not 218 222 … … 227 231 228 232 std::vector<RenderTreeNode*> _testNodes; //!< Nodes currently being tested 233 std::queue<RenderTreeNode*> _testPendingNodes; //!< Nodes with tests pending 229 234 230 235 //----------------------------------------------------------------------- … … 239 244 UInt32 _visPixelThreshold; 240 245 Real32 _coveredProbThreshold; 246 //Real32 _screenPercent; 241 247 242 248 //-----------------------------------------------------------------------
