Changeset 811 for GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
- Timestamp:
- 04/24/06 20:27:38 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
r752 r811 9 9 #include "Environment.h" 10 10 11 //#define GL_GLEXT_PROTOTYPES 11 12 #include <GL/glext.h> 12 13 #include <Cg/cg.h> … … 34 35 PFNGLENDOCCLUSIONQUERYNVPROC glEndOcclusionQueryNV; 35 36 PFNGLGETOCCLUSIONQUERYUIVNVPROC glGetOcclusionQueryuivNV; 37 38 //PFNGLGENQUERIESARBPROC glGenQueriesARB; 39 //PFNGLBEGINQUERYARBPROC glBeginQueryARB; 40 //PFNGLENDQUERYARBPROC glEndQueryARB; 41 //PFNGLGETQUERYUIVARBPROC glGetQueryuivARB; 36 42 #endif 37 43 … … 57 63 mSnapPrefix = "snap/"; 58 64 mUseForcedColors = false; 65 66 mUseGlLists = true; 67 59 68 } 60 69 … … 140 149 { 141 150 // swap bits of the color 142 143 151 glColor3ub(id&255, (id>>8)&255, (id>>16)&255); 144 152 } … … 203 211 204 212 213 #if 0 214 glGenQueriesARB = (PFNGLGENDQUERIESARBPROC) 215 wglGetProcAddress("glGenQueriesARB"); 216 glBeginQueryARB = (PFNGLBEGINQUERYARBPROC) 217 wglGetProcAddress("glBeginQueryARB"); 218 glEndQueryARB = (PFNGLENDQUERYARBPROC) 219 wglGetProcAddress("glEndQueryARB"); 220 glGetQueryuivARB = (PFNGLGETQUERYUIVARBPROC) 221 wglGetProcAddress("glGetQueryuivARB"); 222 223 #endif 224 205 225 206 226 #if 0 … … 391 411 392 412 void 393 GlRenderer::SetupProjection(const int w, const int h )413 GlRenderer::SetupProjection(const int w, const int h, const float angle) 394 414 { 395 415 glViewport(0, 0, w, h); 396 416 glMatrixMode(GL_PROJECTION); 397 417 glLoadIdentity(); 398 gluPerspective( 70.0, 1.0, 0.1, 2.0*Magnitude(mSceneGraph->GetBox().Diagonal()));418 gluPerspective(angle, 1.0, 0.1, 2.0*Magnitude(mSceneGraph->GetBox().Diagonal())); 399 419 glMatrixMode(GL_MODELVIEW); 400 420 } … … 404 424 { 405 425 Vector3 target = mViewPoint + mViewDirection; 426 406 427 Vector3 up(0,1,0); 428 429 if (abs(DotProd(mViewDirection, up)) > 0.99f) 430 up = Vector3(1, 0, 0); 407 431 408 432 glLoadIdentity(); … … 411 435 up.x, up.y, up.z); 412 436 } 437 438 439 void 440 GlRendererBuffer::EvalRenderCostSample( 441 RenderCostSample &sample 442 ) 443 { 444 mViewCellsManager->GetViewPoint(mViewPoint); 445 cout<<mViewPoint<<endl; 446 447 // take a render cost sample by rendering a cube 448 Vector3 directions[6]; 449 directions[0] = Vector3(1,0,0); 450 directions[1] = Vector3(0,1,0); 451 directions[2] = Vector3(0,0,1); 452 directions[3] = Vector3(-1,0,0); 453 directions[4] = Vector3(0,-1,0); 454 directions[5] = Vector3(0,0,-1); 455 456 sample.mVisibleObjects = 0; 457 458 int i, j; 459 460 // reset object visibility 461 for (i=0; i < mObjects.size(); i++) { 462 mObjects[i]->mCounter = 0; 463 } 464 mFrame++; 465 for (i=0; i < 6; i++) { 466 mViewDirection = directions[i]; 467 SetupCamera(); 468 glClearColor(1.0f, 1.0f, 1.0f, 1.0f); 469 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 470 471 glDepthFunc( GL_LESS ); 472 473 mUseFalseColors = true; 474 475 RenderScene(); 476 477 if (1) { 478 char filename[256]; 479 sprintf(filename, "snap/frame-%04d-%d.png", mFrame, i); 480 QImage im = toImage(); 481 im.save(filename, "PNG"); 482 } 483 484 bool useItemBuffer = false; 485 486 if (useItemBuffer) { 487 // read back the texture 488 glReadPixels(0, 0, 489 GetWidth(), GetHeight(), 490 GL_RGBA, 491 GL_UNSIGNED_BYTE, 492 mPixelBuffer); 493 494 int x, y; 495 unsigned int *p = mPixelBuffer; 496 for (y = 0; y < GetHeight(); y++) 497 for (x = 0; x < GetWidth(); x++, p++) { 498 unsigned int id = (*p) & 0xFFFFFF; 499 if (id != 0xFFFFFF) 500 mObjects[id]->mCounter++; 501 } 502 503 } else { 504 505 // glDepthFunc( GL_LEQUAL ); 506 glDepthFunc( GL_LEQUAL ); 507 508 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 509 glDepthMask(GL_FALSE); 510 511 // now issue queries for all objects 512 for (j = 0; j < mObjects.size(); j++) { 513 int q; 514 for (q = 0; j + q < mObjects.size() && q < mOcclusionQueries.size(); q++) { 515 glBeginOcclusionQueryNV(mOcclusionQueries[q]); 516 RenderIntersectable(mObjects[j+q]); 517 glEndOcclusionQueryNV(); 518 } 519 520 521 // collect results of the queries 522 for (q = 0; j + q < mObjects.size() && q < mOcclusionQueries.size(); q++) { 523 unsigned int pixelCount; 524 // reenable other state 525 526 #if 1 527 do { 528 glGetOcclusionQueryuivNV(mOcclusionQueries[q], 529 GL_PIXEL_COUNT_AVAILABLE_NV, 530 &pixelCount); 531 if (!pixelCount) 532 cout<<"W"; 533 } while(!pixelCount); 534 #endif 535 536 glGetOcclusionQueryuivNV(mOcclusionQueries[q], 537 GL_PIXEL_COUNT_NV, 538 &pixelCount); 539 // if (pixelCount) 540 // cout<<"q="<<mOcclusionQueries[q]<<" pc="<<pixelCount<<" "; 541 mObjects[j+q]->mCounter += pixelCount; 542 } 543 j += q; 544 } 545 546 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 547 glDepthMask(GL_TRUE); 548 } 549 550 551 } 552 // now evaluate the statistics over that sample 553 // currently only the number of visible objects is taken into account 554 sample.Reset(); 555 for (j = 0; j < mObjects.size(); j++) { 556 if (mObjects[j]->mCounter) { 557 sample.mVisibleObjects++; 558 sample.mVisiblePixels += mObjects[j]->mCounter; 559 } 560 } 561 cout<<"RS="<<sample.mVisibleObjects<<" "; 562 } 563 564 void 565 GlRendererBuffer::SampleRenderCost( 566 const int n, 567 vector<RenderCostSample> &samples 568 ) 569 { 570 makeCurrent(); 571 572 if (mPixelBuffer == NULL) 573 mPixelBuffer = new unsigned int[GetWidth()*GetHeight()]; 574 575 SetupProjection(GetHeight(), GetHeight(), 90.0f); 576 577 samples.resize(n); 578 halton.Reset(); 579 580 int i; 581 int numQ = 500; 582 583 if (mOcclusionQueries.size() < numQ) { 584 cout<<"allocating occ queries..."<<endl; 585 586 numQ; 587 unsigned int *queries = new unsigned int[numQ]; 588 for (i=0; i < numQ; i++) 589 queries[i] = 111; 590 591 glGenOcclusionQueriesNV(numQ, queries); 592 593 mOcclusionQueries.resize(numQ); 594 595 for (i=0; i < numQ; i++) 596 mOcclusionQueries[i] = queries[i]; 597 598 delete queries; 599 } 600 601 for (i=0; i < n; i++) 602 EvalRenderCostSample( 603 samples[i] 604 ); 605 606 doneCurrent(); 607 608 } 609 413 610 414 611 void … … 455 652 QGLPixelBuffer(QSize(w, h)), GlRenderer(sceneGraph, viewcells, tree) { 456 653 457 environment->GetIntValue("Preprocessor.pvsRenderErrorSamples", mPvsStatFrames); 458 mPvsErrorBuffer.resize(mPvsStatFrames); 459 ClearErrorBuffer(); 460 461 InitGL(); 462 463 } 654 environment->GetIntValue("Preprocessor.pvsRenderErrorSamples", mPvsStatFrames); 655 mPvsErrorBuffer.resize(mPvsStatFrames); 656 ClearErrorBuffer(); 657 658 mPixelBuffer = NULL; 659 660 makeCurrent(); 661 InitGL(); 662 doneCurrent(); 663 664 } 464 665 465 666 float … … 822 1023 } 823 1024 1025 void 1026 GlRenderer::_RenderScene() 1027 { 1028 ObjectContainer::const_iterator oi = mObjects.begin(); 1029 for (; oi != mObjects.end(); oi++) 1030 RenderIntersectable(*oi); 1031 } 824 1032 825 1033 bool … … 827 1035 { 828 1036 static int glList = -1; 829 if ( glList == -1)830 831 glList = glGenLists(1);832 glNewList(glList, GL_COMPILE);833 ObjectContainer::const_iterator oi = mObjects.begin();834 for (; oi != mObjects.end(); oi++)835 RenderIntersectable(*oi);836 gl EndList();837 } 838 839 glCallList(glList); 1037 if (mUseGlLists) { 1038 if (glList == -1) { 1039 glList = glGenLists(1); 1040 glNewList(glList, GL_COMPILE); 1041 _RenderScene(); 1042 glEndList(); 1043 } 1044 glCallList(glList); 1045 } else 1046 _RenderScene(); 1047 840 1048 841 1049 return true; … … 1714 1922 makeCurrent(); 1715 1923 GlRenderer::InitGL(); 1924 1716 1925 #if 1 1717 1926 // initialise dual depth buffer textures
Note: See TracChangeset
for help on using the changeset viewer.