- Timestamp:
- 07/13/05 00:47:40 (19 years ago)
- Location:
- trunk/VUT
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibility/include/HierarchyInterface.h
r158 r171 12 12 typedef std::vector<HierarchyNode *> HierarchyNodeList; 13 13 typedef std::vector<GtpVisibility::Mesh *> GeometryList; 14 typedef std::vector<GtpVisibility::Patch *> PatchList; 14 15 typedef std::pair<HierarchyNode *, OcclusionQuery *> QueryPair; 15 16 typedef std::queue<QueryPair> QueryQueue; -
trunk/VUT/GtpVisibility/src/VisibilityInfo.cpp
r159 r171 48 48 void VisibilityInfo::AddVisibility(const int visiblePixels, const int projectedPixels) 49 49 { 50 mVisiblePixels += visiblePixels;50 mVisiblePixels += visiblePixels; 51 51 mProjectedPixels += projectedPixels; 52 52 } -
trunk/VUT/Ogre/include/OgreOcclusionQueriesQueryManager.h
r159 r171 7 7 8 8 /** 9 Class which implements the QueryManager for Ogre scene queries using occlusion queries.9 Class which implements a query manager for Ogre scene queries using occlusion queries. 10 10 */ 11 11 class __declspec(dllexport) OcclusionQueriesQueryManager: public PlatformQueryManager … … 15 15 on different hierarchy types, while reusing the implementation of the query methods. 16 16 */ 17 OcclusionQueriesQueryManager(PlatformHierarchyInterface *hierarchyInterface, Viewport *vp); 17 OcclusionQueriesQueryManager(PlatformHierarchyInterface *hierarchyInterface, 18 Viewport *vp, 19 bool renderPatches, 20 bool useItemBufferForGeometry); 18 21 19 22 void ComputeCameraVisibility(const Camera &camera, … … 33 36 bool relativeVisibility = false); 34 37 35 bool ShootRay(const Ray &ray, std::vector<Mesh *> *visibleMeshes, bool isGlobalLine = false); 38 39 protected: 40 41 void CollectGeometryVisibility(GtpVisibility::QueryList::iterator &visQueryIt, 42 GtpVisibility::QueryList::iterator &projQueryIt, 43 GtpVisibility::GeometryList *geometryList, 44 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 45 bool relativeVisibility); 46 47 void CollectNodeVisibility(GtpVisibility::QueryList::iterator &visQueryIt, 48 GtpVisibility::QueryList::iterator &projQueryIt, 49 GtpVisibility::HierarchyNodeList *nodeList, 50 InfoContainer<GtpVisibility::NodeInfo> *visibleNodes, 51 bool relativeVisibility); 52 53 void CollectRelativeGeometryVisibilityForItemBuffer(GtpVisibility::QueryList::iterator &projQueryIt, 54 GtpVisibility::GeometryList *geometryList, 55 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry); 56 57 void CollectRelativePatchVisibilityForItemBuffer( 58 GtpVisibility::QueryList::iterator &projQueryIt, 59 GtpVisibility::PatchList *patchList, 60 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches); 61 62 void CollectPatchVisibility(GtpVisibility::QueryList::iterator &visQueryIt, 63 GtpVisibility::QueryList::iterator &projQueryIt, 64 GtpVisibility::PatchList *patchList, 65 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches, 66 bool relativeVisibility); 67 68 void RemoveDuplicateNodes(InfoContainer<GtpVisibility::NodeInfo> *visibleNodes); 69 void RemoveDuplicateGeometry(InfoContainer<GtpVisibility::MeshInfo> *visibleMesh); 70 71 bool mUseItemBuffer; 36 72 }; 37 73 -
trunk/VUT/Ogre/include/OgrePlatformQueryManager.h
r159 r171 15 15 public: 16 16 /** Constructor taking a hierarchy interface as an argument. This allows to operate 17 onmdifferent hierarchy types, while reusing the implementation of the query methods.17 on different hierarchy types, while reusing the implementation of the query methods. 18 18 */ 19 PlatformQueryManager(PlatformHierarchyInterface *hierarchyInterface, Viewport *vp); 19 PlatformQueryManager(PlatformHierarchyInterface *hierarchyInterface, 20 Viewport *vp, 21 bool renderPatches); 20 22 21 23 /** … … 28 30 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches, 29 31 bool relativeVisibility = false); 30 31 /** 32 Ray shooting interface: finds an intersection with objects in the scene. 33 34 @param ray The given input ray (assuming the ray direction is normalized) 35 36 @param visibleMeshes List of meshes intersecting the ray 37 38 @param isGlobalLine If false only first intersection with opaque object is returned. 39 Otherwise all intersections of the ray with the scene are found. 40 41 @return true if there is any intersection. 42 */ 43 virtual bool 44 ShootRay(const Ray &ray, 45 std::vector<Mesh *> *visibleMeshes, 46 bool isGlobalLine = false 47 ); 32 33 void ComputeCameraVisibility(const Camera &camera, 34 InfoContainer<GtpVisibility::NodeInfo> *visibleNodes, 35 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 36 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches, 37 bool relativeVisibility = false); 38 39 bool ShootRay(const Ray &ray, std::vector<Mesh *> *visibleMeshes, bool isGlobalLine = false); 48 40 49 41 /** Sets a viewport for rendering. … … 52 44 53 45 protected: 46 47 void InitItemBuffer(InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 48 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches); 49 54 50 Viewport *mViewport; 55 51 bool mWasInitialised; 52 bool mRenderPatches; 56 53 }; 57 54 -
trunk/VUT/Ogre/scripts/Plugin_VisibilitySceneManager.vcproj
r154 r171 192 192 Filter="h;hpp;hxx;hm;inl;inc"> 193 193 <File 194 RelativePath="..\include\OgreItemBufferQueryManager.h">195 </File>196 <File197 194 RelativePath="..\include\OgreOcclusionQueriesQueryManager.h"> 198 195 </File> … … 228 225 Name="Source Files" 229 226 Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm"> 230 <File231 RelativePath="..\src\OgreItemBufferQueryManager.cpp">232 </File>233 227 <File 234 228 RelativePath="..\src\OgreOcclusionQueriesQueryManager.cpp"> -
trunk/VUT/Ogre/src/OgreItemBufferQueryManager.cpp
r166 r171 15 15 } 16 16 //----------------------------------------------------------------------- 17 bool ItemBufferQueryManager::ShootRay(const Ray &ray,18 std::vector<Mesh *> *visibleMeshes,19 bool isGlobalLine)20 {21 // run OGRE ray shooting query22 return false;23 }24 //-----------------------------------------------------------------------25 17 void ItemBufferQueryManager::ComputeCameraVisibility(const Camera &camera, 26 18 InfoContainer<GtpVisibility::NodeInfo> *visibleNodes, … … 29 21 bool relativeVisibility) 30 22 { 31 // initialise item buffer (if not already initialised)32 InitItemBuffer(visibleNodes, visibleGeometry, visiblePatches);33 34 23 // we need access to the scene manager and the rendersystem 35 24 PlatformHierarchyInterface *pfHierarchyInterface = … … 38 27 SceneManager *sm = pfHierarchyInterface->GetSceneManager(); 39 28 40 // --- Render scene with item buffer (i.e., objects with their id as color codes)41 29 42 30 // const_cast allowed because camera is not changed in renderScene … … 46 34 bool overlayEnabled = mViewport->getOverlaysEnabled(); 47 35 mViewport->setOverlaysEnabled(false); 48 49 // set item buffer (must be provided by scene manager)50 bool useItemBuffer = true;51 sm->setOption("UseItemBuffer", &useItemBuffer);52 36 53 37 // clear background with black (i.e., not a valid item id) 54 38 ColourValue bg = mViewport->getBackgroundColour(); 55 39 mViewport->setBackgroundColour(ColourValue(0, 0, 0, 0)); 56 pfHierarchyInterface->GetRenderSystem()->clearFrameBuffer(FBT_COLOUR | FBT_DEPTH); 57 58 //-- render item buffer 59 sm->_renderScene(pCam, mViewport, false); 60 //mViewport->getTarget()->update(); 61 62 //for(int j=0; j<10000000; j++) printf("wait"); 40 //pfHierarchyInterface->GetRenderSystem()->clearFrameBuffer(FBT_COLOUR | FBT_DEPTH); 63 41 64 42 65 //---- collect results 43 //-- render scene with item buffer (i.e., objects with their id as color codes) 44 45 // enable item buffer (must be provided by scene manager) 46 bool useItemBuffer = true; 47 sm->setOption("UseItemBuffer", &useItemBuffer); 48 sm->_renderScene(pCam, mViewport, false); // render item buffer 49 50 51 //-- collect results 52 53 // initialise item buffer (if not already initialised) 54 InitItemBuffer(visibleNodes, visibleGeometry, visiblePatches); 55 66 56 int dimx = 0; 67 57 int dimy = 0; 68 58 69 // get frame buffer59 // copy frame buffer 70 60 uchar *buf = mViewport->getTarget()->getBufferContents(dimx, dimy); 71 61 72 int n = mRenderPatchesForItemBuffer ? (int)visiblePatches->size() : (int)visibleGeometry->size(); 62 int n = mRenderPatchesForItemBuffer ? 63 (int)visiblePatches->size() : (int)visibleGeometry->size(); 73 64 74 std::stringstream d; d << "dimx: " << dimx << ", dimy: " << dimy; 75 LogManager::getSingleton().logMessage(d.str()); 65 //std::stringstream d; d << "dimx: " << dimx << ", dimy: " << dimy; LogManager::getSingleton().logMessage(d.str()); 76 66 77 // loop through frame buffer &collect visible pixels67 // loop through frame buffer and collect visible pixels 78 68 for (int idx = 0; idx < dimy * dimx * 3; idx += 3) 79 69 { … … 83 73 id += buf[idx + 2]; 84 74 85 //std::stringstream d; d << "myid: " << (int)buf[idx] << " " << (int)buf[idx + 1] << " " << (int)buf[idx + 2]; 86 //LogManager::getSingleton().logMessage(d.str()); 75 //std::stringstream d; d << "myid: " << (int)buf[idx] << " " << (int)buf[idx + 1] << " " << (int)buf[idx + 2]; LogManager::getSingleton().logMessage(d.str()); 87 76 88 77 // if valid id <= add visibility (id values start at 1) … … 100 89 } 101 90 91 102 92 //-- reset options 103 93 104 // don't need item buffer anymore 105 useItemBuffer = false; 94 useItemBuffer = false; // don't need item buffer anymore 106 95 sm->setOption("UseItemBuffer", &useItemBuffer); 107 // reset initialised - flag108 mWasInitialised = false;109 // reset old overlay status110 mViewport->setOverlaysEnabled(overlayEnabled);111 // reset background color112 mViewport->setBackgroundColour(bg);113 96 114 // delete array storing the frame buffer 115 delete [] buf; 97 mWasInitialised = false; // reset initialised - flag 98 mViewport->setOverlaysEnabled(overlayEnabled); // reset old overlay status 99 mViewport->setBackgroundColour(bg); // reset background color 100 101 delete [] buf; // delete copy of the frame buffer 116 102 } 117 103 //----------------------------------------------------------------------- -
trunk/VUT/Ogre/src/OgreOcclusionQueriesQueryManager.cpp
r159 r171 3 3 #include <OgreStringConverter.h> 4 4 #include <vector> 5 #include <OgreSubEntity.h> 5 6 6 7 7 8 namespace Ogre { 9 10 /** 11 These functions necessary to enable sorting of node / mesh / patch info. 12 */ 13 //----------------------------------------------------------------------- 14 inline bool nodeinfo_eq(const GtpVisibility::NodeInfo &info1, const GtpVisibility::NodeInfo &info2) 15 { 16 return info1.GetNode() == info2.GetNode(); 17 } 18 //----------------------------------------------------------------------- 19 inline bool meshinfo_eq(const GtpVisibility::MeshInfo &info1, const GtpVisibility::MeshInfo &info2) 20 { 21 return info1.GetMesh() == info2.GetMesh(); 22 } 23 //----------------------------------------------------------------------- 24 inline bool nodeinfo_lower(const GtpVisibility::NodeInfo &info1, const GtpVisibility::NodeInfo &info2) 25 { 26 return info1.GetNode() < info2.GetNode(); 27 } 28 //----------------------------------------------------------------------- 29 inline bool meshinfo_lower(const GtpVisibility::MeshInfo &info1, const GtpVisibility::MeshInfo &info2) 30 { 31 return info1.GetMesh() < info2.GetMesh(); 32 } 33 34 35 8 36 //----------------------------------------------------------------------- 9 OcclusionQueriesQueryManager::OcclusionQueriesQueryManager(PlatformHierarchyInterface *hierarchyInterface, Viewport *vp): 10 PlatformQueryManager(hierarchyInterface, vp) 11 { 12 } 13 //----------------------------------------------------------------------- 14 bool OcclusionQueriesQueryManager::ShootRay(const Ray &ray, std::vector<Mesh *> *visibleMeshes, bool isGlobalLine) 15 { 16 // run OGRE ray shooting query 17 return false; 37 OcclusionQueriesQueryManager::OcclusionQueriesQueryManager( 38 PlatformHierarchyInterface *hierarchyInterface, 39 Viewport *vp, 40 bool renderPatches, 41 bool useItemBufferForGeometry): 42 PlatformQueryManager(hierarchyInterface, vp, renderPatches), 43 mUseItemBuffer(useItemBufferForGeometry) 44 { 18 45 } 19 46 //----------------------------------------------------------------------- … … 24 51 bool relativeVisibility) 25 52 { 26 // we need access to the scene manager and the rendersystem53 // we need access to the scene manager and the rendersystem 27 54 PlatformHierarchyInterface *pfHierarchyInterface = 28 55 dynamic_cast<PlatformHierarchyInterface *>(mHierarchyInterface); 29 56 30 //-- Render scene to get conservative visibility and fill depth buffer31 32 // const_cast allowed because camera is not changed in renderScene33 Camera *pCam = const_cast<Camera *>(&camera);34 35 57 // disable overlays, reset them later 36 58 bool overlayEnabled = mViewport->getOverlaysEnabled(); 37 mViewport->setOverlaysEnabled(false); 38 39 //-- render the scene once to update depth buffer 40 pfHierarchyInterface->GetSceneManager()->_renderScene(pCam, mViewport, false); 41 42 /* 43 Two query lists for projected pixels and for visibile pixels: 59 60 //-- render scene with item buffer (i.e., objects with their id as color codes) 61 if (mUseItemBuffer) 62 { 63 PlatformQueryManager::ComputeCameraVisibility(camera, visibleNodes, 64 visibleGeometry, visiblePatches, relativeVisibility); 65 66 mViewport->setOverlaysEnabled(false); 67 } 68 else 69 { 70 // const_cast allowed because camera is not changed in renderScene 71 Camera *pCam = const_cast<Camera *>(&camera); 72 mViewport->setOverlaysEnabled(false); 73 74 //-- Render scene to get conservative visibility and fill depth buffer 75 pfHierarchyInterface->GetSceneManager()->_renderScene(pCam, mViewport, false); 76 } 77 78 79 /* Two query lists for projected pixels and for visibile pixels: 44 80 We test queries after a rendering pass 45 81 to get exact visibility with regard to the current camera. … … 48 84 GtpVisibility::QueryList queryList[2]; 49 85 50 // get rendered hierarchy nodes86 // rendered hierarchy nodes from previous render 51 87 GtpVisibility::HierarchyNodeList *nodeList = mHierarchyInterface->GetRenderedNodes(); 88 GtpVisibility::HierarchyNodeList::iterator nodeIt, nodeIt_end = nodeList->end(); 89 52 90 // vector for storing entities of meshes 53 91 GtpVisibility::GeometryList geometryList; 54 92 55 GtpVisibility::HierarchyNodeList::iterator nodeIt, nodeIt_end = nodeList->end(); 56 // geometry list has still do be built 57 GtpVisibility::GeometryList::iterator geometryIt, geometryIt_end; 93 // store geometry of the hierarchy node in a geometry list (only once!) 94 for (nodeIt = nodeList->begin(); nodeIt != nodeIt_end; ++nodeIt) 95 { 96 mHierarchyInterface->GetNodeGeometryList(*nodeIt, &geometryList, false); 97 } 98 99 // geometry list iterator 100 GtpVisibility::GeometryList::iterator geometryIt, geometryIt_end = geometryList.end(); 101 58 102 59 103 // to obtain the correct number of projected pixels, depth write must be disabled 60 104 bool enableDepthWrite = false; 61 62 105 // this option must be provided by the scene manager 63 106 pfHierarchyInterface->GetSceneManager()->setOption("DepthWrite", &enableDepthWrite); 64 107 108 65 109 /* relative visiblity: 66 67 68 69 70 110 1) get visible pixels count of objects 111 2) clear frame buffer 112 3) get projected visible pixels count: 113 test all objects again without depth write (set as option in scene manager) 114 4) calculate ratio between visible vs. projected pixels 71 115 */ 116 72 117 // for relative visibility we need 2 rendering passes 73 118 int n = relativeVisibility ? 2 : 1; 74 119 75 for (int i =0; i<n; ++i)120 for (int i = 0; i < n; ++i) 76 121 { 77 122 //-- queries for hierarchy nodes … … 80 125 // TODO: DELETE QUERIES FROM PREVIOUS RENDER 81 126 queryList[i].push_back(mHierarchyInterface->IssueOcclusionQuery(*nodeIt, false)); 82 83 // store geometry of the hierarchy node in a geometry list (only once!) 84 if (i == 0) 127 } 128 129 //-- queries for geometry: if item buffer, capture only projected visibility 130 if (!(mUseItemBuffer && (i == 0))) 131 { 132 for (geometryIt = geometryList.begin(); geometryIt != geometryIt_end; ++geometryIt) 85 133 { 86 mHierarchyInterface->GetNodeGeometryList(*nodeIt, &geometryList, false);134 queryList[i].push_back(mHierarchyInterface->IssueOcclusionQuery(*geometryIt)); 87 135 } 88 136 } 89 137 90 geometryIt_end = geometryList.end();91 92 //-- add queries for geometry93 for (geometryIt = geometryList.begin(); geometryIt != geometryIt_end; ++geometryIt)94 {95 queryList[i].push_back(mHierarchyInterface->IssueOcclusionQuery(*geometryIt));96 }97 98 99 138 pfHierarchyInterface->GetRenderSystem()->clearFrameBuffer(FBT_DEPTH); 100 139 } 101 140 141 142 //-- collect results 143 GtpVisibility::QueryList::iterator visQueryIt = queryList[0].begin(); 144 GtpVisibility::QueryList::iterator projQueryIt = queryList[1].begin(); 145 146 CollectNodeVisibility(visQueryIt, projQueryIt, nodeList, visibleNodes, relativeVisibility); 147 148 if (mUseItemBuffer) 149 { 150 if (relativeVisibility) 151 { 152 CollectRelativeGeometryVisibilityForItemBuffer(projQueryIt, &geometryList, visibleGeometry); 153 } 154 } 155 else 156 { 157 CollectGeometryVisibility(visQueryIt, projQueryIt, &geometryList, 158 visibleGeometry, relativeVisibility); 159 //CollectPatchVisibility(patchList, visiblePatches); 160 } 161 162 163 //-- reset options 102 164 enableDepthWrite = true; 103 165 // this option must be provided by the scene manager … … 106 168 mViewport->setOverlaysEnabled(overlayEnabled); 107 169 108 // ---- collect results 109 GtpVisibility::QueryList::iterator visQueryIt, projQueryIt; 110 111 visQueryIt = queryList[0].begin(); 112 projQueryIt = queryList[1].begin(); 113 114 115 for (nodeIt = nodeList->begin(); nodeIt != nodeIt_end; ++nodeIt) 170 mWasInitialised = false; 171 } 172 //----------------------------------------------------------------------- 173 void OcclusionQueriesQueryManager::ComputeFromPointVisibility(const Vector3 &point, 174 InfoContainer<GtpVisibility::NodeInfo> *visibleNodes, 175 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 176 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches, 177 bool relativeVisibility) 178 { 179 PlatformQueryManager::ComputeFromPointVisibility(point, visibleNodes, 180 visibleGeometry, visiblePatches, relativeVisibility); 181 182 // remove duplicates (duplicates occur if an object is on the edge of the viewport) 183 // before duplicates can be deleted we have to add up their visibility 184 RemoveDuplicateNodes(visibleNodes); 185 186 if (!mUseItemBuffer) 187 { 188 RemoveDuplicateGeometry(visibleGeometry); 189 } 190 } 191 //----------------------------------------------------------------------- 192 void OcclusionQueriesQueryManager::CollectNodeVisibility( 193 GtpVisibility::QueryList::iterator &visQueryIt, 194 GtpVisibility::QueryList::iterator &projQueryIt, 195 GtpVisibility::HierarchyNodeList *nodeList, 196 InfoContainer<GtpVisibility::NodeInfo> *visibleNodes, 197 bool relativeVisibility) 198 { 199 GtpVisibility::HierarchyNodeList::iterator nodeIt; 200 201 //-- queries for nodes 202 for (nodeIt = nodeList->begin(); nodeIt != nodeList->end(); ++nodeIt) 116 203 { 117 204 unsigned int visiblePixels = 0; … … 132 219 if (visiblePixels > 0) 133 220 { 134 visibleNodes->push_back(GtpVisibility::NodeInfo(*nodeIt, visiblePixels, projectedPixels)); 135 } 136 } 137 138 // ---- queries for geometry 139 geometryIt_end = geometryList.end(); 140 141 for (geometryIt = geometryList.begin(); geometryIt != geometryIt_end; ++geometryIt) 221 visibleNodes->push_back(GtpVisibility::NodeInfo(*nodeIt, visiblePixels, 222 projectedPixels)); 223 } 224 } 225 } 226 //----------------------------------------------------------------------- 227 void OcclusionQueriesQueryManager::CollectRelativeGeometryVisibilityForItemBuffer( 228 GtpVisibility::QueryList::iterator &projQueryIt, 229 GtpVisibility::GeometryList *geometryList, 230 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry) 231 { 232 GtpVisibility::GeometryList::iterator geometryIt; 233 234 //-- queries for geometry 235 for (geometryIt = geometryList->begin(); geometryIt != geometryList->end(); ++ geometryIt) 236 { 237 unsigned int projectedPixels = 0; 238 239 (*projQueryIt)->GetQueryResult(projectedPixels, true); 240 241 ++projQueryIt; 242 int id = (*geometryIt)->getSubEntity(0)->getId(); 243 244 if ((id > 0) && (id < (int)visibleGeometry->size())) 245 { 246 (*visibleGeometry)[id].AddVisibility(0, projectedPixels); 247 } 248 } 249 } 250 //----------------------------------------------------------------------- 251 void OcclusionQueriesQueryManager::CollectRelativePatchVisibilityForItemBuffer( 252 GtpVisibility::QueryList::iterator &projQueryIt, 253 GtpVisibility::PatchList *patchList, 254 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches) 255 { 256 GtpVisibility::PatchList::iterator patchIt; 257 258 //-- queries for geometry 259 for (patchIt = patchList->begin(); patchIt != patchList->end(); ++ patchIt) 260 { 261 unsigned int projectedPixels = 0; 262 263 (*projQueryIt)->GetQueryResult(projectedPixels, true); 264 265 ++projQueryIt; 266 int id = (*patchIt)->getId(); 267 268 if ((id > 0) && (id < (int)visiblePatches->size())) 269 { 270 (*visiblePatches)[id].AddVisibility(0, projectedPixels); 271 } 272 } 273 } 274 //----------------------------------------------------------------------- 275 void OcclusionQueriesQueryManager::CollectGeometryVisibility( 276 GtpVisibility::QueryList::iterator &visQueryIt, 277 GtpVisibility::QueryList::iterator &projQueryIt, 278 GtpVisibility::GeometryList *geometryList, 279 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 280 bool relativeVisibility) 281 { 282 GtpVisibility::GeometryList::iterator geometryIt; 283 284 //-- queries for geometry 285 for (geometryIt = geometryList->begin(); geometryIt != geometryList->end(); ++ geometryIt) 142 286 { 143 287 unsigned int visiblePixels = 0; … … 149 293 { 150 294 (*projQueryIt)->GetQueryResult(projectedPixels, true); 151 152 ++projQueryIt; 153 } 154 155 ++visQueryIt; 295 ++ projQueryIt; 296 } 297 298 ++ visQueryIt; 156 299 157 300 // WARNING: approximate depth ordering during rendering => … … 163 306 } 164 307 } 165 166 } 167 //----------------------------------------------------------------------- 168 inline bool nodeinfo_eq(const GtpVisibility::NodeInfo &info1, const GtpVisibility::NodeInfo &info2) 169 { 170 return info1.GetNode() == info2.GetNode(); 171 } 172 //----------------------------------------------------------------------- 173 inline bool meshinfo_eq(const GtpVisibility::MeshInfo &info1, const GtpVisibility::MeshInfo &info2) 174 { 175 return info1.GetMesh() == info2.GetMesh(); 176 } 177 //----------------------------------------------------------------------- 178 inline bool nodeinfo_lower(const GtpVisibility::NodeInfo &info1, const GtpVisibility::NodeInfo &info2) 179 { 180 return info1.GetNode() < info2.GetNode(); 181 } 182 //----------------------------------------------------------------------- 183 inline bool meshinfo_lower(const GtpVisibility::MeshInfo &info1, const GtpVisibility::MeshInfo &info2) 184 { 185 return info1.GetMesh() < info2.GetMesh(); 186 } 187 //----------------------------------------------------------------------- 188 void OcclusionQueriesQueryManager::ComputeFromPointVisibility(const Vector3 &point, 189 InfoContainer<GtpVisibility::NodeInfo> *visibleNodes, 190 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 191 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches, 192 bool relativeVisibility) 193 { 194 PlatformQueryManager::ComputeFromPointVisibility(point, visibleNodes, 195 visibleGeometry, visiblePatches, relativeVisibility); 196 197 // --- remove duplicates (duplicates occur if an object is on the edge of the viewport) 198 199 // before duplicates can be deleted we have to add up their visibility 200 201 // --- visible nodes 308 } 309 //----------------------------------------------------------------------- 310 void OcclusionQueriesQueryManager::CollectPatchVisibility( 311 GtpVisibility::QueryList::iterator &visQueryIt, 312 GtpVisibility::QueryList::iterator &projQueryIt, 313 GtpVisibility::PatchList *patchList, 314 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches, 315 bool relativeVisibility) 316 { 317 GtpVisibility::PatchList::iterator patchIt; 318 319 //-- queries for patch 320 for (patchIt = patchList->begin(); patchIt != patchList->end(); ++ patchIt) 321 { 322 unsigned int visiblePixels = 0; 323 (*visQueryIt)->GetQueryResult(visiblePixels, true); 324 325 unsigned int projectedPixels = 0; 326 327 if (relativeVisibility) 328 { 329 (*projQueryIt)->GetQueryResult(projectedPixels, true); 330 ++ projQueryIt; 331 } 332 333 ++ visQueryIt; 334 335 // WARNING: approximate depth ordering during rendering => 336 // patch maybe occluded 337 if (visiblePixels > 0) 338 { 339 visiblePatches->push_back(GtpVisibility::PatchInfo(*patchIt, visiblePixels, 340 projectedPixels)); 341 } 342 } 343 } 344 //----------------------------------------------------------------------- 345 void OcclusionQueriesQueryManager::RemoveDuplicateNodes( 346 InfoContainer<GtpVisibility::NodeInfo> *visibleNodes) 347 { 202 348 sort(visibleNodes->begin(), visibleNodes->end(), nodeinfo_lower); 203 349 InfoContainer<GtpVisibility::NodeInfo>::iterator visibleNodesIt, … … 217 363 nodeInfo->AddVisibility(*visibleNodesIt); 218 364 } 219 220 365 } 221 366 … … 223 368 visibleNodes->erase( std::unique(visibleNodes->begin(), 224 369 visibleNodes->end(), nodeinfo_eq), visibleNodes->end()); 225 226 // --- visible geometry 370 } 371 //----------------------------------------------------------------------- 372 void OcclusionQueriesQueryManager::RemoveDuplicateGeometry( 373 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry) 374 { 227 375 sort(visibleGeometry->begin(), visibleGeometry->end(), meshinfo_lower); 376 228 377 InfoContainer<GtpVisibility::MeshInfo>::iterator visibleGeomIt, 229 visibleGeomIt_end = visibleGeometry->end();378 visibleGeomIt_end = visibleGeometry->end(); 230 379 231 380 GtpVisibility::MeshInfo *geomInfo = NULL; 232 381 233 int i=0;234 382 for (visibleGeomIt = visibleGeometry->begin(); visibleGeomIt != visibleGeomIt_end; 235 383 ++visibleGeomIt) -
trunk/VUT/Ogre/src/OgrePlatformQueryManager.cpp
r164 r171 5 5 #include <OgreStringConverter.h> 6 6 #include <vector> 7 #include <OgreSubEntity.h> 7 8 8 9 9 10 namespace Ogre { 11 10 12 //----------------------------------------------------------------------- 11 PlatformQueryManager::PlatformQueryManager(PlatformHierarchyInterface *hierarchyInterface, Viewport *vp): 12 QueryManager(hierarchyInterface), mViewport(vp), mWasInitialised(false) 13 PlatformQueryManager::PlatformQueryManager(PlatformHierarchyInterface *hierarchyInterface, 14 Viewport *vp, bool renderPatches): 15 QueryManager(hierarchyInterface), 16 mViewport(vp), 17 mWasInitialised(false), 18 mRenderPatches(false) 13 19 { 14 20 } … … 65 71 } 66 72 67 ComputeCameraVisibility(*cam, visibleNodes, visibleGeometry, visiblePatches, relativeVisibility);68 73 ComputeCameraVisibility(*cam, visibleNodes, visibleGeometry, visiblePatches, 74 relativeVisibility); 69 75 //mViewport->getTarget()->update(); for(int j=0; j<10000000; j++) printf("wait"); 70 76 … … 80 86 } 81 87 //----------------------------------------------------------------------- 88 void PlatformQueryManager::ComputeCameraVisibility(const Camera &camera, 89 InfoContainer<GtpVisibility::NodeInfo> *visibleNodes, 90 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 91 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches, 92 bool relativeVisibility) 93 { 94 // we need access to the scene manager and the rendersystem 95 PlatformHierarchyInterface *pfHierarchyInterface = 96 dynamic_cast<PlatformHierarchyInterface *>(mHierarchyInterface); 97 98 SceneManager *sm = pfHierarchyInterface->GetSceneManager(); 99 100 101 // const_cast allowed because camera is not changed in renderScene 102 Camera *pCam = const_cast<Camera *>(&camera); 103 104 // disable overlays, reset them later 105 bool overlayEnabled = mViewport->getOverlaysEnabled(); 106 mViewport->setOverlaysEnabled(false); 107 108 // clear background with black (i.e., not a valid item id) 109 ColourValue bg = mViewport->getBackgroundColour(); 110 mViewport->setBackgroundColour(ColourValue(0, 0, 0, 0)); 111 //pfHierarchyInterface->GetRenderSystem()->clearFrameBuffer(FBT_COLOUR | FBT_DEPTH); 112 113 // initialise item buffer (if not already initialised) 114 InitItemBuffer(visibleGeometry, visiblePatches); 115 116 //-- render scene with item buffer (i.e., objects with their id as color codes) 117 118 // enable item buffer (must be provided by scene manager) 119 bool useItemBuffer = true; 120 sm->setOption("UseItemBuffer", &useItemBuffer); 121 122 123 sm->_renderScene(pCam, mViewport, false); // render item buffer 124 125 126 //-- collect results 127 128 int dimx = 0; 129 int dimy = 0; 130 131 // copy frame buffer 132 uchar *buf = mViewport->getTarget()->getBufferContents(dimx, dimy); 133 134 int n = mRenderPatches ? 135 (int)visiblePatches->size() : (int)visibleGeometry->size(); 136 137 //std::stringstream d; d << "dimx: " << dimx << ", dimy: " << dimy; LogManager::getSingleton().logMessage(d.str()); 138 139 // loop through frame buffer and collect visible pixels 140 for (int idx = 0; idx < dimy * dimx * 3; idx += 3) 141 { 142 //-- decode color code to receive id 143 int id = buf[idx] << 16; 144 id += buf[idx + 1] << 8; 145 id += buf[idx + 2]; 146 147 //std::stringstream d; d << "myid: " << (int)buf[idx] << " " << (int)buf[idx + 1] << " " << (int)buf[idx + 2]; LogManager::getSingleton().logMessage(d.str()); 148 149 // if valid id <= add visibility (id values start at 1) 150 if ((id > 0) && (id < n)) 151 { 152 if (mRenderPatches) 153 { 154 ((*visiblePatches)[id]).AddVisibility(1, 0); 155 } 156 else 157 { 158 ((*visibleGeometry)[id]).AddVisibility(1, 0); 159 } 160 } 161 } 162 163 164 //-- reset options 165 166 useItemBuffer = false; // don't need item buffer anymore 167 sm->setOption("UseItemBuffer", &useItemBuffer); 168 169 mWasInitialised = false; // reset initialised - flag 170 mViewport->setOverlaysEnabled(overlayEnabled); // reset old overlay status 171 mViewport->setBackgroundColour(bg); // reset background color 172 173 delete [] buf; // delete copy of the frame buffer 174 } 175 //----------------------------------------------------------------------- 176 void PlatformQueryManager::InitItemBuffer( 177 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 178 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches) 179 { 180 if (mWasInitialised) 181 return; 182 183 mWasInitialised = true; 184 185 SceneManager *sm = 186 dynamic_cast<PlatformHierarchyInterface *>(mHierarchyInterface)->GetSceneManager(); 187 188 SceneManager::EntityIterator it = sm->getEntityIterator(); 189 190 // TODO: make the function more efficient 191 192 visibleGeometry->clear(); 193 visiblePatches->clear(); 194 195 int id = 0; 196 197 /* We can either use patches or meshes. If patches are used, an unique id must 198 be given each patch. Otherwise the same id must be given to all patches belonging 199 to the same mesh. 200 */ 201 while (it.hasMoreElements()) 202 { 203 Entity *ent = it.getNext(); 204 205 for (int i = 0; i < (int)ent->getNumSubEntities(); ++i) 206 { 207 SubEntity *subEnt = ent->getSubEntity(i); 208 209 if (mRenderPatches) 210 { 211 ++ id; 212 visiblePatches->push_back(GtpVisibility::PatchInfo(subEnt, 0, 0)); 213 } 214 215 subEnt->setId(id); 216 //subEnt->setId((41 << 16) + (4 << 8) + 60); 217 //subEnt->setId((2 << 16) + (4 << 8) + 60); 218 } 219 220 if (!mRenderPatches) 221 { 222 visibleGeometry->push_back(GtpVisibility::MeshInfo(ent, 0, 0)); 223 ++ id; 224 } 225 } 226 } 227 //----------------------------------------------------------------------- 82 228 void PlatformQueryManager::SetViewport(Viewport *vp) 83 229 { -
trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp
r164 r171 9 9 #include "OgreVisibilityTerrainSceneManager.h" 10 10 #include "VisibilityInfo.h" 11 #include "OgreItemBufferQueryManager.h"12 11 #include "OgreOcclusionQueriesQueryManager.h" 13 12 #include "TestCullingTerrainApplication.h" … … 414 413 dynamic_cast<VisibilityTerrainSceneManager *>(mSceneMgr); 415 414 416 if (useItemBuffer) 417 { 418 mQueryManager = new ItemBufferQueryManager(sm->GetHierarchyInterface(), 419 mWindow->getViewport(0), mRenderPatchesForItemBuffer); 420 } 421 else 422 { 423 mQueryManager = new OcclusionQueriesQueryManager(sm->GetHierarchyInterface(), 424 mWindow->getViewport(0)); 425 } 426 415 mQueryManager = new OcclusionQueriesQueryManager(sm->GetHierarchyInterface(), 416 mWindow->getViewport(0), false, useItemBuffer); 417 //mQueryManager = new PlatformQueryManager(sm->GetHierarchyInterface(), mWindow->getViewport(0), false); 418 427 419 sm->GetVisibilityManager()->SetQueryManager(mQueryManager); 428 420 … … 431 423 InfoContainer<GtpVisibility::PatchInfo> visiblePatches; 432 424 425 433 426 if (fromPoint) 434 427 { … … 442 435 &visibleNodes, &visibleGeometry, &visiblePatches, relativeVisibility); 443 436 } 437 438 std::stringstream d; 439 d << queryTypeCaptions[fromPoint ? 1 : 0].c_str() << " " 440 << queryRelativeVisCaptions[relativeVisibility ? 1 : 0].c_str() << " " 441 << queryMethodCaptions[useItemBuffer ? 1 : 0].c_str(); 442 LogManager::getSingleton().logMessage(d.str()); 443 444 444 445 445 float averageNodeVis = 0, averageGeometryVis = 0, averagePatchVis = 0; … … 457 457 458 458 averageGeometryVis += vis; 459 ++ geomSize;459 ++ geomSize; 460 460 461 std::stringstream d; d << "Geometry " << geomSize << " visibility: " << vis; 461 std::stringstream d; 462 d << "Geometry " << geomSize << " id: " << (*geomIt).GetMesh()->getSubEntity(0)->getId() 463 << " visibility: " << (*geomIt).GetVisiblePixels() << ", " << (*geomIt).GetProjectedPixels(); 462 464 LogManager::getSingleton().logMessage(d.str()); 463 465 } … … 475 477 476 478 averageNodeVis += vis; 477 ++ nodesSize;479 ++ nodesSize; 478 480 479 481 std::stringstream d; d << "Node visibility: " << vis; … … 484 486 InfoContainer<GtpVisibility::PatchInfo>::iterator patchIt, patchIt_end = visiblePatches.end(); 485 487 486 for (patchIt = visiblePatches.begin(); patchIt != patchIt_end; ++ patchIt)488 for (patchIt = visiblePatches.begin(); patchIt != patchIt_end; ++ patchIt) 487 489 { 488 490 // add if not 0 … … 493 495 494 496 averagePatchVis += vis; 495 ++ patchSize;497 ++ patchSize; 496 498 497 499 std::stringstream d; d << "Patch visibility: " << vis; … … 1410 1412 1411 1413 initOverlayElement(&mQueryTypeInfo , ext, "QueryType", top, ": 0"); top += vert_space; 1414 1415 initOverlayElement(&mQueryVisibleNodesInfo , ext, "VisibleNodes", top, ": 0"); top += vert_space; 1412 1416 initOverlayElement(&mQueryVisibleGeometryInfo , ext, "VisibleGeometry", top, ": 0"); top += vert_space; 1413 initOverlayElement(&mQueryVisibleNodesInfo , ext, "VisibleNodes", top, ": 0"); top += vert_space;1414 1417 initOverlayElement(&mQueryVisiblePatchInfo , ext, "VisiblePatches", top, ": 0"); top += vert_space; 1418 1415 1419 initOverlayElement(&mQueryNodeVisibilityInfo , ext, "NodeVisibility", top, ": 0"); top += vert_space; 1416 1420 initOverlayElement(&mQueryGeometryVisibilityInfo , ext, "GeometryVisibility", top, ": 0"); top += vert_space; -
trunk/VUT/work/ogre_changes/RenderSystems/Direct3D9/src/OgreD3D9RenderWindow.cpp
r166 r171 928 928 HRESULT hr; 929 929 LPDIRECT3DSURFACE9 pSurf=NULL, pTempSurf=NULL; 930 //IDirect3DSurface9 *pTempSurf=NULL; 930 931 D3DSURFACE_DESC desc; 931 932 D3DDISPLAYMODE dm; … … 953 954 } 954 955 955 //if (FAILED(hr = mpD3DDevice->GetFrontBufferData(0, pTempSurf)))956 if (FAILED(hr = mpD3DDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pTempSurf)))956 if (FAILED(hr = mpD3DDevice->GetFrontBufferData(0, pTempSurf))) 957 //if (FAILED(hr = mpD3DDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pTempSurf))) 957 958 { 958 959 SAFE_RELEASE(pTempSurf); … … 1058 1059 } 1059 1060 1060 1061 //pTempSurf->UnlockRect(); 1061 1062 SAFE_RELEASE(pTempSurf); 1062 1063 SAFE_RELEASE(pSurf);
Note: See TracChangeset
for help on using the changeset viewer.