Changeset 2505 for GTP/trunk/Lib/Vis
- Timestamp:
- 07/03/07 15:23:55 (17 years ago)
- Location:
- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionQueriesQueryManager.h
r2280 r2505 21 21 OcclusionQueriesQueryManager(PlatformHierarchyInterface *hierarchyInterface, 22 22 Viewport *vp, 23 int queryModes, 24 int itemBufferMode): 25 PlatformQueryManager(hierarchyInterface, vp, queryModes), 26 mItemBufferMode(itemBufferMode) 23 int queryModes): 24 PlatformQueryManager(hierarchyInterface, vp, queryModes) 27 25 {} 28 26 … … 59 57 bool relativeVisibility); 60 58 61 void CollectRelativeGeometryVisibilityForItemBuffer(GtpVisibility::QueryList::iterator &projQueryIt,62 GeometryVector *geometryList,63 MeshInfoContainer *visibleGeometry);64 65 void CollectRelativePatchVisibilityForItemBuffer(GtpVisibility::QueryList::iterator &projQueryIt,66 PatchVector *patchList,67 PatchInfoContainer *visiblePatches);68 59 69 60 void CollectPatchVisibility(GtpVisibility::QueryList::iterator &visQueryIt, … … 84 75 PatchVector *patchList); 85 76 86 int mItemBufferMode;87 77 }; 88 78 -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgrePlatformQueryManager.h
r2280 r2505 52 52 protected: 53 53 54 #ifdef ITEM_BUFFER55 void CollectItemBufferResults(MeshInfoContainer *visibleGeometry,56 PatchInfoContainer *visiblePatches);57 58 void InitItemBuffer(MeshInfoContainer *visibleGeometry,59 PatchInfoContainer *visiblePatches);60 #endif // ITEM_BUFFER61 62 54 Viewport *mViewport; 63 55 bool mWasInitialised; -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp
r2502 r2505 2206 2206 const bool nodeVisibility) 2207 2207 { 2208 const int itemBufferMode = 0;2209 2208 const bool relativeVisibility = false; 2210 2209 const bool approximateVisibility = false; … … 2220 2219 new OcclusionQueriesQueryManager(mHierarchyInterface, 2221 2220 vp, 2222 queryModes, 2223 itemBufferMode); 2221 queryModes); 2224 2222 2225 2223 mVisibilityManager->SetQueryManager(queryManager); … … 2397 2395 // don't have to fill queue, just render depth 2398 2396 const bool fillQueue = false; 2399 2400 2397 RenderHierarchicalCulling(fillQueue); 2401 2398 … … 2495 2492 mBoxes.clear(); 2496 2493 2497 const int itemBufferMode = 0;2498 2494 const bool relativeVisibility = false; 2499 2495 bool approximateVisibility = false; … … 2518 2514 new OcclusionQueriesQueryManager(mHierarchyInterface, 2519 2515 cam->getViewport(), 2520 queryModes, 2521 itemBufferMode); 2516 queryModes); 2522 2517 2523 2518 mVisibilityManager->SetQueryManager(queryManager); … … 2546 2541 } 2547 2542 2548 if ( 1)2543 if (0) 2549 2544 { 2550 2545 std::stringstream d; … … 2563 2558 //////////// 2564 2559 //-- apply queries on geometry level 2565 2566 2560 AddVisibleNodeGeometryToQueue(visibleNodes, cam); 2567 2561 } -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionQueriesQueryManager.cpp
r2280 r2505 19 19 int queryModes, 20 20 int itemBufferMode) 21 :PlatformQueryManager(hierarchyInterface, vp, queryModes), 22 mItemBufferMode(itemBufferMode) 21 :PlatformQueryManager(hierarchyInterface, vp, queryModes) 23 22 { 24 23 }*/ … … 39 38 bool overlayEnabled = mViewport->getOverlaysEnabled(); 40 39 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); 96 72 97 73 … … 164 140 // for relative visibility we need 2 rendering passes 165 141 int n = relativeVisibility ? 2 : 1; 166 if (mItemBufferMode > 0) 167 LogManager::getSingleton().logMessage("using item buffer"); 142 168 143 169 144 for (int i = 0; i < n; ++ i) 170 145 { 171 //-- quer ies forhierarchy nodes146 //-- query the hierarchy nodes 172 147 for (nodeIt = nodeList.begin(); nodeIt != nodeIt_end; ++ nodeIt) 173 148 { 174 149 // TODO: DELETE QUERIES FROM PREVIOUS RENDER 175 150 bool intersects = false; 176 177 151 pfHierarchyInterface->CheckFrustumVisible(*nodeIt, intersects); 178 152 179 // always push back if only checkingapproximate visibility or intersects153 // always add node if only checking for approximate visibility or intersects 180 154 if (approximateVisibility || intersects) 181 155 { … … 195 169 /////////////// 196 170 //-- 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 219 188 /////////////// 220 189 //-- queries for patches 221 190 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 241 209 pfHierarchyInterface->GetRenderSystem()->clearFrameBuffer(FBT_DEPTH); 242 210 } 211 243 212 244 213 /////////////// … … 248 217 GtpVisibility::QueryList::iterator projQueryIt = queryList[1].begin(); 249 218 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 { 269 231 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 286 241 CollectPatchVisibility(visQueryIt, 287 projQueryIt, 288 &patchList, 289 visiblePatches, 290 relativeVisibility); 291 } 242 projQueryIt, 243 &patchList, 244 visiblePatches, 245 relativeVisibility); 246 } 247 292 248 293 249 //////////// … … 321 277 // (duplicates occur if an object is on the edge of the viewport) 322 278 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); 333 281 } 334 282 //------------------------------------------------------------------------ … … 374 322 } 375 323 //----------------------------------------------------------------------- 376 void OcclusionQueriesQueryManager::CollectRelativeGeometryVisibilityForItemBuffer(377 GtpVisibility::QueryList::iterator &projQueryIt,378 GeometryVector *geometryList,379 MeshInfoContainer *visibleGeometry)380 {381 GeometryVector::iterator geometryIt;382 383 //-- queries for geometry384 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 geometry408 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 //-----------------------------------------------------------------------424 324 void OcclusionQueriesQueryManager::CollectGeometryVisibility( 425 325 GtpVisibility::QueryList::iterator &visQueryIt, -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformQueryManager.cpp
r2455 r2505 12 12 namespace Ogre { 13 13 14 14 //----------------------------------------------------------------------- 15 void PlatformQueryManager::SetViewport(Viewport *vp) 16 { 17 mViewport = vp; 18 } 15 19 //----------------------------------------------------------------------- 16 20 void PlatformQueryManager::ComputeFromPointVisibility( … … 65 69 // prevent from initialising geometry / node array again 66 70 if (dir > 0) 67 {68 71 mWasInitialised = true; 69 }70 72 71 73 ComputeCameraVisibility(*cam, … … 114 116 //pfHierarchyInterface->GetRenderSystem()->clearFrameBuffer(FBT_COLOUR | FBT_DEPTH); 115 117 116 #ifdef ITEM_BUFFER 117 // initialise item buffer (if not already initialised) 118 InitItemBuffer(visibleGeometry, visiblePatches); 119 120 ////////// 121 //-- render scene with item buffer (i.e., objects with their id as color codes) 122 123 // enable item buffer (must be provided by scene manager) 124 bool useItemBuffer = true; 125 sm->setOption("UseItemBuffer", &useItemBuffer); 126 #endif // ITEM_BUFFER 127 128 sm->_renderScene(pCam, mViewport, false); // render item buffer 118 // render scene once to fill depth buffer 119 sm->_renderScene(pCam, mViewport, false); 129 120 130 #ifdef ITEM_BUFFER 131 ///////// 132 //-- collect results 133 CollectItemBufferResults(visibleGeometry, visiblePatches); 134 135 ///////// 136 //-- reset state 137 useItemBuffer = false; // don't need item buffer anymore 138 sm->setOption("UseItemBuffer", &useItemBuffer); 139 #endif // ITEM_BUFFER 140 141 mWasInitialised = false; // reset initialised - flag 121 mWasInitialised = false; // reset flag 142 122 mViewport->setOverlaysEnabled(overlayEnabled); // reset old overlay status 143 123 mViewport->setBackgroundColour(bg); // reset background color 144 124 } 145 #ifdef ITEM_BUFFER146 //-----------------------------------------------------------------------147 void PlatformQueryManager::CollectItemBufferResults(148 MeshInfoContainer *visibleGeometry,149 PatchInfoContainer *visiblePatches)150 {151 int dimx = 0;152 int dimy = 0;153 125 154 // copy frame buffer155 uchar *buf = mViewport->getTarget()->getBufferContents(dimx, dimy);156 157 // loop through frame buffer and collect visible pixels158 for (int idx = 0; idx < dimy * dimx * 3; idx += 3)159 {160 //-- decode color code to receive id161 int id = buf[idx] << 16;162 id += buf[idx + 1] << 8;163 id += buf[idx + 2];164 165 // if valid id <= add visibility (id values start at 1)166 if (mQueryModes == PATCH_VISIBILITY)167 {168 if ((id > 0) && (id < (int)visiblePatches->size()))169 {170 ((*visiblePatches)[id]).AddVisibility(1, 0);171 }172 }173 else if (mQueryModes == GEOMETRY_VISIBILITY)174 {175 if ((id > 0) && (id < (int)visibleGeometry->size()))176 {177 ((*visibleGeometry)[id]).AddVisibility(1, 0);178 }179 }180 }181 182 delete [] buf;183 }184 185 //-----------------------------------------------------------------------186 void PlatformQueryManager::InitItemBuffer(187 MeshInfoContainer *visibleGeometry,188 PatchInfoContainer *visiblePatches)189 {190 if (mWasInitialised)191 return;192 193 mWasInitialised = true;194 195 SceneManager *sm =196 //static_cast<PlatformHierarchyInterface *>(mHierarchyInterface)->GetSceneManager();197 static_cast<PlatformHierarchyInterface *>(mHierarchyInterface)->GetSceneManager();198 199 SceneManager::EntityIterator it = sm->getEntityIterator();200 201 // TODO: make the function more efficient202 203 visibleGeometry->clear();204 visiblePatches->clear();205 206 int id = 0;207 208 /* We can either use patches or meshes. If patches are used, an unique id must209 be given each patch. Otherwise the same id must be given to all patches belonging210 to the same mesh.211 */212 while (it.hasMoreElements())213 {214 Entity *ent = it.getNext();215 216 for (int i = 0; i < (int)ent->getNumSubEntities(); ++i)217 {218 SubEntity *subEnt = ent->getSubEntity(i);219 220 if (mQueryModes == PATCH_VISIBILITY)221 {222 ++ id;223 visiblePatches->push_back(GtpVisibility::PatchInfo(subEnt, 0, 0));224 }225 226 subEnt->setId(id);227 //subEnt->setId((41 << 16) + (4 << 8) + 60);228 }229 230 if (mQueryModes == GEOMETRY_VISIBILITY)231 {232 visibleGeometry->push_back(GtpVisibility::MeshInfo(ent, 0, 0));233 ++ id;234 }235 }236 }237 #endif // ITEM_BUFFER238 //-----------------------------------------------------------------------239 void PlatformQueryManager::SetViewport(Viewport *vp)240 {241 mViewport = vp;242 }243 126 } // namespace Ogre -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/Plugin_VisibilitySceneManager.vcproj
r2353 r2505 114 114 AdditionalLibraryDirectories=""$(OGRE_PATH)\PlugIns\OctreeSceneManager\bin\$(ConfigurationName)";"$(OGRE_PATH)\OgreMain\lib\$(ConfigurationName)";"$(OGRE_PATH)\Samples\Common\CEGUIRenderer\lib";"$(OGRE_PATH)\Dependencies\lib\$(ConfigurationName)";"..\..\..\Preprocessing\lib\$(ConfigurationName)";..\..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\Preprocessing\src\GL;..\..\..\..\..\..\..\NonGTP\Zlib\lib;"..\..\lib\$(ConfigurationName)";"..\..\..\..\..\Lib\Vis\OnlineCullingCHC\IVReader\lib\$(ConfigurationName)";"..\..\..\..\..\Lib\Vis\OnlineCullingCHC\ObjReader\lib\$(ConfigurationName)"" 115 115 ModuleDefinitionFile="..\misc\OgreVisibilitySceneManager.def" 116 GenerateDebugInformation=" FALSE"116 GenerateDebugInformation="TRUE" 117 117 SubSystem="2" 118 118 OptimizeReferences="2"
Note: See TracChangeset
for help on using the changeset viewer.