Ignore:
Timestamp:
07/03/07 15:23:55 (17 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionQueriesQueryManager.cpp

    r2280 r2505  
    1919                                                        int queryModes, 
    2020                                                        int itemBufferMode) 
    21 :PlatformQueryManager(hierarchyInterface, vp, queryModes),  
    22 mItemBufferMode(itemBufferMode) 
     21:PlatformQueryManager(hierarchyInterface, vp, queryModes) 
    2322{ 
    2423}*/ 
     
    3938        bool overlayEnabled = mViewport->getOverlaysEnabled(); 
    4039 
    41         //mItemBufferMode = 0; 
    42         if (0 && (mItemBufferMode && mQueryModes) != 0) 
    43         { 
    44                 /////////// 
    45                 //-- render scene with item buffer (ids are used as color codes) 
    46  
    47                 int savedQueryModes = mQueryModes; 
    48                 mQueryModes = mItemBufferMode; 
    49                  
    50                 PlatformQueryManager::ComputeCameraVisibility(camera,  
    51                                                                                                           visibleNodes, 
    52                                                                                                           visibleGeometry,  
    53                                                                                                           visiblePatches,  
    54                                                                                                           relativeVisibility, 
    55                                                                                                           approximateVisibility); 
    56                  
    57                 // overlays cause false visibility 
    58                 mViewport->setOverlaysEnabled(false); 
    59                 mQueryModes = savedQueryModes; 
    60         } 
    61         else 
    62         { 
    63                 // const_cast allowed because camera is not changed in renderScene 
    64                 Camera *pCam = const_cast<Camera *>(&camera);  
    65                 mViewport->setOverlaysEnabled(false); 
    66  
    67                 //////////////////////// 
    68                 //-- Render scene to get conservative visibility and fill depth buffer 
    69  
    70                 OcclusionCullingSceneManager *occlusionSceneMgr =  
    71                         static_cast<OcclusionCullingSceneManager *>(pfHierarchyInterface->GetSceneManager()); 
    72  
    73                 // no visibility manager available => no visibility scene manager, return 
    74                 GtpVisibility::VisibilityManager *visManager = NULL;     
    75                  
    76                 if (!occlusionSceneMgr->getOption("VisibilityManager", &visManager)) 
    77                 { 
    78                         Ogre::LogManager::getSingleton().logMessage("no vismanager found"); 
    79                         return; 
    80                 } 
    81  
    82                 // use stop and wait culling for from view point queries because probably 
    83                 // no temporal coherence 
    84                 GtpVisibility::VisibilityEnvironment::CullingManagerType occlusionType =  
    85                         visManager->GetCullingManagerType(); 
    86  
    87                 visManager->SetCullingManager(GtpVisibility::VisibilityEnvironment::STOP_AND_WAIT_CULLING); 
    88  
    89                 if (1) 
    90                         occlusionSceneMgr->RenderDepthForQuery(pCam, mViewport); 
    91                 else 
    92                         pfHierarchyInterface->GetSceneManager()->_renderScene(pCam, mViewport, false); 
    93  
    94                 visManager->SetCullingManager(occlusionType); 
    95         } 
     40        // const_cast allowed because camera is not changed in renderScene 
     41        Camera *pCam = const_cast<Camera *>(&camera);  
     42        mViewport->setOverlaysEnabled(false); 
     43 
     44        //////////////////////// 
     45        //-- Render scene to get conservative visibility and fill depth buffer 
     46 
     47        OcclusionCullingSceneManager *occlusionSceneMgr =  
     48                static_cast<OcclusionCullingSceneManager *>(pfHierarchyInterface->GetSceneManager()); 
     49 
     50        // no visibility manager available => no visibility scene manager, return 
     51        GtpVisibility::VisibilityManager *visManager = NULL;     
     52 
     53        if (!occlusionSceneMgr->getOption("VisibilityManager", &visManager)) 
     54        { 
     55                Ogre::LogManager::getSingleton().logMessage("no vismanager found"); 
     56                return; 
     57        } 
     58 
     59        // use stop and wait culling for from view point queries because 
     60        // of issues with temporal coherence 
     61        GtpVisibility::VisibilityEnvironment::CullingManagerType occlusionType =  
     62                visManager->GetCullingManagerType(); 
     63 
     64        visManager->SetCullingManager(GtpVisibility::VisibilityEnvironment::STOP_AND_WAIT_CULLING); 
     65 
     66        // rendert the scene once to fill depth buffer and to get a first approximation 
     67        // of visible objects 
     68        occlusionSceneMgr->RenderDepthForQuery(pCam, mViewport); 
     69 
     70        // reset occlusion culling manager 
     71        visManager->SetCullingManager(occlusionType); 
    9672 
    9773         
     
    164140        // for relative visibility we need 2 rendering passes 
    165141        int n = relativeVisibility ? 2 : 1; 
    166         if (mItemBufferMode > 0) 
    167                 LogManager::getSingleton().logMessage("using item buffer"); 
     142         
    168143 
    169144        for (int i = 0; i < n; ++ i) 
    170145        { 
    171                 //-- queries for hierarchy nodes 
     146                //-- query the hierarchy nodes 
    172147                for (nodeIt = nodeList.begin(); nodeIt != nodeIt_end; ++ nodeIt)                 
    173148                { 
    174149                        // TODO: DELETE QUERIES FROM PREVIOUS RENDER 
    175150                        bool intersects = false; 
    176  
    177151                        pfHierarchyInterface->CheckFrustumVisible(*nodeIt, intersects); 
    178152 
    179                         // always push back if only checking approximate visibility or intersects 
     153                        // always add node if only checking for approximate visibility or intersects 
    180154                        if (approximateVisibility || intersects) 
    181155                        { 
     
    195169                /////////////// 
    196170                //-- queries for geometry 
    197                  
    198                 // note: for item buffer we can capture only projected visibility 
    199  
    200                 if ((mItemBufferMode != GEOMETRY_VISIBILITY) || (i == 1)) 
    201                 {                        
    202                         for (geometryIt = geometryList.begin(); geometryIt != geometryIt_end; ++ geometryIt) 
    203                         { 
    204                                 if (approximateVisibility) 
    205                                 { 
    206                                         // no more information available 
    207                                         const int visPixels = 1; 
    208                                         const int projPixels = 1; 
    209  
    210                                         visibleGeometry->push_back(MeshInfo(*geometryIt, visPixels, projPixels)); 
    211                                 } 
    212                                 else 
    213                                 { 
    214                                         queryList[i].push_back(pfHierarchyInterface->IssueMeshOcclusionQuery(*geometryIt)); 
    215                                 } 
    216                         } 
    217                 } 
    218                  
     171 
     172                for (geometryIt = geometryList.begin(); geometryIt != geometryIt_end; ++ geometryIt) 
     173                { 
     174                        if (approximateVisibility) 
     175                        { 
     176                                // no more information available 
     177                                const int visPixels = 1; 
     178                                const int projPixels = 1; 
     179 
     180                                visibleGeometry->push_back(MeshInfo(*geometryIt, visPixels, projPixels)); 
     181                        } 
     182                        else 
     183                        { 
     184                                queryList[i].push_back(pfHierarchyInterface->IssueMeshOcclusionQuery(*geometryIt)); 
     185                        } 
     186                } 
     187 
    219188                /////////////// 
    220189                //-- queries for patches 
    221190 
    222                 if ((mItemBufferMode != PATCH_VISIBILITY) || (i == 1)) 
    223                 { 
    224                         for (patchIt = patchList.begin(); patchIt != patchIt_end; ++patchIt) 
    225                         { 
    226                                 if (approximateVisibility) 
    227                                 { 
    228                                         // no more information available 
    229                                         const int visPixels = 1; 
    230                                         const int projPixels = 1; 
    231  
    232                                         visiblePatches->push_back(PatchInfo(*patchIt, visPixels, projPixels)); 
    233                                 } 
    234                                 else 
    235                                 { 
    236                                         queryList[i].push_back(pfHierarchyInterface->IssuePatchOcclusionQuery(*patchIt)); 
    237                                 } 
    238                         } 
    239                 } 
    240  
     191                for (patchIt = patchList.begin(); patchIt != patchIt_end; ++patchIt) 
     192                { 
     193                        if (approximateVisibility) 
     194                        { 
     195                                // there is not more information available 
     196                                const int visPixels = 1; 
     197                                const int projPixels = 1; 
     198 
     199                                visiblePatches->push_back(PatchInfo(*patchIt, visPixels, projPixels)); 
     200                        } 
     201                        else 
     202                        { 
     203                                queryList[i].push_back(pfHierarchyInterface->IssuePatchOcclusionQuery(*patchIt)); 
     204                        } 
     205                } 
     206 
     207                // the second time we have to render against the cleared depth buffer to obtain 
     208                // projected pixels 
    241209                pfHierarchyInterface->GetRenderSystem()->clearFrameBuffer(FBT_DEPTH); 
    242210        } 
     211 
    243212 
    244213        ///////////////  
     
    248217        GtpVisibility::QueryList::iterator projQueryIt = queryList[1].begin(); 
    249218         
    250         // collect occlusion queries for hierarchy nodes 
    251         CollectNodeVisibility(visQueryIt,  
    252                                                   projQueryIt,  
    253                                                   &nodeList,  
    254                                                   visibleNodes,  
    255                                                   relativeVisibility); 
    256  
    257  
    258         // collect occlusion queries for geometry 
    259         if ((mItemBufferMode == GEOMETRY_VISIBILITY) && relativeVisibility) 
    260         { 
    261                 // if visibility was established using the item buffer, 
    262                 // the array is organized different (e.g., ordered by id, all possible objects) 
    263                 CollectRelativeGeometryVisibilityForItemBuffer(projQueryIt,  
    264                                                                                                            &geometryList,  
    265                                                                                                            visibleGeometry); 
    266         } 
    267         else if (mItemBufferMode != GEOMETRY_VISIBILITY) 
    268         { 
     219        if (1) 
     220        {        
     221                // collect occlusion queries for hierarchy nodes 
     222                CollectNodeVisibility(visQueryIt,  
     223                        projQueryIt,  
     224                        &nodeList,  
     225                        visibleNodes,  
     226                        relativeVisibility); 
     227        } 
     228 
     229        if (1) 
     230        {        
    269231                CollectGeometryVisibility(visQueryIt,  
    270                                                                   projQueryIt,  
    271                                                                   &geometryList,  
    272                                                                   visibleGeometry,  
    273                                                                   relativeVisibility); 
    274         } 
    275  
    276  
    277         // collect occlusion queries for patches 
    278         if ((mItemBufferMode == PATCH_VISIBILITY) && relativeVisibility) 
    279         { 
    280                 CollectRelativePatchVisibilityForItemBuffer(projQueryIt,  
    281                                                                                                         &patchList,  
    282                                                                                                         visiblePatches); 
    283         } 
    284         else if (mItemBufferMode != PATCH_VISIBILITY) 
    285         { 
     232                        projQueryIt,  
     233                        &geometryList,  
     234                        visibleGeometry,  
     235                        relativeVisibility); 
     236        } 
     237 
     238        if (1) 
     239        { 
     240                // collect occlusion queries for patches 
    286241                CollectPatchVisibility(visQueryIt,  
    287                                                            projQueryIt,  
    288                                                            &patchList,  
    289                                                            visiblePatches,  
    290                                                            relativeVisibility); 
    291         }        
     242                        projQueryIt,  
     243                        &patchList,  
     244                        visiblePatches,  
     245                        relativeVisibility); 
     246        } 
     247 
    292248 
    293249        //////////// 
     
    321277        // (duplicates occur if an object is on the edge of the viewport) 
    322278        RemoveDuplicateNodes(visibleNodes); 
    323  
    324         if (mItemBufferMode != GEOMETRY_VISIBILITY) 
    325         { 
    326                 RemoveDuplicateGeometry(visibleGeometry); 
    327         } 
    328  
    329         if (mItemBufferMode != PATCH_VISIBILITY) 
    330         { 
    331                 RemoveDuplicatePatches(visiblePatches); 
    332         } 
     279        RemoveDuplicateGeometry(visibleGeometry); 
     280        RemoveDuplicatePatches(visiblePatches); 
    333281} 
    334282//------------------------------------------------------------------------ 
     
    374322} 
    375323//----------------------------------------------------------------------- 
    376 void OcclusionQueriesQueryManager::CollectRelativeGeometryVisibilityForItemBuffer( 
    377                                                                         GtpVisibility::QueryList::iterator &projQueryIt, 
    378                                                                         GeometryVector *geometryList,  
    379                                                                         MeshInfoContainer *visibleGeometry) 
    380 { 
    381         GeometryVector::iterator geometryIt; 
    382  
    383         //-- queries for geometry 
    384         for (geometryIt = geometryList->begin(); geometryIt != geometryList->end(); ++ geometryIt) 
    385         { 
    386                 unsigned int projectedPixels = 0; 
    387  
    388                 (*projQueryIt)->GetQueryResult(projectedPixels, true); 
    389  
    390                 ++projQueryIt; 
    391                 int id = (*geometryIt)->getSubEntity(0)->getId(); 
    392  
    393                 if ((id > 0) && (id < (int)visibleGeometry->size())) 
    394                 { 
    395                         (*visibleGeometry)[id].AddVisibility(0, projectedPixels); 
    396                 } 
    397         } 
    398 } 
    399 //----------------------------------------------------------------------- 
    400 void OcclusionQueriesQueryManager::CollectRelativePatchVisibilityForItemBuffer( 
    401                                                                         GtpVisibility::QueryList::iterator &projQueryIt, 
    402                                                                         PatchVector *patchList,  
    403                                                                         PatchInfoContainer *visiblePatches) 
    404 { 
    405         PatchVector::iterator patchIt; 
    406  
    407         //-- queries for geometry 
    408         for (patchIt = patchList->begin(); patchIt != patchList->end(); ++ patchIt) 
    409         { 
    410                 unsigned int projectedPixels = 0; 
    411  
    412                 (*projQueryIt)->GetQueryResult(projectedPixels, true); 
    413  
    414                 ++projQueryIt; 
    415                 int id = (*patchIt)->getId(); 
    416  
    417                 if ((id > 0) && (id < (int)visiblePatches->size())) 
    418                 { 
    419                         (*visiblePatches)[id].AddVisibility(0, projectedPixels); 
    420                 } 
    421         } 
    422 } 
    423 //----------------------------------------------------------------------- 
    424324void  OcclusionQueriesQueryManager::CollectGeometryVisibility( 
    425325                                                        GtpVisibility::QueryList::iterator &visQueryIt,  
Note: See TracChangeset for help on using the changeset viewer.