Changeset 2764 for GTP/trunk/App/Demos/Vis/CHC_revisited
- Timestamp:
- 06/17/08 03:47:02 (17 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/CHC_revisited
- Files:
-
- 3 added
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/CHC_revisited/BinaryLoader.cpp
r2763 r2764 18 18 SceneEntity *BinaryLoader::LoadSceneEntity(ifstream &str) 19 19 { 20 Geometry *geom = LoadGeometry(str); 21 Material *mat = LoadMaterial(str); 22 Matrix4x4 *trafo = NULL;//IdentityMatrix(); 20 // shape 21 int shapeId; 22 str.read(reinterpret_cast<char *>(&shapeId), sizeof(int)); 23 24 Geometry *geom = mGeometryTable[shapeId]; 25 Material *mat = mMaterialTable[shapeId]; 26 27 28 bool hasTrafo; 29 str.read(reinterpret_cast<char *>(&hasTrafo), sizeof(bool)); 30 31 Matrix4x4 *trafo; 32 33 if (!hasTrafo) 34 { 35 trafo = NULL; 36 } 37 else 38 { 39 trafo = new Matrix4x4(); 40 //*trafo = IdentityMatrix(); 41 str.read(reinterpret_cast<char *>(trafo->x), sizeof(Matrix4x4)); 42 //str.read(reinterpret_cast<char *>(trafo), sizeof(Matrix4x4)); 43 //cout << "m:\n" << *trafo<<endl; 44 } 23 45 24 46 SceneEntity *sceneGeom = new SceneEntity(geom, mat, trafo); … … 37 59 // texture 38 60 int texnameSize; 39 int id; 40 41 str.read(reinterpret_cast<char *>(&id), sizeof(int)); 61 62 //str.read(reinterpret_cast<char *>(&id), sizeof(int)); 42 63 str.read(reinterpret_cast<char *>(&texnameSize), sizeof(int)); 43 64 … … 48 69 Texture *tex = new Texture(texname); 49 70 50 mTextureTable[id] = tex; 51 } 71 mTextureTable[i] = tex; 72 } 73 74 cout << "loaded " << mTextureTable.size() << " textures" << endl; 75 } 76 77 78 void BinaryLoader::LoadShapes(ifstream &str) 79 { 80 int numShapes; 81 str.read(reinterpret_cast<char *>(&numShapes), sizeof(int)); 82 83 for (int i = 0; i < numShapes; ++ i) 84 { 85 Geometry *geom = LoadGeometry(str); 86 Material *mat = LoadMaterial(str); 87 88 mGeometryTable[i] = geom; 89 mMaterialTable[i] = mat; 90 } 91 92 cout << "loaded " << mGeometryTable.size() << " shapes" << endl; 52 93 } 53 94 … … 61 102 // texture 62 103 int texId; 63 64 104 str.read(reinterpret_cast<char *>(&texId), sizeof(int)); 65 //cout << "texid: " << texId << endl;66 105 67 106 if (texId >= 0) 68 {69 107 mat->SetTexture(mTextureTable[texId]); 70 }108 71 109 72 110 // material … … 99 137 100 138 return app;*/ 101 102 139 return mat; 103 140 } … … 156 193 157 194 158 bool BinaryLoader::Load(const std::string &filename, SceneEntityContainer &geometry) 195 void BinaryLoader::LoadSceneEntities(ifstream &str, SceneEntityContainer &entities) 196 { 197 int entityCount; 198 str.read(reinterpret_cast<char *>(&entityCount), sizeof(int)); 199 200 entities.resize(entityCount); 201 202 for (int i = 0; i < entityCount; ++ i) 203 { 204 SceneEntity *ent = LoadSceneEntity(str); 205 ent->id = i; 206 entities[i] = ent; 207 } 208 209 cout << "loaded " << entityCount << " scene entities" << endl; 210 } 211 212 213 bool BinaryLoader::Load(const std::string &filename, SceneEntityContainer &entities) 159 214 { 160 215 //clear_textures(); // clear the texture table … … 166 221 return false; 167 222 223 cout << "loading textures" << endl; 224 168 225 // load the texture table 169 226 LoadTextures(istr); 170 227 171 // #shapes 172 int shapeCount; 173 istr.read(reinterpret_cast<char *>(&shapeCount), sizeof(int)); 174 175 geometry.resize(shapeCount); 176 177 for (size_t i = 0; i < geometry.size(); ++ i) 178 geometry[i] = NULL; 179 180 181 int progress = 0; 182 183 for (int i = 0; i < shapeCount; ++ i) 184 { 185 //int id;istr.read(reinterpret_cast<char *>(&id), sizeof(int)); 186 SceneEntity *ent = LoadSceneEntity(istr); 187 ent->id = i; 188 189 geometry[i] = ent; 190 191 int p = (i + 1) * 100 / shapeCount; 192 193 if (p >= progress) 194 { 195 cout << "% loaded: " << p << endl; 196 progress += 10; 197 } 198 } 199 200 for (size_t i = 0; i < geometry.size(); ++ i) 201 { 202 if (!geometry[i]) 203 Debug << "error: index " << i << " missing" << endl; 204 } 205 228 cout << "loading shapes (geometry + materials)" << endl; 229 230 // load the shapees 231 LoadShapes(istr); 232 233 cout << "loading scene entites" << endl; 234 LoadSceneEntities(istr, entities); 235 206 236 cout << "bin loading finished" << endl; 207 237 -
GTP/trunk/App/Demos/Vis/CHC_revisited/BinaryLoader.h
r2757 r2764 30 30 31 31 void LoadTextures(std::ifstream &str); 32 void LoadShapes(std::ifstream &str); 33 void LoadSceneEntities(std::ifstream &str, SceneEntityContainer &entities); 32 34 33 35 SceneEntity *LoadSceneEntity(std::ifstream &str); … … 35 37 Geometry *LoadGeometry(std::ifstream &str); 36 38 37 /*SceneEntity *LoadShape(igzstream &str);38 Material *LoadMaterial(igzstream &str);39 Geometry *LoadGeometry(igzstream &str);40 */41 42 39 std::map<int, Texture *> mTextureTable; 40 std::map<int, Material *> mMaterialTable; 41 std::map<int, Geometry *> mGeometryTable; 43 42 }; 44 43 -
GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.cpp
r2763 r2764 366 366 // store near plane 367 367 sNearPlane = Plane3(mCamera->GetDirection(), mCamera->GetPosition()); 368 // Debug << "near: " << sNearPlane << " d " << mCamera->GetDirection() << " " << mCamera->GetPosition() << std::endl; 369 // for (int i = 0; i < 6; ++ i) Debug << "plane: " << sFrustum.mClipPlanes[i] << std::endl; 370 } 371 372 373 float Bvh::CalcDistance(BvhNode *node) const 374 { 375 return node->GetBox().GetMinVisibleDistance(sNearPlane); 368 } 369 370 371 void Bvh::CalcDistance(BvhNode *node) const 372 { 373 node->mDistance = node->GetBox().GetMinVisibleDistance(sNearPlane); 376 374 } 377 375 … … 872 870 } 873 871 872 mNumVirtualNodes = 0; 873 874 874 // assign new virtual leaves based on specified number of triangles per leaf 875 875 std::stack<BvhNode *> nodeStack; … … 880 880 BvhNode *node = nodeStack.top(); 881 881 nodeStack.pop(); 882 883 ++ mNumVirtualNodes; 882 884 883 885 if (node->IsLeaf()) … … 948 950 const Vector3 u = box.Max(); 949 951 950 /////////// 951 //-- render AABB as triangle strips 952 953 glVertex3f(l.x, l.y, u.z); 954 glVertex3f(u.x, l.y, u.z); 955 glVertex3f(l.x, u.y, u.z); 956 glVertex3f(u.x, u.y, u.z); 957 glVertex3f(l.x, u.y, l.z); 958 glVertex3f(u.x, u.y, l.z); 959 glVertex3f(l.x, l.y, l.z); 960 glVertex3f(u.x, l.y, l.z); 961 962 glPrimitiveRestartNV(); 963 964 //-- render second half of AABB 965 glVertex3f(l.x, u.y, u.z); 966 glVertex3f(l.x, u.y, l.z); 967 glVertex3f(l.x, l.y, u.z); 968 glVertex3f(l.x, l.y, l.z); 969 glVertex3f(u.x, l.y, u.z); 970 glVertex3f(u.x, l.y, l.z); 971 glVertex3f(u.x, u.y, u.z); 972 glVertex3f(u.x, u.y, l.z); 973 } 974 975 976 977 } 952 glBegin(GL_TRIANGLE_STRIP); 953 { 954 /////////// 955 //-- render AABB as triangle strips 956 957 glVertex3f(l.x, l.y, u.z); 958 glVertex3f(u.x, l.y, u.z); 959 glVertex3f(l.x, u.y, u.z); 960 glVertex3f(u.x, u.y, u.z); 961 glVertex3f(l.x, u.y, l.z); 962 glVertex3f(u.x, u.y, l.z); 963 glVertex3f(l.x, l.y, l.z); 964 glVertex3f(u.x, l.y, l.z); 965 966 glPrimitiveRestartNV(); 967 968 //-- render second half of AABB 969 glVertex3f(l.x, u.y, u.z); 970 glVertex3f(l.x, u.y, l.z); 971 glVertex3f(l.x, l.y, u.z); 972 glVertex3f(l.x, l.y, l.z); 973 glVertex3f(u.x, l.y, u.z); 974 glVertex3f(u.x, l.y, l.z); 975 glVertex3f(u.x, u.y, u.z); 976 glVertex3f(u.x, u.y, l.z); 977 } 978 glEnd(); 979 } 980 981 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.h
r2763 r2764 505 505 note that negative values can appear because culling is done only afterwards 506 506 */ 507 float CalcDistance(BvhNode *node) const; 507 void CalcDistance(BvhNode *node) const; 508 /** Returns the stored distance. 509 */ 510 float GetDistance(BvhNode *node) const { return node->mDistance; } 508 511 /** Pulls up the last visited classification in the bvh. 509 512 */ … … 544 547 */ 545 548 const BvhStats &GetBvhStats() const {return mBvhStats;} 546 549 /** Renders the geometry contained in this node. 550 */ 547 551 int Render(BvhNode *node, RenderState *state); 552 /** Returns number of 'virtual' nodes in the hierarchy, i.e. 553 the number of nodes actually used for traversal. 554 */ 555 int GetNumVirtualNodes() const { return mNumVirtualNodes; } 548 556 549 557 … … 602 610 603 611 void RenderBoundingBoxImmediate(const AxisAlignedBox3 &box); 612 613 604 614 605 615 //////////////////////// … … 645 655 AxisAlignedBox3 mBox; 646 656 657 int mNumVirtualNodes; 658 647 659 ////////////// 648 660 -
GTP/trunk/App/Demos/Vis/CHC_revisited/CHCTraverser.cpp
r2755 r2764 1 1 #include "CHCTraverser.h" 2 #include "SceneEntity.h" 3 2 4 3 5 namespace CHCDemo … … 17 19 void CHCTraverser::Render() 18 20 { 19 #if 0 21 mStats.Reset(); 22 mRenderState->mTexturesEnabled = false; 23 EnqueueNode(mBvh->GetRoot()); 24 20 25 QueryQueue queryQueue; 21 26 … … 24 29 { 25 30 while (!queryQueue.empty() && 26 ( ResultAvailable(queryQueue.front()) || mDistanceQueue.empty()))31 (queryQueue.front()->ResultAvailable() || mDistanceQueue.empty())) 27 32 { 28 HierarchyNode *node= queryQueue.front();33 OcclusionQuery *query = queryQueue.front(); 29 34 queryQueue.pop(); 30 35 31 36 // wait until result available 32 int visiblePixels = GetOcclusionQueryResult(node);37 int visiblePixels = query->GetQueryResult(); 33 38 34 if (visiblePixels > mVisibilityThreshold)39 if (visiblePixels > mVisibilityThreshold) 35 40 { 36 PullUpVisibility(node); 41 BvhNode *node = query->GetFrontNode(); 42 43 mBvh->MakeParentsVisible(node); 37 44 TraverseNode(node); 38 45 } 39 46 else 40 47 { 41 mNumQueryCulledNodes ++;48 ++ mStats.mNumQueryCulledNodes; 42 49 } 43 50 } … … 46 53 if (!mDistanceQueue.empty()) 47 54 { 48 HierarchyNode *node = mDistanceQueue.top(); 49 55 BvhNode *node = mDistanceQueue.top(); 50 56 mDistanceQueue.pop(); 51 57 52 mNumTraversedNodes ++; 53 54 bool intersects; 55 56 if (InsideViewFrustum(node, intersects)) 58 if (mBvh->IsWithinViewFrustum(node)) 57 59 { 58 60 // for near plane intersecting bounding box possible 59 61 // wrong results => skip occlusion query 60 if (intersects)62 if (IntersectsNearPlane(node)) 61 63 { 62 64 // update node's visited flag 63 node->SetLastVisited (mFrameID);65 node->SetLastVisitedFrame(mFrameID); 64 66 node->SetVisible(true); 65 PullUpVisibility(node); 67 mBvh->MakeParentsVisible(node); 68 66 69 TraverseNode(node); 67 70 } … … 69 72 { 70 73 // identify previously visible nodes 71 bool wasVisible = node->Visible() && (node->LastVisited() == mFrameID - 1);74 const bool wasVisible = node->IsVisible() && (node->GetLastVisitedFrame() == mFrameID - 1); 72 75 73 76 // identify nodes that we cannot skip queries for 74 bool leafOrWasInvisible = (node->LastVisited() != mFrameID) && (!wasVisible || node->IsLeaf()); 77 const bool leafOrWasInvisible = 78 (node->GetLastVisitedFrame() != mFrameID) && (!wasVisible || node->IsVirtualLeaf()); 75 79 76 80 // reset node's visibility classification … … 78 82 79 83 // update node's visited flag 80 node->SetLastVisited (mFrameID);84 node->SetLastVisitedFrame(mFrameID); 81 85 82 86 // skip testing previously visible interior nodes 83 if (leafOrWasInvisible)87 if (leafOrWasInvisible) 84 88 { 85 IssueOcclusionQuery(node, wasVisible);86 queryQueue.push( node);89 OcclusionQuery *query = IssueOcclusionQuery(node, wasVisible); 90 queryQueue.push(query); 87 91 } 88 92 89 93 // always traverse a node if it was visible 90 if (wasVisible)94 if (wasVisible) 91 95 TraverseNode(node); 92 96 } … … 95 99 { 96 100 // for stats 97 mNumFrustumCulledNodes ++;101 ++ mStats.mNumFrustumCulledNodes; 98 102 } 99 103 } 100 104 } 101 #endif102 105 } 103 106 -
GTP/trunk/App/Demos/Vis/CHC_revisited/Camera.cpp
r2762 r2764 29 29 mDirection.Normalize(); 30 30 31 Vector3 side = CrossProd(Vector3(0, 1, 0), mDirection); 31 //Vector3 side = CrossProd(Vector3(0, 1, 0), mDirection); 32 Vector3 side = CrossProd(Vector3(0, 0, 1), mDirection); 33 32 34 mUp = -Normalize(CrossProd(side, mDirection)); 33 35 mRight = -Normalize(CrossProd(mDirection, mUp)); 36 34 37 35 38 float k = tan(mFovy/2); … … 53 56 54 57 58 void Camera::SetNear(float nearDist) 59 { 60 mNear = nearDist; 61 } 62 63 55 64 void Camera::LookInBox(const AxisAlignedBox3 &box) 56 65 { 57 mDirection = Vector3(0, 0, 1); 66 //mDirection = Vector3(0, 0, 1); 67 mDirection = Vector3(0, 1, 0); 58 68 mPosition = box.Center(); 59 mPosition. y += 50;69 mPosition.z = box.Min(2) + 0.9f * box.Size(2); 60 70 61 71 Precompute(); … … 65 75 void Camera::LookAtBox(const AxisAlignedBox3 &box) 66 76 { 67 mDirection = Vector3(0, 0, box.Min().z - box.Max().z);77 mDirection = Vector3(0, box.Min().y - box.Max().y, 0); 68 78 mPosition = Vector3(0);//box.Max() - mDirection; 69 79 -
GTP/trunk/App/Demos/Vis/CHC_revisited/Camera.h
r2762 r2764 57 57 void ComputePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr, 58 58 Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr); 59 60 inline float GetNear() const { return mNear; } 61 void SetNear(float nearDist); 59 62 60 63 … … 74 77 int mWidth; 75 78 int mHeight; 79 80 float mNear; 76 81 }; 77 82 -
GTP/trunk/App/Demos/Vis/CHC_revisited/FrustumCullingTraverser.cpp
r2763 r2764 15 15 void FrustumCullingTraverser::Render() 16 16 { 17 mStats.Reset(); 17 18 mRenderState->mTexturesEnabled = false; 18 mDistanceQueue.push(mBvh->GetRoot());19 EnqueueNode(mBvh->GetRoot()); 19 20 20 21 int traversed = 0;22 21 while (!mDistanceQueue.empty()) 23 22 { … … 27 26 // interesting for the visualization, so rest and set 28 27 node->SetVisible(false); 29 //mNumTraversedNodes ++;30 28 31 29 if (mBvh->IsWithinViewFrustum(node)) … … 34 32 // so set it also here 35 33 //node->SetLastVisited(mFrameID); 36 //node->SetVisible(true); 37 ++ traversed; 34 node->SetVisible(true); 38 35 TraverseNode(node); 39 36 } 40 37 else 41 38 { 42 //mNumFrustumCulledNodes ++;39 mStats.mNumFrustumCulledNodes ++; 43 40 } 44 //cout << "intersect: " << intersect << " bx " << node->GetBox() << endl;45 41 } 46 47 //std::cout << "traversed: " << traversed << std::endl;48 42 } 49 43 -
GTP/trunk/App/Demos/Vis/CHC_revisited/OcclusionQuery.cpp
r2763 r2764 85 85 } 86 86 else 87 { 87 88 query = mOcclusionQueries[mCurrentQueryIdx]; 89 } 90 91 ++ mCurrentQueryIdx; 88 92 89 93 return query; -
GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp
r2763 r2764 7 7 namespace CHCDemo 8 8 { 9 10 11 void TraversalStatistics::Reset() 12 { 13 // reset statistics 14 mNumTraversedNodes = 0; 15 mNumQueryCulledNodes = 0; 16 mNumFrustumCulledNodes = 0; 17 mNumRenderedGeometry = 0; 18 mNumRenderedTriangles = 0; 19 20 mNumIssuedQueries = 0; 21 mRenderTime = 0; 22 } 23 24 25 26 /******************************************************/ 27 /* RenderTraverser implementation */ 28 /******************************************************/ 29 9 30 10 31 RenderTraverser::RenderTraverser(): … … 13 34 mBvh(NULL), 14 35 mIsQueryMode(false), 15 mUseOptimization(true), 16 mCurrentQueryIdx(0) 36 mUseOptimization(true) 17 37 { 18 38 } … … 21 41 RenderTraverser::~RenderTraverser() 22 42 { 23 //DelQueries(); 24 } 25 26 27 /*void RenderTraverser::Render(int mode) 28 { 29 mDistanceQueue.push(mHierarchyRoot); 30 31 long startTime = getTime(); 32 33 Preprocess(); 34 35 switch(mode) 36 { 37 case RENDER_CULL_FRUSTUM: 38 RenderCullFrustum(); 39 break; 40 case RENDER_STOP_AND_WAIT: 41 RenderStopAndWait(); 42 break; 43 case RENDER_COHERENT: 44 RenderCoherentWithQueue(); 45 break; 46 default: 47 RenderCullFrustum(); 48 break; 49 } 50 51 mFrameID ++; 52 53 54 long endTime = getTime(); 55 mRenderTime = endTime - startTime; 56 57 finishTiming(); 58 }*/ 43 mQueryHandler.DestroyQueries(); 44 } 45 59 46 60 47 void RenderTraverser::EnqueueNode(BvhNode *node) … … 67 54 void RenderTraverser::TraverseNode(BvhNode *node) 68 55 { 56 ++ mStats.mNumTraversedNodes; 69 57 70 58 if (node->IsVirtualLeaf()) 71 59 { 72 60 //RenderBox(node->GetBox()); 73 74 //mNumRenderedGeometry += 75 mBvh->Render(node, mRenderState); 61 mStats.mNumRenderedGeometry += mBvh->Render(node, mRenderState); 76 62 } 77 63 else … … 117 103 OcclusionQuery *RenderTraverser::IssueOcclusionQuery(BvhNode *node, bool wasVisible) 118 104 { 105 ++ mStats.mNumIssuedQueries; 106 119 107 OcclusionQuery *query = mQueryHandler.RequestQuery(); 108 query->Reset(); 109 query->AddNode(node); 120 110 121 111 query->BeginQuery(); … … 131 121 132 122 // change state so the bounding box gets not actually rendered on the screen 133 //Switch2GLQueryState();123 Switch2GLQueryState(); 134 124 mBvh->RenderBoundingBox(node); 135 //Switch2GLRenderState();125 Switch2GLRenderState(); 136 126 137 127 query->EndQuery(); … … 155 145 156 146 157 #if 0 158 159 Bvh *RenderTraverser::GetHierarchy() 160 { 161 return mBvh; 162 } 163 164 147 void RenderTraverser::PullUpVisibility(BvhNode *node) 148 { 149 while(node && ! node->IsVisible()) 150 { 151 node->SetVisible(true); 152 node = node->GetParent(); 153 } 154 } 155 156 157 void RenderTraverser::SetVisibilityThreshold(int threshold) 158 { 159 mVisibilityThreshold = threshold; 160 } 161 162 163 int RenderTraverser::GetVisibilityThreshold() const 164 { 165 return mVisibilityThreshold; 166 } 167 168 169 /* 165 170 void RenderTraverser::RenderVisualization() 166 171 { … … 184 189 } 185 190 } 186 } 187 188 189 void RenderTraverser::PullUpVisibility(HierarchyNode *node) 190 { 191 while(node && !node->Visible()) 192 { 193 node->SetVisible(true); 194 node = node->GetParent(); 195 } 196 } 197 198 bool RenderTraverser::ResultAvailable(HierarchyNode *node) const 199 { 200 unsigned int result; 201 if (mUseArbQueries) 202 { 203 glGetQueryObjectuivARB(node->GetOcclusionQuery(), 204 GL_QUERY_RESULT_AVAILABLE_ARB, &result); 205 } 206 else 207 { 208 209 glGetOcclusionQueryuivNV(node->GetOcclusionQuery(), 210 GL_PIXEL_COUNT_AVAILABLE_NV, &result); 211 212 } 213 214 return (result == GL_TRUE); 215 } 216 217 218 void RenderTraverser::Preprocess() 219 { 220 if (!mOcclusionQueries) 221 { 222 mOcclusionQueries = new unsigned int[mHierarchyRoot->GetNumHierarchyNodes()]; 223 224 // generate ids for occlusion test 225 if (mUseArbQueries) 226 { 227 glGenQueriesARB(mHierarchyRoot->GetNumHierarchyNodes(), mOcclusionQueries); 228 } 229 else 230 { 231 glGenOcclusionQueriesNV(mHierarchyRoot->GetNumHierarchyNodes(), mOcclusionQueries); 232 } 233 } 234 235 // view frustum planes for view frustum culling 236 calcViewFrustumPlanes(&mClipPlanes, mProjViewMatrix); 237 calcAABNPVertexIndices(mNPVertexIndices, mClipPlanes); 238 239 mCurrentQueryIdx = 0; 240 241 // reset statistics 242 mNumTraversedNodes = 0; 243 mNumQueryCulledNodes = 0; 244 mNumFrustumCulledNodes = 0; 245 mNumRenderedGeometry = 0; 246 } 247 248 249 void RenderTraverser::DelQueries() 250 { 251 if (!mOcclusionQueries) 252 return; 253 254 // tell the driver that the occlusion queries won't be needed any more 255 if (mUseArbQueries) 256 { 257 glDeleteQueriesARB(mHierarchyRoot->GetNumHierarchyNodes(), mOcclusionQueries); 258 } 259 else 260 { 261 glDeleteOcclusionQueriesNV(mHierarchyRoot->GetNumHierarchyNodes(), mOcclusionQueries); 262 } 263 264 delete [] mOcclusionQueries; 265 266 mOcclusionQueries = NULL; 267 } 268 269 270 void RenderTraverser::SetViewpoint(Vector3 const &viewpoint) 271 { 272 copyVector3(mViewpoint, viewpoint); 273 } 274 275 276 void RenderTraverser::SetProjViewMatrix(Matrix4x4 const &projViewMatrix) 277 { 278 copyMatrix(mProjViewMatrix, projViewMatrix); 279 } 280 281 282 bool RenderTraverser::InsideViewFrustum(HierarchyNode *node, bool &intersects) 283 { 284 Vector3x8 vertices; 285 286 bool intersect = false; 287 288 calcAABoxPoints(vertices, node->GetBoundingVolume()); 289 290 // simply test all 6 vertices 291 for (int i = 0; i < 6; i++) 292 { 293 // test the n-vertex 294 // note: the calcAABNearestVertexId should be preprocessed 295 if(!pointBeforePlane(mClipPlanes.plane[i], vertices[mNPVertexIndices[i * 2]])) 296 { 297 // outside 298 return false; 299 } 300 } 301 302 // test if bounding box is intersected by nearplane (using the p-vertex) 303 intersects = (!pointBeforePlane(mClipPlanes.plane[5], vertices[mNPVertexIndices[11]])); 304 305 // -- get vector from viewpoint to center of bounding volume 306 Vector3 vec; 307 calcAABoxCenter(vec, node->GetBoundingVolume()); 308 diffVector3(vec, vec, mViewpoint); 309 310 // compute distance from nearest point to viewpoint 311 diffVector3(vec, vertices[calcAABNearestVertexIdx(vec)], mViewpoint); 312 node->SetDistance(squaredLength(vec)); 313 314 return true; 315 } 316 317 318 void RenderTraverser::SetVisibilityThreshold(int threshold) 319 { 320 mVisibilityThreshold = threshold; 321 } 322 323 void RenderTraverser::SetUseArbQueries(const bool useArbQueries) 324 { 325 DelQueries(); 326 mUseArbQueries = useArbQueries; 327 } 328 329 bool RenderTraverser::GetUseArbQueries() const 330 { 331 return mUseArbQueries; 332 } 333 334 long RenderTraverser::GetRenderTime() 335 { 336 return mRenderTime; 337 } 338 339 int RenderTraverser::GetNumTraversedNodes() 340 { 341 return mNumTraversedNodes; 342 } 343 344 int RenderTraverser::GetNumQueryCulledNodes() 345 { 346 return mNumQueryCulledNodes; 347 } 348 349 int RenderTraverser::GetNumFrustumCulledNodes() 350 { 351 return mNumFrustumCulledNodes; 352 } 353 354 355 int RenderTraverser::GetNumRenderedGeometry() 356 { 357 return mNumRenderedGeometry; 358 } 359 360 361 #endif 191 }*/ 362 192 363 193 … … 474 304 475 305 476 } 306 307 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h
r2763 r2764 7 7 #include "Bvh.h" 8 8 #include "OcclusionQuery.h" 9 9 #include "Camera.h" 10 10 11 11 namespace CHCDemo … … 19 19 struct TraversalStatistics 20 20 { 21 friend class RenderTraverser; 21 public: 22 22 23 public: 23 void Reset(); 24 24 25 25 ////////// 26 26 //-- several statistics for a rendering pass 27 27 28 long GetRenderTime();29 int GetNumTraversedNodes();30 int GetNumQueryCulledNodes();31 int GetNumFrustumCulledNodes();32 int GetNumRenderedGeometry();33 34 protected:35 36 // statistics37 28 int mNumTraversedNodes; 38 29 int mNumQueryCulledNodes; 39 30 int mNumFrustumCulledNodes; 40 31 int mNumRenderedGeometry; 32 int mNumRenderedTriangles; 33 int mNumIssuedQueries; 41 34 42 35 long mRenderTime; … … 52 45 { 53 46 public: 54 //enum {RENDER_CULL_FRUSTUM, RENDER_STOP_AND_WAIT, RENDER_COHERENT, NUM_RENDERMODES};47 enum {CULL_FRUSTUM, STOP_AND_WAIT, CHC, NUM_RENDERMODES}; 55 48 56 49 RenderTraverser(); … … 71 64 */ 72 65 void SetCamera(Camera *cam) {mCamera = cam;} 73 /** sets view projection matrix74 */75 //void SetProjViewMatrix(Matrix4x4 const &projViewMatrix);76 66 /** Sets visible pixels threshold for visibility classification 77 67 */ … … 92 82 void RenderFrustum(); 93 83 84 const TraversalStatistics &GetStats() const { return mStats; } 94 85 95 86 protected: … … 120 111 void Switch2GLQueryState(); 121 112 113 inline bool IntersectsNearPlane(BvhNode *node) const {return mBvh->GetDistance(node) < mCamera->GetNear();} 114 122 115 void EnqueueNode(BvhNode *node); 123 116 … … 129 122 //-- members 130 123 131 // /the current clip planes of the view frustum132 //VecPlane mClipPlanes;133 /// the indices of the np-vertices of the bounding box for view frustum culling134 //int mNPVertexIndices[12];135 136 124 /// the current camera 137 125 Camera *mCamera; 138 //Matrix4x4 mProjViewMatrix;139 126 /// the root of the scene hierarchy 140 127 Bvh *mBvh; … … 144 131 int mFrameID; 145 132 int mVisibilityThreshold; 146 147 //unsigned int *mOcclusionQueries; 148 int mCurrentQueryIdx; 133 149 134 bool mIsQueryMode; 150 135 … … 155 140 156 141 QueryHandler mQueryHandler; 142 143 TraversalStatistics mStats; 157 144 }; 158 145 -
GTP/trunk/App/Demos/Vis/CHC_revisited/StopAndWaitTraverser.cpp
r2763 r2764 23 23 void StopAndWaitTraverser::Render() 24 24 { 25 mStats.Reset(); 25 26 mRenderState->mTexturesEnabled = false; 26 mDistanceQueue.push(mBvh->GetRoot());27 EnqueueNode(mBvh->GetRoot()); 27 28 28 29 //cout<<"\n***** starting frame **********\n"; 29 30 int traversed = 0; 30 31 while (!mDistanceQueue.empty()) … … 33 34 mDistanceQueue.pop(); 34 35 36 //float d = mBvh->GetDistance(node);cout << d << " "; 37 35 38 // interesting for the visualization, so rest and set 36 39 node->SetVisible(false); 37 //mNumTraversedNodes ++; 40 38 41 39 42 if (mBvh->IsWithinViewFrustum(node)) 40 43 { 41 44 // if intersects near plane assume visible and don't issue test 42 if ( mBvh->CalcDistance(node) < 0.1f)45 if (IntersectsNearPlane(node)) 43 46 { 44 47 TraverseNode(node); … … 50 53 int visiblePixels = query->GetQueryResult(); 51 54 52 if (visiblePixels > 0)55 if (visiblePixels > mVisibilityThreshold) 53 56 { 54 cout<< "visible: " << visiblePixels << endl;57 //cout<< "visible: " << visiblePixels << endl; 55 58 // update node's visited flag => needed for rendering 56 59 // so set it also here 57 60 //node->SetLastVisited(mFrameID); 58 61 //node->SetVisible(true); 59 ++ traversed;62 60 63 TraverseNode(node); 64 } 65 else 66 { 67 ++ mStats.mNumQueryCulledNodes; 61 68 } 62 69 } … … 64 71 else 65 72 { 66 //mNumFrustumCulledNodes ++;73 ++ mStats.mNumFrustumCulledNodes; 67 74 } 68 75 //cout << "intersect: " << intersect << " bx " << node->GetBox() << endl; -
GTP/trunk/App/Demos/Vis/CHC_revisited/Texture.cpp
r2758 r2764 60 60 glBindTexture(GL_TEXTURE_2D, mTexId); 61 61 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 62 //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); 62 63 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 63 64 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); -
GTP/trunk/App/Demos/Vis/CHC_revisited/chc_revisited.vcproj
r2756 r2764 128 128 AdditionalIncludeDirectories="GL;Devil/include" 129 129 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" 130 StringPooling="true" 130 131 RuntimeLibrary="2" 132 BufferSecurityCheck="false" 133 EnableEnhancedInstructionSet="2" 131 134 RuntimeTypeInfo="false" 132 135 UsePrecompiledHeader="0" … … 154 157 OptimizeReferences="2" 155 158 EnableCOMDATFolding="2" 159 OptimizeForWindows98="1" 156 160 TargetMachine="1" 157 161 /> … … 241 245 </File> 242 246 <File 247 RelativePath=".\SceneQuery.cpp" 248 > 249 </File> 250 <File 251 RelativePath=".\SceneQuery.h" 252 > 253 </File> 254 <File 243 255 RelativePath=".\Timers.cpp" 244 256 > -
GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp
r2763 r2764 16 16 #include "FrustumCullingTraverser.h" 17 17 #include "StopAndWaitTraverser.h" 18 18 #include "CHCTraverser.h" 19 19 20 20 … … 36 36 /// the current render state 37 37 RenderState state; 38 38 /// the rendering algorithm 39 int renderMode = RenderTraverser::CULL_FRUSTUM; 40 /// the visibility threshold 41 int threshold = 0; 39 42 // eye near plane distance 40 43 float nearDist = 0.1f; 44 41 45 int winWidth = 1024; 42 46 int winHeight = 768; … … 49 53 bool showBoundingVolumes = false; 50 54 bool visMode = false; 51 bool showCreateParams = false; 55 52 56 53 57 int currentFrame = -1; … … 58 62 //mouse navigation state 59 63 int xEyeBegin, yEyeBegin, yMotionBegin, verticalMotionBegin, horizontalMotionBegin = 0; 60 //int renderMode = RenderTraverser::RENDER_COHERENT;61 64 62 65 const int renderTimeSize = 100; … … 79 82 void UpdateEyeMtx(); 80 83 void SetupLighting(); 84 void DisplayStats(); 81 85 82 86 void begin2D(); … … 97 101 long calcRenderTime(void); 98 102 void resetTimer(void); 99 void calcDecimalPoint(std::string &str, int d);100 103 void CalcDecimalPoint(std::string &str, int d); 104 void ResetTraverser(); 101 105 102 106 … … 105 109 { 106 110 camera = new Camera(winWidth, winHeight); 111 camera->SetNear(nearDist); 107 112 108 113 glutInitWindowSize(winWidth, winHeight); … … 145 150 sceneBox = bvh->GetBox(); 146 151 147 //traverser = new FrustumCullingTraverser(); 148 traverser = new StopAndWaitTraverser(); 149 traverser->SetHierarchy(bvh); 150 traverser->SetRenderState(&state); 151 152 //SetupProjection(800, 600, 60, sceneBox); 152 ResetTraverser(); 153 153 154 //camera->LookAtBox(sceneBox); 154 155 camera->LookInBox(sceneBox); 155 //camera->SetPosition(Vector3(0, 0, -3));156 //camera->SetDirection(Vector3(0, 0, 1));157 156 158 157 /// initialise rendertime array … … 274 273 275 274 275 void ResetTraverser() 276 { 277 DEL_PTR(traverser); 278 279 switch (renderMode) 280 { 281 case RenderTraverser::CULL_FRUSTUM: 282 traverser = new FrustumCullingTraverser(); 283 break; 284 case RenderTraverser::STOP_AND_WAIT: 285 traverser = new StopAndWaitTraverser(); 286 break; 287 case RenderTraverser::CHC: 288 traverser = new CHCTraverser(); 289 break; 290 default: 291 traverser = new FrustumCullingTraverser(); 292 } 293 294 traverser->SetHierarchy(bvh); 295 traverser->SetRenderState(&state); 296 } 297 298 276 299 void SetupLighting() 277 300 { … … 343 366 void display(void) 344 367 { 345 char * msg[] = {"Frustum culling only", "Hierarchical stop and wait",346 "Coherent hierarchical culling"};347 348 char msg2[200];349 char msg3[200];350 char msg4[100];351 char msg5[100];352 char msg6[100];353 char msg7[100];354 char msg8[100];355 356 357 /*sprintf_s(msg2, "Traversed: %4d, frustum culled: %4d, query culled: %4d (of %d nodes)",358 traverser.GetNumTraversedNodes(), traverser.GetNumFrustumCulledNodes(),359 traverser.GetNumQueryCulledNodes(),360 traverser.GetHierarchy()->GetNumHierarchyNodes());361 */362 char *optstr[2] = {"", ", using optimization"};363 364 float fps = 1e3f;365 long renderTime = calcRenderTime();366 if (renderTime) fps = 1e3f / (float)renderTime;367 368 //sprintf_s(msg3, "Threshold: %4d, algorithm rendering time: %ld ms (%3.3f fps), queries: %s",369 // traverser.GetVisibilityThreshold(), renderTime / 1000, fps, optstr[useOptimization]);370 sprintf_s(msg3, "render time: %ld ms (%3.3f fps), queries: %s", renderTime, fps, optstr[useOptimization]);371 372 string str;373 string str2;374 375 /*calcDecimalPoint(str, Geometry::CountTriangles(objectType) * traverser.GetNumRenderedGeometry());376 calcDecimalPoint(str2, Geometry::CountTriangles(objectType) * numObjects);377 378 sprintf_s(msg4, "Rendered objects %d (of %d), rendered triangles: %s (of %s)",379 traverser.GetNumRenderedGeometry(), numObjects, str.c_str(), str2.c_str());380 */381 382 368 ++ currentFrame; 383 369 … … 391 377 392 378 InitTiming(); 393 394 379 long t1, t2; 395 380 … … 404 389 405 390 traverser->Render(); 406 /* 407 bool usesTextures = false; 408 409 SceneEntityContainer::const_iterator sit, sit_end = sceneEntities.end(); 410 411 for (sit = sceneEntities.begin(); sit != sit_end; ++ sit) 412 { 413 SceneEntity *entity = *sit; 414 415 if (!usesTextures && entity->GetGeometry()->HasTexture()) 416 { 417 glEnable(GL_TEXTURE_2D); 418 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 419 usesTextures = true; 420 } 421 else if (usesTextures && !entity->GetGeometry()->HasTexture()) 422 { 423 glDisable(GL_TEXTURE_2D); 424 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 425 usesTextures = false; 426 } 427 428 entity->Render(); 429 } 430 */ 391 431 392 glDisableClientState(GL_VERTEX_ARRAY); 432 393 glDisableClientState(GL_NORMAL_ARRAY); … … 438 399 t2 = GetTime(); 439 400 long loop_time = TimeDiff(t1, t2); 440 //cout<<"t: " << loop_time<<endl; 441 442 /* 443 traverser.SetViewpoint(eyePos); 444 traverser.SetProjViewMatrix(eyeProjView); 445 traverser.Render(renderMode); 446 */ 447 401 448 402 // cycle through rendertime array 449 403 renderTimes[renderTimesIdx] = loop_time;// traverser.GetRenderTime(); … … 455 409 //if(visMode) displayVisualization(); 456 410 457 458 begin2D(); 459 460 if(showHelp) 461 { 462 drawHelpMessage(); 463 } 464 else 465 { 466 glColor3f(1.0,1.0,1.0); 467 //output(10, winHeight-10, msg[renderMode]); 468 469 if(showStatistics) 470 { 471 if(showCreateParams) 472 { 473 output(10, winHeight-150, msg8); 474 output(10, winHeight-130, msg7); 475 output(10, winHeight-110, msg6); 476 output(10, winHeight-90, msg5); 477 } 478 479 output(10, winHeight-70, msg3); 480 //output(10, winHeight-50, msg4); 481 //output(10, winHeight-30, msg2); 482 } 483 } 484 end2D(); 485 411 DisplayStats(); 486 412 glutSwapBuffers(); 487 413 } … … 491 417 void keyboard(const unsigned char c, const int x, const int y) 492 418 { 493 //int threshold;494 //HierarchyNode *hierarchy;495 496 419 switch(c) 497 420 { … … 500 423 break; 501 424 case 32: //space 502 //renderMode = (renderMode + 1) % RenderTraverser::NUM_RENDERMODES;425 renderMode = (renderMode + 1) % RenderTraverser::NUM_RENDERMODES; 503 426 resetTimer(); 504 //traverser.Render(renderMode); // render once so stats are updated427 ResetTraverser(); 505 428 break; 506 429 case 'h': … … 518 441 break; 519 442 case '+': 520 //threshold = traverser.GetVisibilityThreshold() + 10;521 //traverser.SetVisibilityThreshold(threshold);443 threshold = traverser->GetVisibilityThreshold() + 10; 444 traverser->SetVisibilityThreshold(threshold); 522 445 break; 523 446 case '-': 524 //threshold = traverser.GetVisibilityThreshold() - 10;525 //if(threshold < 0) threshold = 0;526 527 //traverser.SetVisibilityThreshold(threshold);447 threshold = traverser->GetVisibilityThreshold() - 10; 448 if(threshold < 0) threshold = 0; 449 450 traverser->SetVisibilityThreshold(threshold); 528 451 break; 529 452 case '1': … … 541 464 setupVisView(); 542 465 break; 543 case 'r':544 case 'R':545 showCreateParams = !showCreateParams;546 break;547 466 case 'g': 548 467 case 'G': 549 468 useOptimization = !useOptimization; 550 //traverser.SetUseOptimization(useOptimization); 551 break; 552 /* 553 case 'c': 554 case 'C': 555 hierarchy = traverser.GetHierarchy(); 556 // delete old hierarchy 557 if (hierarchy) delete hierarchy; 558 deleteGeometry(); 559 560 maxTranslation[2] = -3.0 - zLength; 561 numObjects = numNextObjects; 562 objectType = nextObjectType; 563 564 hierarchy = generateHierarchy(numObjects); 565 traverser.SetHierarchy(hierarchy); 566 567 showCreateParams = false; 568 569 traverser.Render(renderMode); // render once to update stats 570 resetTimer(); 571 break; 572 */ 469 traverser->SetUseOptimization(useOptimization); 573 470 default: 574 471 return; … … 694 591 695 592 // don't move in the vertical direction 696 Vector3 horView(viewDir[0], 0, viewDir[2]); 697 698 eyeXAngle = -0.2f * M_PI * (xEyeBegin - x) / 180.0; 593 //Vector3 horView(viewDir[0], 0, viewDir[2]); 594 Vector3 horView(viewDir[0], viewDir[1], 0); 595 596 eyeXAngle = 0.2f * M_PI * (xEyeBegin - x) / 180.0; 699 597 700 598 // rotate view vector 701 Matrix4x4 rot = RotationYMatrix(eyeXAngle); 599 //Matrix4x4 rot = RotationYMatrix(eyeXAngle); 600 Matrix4x4 rot = RotationZMatrix(eyeXAngle); 702 601 viewDir = rot * viewDir; 703 602 … … 746 645 // the 90 degree rotated view vector 747 646 // y zero so we don't move in the vertical 748 Vector3 rVec(viewDir[0], 0, viewDir[2]); 749 750 Matrix4x4 rot = RotationYMatrix(M_PI * 0.5f); 647 //Vector3 rVec(viewDir[0], 0, viewDir[2]); 648 Vector3 rVec(viewDir[0], viewDir[1], 0); 649 650 //Matrix4x4 rot = RotationYMatrix(M_PI * 0.5f); 651 Matrix4x4 rot = RotationZMatrix(M_PI * 0.5f); 751 652 rVec = rot * rVec; 752 653 753 pos += rVec * (x - horizontalMotionBegin) * 0.1f; 754 pos[1] += (verticalMotionBegin - y) * 0.1f; 654 pos -= rVec * (x - horizontalMotionBegin) * 0.1f; 655 //pos[1] += (verticalMotionBegin - y) * 0.1f; 656 pos[2] += (verticalMotionBegin - y) * 0.1f; 755 657 756 658 camera->SetPosition(pos); … … 902 804 903 805 // this function inserts a dezimal point after each 1000 904 void calcDecimalPoint(string &str, int d)806 void CalcDecimalPoint(string &str, int d) 905 807 { 906 808 vector<int> numbers; … … 920 822 } 921 823 922 for ( size_t i =numbers.size() - 2; i >= 0; i--)824 for (int i = (int)numbers.size() - 2; i >= 0; i--) 923 825 { 924 826 sprintf_s(hstr, ",%03d", numbers[i]); … … 926 828 } 927 829 } 830 831 832 void DisplayStats() 833 { 834 char *msg[] = {"Frustum Culling", "Stop and Wait", 835 "Coherent Culling"}; 836 837 char msg2[200]; 838 char msg3[200]; 839 char msg4[200]; 840 841 842 sprintf_s(msg2, "traversed: %4d, frustum culled: %4d, query culled: %4d (of %d nodes)", 843 traverser->GetStats().mNumTraversedNodes, traverser->GetStats().mNumFrustumCulledNodes, 844 traverser->GetStats().mNumQueryCulledNodes, bvh->GetNumVirtualNodes()); 845 846 char *optstr[2] = {"", ", using optimization"}; 847 848 float fps = 1e3f; 849 long renderTime = calcRenderTime(); 850 if (renderTime) fps /= (float)renderTime; 851 852 sprintf_s(msg3, "Threshold: %4d, render time: %ld ms (%3.3f fps), issued queries: %d%s", 853 traverser->GetVisibilityThreshold(), renderTime, fps, traverser->GetStats().mNumIssuedQueries, optstr[useOptimization]); 854 855 string str; 856 string str2; 857 858 int dummy = 0; 859 CalcDecimalPoint(str, dummy); 860 CalcDecimalPoint(str2, traverser->GetStats().mNumRenderedTriangles); 861 862 sprintf_s(msg4, "rendered objects %d (of %d), rendered triangles: %s (of %s)", 863 traverser->GetStats().mNumRenderedGeometry, sceneEntities.size(), str.c_str(), str2.c_str()); 864 865 866 begin2D(); 867 868 if(showHelp) 869 { 870 drawHelpMessage(); 871 } 872 else 873 { 874 glColor3f(1.0f ,1.0f ,1.0f ); 875 output(20, winHeight - 10, msg[renderMode]); 876 877 if(showStatistics) 878 { 879 output(20, winHeight - 70, msg3); 880 output(20, winHeight - 50, msg4); 881 output(20, winHeight - 30, msg2); 882 } 883 } 884 885 end2D(); 886 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/common.cpp
r2756 r2764 194 194 // get the absolute path 195 195 size_t c = strlen(name); 196 int i = c - 1;196 size_t i = c - 1; 197 197 bool wasDot = false; 198 198 … … 258 258 StripPath(const char *s) 259 259 { 260 const int len = strlen(s);261 262 int i = len;260 const size_t len = strlen(s); 261 262 size_t i = len; 263 263 for (; i>0; i--) { 264 264 if (s[i]=='/' || s[i]=='\\')
Note: See TracChangeset
for help on using the changeset viewer.