Ignore:
Timestamp:
04/24/06 20:27:38 (18 years ago)
Author:
bittner
Message:

first merge after the svn server crash

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp

    r752 r811  
    99#include "Environment.h" 
    1010 
     11//#define GL_GLEXT_PROTOTYPES 
    1112#include <GL/glext.h> 
    1213#include <Cg/cg.h> 
     
    3435PFNGLENDOCCLUSIONQUERYNVPROC glEndOcclusionQueryNV; 
    3536PFNGLGETOCCLUSIONQUERYUIVNVPROC glGetOcclusionQueryuivNV; 
     37 
     38//PFNGLGENQUERIESARBPROC glGenQueriesARB; 
     39//PFNGLBEGINQUERYARBPROC glBeginQueryARB; 
     40//PFNGLENDQUERYARBPROC glEndQueryARB; 
     41//PFNGLGETQUERYUIVARBPROC glGetQueryuivARB; 
    3642#endif 
    3743 
     
    5763  mSnapPrefix = "snap/"; 
    5864  mUseForcedColors = false; 
     65 
     66  mUseGlLists = true; 
     67   
    5968} 
    6069 
     
    140149{ 
    141150  // swap bits of the color 
    142    
    143151  glColor3ub(id&255, (id>>8)&255, (id>>16)&255); 
    144152} 
     
    203211 
    204212 
     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   
    205225 
    206226#if 0 
     
    391411 
    392412void 
    393 GlRenderer::SetupProjection(const int w, const int h) 
     413GlRenderer::SetupProjection(const int w, const int h, const float angle) 
    394414{ 
    395415  glViewport(0, 0, w, h); 
    396416  glMatrixMode(GL_PROJECTION); 
    397417  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())); 
    399419  glMatrixMode(GL_MODELVIEW); 
    400420} 
     
    404424{ 
    405425  Vector3 target = mViewPoint + mViewDirection; 
     426 
    406427  Vector3 up(0,1,0); 
     428   
     429  if (abs(DotProd(mViewDirection, up)) > 0.99f) 
     430        up = Vector3(1, 0, 0); 
    407431   
    408432  glLoadIdentity(); 
     
    411435                        up.x, up.y, up.z); 
    412436} 
     437 
     438 
     439void 
     440GlRendererBuffer::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 
     564void 
     565GlRendererBuffer::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   
    413610 
    414611void 
     
    455652QGLPixelBuffer(QSize(w, h)), GlRenderer(sceneGraph, viewcells, tree) { 
    456653  
    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} 
    464665 
    465666float 
     
    8221023} 
    8231024 
     1025void 
     1026GlRenderer::_RenderScene() 
     1027{ 
     1028  ObjectContainer::const_iterator oi = mObjects.begin(); 
     1029  for (; oi != mObjects.end(); oi++) 
     1030        RenderIntersectable(*oi); 
     1031} 
    8241032 
    8251033bool 
     
    8271035{ 
    8281036  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         glEndList(); 
    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         
    8401048   
    8411049  return true; 
     
    17141922 makeCurrent();  
    17151923 GlRenderer::InitGL(); 
     1924 
    17161925#if 1 
    17171926        // initialise dual depth buffer textures 
Note: See TracChangeset for help on using the changeset viewer.