Ignore:
Timestamp:
08/21/07 19:37:28 (17 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r2539 r2543  
    55#include "ViewCellsManager.h" 
    66#include "SceneGraph.h" 
    7 //#include "ObjectPvs.h" 
    87#include "Viewcell.h" 
    98#include "Beam.h" 
     
    7170                                           ViewCellsManager *viewCellsManager, 
    7271                                           KdTree *tree): 
    73   Renderer(sceneGraph, viewCellsManager), 
    74   mKdTree(tree), 
    75   mUseFalseColors(false), 
    76   mVboId(-1), 
    77   mData(NULL), 
    78   mIndices(NULL), 
    79   mUseVbos(true) 
    80   //mUseVbos(false) 
    81 { 
    82   mSceneGraph->CollectObjects(&mObjects); 
    83  
    84   //  mViewCellsManager->GetViewPoint(mViewPoint); 
    85  
    86   viewCellsManager->GetViewPoint(mViewPoint); 
    87         //mSceneGraph->GetBox().Center(); 
    88   mViewDirection = Vector3(0,0,1); 
    89  
    90   //  mViewPoint = Vector3(991.7, 187.8, -271); 
    91   //  mViewDirection = Vector3(0.9, 0, -0.4); 
    92  
    93   //  timerId = startTimer(10); 
    94   // debug coords for atlanta 
    95   //  mViewPoint = Vector3(3473, 6.778, -1699); 
    96   //  mViewDirection = Vector3(-0.2432, 0, 0.97); 
    97    
    98   mFrame = 0; 
    99   mWireFrame = false; 
    100   Environment::GetSingleton()->GetBoolValue("Preprocessor.detectEmptyViewSpace", 
    101                                                                                         mDetectEmptyViewSpace); 
    102   mSnapErrorFrames = true; 
    103   mSnapPrefix = "snap/"; 
    104   mUseForcedColors = false; 
    105   mRenderBoxes = false; 
    106   mUseGlLists = true; 
    107   //mUseGlLists = false; 
    108  
    109   if (mViewCellsManager->GetViewCellPoints()->size()) 
    110         mPvsStatFrames = (int)mViewCellsManager->GetViewCellPoints()->size(); 
    111   else 
    112         Environment::GetSingleton()->GetIntValue("Preprocessor.pvsRenderErrorSamples", mPvsStatFrames); 
    113  
    114  
    115   mPvsErrorBuffer.resize(mPvsStatFrames); 
    116   ClearErrorBuffer(); 
     72Renderer(sceneGraph, viewCellsManager), 
     73mKdTree(tree), 
     74mUseFalseColors(false), 
     75mVboId(-1), 
     76mData(NULL), 
     77mIndices(NULL), 
     78mUseVbos(true), 
     79mCurrentFrame(-1) 
     80{ 
     81        mSceneGraph->CollectObjects(&mObjects); 
     82 
     83        viewCellsManager->GetViewPoint(mViewPoint); 
     84 
     85        mViewDirection = Vector3(0,0,1); 
     86 
     87        mFrame = 0; 
     88        mWireFrame = false; 
     89        Environment::GetSingleton()->GetBoolValue("Preprocessor.detectEmptyViewSpace", 
     90                                                      mDetectEmptyViewSpace); 
     91        mSnapErrorFrames = true; 
     92        mSnapPrefix = "snap/"; 
     93        mUseForcedColors = false; 
     94        mRenderBoxes = false; 
     95        //mUseGlLists = true; 
     96        mUseGlLists = false; 
     97 
     98        if (mViewCellsManager->GetViewCellPoints()->size()) 
     99                mPvsStatFrames = (int)mViewCellsManager->GetViewCellPoints()->size(); 
     100        else 
     101                Environment::GetSingleton()->GetIntValue("Preprocessor.pvsRenderErrorSamples", mPvsStatFrames); 
     102 
     103 
     104        mPvsErrorBuffer.resize(mPvsStatFrames); 
     105        ClearErrorBuffer(); 
    117106} 
    118107 
     
    120109GlRenderer::~GlRenderer() 
    121110{ 
    122   cerr<<"gl renderer destructor..\n"; 
    123   
    124   CLEAR_CONTAINER(mOcclusionQueries); 
    125  
    126   DeleteVbos(); 
    127  
    128   if (mData) delete [] mData; 
    129   if (mIndices) delete [] mIndices; 
    130  
    131   glDeleteBuffersARB(1, &mVboId); 
    132   cerr<<"done."<<endl; 
    133 } 
    134  
    135  
    136 void 
    137 GlRenderer::RenderTriangle(TriangleIntersectable *object) 
    138 { 
    139   Triangle3 &t = object->GetItem(); 
    140  
    141   glBegin(GL_TRIANGLES); 
    142   Vector3 normal = t.GetNormal(); 
    143   glNormal3f(normal.x, normal.y, normal.z); 
    144   glVertex3f(t.mVertices[0].x, t.mVertices[0].y, t.mVertices[0].z); 
    145   glVertex3f(t.mVertices[1].x, t.mVertices[1].y, t.mVertices[1].z); 
    146   glVertex3f(t.mVertices[2].x, t.mVertices[2].y, t.mVertices[2].z); 
    147   glEnd(); 
    148 } 
    149  
    150 void 
    151 GlRenderer::RenderIntersectable(Intersectable *object) 
    152 { 
    153   if (!object) 
    154         return; 
    155    
    156   if (object->Mailed()) 
    157         return; 
    158  
    159   object->Mail(); 
    160    
    161   glPushAttrib(GL_CURRENT_BIT); 
    162   if (mUseFalseColors) 
    163         SetupFalseColor(object->mId); 
    164    
    165   switch (object->Type()) { 
    166   case Intersectable::MESH_INSTANCE: 
    167         RenderMeshInstance((MeshInstance *)object); 
    168         break; 
    169   case Intersectable::VIEW_CELL: 
    170         RenderViewCell(static_cast<ViewCell *>(object)); 
    171         break; 
    172   case Intersectable::TRANSFORMED_MESH_INSTANCE: 
    173         RenderTransformedMeshInstance(static_cast<TransformedMeshInstance *>(object)); 
    174         break; 
    175   case Intersectable::TRIANGLE_INTERSECTABLE: 
    176         RenderTriangle(static_cast<TriangleIntersectable *>(object)); 
    177         break; 
    178   case Intersectable::BVH_INTERSECTABLE: { 
    179  
    180         BvhNode *node = static_cast<BvhNode *>(object); 
    181          
    182         if (mRenderBoxes) 
    183           RenderBox(node->GetBoundingBox()); 
    184         else 
    185           RenderBvhNode(node); 
    186         break; 
    187   } 
    188   case Intersectable::KD_INTERSECTABLE: { 
    189         KdNode *node = (static_cast<KdIntersectable *>(object))->GetItem(); 
    190          
    191         if (mRenderBoxes) 
    192           RenderBox(mKdTree->GetBox(node)); 
    193         else 
    194           RenderKdNode(node); 
    195         break; 
    196   } 
    197          
    198   default: 
    199         cerr<<"Rendering this object not yet implemented\n"; 
    200         break; 
    201   } 
    202  
    203   glPopAttrib(); 
    204 } 
    205  
    206 void 
    207 GlRenderer::RenderRays(const VssRayContainer &rays) 
    208 { 
    209   VssRayContainer::const_iterator it = rays.begin(), it_end = rays.end(); 
    210  
    211   glBegin(GL_LINES); 
    212   for (; it != it_end; ++it) { 
    213         VssRay *ray = *it; 
    214         float importance = log10(1e3*ray->mWeightedPvsContribution)/3.0f; 
    215         //      cout<<"w="<<ray->mWeightedPvsContribution<<" r="<<ray->mWeightedPvsContribution; 
    216         glColor3f(importance, importance, importance); 
    217         glVertex3fv(&ray->mOrigin.x); 
    218         glVertex3fv(&ray->mTermination.x); 
    219   } 
    220   glEnd(); 
    221 } 
    222  
    223  
    224  
    225 void 
    226 GlRenderer::RenderViewCell(ViewCell *vc) 
    227 { 
    228   if (vc->GetMesh()) { 
    229  
    230         if (!mUseFalseColors) { 
    231           if (vc->GetValid())  
    232                 glColor3f(0,1,0); 
    233           else 
    234                 glColor3f(0,0,1); 
    235         } 
    236          
    237         RenderMesh(vc->GetMesh()); 
    238   } else { 
    239         // render viewcells in the subtree 
    240         if (!vc->IsLeaf()) { 
    241           ViewCellInterior *vci = (ViewCellInterior *) vc; 
    242  
    243           ViewCellContainer::iterator it = vci->mChildren.begin(); 
    244           for (; it != vci->mChildren.end(); ++it) { 
    245                 RenderViewCell(*it); 
    246           } 
    247         } else { 
    248           //      cerr<<"Empty viewcell mesh\n"; 
    249         } 
    250   } 
     111        cerr<<"gl renderer destructor..\n"; 
     112 
     113        CLEAR_CONTAINER(mOcclusionQueries); 
     114 
     115        DeleteVbos(); 
     116 
     117        if (mData) delete [] mData; 
     118        if (mIndices) delete [] mIndices; 
     119 
     120        glDeleteBuffersARB(1, &mVboId); 
     121        cerr<<"done."<<endl; 
     122} 
     123 
     124 
     125void GlRenderer::RenderTriangle(TriangleIntersectable *object) 
     126{ 
     127        Triangle3 &t = object->GetItem(); 
     128 
     129        glBegin(GL_TRIANGLES); 
     130        Vector3 normal = t.GetNormal(); 
     131        glNormal3f(normal.x, normal.y, normal.z); 
     132        glVertex3f(t.mVertices[0].x, t.mVertices[0].y, t.mVertices[0].z); 
     133        glVertex3f(t.mVertices[1].x, t.mVertices[1].y, t.mVertices[1].z); 
     134        glVertex3f(t.mVertices[2].x, t.mVertices[2].y, t.mVertices[2].z); 
     135        glEnd(); 
     136} 
     137 
     138 
     139void GlRenderer::RenderIntersectable(Intersectable *object) 
     140{ 
     141        if (!object) 
     142                return; 
     143 
     144        if (object->mRenderedFrame == mCurrentFrame) 
     145                return; 
     146 
     147        object->mRenderedFrame = mCurrentFrame; 
     148 
     149        //if (object->Mailed()) return; 
     150        //object->Mail(); 
     151 
     152        glPushAttrib(GL_CURRENT_BIT); 
     153 
     154        if (mUseFalseColors) 
     155                SetupFalseColor(object->mId); 
     156 
     157        switch (object->Type())  
     158        { 
     159        case Intersectable::MESH_INSTANCE: 
     160                RenderMeshInstance((MeshInstance *)object); 
     161                break; 
     162        case Intersectable::VIEW_CELL: 
     163                RenderViewCell(static_cast<ViewCell *>(object)); 
     164                break; 
     165        case Intersectable::TRANSFORMED_MESH_INSTANCE: 
     166                RenderTransformedMeshInstance(static_cast<TransformedMeshInstance *>(object)); 
     167                break; 
     168        case Intersectable::TRIANGLE_INTERSECTABLE: 
     169                RenderTriangle(static_cast<TriangleIntersectable *>(object)); 
     170                break; 
     171        case Intersectable::BVH_INTERSECTABLE:  
     172                { 
     173                        BvhNode *node = static_cast<BvhNode *>(object); 
     174 
     175                        if (mRenderBoxes) 
     176                                RenderBox(node->GetBoundingBox()); 
     177                        else 
     178                                RenderBvhNode(node); 
     179                        break; 
     180                } 
     181        case Intersectable::KD_INTERSECTABLE:  
     182                { 
     183                        KdNode *node = (static_cast<KdIntersectable *>(object))->GetItem(); 
     184 
     185                        if (mRenderBoxes) 
     186                                RenderBox(mKdTree->GetBox(node)); 
     187                        else 
     188                                RenderKdNode(node); 
     189                        break; 
     190                } 
     191 
     192        default: 
     193                cerr<<"Rendering this object not yet implemented\n"; 
     194                break; 
     195        } 
     196 
     197        glPopAttrib(); 
     198} 
     199 
     200 
     201void GlRenderer::RenderRays(const VssRayContainer &rays) 
     202{ 
     203        VssRayContainer::const_iterator it = rays.begin(), it_end = rays.end(); 
     204 
     205        glBegin(GL_LINES); 
     206         
     207        for (; it != it_end; ++it)  
     208        { 
     209                VssRay *ray = *it; 
     210                const float importance = log10(1e3*ray->mWeightedPvsContribution)/3.0f; 
     211                 
     212                glColor3f(importance, importance, importance); 
     213                glVertex3fv(&ray->mOrigin.x); 
     214                glVertex3fv(&ray->mTermination.x); 
     215        } 
     216 
     217        glEnd(); 
     218} 
     219 
     220 
     221void GlRenderer::RenderViewCell(ViewCell *vc) 
     222{ 
     223        if (vc->GetMesh())  
     224        { 
     225                if (!mUseFalseColors)  
     226                { 
     227                        if (vc->GetValid())  
     228                                glColor3f(0,1,0); 
     229                        else 
     230                                glColor3f(0,0,1); 
     231                } 
     232 
     233                RenderMesh(vc->GetMesh()); 
     234        }  
     235        else  
     236        { 
     237                // render viewcells in the subtree 
     238                if (!vc->IsLeaf())  
     239                { 
     240                        ViewCellInterior *vci = (ViewCellInterior *) vc; 
     241 
     242                        ViewCellContainer::iterator it = vci->mChildren.begin(); 
     243                        for (; it != vci->mChildren.end(); ++it)  
     244                        { 
     245                                RenderViewCell(*it); 
     246                        } 
     247                }  
     248                else  
     249                { 
     250                        // cerr<<"Empty viewcell mesh\n"; 
     251                } 
     252        } 
    251253} 
    252254 
     
    266268 
    267269        glPushMatrix(); 
    268 /* cout << "\n"; 
    269         for (int i = 0; i < 4; ++ i) 
    270                 for (int j = 0; j < 4; ++ j) 
    271                         cout << m.x[i][j] << " "; cout << "\n"*/ 
    272270 
    273271        glMultMatrixf((float *)m.x); 
    274272 
    275         /*GLfloat dummy[16]; 
    276         glGetFloatv(GL_MODELVIEW_MATRIX, dummy); 
    277         for (int i = 0; i < 16; ++ i) 
    278                 cout << dummy[i] << " "; 
    279         cout << endl;*/ 
    280273        RenderMesh(mi->GetMesh()); 
    281274         
     
    308301 
    309302 
    310 void 
    311 GlRenderer::RenderMesh(Mesh *mesh) 
    312 { 
    313   int i = 0; 
    314  
    315   if (!mUseFalseColors && !mUseForcedColors) 
    316           SetupMaterial(mesh->mMaterial); 
    317    
    318   for (i=0; i < mesh->mFaces.size(); i++) { 
    319         if (mWireFrame) 
    320           glBegin(GL_LINE_LOOP); 
    321         else 
    322           glBegin(GL_POLYGON); 
    323  
    324         Face *face = mesh->mFaces[i]; 
    325         for (int j = 0; j < face->mVertexIndices.size(); j++) { 
    326           glVertex3fv(&mesh->mVertices[face->mVertexIndices[j]].x); 
    327         } 
    328         glEnd(); 
    329   } 
     303void GlRenderer::RenderMesh(Mesh *mesh) 
     304{ 
     305        int i = 0; 
     306 
     307        if (!mUseFalseColors && !mUseForcedColors) 
     308                SetupMaterial(mesh->mMaterial); 
     309 
     310        for (i=0; i < mesh->mFaces.size(); i++)  
     311        { 
     312                if (mWireFrame) 
     313                        glBegin(GL_LINE_LOOP); 
     314                else 
     315                        glBegin(GL_POLYGON); 
     316 
     317                Face *face = mesh->mFaces[i]; 
     318                for (int j = 0; j < face->mVertexIndices.size(); j++) { 
     319                        glVertex3fv(&mesh->mVertices[face->mVertexIndices[j]].x); 
     320                } 
     321                glEnd(); 
     322        } 
    330323} 
    331324         
     
    758751                                                                           ) 
    759752{ 
    760   // choose a random view point 
    761   mViewCellsManager->GetViewPoint(mViewPoint); 
    762   sample.mPosition = mViewPoint; 
    763   //cout << "viewpoint: " << mViewPoint << endl; 
    764    
    765   // take a render cost sample by rendering a cube 
    766   Vector3 directions[6]; 
    767    
    768   directions[0] = Vector3(1,0,0); 
    769   directions[1] = Vector3(0,1,0); 
    770   directions[2] = Vector3(0,0,1); 
    771   directions[3] = Vector3(-1,0,0); 
    772   directions[4] = Vector3(0,-1,0); 
    773   directions[5] = Vector3(0,0,-1); 
    774    
    775   sample.mVisibleObjects = 0; 
    776    
    777   // reset object counters 
    778   ObjectContainer::const_iterator it, it_end = mObjects.end(); 
    779    
    780   for (it = mObjects.begin(); it != it_end; ++ it)  
    781         { 
    782           (*it)->mCounter = 0; 
    783           
    784         } 
    785  
    786   ++ mFrame; 
    787    
    788   //glCullFace(GL_FRONT); 
    789   glCullFace(GL_BACK); 
    790   glDisable(GL_CULL_FACE); 
    791    
    792    
     753        // choose a random view point 
     754        mViewCellsManager->GetViewPoint(mViewPoint); 
     755        sample.mPosition = mViewPoint; 
     756        //cout << "viewpoint: " << mViewPoint << endl; 
     757 
     758        // take a render cost sample by rendering a cube 
     759        Vector3 directions[6]; 
     760 
     761        directions[0] = Vector3(1,0,0); 
     762        directions[1] = Vector3(0,1,0); 
     763        directions[2] = Vector3(0,0,1); 
     764        directions[3] = Vector3(-1,0,0); 
     765        directions[4] = Vector3(0,-1,0); 
     766        directions[5] = Vector3(0,0,-1); 
     767 
     768        sample.mVisibleObjects = 0; 
     769 
     770        // reset object counters 
     771        ObjectContainer::const_iterator it, it_end = mObjects.end(); 
     772 
     773        for (it = mObjects.begin(); it != it_end; ++ it)  
     774        { 
     775                (*it)->mCounter = 0; 
     776 
     777        } 
     778 
     779        ++ mFrame; 
     780 
     781        //glCullFace(GL_FRONT); 
     782        glCullFace(GL_BACK); 
     783        glDisable(GL_CULL_FACE); 
     784 
     785 
    793786        // query all 6 directions for a full point sample 
    794   for (int i = 0; i < 6; ++ i)  
    795         { 
    796           mViewDirection = directions[i]; 
    797           SetupCamera(); 
    798            
    799           glClearColor(1.0f, 1.0f, 1.0f, 1.0f); 
    800           glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    801           //glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);    glDepthMask(GL_TRUE); 
    802           glDepthFunc(GL_LESS); 
    803            
    804           mUseFalseColors = true; 
    805            
    806           // the actual scene rendering fills the depth (for occlusion queries) 
    807           // and the frame buffer (for item buffer) 
    808           RenderScene(); 
    809            
    810            
    811           if (0)  
     787        for (int i = 0; i < 6; ++ i)  
     788        { 
     789                mViewDirection = directions[i]; 
     790                SetupCamera(); 
     791 
     792                glClearColor(1.0f, 1.0f, 1.0f, 1.0f); 
     793                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     794                //glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);      glDepthMask(GL_TRUE); 
     795                glDepthFunc(GL_LESS); 
     796 
     797                mUseFalseColors = true; 
     798 
     799                // the actual scene rendering fills the depth (for occlusion queries) 
     800                // and the frame buffer (for item buffer) 
     801                RenderScene(); 
     802 
     803 
     804                if (0)  
    812805                { 
    813                   char filename[256]; 
    814                   sprintf(filename, "snap/frame-%04d-%d.png", mFrame, i); 
    815                   //              QImage im = toImage(); 
    816                   //              im.save(filename, "PNG"); 
    817                 } 
    818            
    819           // evaluate the sample 
    820           if (useOcclusionQueries)  
     806                        char filename[256]; 
     807                        sprintf(filename, "snap/frame-%04d-%d.png", mFrame, i); 
     808                        //                QImage im = toImage(); 
     809                        //                im.save(filename, "PNG"); 
     810                } 
     811 
     812                // evaluate the sample 
     813                if (useOcclusionQueries)  
    821814                { 
    822                   EvalQueryWithOcclusionQueries(); 
    823                 } 
    824           else  
     815                        EvalQueryWithOcclusionQueries(); 
     816                } 
     817                else  
    825818                { 
    826                   EvalQueryWithItemBuffer(); 
     819                        EvalQueryWithItemBuffer(); 
    827820                } 
    828821        }   
    829    
    830   // now evaluate the statistics over that sample 
    831   // currently only the number of visible objects is taken into account 
    832   sample.Reset(); 
    833    
    834   for (it = mObjects.begin(); it != it_end; ++ it)  
    835         { 
    836           Intersectable *obj = *it; 
    837           if (obj->mCounter >= threshold)  
     822 
     823        // now evaluate the statistics over that sample 
     824        // currently only the number of visible objects is taken into account 
     825        sample.Reset(); 
     826 
     827        for (it = mObjects.begin(); it != it_end; ++ it)  
     828        { 
     829                Intersectable *obj = *it; 
     830                if (obj->mCounter >= threshold)  
    838831                { 
    839                   ++ sample.mVisibleObjects; 
    840                   sample.mVisiblePixels += obj->mCounter; 
    841                 } 
    842         } 
    843    
    844   //cout << "RS=" << sample.mVisibleObjects << " "; 
     832                        ++ sample.mVisibleObjects; 
     833                        sample.mVisiblePixels += obj->mCounter; 
     834                } 
     835        } 
     836 
     837        //cout << "RS=" << sample.mVisibleObjects << " "; 
    845838} 
    846839 
     
    856849#endif 
    857850#endif 
    858          
     851 
    859852} 
    860853 
     
    867860                                                                   ) 
    868861{ 
    869   MakeCurrent(); 
    870  
    871   if (mPixelBuffer == NULL) 
    872           mPixelBuffer = new unsigned int[GetWidth()*GetHeight()]; 
    873    
    874   // using 90 degree projection to capture 360 view with 6 samples 
    875   SetupProjection(GetHeight(), GetHeight(), 90.0f); 
    876  
    877   //samples.resize(numSamples); 
    878   halton.Reset(); 
    879    
    880   // the number of queries queried in batch mode 
    881   const int numQ = 500; 
    882  
    883   //const int numQ = (int)mObjects.size(); 
    884   if (useOcclusionQueries) 
    885   { 
    886           cout << "\ngenerating " << numQ << " queries ... "; 
    887           OcclusionQuery::GenQueries(mOcclusionQueries, numQ); 
    888           cout << "finished" << endl; 
    889   } 
    890  
    891   // sampling queries  
    892   for (int i = 0; i < numSamples; ++ i) 
    893   { 
    894           cout << "."; 
    895           EvalRenderCostSample(samples[i], useOcclusionQueries, threshold); 
    896   } 
    897  
    898   DoneCurrent(); 
    899 } 
    900    
     862        MakeCurrent(); 
     863 
     864        if (mPixelBuffer == NULL) 
     865                mPixelBuffer = new unsigned int[GetWidth()*GetHeight()]; 
     866 
     867        // using 90 degree projection to capture 360 view with 6 samples 
     868        SetupProjection(GetHeight(), GetHeight(), 90.0f); 
     869 
     870        //samples.resize(numSamples); 
     871        halton.Reset(); 
     872 
     873        // the number of queries queried in batch mode 
     874        const int numQ = 500; 
     875 
     876        //const int numQ = (int)mObjects.size(); 
     877        if (useOcclusionQueries) 
     878        { 
     879                cout << "\ngenerating " << numQ << " queries ... "; 
     880                OcclusionQuery::GenQueries(mOcclusionQueries, numQ); 
     881                cout << "finished" << endl; 
     882        } 
     883 
     884        // sampling queries  
     885        for (int i = 0; i < numSamples; ++ i) 
     886        { 
     887                cout << "."; 
     888                EvalRenderCostSample(samples[i], useOcclusionQueries, threshold); 
     889        } 
     890 
     891        DoneCurrent(); 
     892} 
     893 
    901894 
    902895 
     
    15001493GlRenderer::ValidViewPoint() 
    15011494{ 
    1502    //cout<<"VV4 "; 
     1495        //cout<<"VV4 "; 
    15031496        if (!mDetectEmptyViewSpace) 
    15041497                return true; 
    15051498        //cout << "vp: " << mViewPoint << " dir: " << mViewDirection << endl; 
    15061499 
    1507   OcclusionQuery *query = mOcclusionQueries[0]; 
    1508  
    1509   // now check whether any backfacing polygon would pass the depth test 
    1510   SetupCamera(); 
    1511   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    1512   glEnable( GL_CULL_FACE ); 
    1513   glCullFace(GL_BACK); 
    1514    
    1515   //cout<<"VV1 "; 
    1516   RenderScene(); 
    1517    
    1518   glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 
    1519   glDepthMask(GL_FALSE); 
    1520   glDisable( GL_CULL_FACE ); 
    1521    
    1522   query->BeginQuery(); 
    1523    
    1524   //  cout<<"VV2 "; 
    1525   RenderScene(); 
    1526   //  cout<<"VV3 "; 
    1527    
    1528   query->EndQuery(); 
    1529    
    1530   // at this point, if possible, go and do some other computation 
    1531   glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
    1532   glDepthMask(GL_TRUE); 
    1533   glEnable( GL_CULL_FACE ); 
    1534  
    1535   //  int wait = 0; 
    1536   //  while (!query.ResultAvailable()) { 
    1537   //    wait++; 
    1538   //  } 
    1539    
    1540   // reenable other state 
    1541   unsigned int pixelCount = query->GetQueryResult(); 
    1542   //  cout<<"VV4 "; 
    1543    
    1544           //cout<<"count: " << pixelCount<<endl; 
    1545    
    1546   if (pixelCount > 0) 
    1547   { 
    1548         return false; // backfacing polygon found -> not a valid viewspace sample 
    1549   } 
    1550   return true; 
    1551 } 
    1552  
    1553 float 
    1554 GlRenderer::GetPixelError(int &pvsSize) 
     1500        OcclusionQuery *query = mOcclusionQueries[0]; 
     1501 
     1502        // now check whether any backfacing polygon would pass the depth test 
     1503        SetupCamera(); 
     1504        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     1505        glEnable( GL_CULL_FACE ); 
     1506        glCullFace(GL_BACK); 
     1507 
     1508        //cout<<"VV1 "; 
     1509        RenderScene(); 
     1510 
     1511        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 
     1512        glDepthMask(GL_FALSE); 
     1513        glDisable( GL_CULL_FACE ); 
     1514 
     1515        query->BeginQuery(); 
     1516 
     1517        //  cout<<"VV2 "; 
     1518        RenderScene(); 
     1519        //  cout<<"VV3 "; 
     1520 
     1521        query->EndQuery(); 
     1522 
     1523        // at this point, if possible, go and do some other computation 
     1524        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
     1525        glDepthMask(GL_TRUE); 
     1526        glEnable( GL_CULL_FACE ); 
     1527 
     1528        //  int wait = 0; 
     1529        //  while (!query.ResultAvailable()) { 
     1530        //      wait++; 
     1531        //  } 
     1532 
     1533        // reenable other state 
     1534        unsigned int pixelCount = query->GetQueryResult(); 
     1535        //  cout<<"VV4 "; 
     1536 
     1537        //cout<<"count: " << pixelCount<<endl; 
     1538 
     1539        if (pixelCount > 0) 
     1540        { 
     1541                return false; // backfacing polygon found -> not a valid viewspace sample 
     1542        } 
     1543        return true; 
     1544} 
     1545 
     1546 
     1547float GlRenderer::GetPixelError(int &pvsSize) 
    15551548{ 
    15561549  return -1.0f; 
    15571550} 
    15581551 
    1559 void 
    1560 GlRenderer::RenderViewPoint() 
     1552 
     1553void GlRenderer::RenderViewPoint() 
    15611554{ 
    15621555        mWireFrame = true; 
Note: See TracChangeset for help on using the changeset viewer.