- Timestamp:
- 06/22/08 05:24:22 (17 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 1347 added
- 20 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/chc_revisited.vcproj
r2793 r2795 41 41 Name="VCCLCompilerTool" 42 42 Optimization="0" 43 AdditionalIncludeDirectories="libs;libs/GL;libs/Devil/include;src "43 AdditionalIncludeDirectories="libs;libs/GL;libs/Devil/include;src;libs/Zlib/include" 44 44 PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS" 45 45 MinimalRebuild="true" … … 63 63 <Tool 64 64 Name="VCLinkerTool" 65 AdditionalDependencies="glut32.lib glew32s.lib glew32.lib DevIL.lib ILUT.lib "65 AdditionalDependencies="glut32.lib glew32s.lib glew32.lib DevIL.lib ILUT.lib zlib.lib" 66 66 LinkIncremental="2" 67 AdditionalLibraryDirectories="libs/GL;libs/Devil/lib "67 AdditionalLibraryDirectories="libs/GL;libs/Devil/lib;libs/Zlib/lib" 68 68 GenerateDebugInformation="true" 69 69 SubSystem="1" … … 126 126 OmitFramePointers="true" 127 127 EnableFiberSafeOptimizations="true" 128 AdditionalIncludeDirectories="libs;libs/GL;libs/Devil/include;src "128 AdditionalIncludeDirectories="libs;libs/GL;libs/Devil/include;src;libs/Zlib/include" 129 129 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE; _CRT_SECURE_NO_WARNINGS" 130 130 StringPooling="true" … … 150 150 <Tool 151 151 Name="VCLinkerTool" 152 AdditionalDependencies="glut32.lib glew32s.lib glew32.lib DevIL.lib ILUT.lib "152 AdditionalDependencies="glut32.lib glew32s.lib glew32.lib DevIL.lib ILUT.lib zlib.lib" 153 153 LinkIncremental="1" 154 AdditionalLibraryDirectories="libs/GL;libs/Devil/lib "154 AdditionalLibraryDirectories="libs/GL;libs/Devil/lib;libs/Zlib/lib" 155 155 GenerateDebugInformation="false" 156 156 SubSystem="1" … … 197 197 </File> 198 198 <File 199 RelativePath=".\src\BinaryLoader.cpp"200 >201 </File>202 <File203 RelativePath=".\src\BinaryLoader.h"204 >205 </File>206 <File207 199 RelativePath=".\src\BvhLoader.cpp" 208 200 > … … 225 217 </File> 226 218 <File 219 RelativePath=".\src\gzstream.cpp" 220 > 221 </File> 222 <File 223 RelativePath=".\src\gzstream.h" 224 > 225 </File> 226 <File 227 227 RelativePath=".\src\Matrix4x4.cpp" 228 228 > … … 238 238 <File 239 239 RelativePath=".\src\Plane3.h" 240 > 241 </File> 242 <File 243 RelativePath=".\src\ResourceManager.cpp" 244 > 245 </File> 246 <File 247 RelativePath=".\src\ResourceManager.h" 240 248 > 241 249 </File> -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
r2792 r2795 13 13 #include "Geometry.h" 14 14 #include "RenderState.h" 15 #include "gzstream.h" 15 16 16 17 … … 66 67 static int sClipPlaneAABBVertexIndices[12]; 67 68 69 70 #define ALIGN_INDICES 68 71 69 72 BvhNode::BvhNode(BvhNode *parent): … … 177 180 mCurrentIndicesPtr = 0; 178 181 mNumNodes = 0; 179 mMaxDepthForTestingChildren = 4; 180 mAreaRatioThreshold = 1.4f; 182 183 mMaxDepthForTestingChildren = 3; 184 //mMaxDepthForTestingChildren = 4; 185 mAreaRatioThreshold = 2.0f; 186 //mAreaRatioThreshold = 1.4f; 187 181 188 mVboId = -1; 182 189 } … … 452 459 memcpy(mIndices + numNodes * sNumIndicesPerBox, 453 460 mTestIndices + node->mIndicesPtr, 454 #if 0 //ALIGN_INDICES455 ((numIndices / 32) * 32 + 32) * sizeof(unsigned int));456 #else457 461 numIndices * sizeof(unsigned int)); 458 #endif 462 459 463 numNodes += node->mNumTestNodes; 460 464 } … … 485 489 486 490 487 #define ALIGN_INDICES 1488 489 491 void Bvh::CreateIndices() 490 492 { … … 502 504 { 503 505 int offset = (*lit)->mNumTestNodes * sNumIndicesPerBox; 504 #if ALIGN_INDICES506 #ifdef ALIGN_INDICES 505 507 // align with 32 506 508 offset = (offset / 32) * 32 + 32; … … 547 549 548 550 // align with 32 549 #if ALIGN_INDICES551 #ifdef ALIGN_INDICES 550 552 const int offset = (numIndices / 32) * 32 + 32; 551 553 #else … … 654 656 BvhNode *node = *lit; 655 657 656 // recreate list of nodes that will be tested as a proxy ...658 // recreate list of nodes that will be queried as a proxy 657 659 if (CreateNodeRenderList(node)) 658 660 ++ success; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp
r2786 r2795 5 5 6 6 #include "BvhLoader.h" 7 7 #include "gzstream.h" 8 8 9 9 … … 19 19 20 20 21 BvhNode *BvhLoader::LoadNextNode(i fstream &stream, BvhInterior *parent)21 BvhNode *BvhLoader::LoadNextNode(igzstream &stream, BvhInterior *parent) 22 22 { 23 23 int nodeType; … … 55 55 { 56 56 queue<BvhNode *> tQueue; 57 i fstream stream(filename.c_str(), ifstream::binary);57 igzstream stream(filename.c_str()); 58 58 59 59 if (!stream.is_open()) return NULL; … … 98 98 99 99 bvh->PostProcess(); 100 const int n = 1000; 101 // set virtual leaves for n triangles 102 bvh->SetVirtualLeaves(n); 100 101 const int trianglesPerVirtualLeaves = 1000; 102 // set virtual leaves for specified number of triangles 103 bvh->SetVirtualLeaves(trianglesPerVirtualLeaves); 103 104 104 105 bvh->UpdateNumLeaves(bvh->mRoot); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.h
r2782 r2795 5 5 6 6 #include "Bvh.h" 7 8 class igzstream; 7 9 8 10 … … 20 22 protected: 21 23 22 BvhNode *LoadNextNode( std::ifstream &stream, BvhInterior *parent);24 BvhNode *LoadNextNode(igzstream &stream, BvhInterior *parent); 23 25 }; 24 26 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/CHCPlusPlusTraverser.cpp
r2792 r2795 184 184 185 185 // render the rest of the objects 186 if (mUseRenderQueue) 187 { 188 if (mRenderState->SetState(RenderState::RENDER)) 189 ++ mStats.mNumStateChanges; 190 191 mRenderQueue.Render(); 192 mRenderQueue.Clear(); 193 } 186 if (mUseRenderQueue) ApplyRenderQueue(); 194 187 195 188 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/CHCTraverser.cpp
r2792 r2795 12 12 OcclusionQuery *CHCTraverser::IssueOcclusionQueryWithGeometry(BvhNode *node) 13 13 { 14 // render out what is left in the qeue 15 if (mUseRenderQueue) ApplyRenderQueue(); 16 14 17 OcclusionQuery *query = mQueryHandler.RequestQuery(); 15 18 query->AddNode(node); … … 20 23 21 24 RenderNode(node); 22 23 if (mUseRenderQueue) 24 { 25 mRenderQueue.Render(); 26 mRenderQueue.Clear(); 27 } 25 if (mUseRenderQueue) ApplyRenderQueue(); 28 26 29 27 query->EndQuery(); … … 134 132 } 135 133 } 136 137 /// Empty render queue.138 if (mUseRenderQueue)139 {140 mRenderQueue.Render();141 mRenderQueue.Clear();142 }143 134 } 144 135 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrustumCullingTraverser.cpp
r2792 r2795 36 36 } 37 37 } 38 39 // render the contents of the render queue40 if (mUseRenderQueue)41 {42 mRenderQueue.Render();43 mRenderQueue.Clear();44 }45 38 } 46 39 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.cpp
r2786 r2795 19 19 mVboId(-1) 20 20 { 21 mHasTexture = (mTexCoords != NULL); 22 21 23 Prepare(); 22 24 23 25 if (delData) 24 26 { 25 delete [] mVertices; mVertices = NULL;26 delete [] mNormals; mNormals = NULL;27 //if (mTexCoords) delete [] mTexCoords; mTexCoords = NULL;27 DEL_ARRAY_PTR(mVertices); 28 DEL_ARRAY_PTR(mNormals); 29 DEL_ARRAY_PTR(mTexCoords); 28 30 } 29 31 } … … 32 34 Geometry::~Geometry() 33 35 { 34 if (mVertices) delete [] mVertices;35 if (mNormals) delete [] mNormals;36 if (mTexCoords) delete [] mTexCoords;36 DEL_ARRAY_PTR(mVertices); 37 DEL_ARRAY_PTR(mNormals); 38 DEL_ARRAY_PTR(mTexCoords); 37 39 38 40 // delete vbo … … 65 67 66 68 glGenBuffersARB(1, &mVboId); 67 68 69 glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId); 69 70 … … 93 94 { 94 95 glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId); 95 glVertexPointer(3, GL_FLOAT, 0, (char *)NULL); 96 97 if (mHasTexture) 98 glTexCoordPointer(2, GL_FLOAT, 0, (char *)NULL + 2 * mNumVertices * sizeof(Vector3)); 99 96 100 glNormalPointer(GL_FLOAT, 0, (char *)NULL + mNumVertices * sizeof(Vector3)); 97 101 98 if (mTexCoords) 99 glTexCoordPointer(2, GL_FLOAT, 0, (char *)NULL + 2 * mNumVertices * sizeof(Vector3)); 102 glVertexPointer(3, GL_FLOAT, 0, (char *)NULL); 100 103 101 104 state->SetCurrentVboId(mVboId); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.h
r2793 r2795 28 28 int GetNumTriangles() const { return mNumVertices / 3; } 29 29 30 inline bool HasTexture() const { return m TexCoords != NULL; }30 inline bool HasTexture() const { return mHasTexture; } 31 31 const AxisAlignedBox3& GetBoundingBox() const; 32 32 … … 52 52 53 53 AxisAlignedBox3 mBoundingBox; 54 55 bool mHasTexture; 54 56 }; 55 57 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp
r2782 r2795 20 20 mAlphaTestEnabled = false; 21 21 22 mAmbientColor = RgbaColor( .2f, .2f,.2f, 1.0f);22 mAmbientColor = RgbaColor(0.2f, 0.2f, 0.2f, 1.0f); 23 23 mDiffuseColor = RgbaColor(1.0f, 1.0f, 1.0f, 1.0f); 24 //mSpecularColor = RgbaColor( 0.0f, 0.0f, 0.0f, 1.0f);24 //mSpecularColor = RgbaColor(.0f, .0f, .0f, 1.0f); 25 25 mSpecularColor = RgbaColor(0.5f, 0.5f, 0.5f, 1.0f); 26 mEmmisiveColor = RgbaColor(.0f, .0f, .0f, 1.0f); 26 27 } 27 28 28 29 29 Material::Material(): mId(0) 30 { 31 InitMaterial(); 32 } 33 34 35 Material::Material(int id): 36 mId(id) 30 Material::Material() 37 31 { 38 32 InitMaterial(); … … 43 37 mDiffuseColor(color), 44 38 mAmbientColor(color), 45 mSpecularColor(0, 0, 0, 1), 46 mId(0), 39 mSpecularColor(0, 0, 0, 1), 47 40 mTexture(NULL) 48 41 { 49 }50 51 52 int Material::GetId() const53 {54 return mId;55 42 } 56 43 … … 80 67 glMaterialfv(GL_FRONT, GL_AMBIENT, (float *)&mAmbientColor.r); 81 68 glMaterialfv(GL_FRONT, GL_DIFFUSE, (float *)&mDiffuseColor.r); 69 glMaterialfv(GL_FRONT, GL_EMISSION, (float *)&mEmmisiveColor.r); 82 70 glMaterialfv(GL_FRONT, GL_SPECULAR, (float *)&mSpecularColor.r); 83 71 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h
r2782 r2795 1 1 #ifndef __MATERIAL_H 2 2 #define __MATERIAL_H 3 4 #include "common.h" 3 5 4 6 … … 34 36 class Material 35 37 { 38 friend class ResourceManager; 39 36 40 public: 37 41 38 42 Material(); 39 43 40 Material(int id);41 42 44 Material(const RgbaColor &color); 43 /** Returns unique material id.44 */45 int GetId() const;46 45 47 46 friend Material RandomMaterial(); … … 49 48 inline Texture *GetTexture() const { return mTexture; } 50 49 51 void SetTexture(Texture *texture) { mTexture = texture; } 50 inline RgbaColor GetAmbient() const { return mAmbientColor; } 51 inline RgbaColor GetDiffuse() const { return mDiffuseColor; } 52 inline RgbaColor GetSpecular() const { return mSpecularColor; } 53 inline RgbaColor GetEmmisive() const { return mEmmisiveColor; } 54 55 inline void SetTexture(Texture *texture) { mTexture = texture; } 56 57 inline void SetAmbient(const RgbaColor &color) { mAmbientColor = color; } 58 inline void SetDiffuse(const RgbaColor &color) { mDiffuseColor = color; } 59 inline void SetSpecular(const RgbaColor &color) { mSpecularColor = color; } 60 inline void SetEmmisive(const RgbaColor &color) { mEmmisiveColor = color; } 61 62 inline void SetAlphaTestEnabled(bool alpha) { mAlphaTestEnabled = alpha; } 63 inline bool IsAlphaTestEnabled() const { return mAlphaTestEnabled; } 52 64 /** Renders this material. 53 65 */ 54 66 void Render(RenderState *state); 67 /** Initialize the material with default values 68 */ 69 void InitMaterial(); 55 70 71 72 protected: 56 73 57 74 /////////// … … 60 77 RgbaColor mSpecularColor; 61 78 RgbaColor mAmbientColor; 79 RgbaColor mEmmisiveColor; 62 80 63 81 bool mAlphaTestEnabled; 64 65 protected:66 67 /** Initialize the material with default values68 */69 void InitMaterial();70 71 ////////////////72 73 /// unique material id74 int mId;75 82 /// the assciated texture 76 83 Texture *mTexture; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp
r2782 r2795 4 4 #include "Texture.h" 5 5 #include "Material.h" 6 7 6 8 7 using namespace std; … … 22 21 int tsize2 = t2 ? t2->GetByteSize() : 0; 23 22 24 // if texture size equal, group by material 25 if (tsize1 == tsize2) 26 return ent1->GetMaterial() < ent2->GetMaterial(); 23 return tsize1 < tsize2; 24 } 27 25 28 return tsize1 < tsize2; 26 27 inline static bool IsLower2(SceneEntity *ent1, SceneEntity *ent2) 28 { 29 return ent1->GetMaterial() < ent2->GetMaterial(); 29 30 } 30 31 … … 63 64 { 64 65 if (mEntities.size() >= mMinSizeForSorting) 66 { 67 sortTimer.Entry(); 65 68 Sort(); 69 sortTimer.Exit(); 70 } 66 71 67 72 SceneEntityContainer::const_iterator sit, sit_end = mEntities.end(); … … 72 77 ent->Render(mState); 73 78 } 79 80 //Print(); 74 81 } 82 83 84 void RenderQueue::Print() 85 { 86 SceneEntityContainer::const_iterator sit, sit_end = mEntities.end(); 87 88 Debug << "\nrq size: " << GetSize() << endl; 89 Debug << "texture size: " << endl; 90 // show ordering by texture size 91 for (sit = mEntities.begin(); sit != sit_end; ++ sit) 92 { 93 SceneEntity *ent = *sit; 94 Texture *t = ent->GetMaterial()->GetTexture(); 95 int tsize = t ? t->GetByteSize() : 0; 96 Debug << tsize << " "; 97 } 98 99 // show ordering by material 100 Debug << "\nmaterial ptr: " << endl; 75 101 102 for (sit = mEntities.begin(); sit != sit_end; ++ sit) 103 { 104 Debug << (*sit)->GetMaterial() << " "; 105 } 106 } 107 108 109 void RenderQueue::Apply() 110 { 111 Render(); 112 Clear(); 113 } 114 76 115 77 116 void RenderQueue::Sort() 78 117 { 79 sort(mEntities.begin(), mEntities.end(), IsLower); 118 // sort by material 119 sort(mEntities.begin(), mEntities.end(), IsLower2); 120 // sort by texture size 121 stable_sort(mEntities.begin(), mEntities.end(), IsLower); 80 122 } 81 123 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.h
r2793 r2795 3 3 4 4 #include "common.h" 5 #include "Timer/PerfTimer.h" 6 5 7 6 8 namespace CHCDemoEngine … … 38 40 */ 39 41 int GetSize() const { return (int)mEntities.size(); } 42 /** Renders and clears the queue. 43 */ 44 void Apply(); 45 /** Prints the ordering in the render queue. 46 */ 47 void Print(); 48 49 PerfTimer sortTimer; 50 40 51 41 52 protected: -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp
r2792 r2795 130 130 void RenderTraverser::RenderScene() 131 131 { 132 //glFinish();133 132 PerfTimer timer; 133 134 134 timer.Start(); 135 135 … … 152 152 Traverse(); 153 153 154 // render the contents of the render queue 155 if (mUseRenderQueue) ApplyRenderQueue(); 154 156 mRenderState->Reset(); 155 157 … … 157 159 glDisableClientState(GL_NORMAL_ARRAY); 158 160 159 //glFinish();160 161 mStats.mRenderTime = timer.Elapsedms(); 162 163 //if (mUseRenderQueue) Debug << "rq sort: " << 1e3f * mRenderQueue.sortTimer.TotalTime() << " ms" << endl; 161 164 } 162 165 … … 178 181 { 179 182 mUseOptimization = useOptimization; 180 //cout << "using optimization: " << mUseOptimization << endl;183 cout << "using optimization: " << mUseOptimization << endl; 181 184 } 182 185 … … 229 232 ++ mStats.mNumIssuedQueries; 230 233 234 // render pending objects before changing to query mode 231 235 if (mUseRenderQueue && (mRenderState->GetMode() == RenderState::RENDER)) 232 { 233 //Debug << "render queue: " << mRenderQueue.GetSize() << endl; 234 mRenderQueue.Render(); 235 mRenderQueue.Clear(); 236 } 236 ApplyRenderQueue(); 237 237 238 238 239 query.BeginQuery(); … … 248 249 249 250 250 } 251 void RenderTraverser::ApplyRenderQueue() 252 { 253 if (mRenderState->SetState(RenderState::RENDER)) 254 ++ mStats.mNumStateChanges; 255 256 mRenderQueue.Apply(); 257 } 258 259 260 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.h
r2792 r2795 118 118 void SetShowBounds(bool showBounds); 119 119 120 120 121 protected: 121 122 … … 142 143 */ 143 144 void RenderNode(BvhNode *node); 145 /** Renders and clears the contents of the render queue. 146 */ 147 void ApplyRenderQueue(); 144 148 145 149 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
r2793 r2795 1 #include " BinaryLoader.h"1 #include "ResourceManager.h" 2 2 #include "Matrix4x4.h" 3 3 #include "Geometry.h" … … 5 5 #include "Material.h" 6 6 #include "Texture.h" 7 //#include "gzstream.h"7 #include "gzstream.h" 8 8 9 9 … … 15 15 16 16 17 BinaryLoader::~BinaryLoader() 18 { 19 /** delete all maps. 20 */ 21 std::map<int, Texture *>::iterator it, it_end = mTextureTable.end(); 22 23 for (it = mTextureTable.begin(); it != it_end; ++ it) 24 { 25 Texture *tex = (*it).second; 26 delete tex; 27 } 28 29 std::map<int, Material *>::iterator nit, nit_end = mMaterialTable.end(); 30 31 for (nit = mMaterialTable.begin(); nit != nit_end; ++ nit) 32 { 33 Material *mat = (*nit).second; 34 delete mat; 35 } 36 37 38 std::map<int, Geometry *>::iterator git, git_end = mGeometryTable.end(); 39 40 for (git = mGeometryTable.begin(); git != git_end; ++git) 41 { 42 Geometry *geom = (*git).second; 43 delete geom; 44 } 45 } 46 47 //SceneEntity *BinaryLoader::LoadSceneEntity(igzstream &str) 48 SceneEntity *BinaryLoader::LoadSceneEntity(ifstream &str) 17 ResourceManager::~ResourceManager() 18 { 19 // delete all resources. 20 CLEAR_CONTAINER(mSceneEntities); 21 CLEAR_CONTAINER(mGeometry); 22 CLEAR_CONTAINER(mMaterials); 23 CLEAR_CONTAINER(mTextures); 24 CLEAR_CONTAINER(mTrafos); 25 } 26 27 28 SceneEntity *ResourceManager::LoadSceneEntity(igzstream &str) 49 29 { 50 30 // shape … … 69 49 trafo = new Matrix4x4(); 70 50 str.read(reinterpret_cast<char *>(trafo->x), sizeof(Matrix4x4)); 51 mTrafos.push_back(trafo); 71 52 } 72 53 … … 77 58 78 59 79 void BinaryLoader::LoadTextures(ifstream &str)60 void ResourceManager::LoadTextures(igzstream &str) 80 61 { 81 62 int numTextures; … … 97 78 98 79 mTextureTable[i] = tex; 80 mTextures.push_back(tex); 99 81 } 100 82 … … 103 85 104 86 105 void BinaryLoader::LoadShapes(ifstream &str)87 void ResourceManager::LoadShapes(igzstream &str) 106 88 { 107 89 int numShapes; … … 115 97 mGeometryTable[i] = geom; 116 98 mMaterialTable[i] = mat; 99 100 mGeometry.push_back(geom); 101 mMaterials.push_back(mat); 117 102 } 118 103 … … 121 106 122 107 123 //Appearance *BinaryLoader::LoadMaterial(igzstream &str) 124 Material *BinaryLoader::LoadMaterial(ifstream &str) 108 Material *ResourceManager::LoadMaterial(igzstream &str) 125 109 { 126 110 // default material … … 145 129 str.read(reinterpret_cast<char *>(&mat->mAmbientColor), sizeof(Vector3)); 146 130 str.read(reinterpret_cast<char *>(&mat->mDiffuseColor), sizeof(Vector3)); 131 str.read(reinterpret_cast<char *>(&mat->mEmmisiveColor), sizeof(Vector3)); 147 132 str.read(reinterpret_cast<char *>(&mat->mSpecularColor), sizeof(Vector3)); 148 133 } … … 152 137 153 138 154 //Geometry *BinaryLoader::LoadGeometry(igzstream &str) 155 Geometry *BinaryLoader::LoadGeometry(ifstream &str) 139 Geometry *ResourceManager::LoadGeometry(igzstream &str) 156 140 { 157 141 Vector3 *vertices; … … 183 167 if (texCoordCount) 184 168 { 185 //cout << "loading texcoords of size " << texCoordCount << endl;186 169 texcoords = new float[texCoordCount * 2]; 187 170 str.read(reinterpret_cast<char *>(texcoords), sizeof(float) * vertexCount * 2); … … 194 177 195 178 196 void BinaryLoader::LoadSceneEntities(ifstream &str, SceneEntityContainer &entities)179 void ResourceManager::LoadSceneEntities(igzstream &str, SceneEntityContainer &entities) 197 180 { 198 181 int entityCount; … … 205 188 SceneEntity *ent = LoadSceneEntity(str); 206 189 entities[i] = ent; 190 mSceneEntities.push_back(ent); 207 191 } 208 192 … … 211 195 212 196 213 bool BinaryLoader::Load(const std::string &filename, SceneEntityContainer &entities) 214 { 215 //clear_textures(); // clear the texture table 216 217 //igzstream str(filename.c_str());//, ios::binary); 218 ifstream istr(filename.c_str(), ios::binary); 197 bool ResourceManager::Load(const std::string &filename, SceneEntityContainer &entities) 198 { 199 igzstream istr(filename.c_str()); 219 200 220 201 if (!istr.is_open()) … … 236 217 cout << "bin loading finished" << endl; 237 218 219 // clean up 220 mTextureTable.clear(); 221 mGeometryTable.clear(); 222 mMaterialTable.clear(); 223 238 224 return true; 239 225 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h
r2782 r2795 1 #ifndef __ BinaryLoader_H__2 #define __ BinaryLoader_H__1 #ifndef __ResourceManager_H__ 2 #define __ResourceManager_H__ 3 3 4 // note use forward declaration instead 4 5 5 #include <string> 6 6 #include <iostream> … … 10 10 #include "common.h" 11 11 12 class igzstream; 13 12 14 13 15 namespace CHCDemoEngine 14 16 { 15 17 16 class igzstream;17 18 class SceneEntity; 18 19 class Material; 19 20 class Geometry; 20 21 class Texture; 22 class Matrix4x4; 21 23 22 23 class BinaryLoader 24 /** Loads a scene and also handles the cleanup 25 */ 26 class ResourceManager 24 27 { 25 28 public: 26 29 27 ~BinaryLoader(); 28 30 ~ResourceManager(); 31 /** Loads a model 32 */ 29 33 bool Load(const std::string &filename, SceneEntityContainer &geometry); 30 34 31 35 protected: 32 36 33 void LoadTextures( std::ifstream &str);34 void LoadShapes( std::ifstream &str);35 void LoadSceneEntities( std::ifstream &str, SceneEntityContainer &entities);37 void LoadTextures(igzstream &str); 38 void LoadShapes(igzstream &str); 39 void LoadSceneEntities(igzstream &str, SceneEntityContainer &entities); 36 40 37 SceneEntity *LoadSceneEntity( std::ifstream &str);38 Material *LoadMaterial( std::ifstream &str);39 Geometry *LoadGeometry( std::ifstream &str);41 SceneEntity *LoadSceneEntity(igzstream &str); 42 Material *LoadMaterial(igzstream &str); 43 Geometry *LoadGeometry(igzstream &str); 40 44 41 45 std::map<int, Texture *> mTextureTable; 42 46 std::map<int, Material *> mMaterialTable; 43 47 std::map<int, Geometry *> mGeometryTable; 48 49 // these are kept to be able to delete these resources afterwards 50 std::vector<Texture *> mTextures; 51 std::vector<Material *> mMaterials; 52 std::vector<Geometry *> mGeometry; 53 std::vector<SceneEntity *> mSceneEntities; 54 std::vector<Matrix4x4 *> mTrafos; 44 55 }; 45 56 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp
r2792 r2795 20 20 SceneEntity::~SceneEntity() 21 21 { 22 // delete only trafo here, the other members could be shared23 // among several entities and are therefore handled separately24 DEL_PTR(mTransform);25 22 } 26 23 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h
r2793 r2795 59 59 Geometry *mGeometry; 60 60 Material *mMaterial; 61 62 //AxisAlignedBox3 mBoundingBox;63 61 64 62 int mLastRendered; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/StopAndWaitTraverser.cpp
r2792 r2795 22 22 mDistanceQueue.pop(); 23 23 24 // interesting for the visualization25 node->SetVisible(false);26 27 28 24 if (mBvh->IsWithinViewFrustum(node)) 29 25 { … … 37 33 OcclusionQuery *query = IssueOcclusionQuery(node); 38 34 39 int visiblePixels = query->GetQueryResult();35 bool visible = query->GetQueryResult() > mVisibilityThreshold; 40 36 41 if (visible Pixels > mVisibilityThreshold)37 if (visible) 42 38 { 43 //cout<< "visible: " << visiblePixels << endl;44 // update node's visited flag => needed for rendering45 // so set it also here46 //node->SetLastVisited(mFrameID);47 //node->SetVisible(true);48 49 39 TraverseNode(node); 50 40 } 51 41 else 52 42 { 43 node->SetVisible(false); 53 44 ++ mStats.mNumQueryCulledNodes; 54 45 } 46 47 // update node's visited flag (could be interesting for the visualization) 48 node->SetVisible(visible); 55 49 } 56 50 } … … 60 54 } 61 55 } 62 63 /// Empty render queue.64 if (mUseRenderQueue)65 {66 mRenderQueue.Render();67 mRenderQueue.Clear();68 }69 56 } 70 57 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2794 r2795 9 9 #include "Vector3.h" 10 10 #include "Matrix4x4.h" 11 #include " BinaryLoader.h"11 #include "ResourceManager.h" 12 12 #include "Bvh.h" 13 13 #include "Camera.h" … … 20 20 #include "Visualization.h" 21 21 #include "RenderState.h" 22 22 #include "Timer/PerfTimer.h" 23 23 24 24 … … 35 35 Bvh *bvh = NULL; 36 36 /// handles scene loading 37 BinaryLoader *loader = NULL;37 ResourceManager *loader = NULL; 38 38 /// the scene camera 39 39 Camera *camera = NULL; 40 /// the scene camera 41 Camera *visCamera = NULL; 40 42 /// the visualization 41 43 Visualization *visualization = NULL; … … 43 45 RenderState state; 44 46 /// the rendering algorithm 45 int renderMode = RenderTraverser::C ULL_FRUSTUM;47 int renderMode = RenderTraverser::CHCPLUSPLUS; 46 48 // eye near plane distance 47 49 float nearDist = 0.1f; … … 49 51 int threshold; 50 52 53 float fov = 50.0f; 54 51 55 int assumedVisibleFrames = 10; 52 56 int maxBatchSize = 50; 53 57 54 const float keyForwardMotion = 0.5f; 55 const float keyRotation = 0.05f; 58 int trianglesPerVirtualLeaf = 1000; 59 60 /// these values get scaled with the frame rate 61 const float keyForwardMotion = 50.0f; 62 const float keyRotation = 2.0f; 63 /// elapsed time in seconds 64 double elapsedTime = 1.0f; 56 65 57 66 int winWidth = 1024; … … 84 93 bool useOptimization = false; 85 94 bool useTightBounds = true; 86 bool useRenderQueue = false;95 bool useRenderQueue = true; 87 96 bool useMultiQueries = true; 88 97 98 /// the accumulated z axis rotation 89 99 float rotation = 0; 90 100 91 101 Matrix4x4 visView = IdentityMatrix(); 102 103 SceneEntityContainer skyGeometry; 92 104 93 105 bool leftKeyPressed = false; … … 129 141 void KeyHorizontalMotion(float shift); 130 142 void KeyVerticalMotion(float shift); 131 void KeyRotate(float angle); 143 144 145 inline float KeyRotationAngle() { return keyRotation * elapsedTime; } 146 inline float KeyShift() { return keyForwardMotion * elapsedTime; } 132 147 133 148 … … 137 152 int returnCode = 0; 138 153 139 #ifdef _CRT_SET 140 141 //Now just call this function at the start of your program and if you're 142 //compiling in debug mode (F5), any leaks will be displayed in the Output 143 //window when the program shuts down. If you're not in debug mode this will 144 //be ignored. Use it as you will! 145 //note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() { 146 147 _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF); 148 _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE); 149 _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR); 150 #endif 151 152 153 camera = new Camera(winWidth, winHeight, 60); 154 camera = new Camera(winWidth, winHeight, fov); 154 155 camera->SetNear(nearDist); 156 157 visCamera = new Camera(winWidth, winHeight, fov); 158 visCamera->SetNear(nearDist); 155 159 156 160 glutInitWindowSize(winWidth, winHeight); … … 158 162 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); 159 163 160 glutCreateWindow(" Coherent HierarchicalCulling");164 glutCreateWindow("FriendlyCulling"); 161 165 162 166 glutDisplayFunc(Display); … … 177 181 178 182 179 loader = new BinaryLoader();183 loader = new ResourceManager(); 180 184 181 185 //const string filename("data/city/model/city.dem"); … … 190 194 exit(0); 191 195 } 196 197 SceneEntityContainer dummy; 198 199 const string envname = string(model_path + "env.dem"); 200 201 if (loader->Load(envname, skyGeometry)) 202 cout << "sky box " << filename << " loaded" << endl; 203 else 204 { 205 cerr << "loading sky box " << filename << " failed" << endl; 206 CleanUp(); 207 exit(0); 208 } 209 192 210 193 211 const string bvh_filename = string(model_path + "city.bvh"); … … 206 224 ResetTraverser(); 207 225 208 camera->SetDirection(Vector3(0.961829f, 0.273652f, 0.0f)); 226 //camera->SetDirection(Vector3(0.961829f, 0.273652f, 0.0f)); 227 camera->Pitch(-M_PI * 0.5); 209 228 camera->SetPosition(Vector3(483.398f, 242.364f, 186.078f)); 210 229 … … 265 284 "", 266 285 "'F1' - shows/dismisses this message", 267 "'F2' - shows/hides statistics",286 "'F2' - shows/hides bird eye view", 268 287 "'F3' - shows/hides bounds (boxes or tight bounds)", 269 "'F4' - shows/hides bird eye view",270 "' f5', - load helpScreen",288 "'F4' - shows/hides statistics", 289 "'F5', - shows/hides parameters", 271 290 "'SPACE' - cycles through occlusion culling algorithms", 272 291 "", … … 281 300 "'-' - decreases max batch size", 282 301 "'+' - increases max batch size", 302 "'4' - decrease triangles per virtual leaf (sets depth of bvh)", 303 "'5' - increase triangles per virtual leaf (sets depth of bvh)", 283 304 "'6' - decrease assumed visible frames", 284 305 "'7' - increase assumed visible frames", 285 "'8' - upward motion",286 "'9' - downward motion",306 "'8' - downward motion", 307 "'9' - upward motion", 287 308 "", 288 309 "'R' - use render queue", … … 405 426 } 406 427 407 void SetupEyeView( void)428 void SetupEyeView() 408 429 { 409 430 glMatrixMode(GL_PROJECTION); 410 431 glLoadIdentity(); 411 432 412 gluPerspective( 60.0f, 1.0f / winAspectRatio, nearDist, 2.0f * Magnitude(bvh->GetBox().Diagonal()));433 gluPerspective(fov, 1.0f / winAspectRatio, nearDist, 10.0f * Magnitude(bvh->GetBox().Diagonal())); 413 434 414 435 glMatrixMode(GL_MODELVIEW); 436 glLoadIdentity(); 415 437 camera->SetupCameraView(); 416 438 … … 423 445 424 446 425 void KeyRotate(float angle)426 {427 Vector3 viewDir = camera->GetDirection();428 // rotate view vector429 Matrix4x4 rot = RotationZMatrix(angle);430 viewDir = rot * viewDir;431 camera->SetDirection(viewDir);432 }433 434 435 447 void KeyHorizontalMotion(float shift) 436 448 { … … 459 471 void Display() 460 472 { 473 PerfTimer frameTimer; 474 475 frameTimer.Start(); 476 461 477 if (leftKeyPressed) 462 KeyRotate(keyRotation);478 camera->Pitch(KeyRotationAngle()); 463 479 if (rightKeyPressed) 464 KeyRotate(-keyRotation);480 camera->Pitch(-KeyRotationAngle()); 465 481 if (upKeyPressed) 466 KeyHorizontalMotion( keyForwardMotion);482 KeyHorizontalMotion(KeyShift()); 467 483 if (downKeyPressed) 468 KeyHorizontalMotion(- keyForwardMotion);484 KeyHorizontalMotion(-KeyShift()); 469 485 if (eightKeyPressed) 470 KeyVerticalMotion( keyForwardMotion);486 KeyVerticalMotion(-KeyShift()); 471 487 if (nineKeyPressed) 472 KeyVerticalMotion( -keyForwardMotion);488 KeyVerticalMotion(KeyShift()); 473 489 474 490 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); … … 479 495 // actually render the scene geometry using one of the specified algorithms 480 496 traverser->RenderScene(); 481 497 498 499 glEnableClientState(GL_VERTEX_ARRAY); 500 glEnableClientState(GL_NORMAL_ARRAY); 501 502 SceneEntityContainer::const_iterator sit, sit_end = skyGeometry.end(); 503 504 for (sit = skyGeometry.begin(); sit != sit_end; ++ sit) 505 (*sit)->Render(&state); 506 507 glDisableClientState(GL_VERTEX_ARRAY); 508 glDisableClientState(GL_NORMAL_ARRAY); 509 510 state.Reset(); 511 482 512 if (visMode) DisplayVisualization(); 483 513 … … 485 515 486 516 glutSwapBuffers(); 517 518 elapsedTime = frameTimer.Elapsed(); 487 519 } 488 520 … … 531 563 { 532 564 eightKeyPressed = true; 533 KeyVerticalMotion( keyForwardMotion);565 KeyVerticalMotion(-KeyShift()); 534 566 break; 535 567 } … … 537 569 { 538 570 nineKeyPressed = true; 539 KeyVerticalMotion( -keyForwardMotion);571 KeyVerticalMotion(+KeyShift()); 540 572 break; 541 573 } … … 549 581 { 550 582 leftKeyPressed = true; 551 KeyRotate(keyRotation);583 camera->Pitch(KeyRotationAngle()); 552 584 } 553 585 break; … … 556 588 { 557 589 rightKeyPressed = true; 558 KeyRotate(-keyRotation);590 camera->Pitch(-KeyRotationAngle()); 559 591 } 560 592 break; … … 563 595 { 564 596 upKeyPressed = true; 565 KeyHorizontalMotion( keyForwardMotion);597 KeyHorizontalMotion(KeyShift()); 566 598 } 567 599 break; … … 570 602 { 571 603 downKeyPressed = true; 572 KeyHorizontalMotion(- keyForwardMotion);604 KeyHorizontalMotion(-KeyShift()); 573 605 } 574 606 break; … … 587 619 } 588 620 break; 589 590 591 621 case '4': 622 if (trianglesPerVirtualLeaf >= 100) 623 trianglesPerVirtualLeaf -= 100; 624 625 bvh->SetVirtualLeaves(trianglesPerVirtualLeaf); 626 break; 627 case '5': 628 trianglesPerVirtualLeaf += 100; 629 bvh->SetVirtualLeaves(trianglesPerVirtualLeaf); 630 break; 592 631 default: 593 632 return; … … 658 697 void Special(int c, int x, int y) 659 698 { 660 // used to avoid vertical motion with the keys661 Vector3 hvec = Vector3(camera->GetDirection()[0], camera->GetDirection()[1], 0.0f);662 663 699 switch(c) 664 700 { … … 667 703 break; 668 704 case GLUT_KEY_F2: 669 showStatistics = !showStatistics;705 visMode = !visMode; 670 706 break; 671 707 case GLUT_KEY_F3: … … 674 710 break; 675 711 case GLUT_KEY_F4: 676 visMode = !visMode;712 showStatistics = !showStatistics; 677 713 break; 678 714 case GLUT_KEY_F5: … … 682 718 { 683 719 leftKeyPressed = true; 684 KeyRotate(keyRotation);720 camera->Pitch(KeyRotationAngle()); 685 721 } 686 722 break; … … 688 724 { 689 725 rightKeyPressed = true; 690 KeyRotate(-keyRotation);726 camera->Pitch(-KeyRotationAngle()); 691 727 } 692 728 break; … … 694 730 { 695 731 upKeyPressed = true; 696 KeyHorizontalMotion( keyForwardMotion);732 KeyHorizontalMotion(KeyShift()); 697 733 } 698 734 break; … … 700 736 { 701 737 downKeyPressed = true; 702 KeyHorizontalMotion(- keyForwardMotion);738 KeyHorizontalMotion(-KeyShift()); 703 739 } 704 740 break; … … 728 764 glLoadIdentity(); 729 765 730 gluPerspective( 60.0f, 1.0f / winAspectRatio, nearDist, 2.0f * Magnitude(bvh->GetBox().Diagonal()));766 gluPerspective(fov, 1.0f / winAspectRatio, nearDist, 2.0f * Magnitude(bvh->GetBox().Diagonal())); 731 767 732 768 glMatrixMode(GL_MODELVIEW); … … 768 804 void LeftMotion(int x, int y) 769 805 { 770 static float eyeXAngle = 0.0f;771 772 806 Vector3 viewDir = camera->GetDirection(); 773 807 Vector3 pos = camera->GetPosition(); … … 776 810 Vector3 horView(viewDir[0], viewDir[1], 0); 777 811 778 eyeXAngle = 0.2f * M_PI * (xEyeBegin - x) / 180.0; 779 780 rotation += eyeXAngle; 781 782 // rotate view vector 783 Matrix4x4 rot = RotationZMatrix(eyeXAngle); 784 viewDir = rot * viewDir; 812 float eyeXAngle = 0.2f * M_PI * (xEyeBegin - x) / 180.0; 813 814 camera->Pitch(eyeXAngle); 785 815 786 816 pos += horView * (yMotionBegin - y) * 0.2f; 787 788 camera->SetDirection(viewDir); 817 789 818 camera->SetPosition(pos); 790 819 … … 801 830 void RightMotion(int x, int y) 802 831 { 803 static float eyeYAngle = 0.0f; 804 805 Vector3 viewDir = camera->GetDirection(); 806 Vector3 right = camera->GetRightVector(); 807 808 eyeYAngle = -0.2f * M_PI * (yEyeBegin - y) / 180.0; 809 810 // rotate view vector 811 Matrix4x4 rot = RotationAxisMatrix(right, eyeYAngle); 812 viewDir = rot * viewDir; 813 814 camera->SetDirection(viewDir); 815 832 float eyeYAngle = -0.2f * M_PI * (yEyeBegin - y) / 180.0; 833 834 camera->Yaw(eyeYAngle); 835 816 836 yEyeBegin = y; 817 818 837 glutPostRedisplay(); 819 838 } … … 907 926 // displays the visualisation of culling algorithm 908 927 void DisplayVisualization() 909 { 928 {cout<<"here34"<<endl; 910 929 SetupVisView(); 911 930 … … 923 942 glViewport(winWidth - winWidth / 4, winHeight - winHeight / 3, winWidth, winHeight); 924 943 925 926 944 glMatrixMode(GL_PROJECTION); 927 945 glLoadIdentity(); 928 946 929 //gluPerspective(60.0f, 1.0f / winAspectRatio, nearDist, 2.0f * Magnitude(bvh->GetBox().Diagonal())); 947 gluPerspective(fov, 1.0f / winAspectRatio, nearDist, 20.0f * Magnitude(bvh->GetBox().Diagonal())); 948 930 949 AxisAlignedBox3 box = bvh->GetBox(); 931 950 const float offs = 2000; 932 glOrtho(box.Min().y - offs, box.Max().y + offs, box.Min().y - offs, box.Max().y + offs, 0.1, 20.0f * Magnitude(bvh->GetBox().Diagonal())); 933 934 935 glPushMatrix(); 936 951 952 //glOrtho(box.Min().y - offs, box.Max().y + offs, box.Min().y - offs, box.Max().y + offs, 0.1, 20.0f * Magnitude(bvh->GetBox().Diagonal())); 953 //glOrtho(-offs, offs, offs, -offs, 0.1, 20.0f * Magnitude(bvh->GetBox().Diagonal())); 954 //glPushMatrix(); 955 956 Vector3 vizpos = Vector3(box.Center().x, box.Center().y, box.Max().z); 957 visCamera->SetPosition(vizpos); 958 visCamera->Yaw(-0.5 * M_PI); 959 cout<<"pos: " << visCamera->GetPosition()<<endl; 937 960 glMatrixMode(GL_MODELVIEW); 938 961 glLoadIdentity(); 939 962 940 glMultMatrixf((float *)visView.x); 963 visCamera->SetupCameraView(); 964 //glMultMatrixf((float *)visView.x); 941 965 942 966 //SetupLighting(); … … 947 971 glLightfv(GL_LIGHT1, GL_POSITION, position1); 948 972 949 950 951 973 glClear(GL_DEPTH_BUFFER_BIT); 952 974 … … 956 978 visualization->Render(); 957 979 958 glPopMatrix();980 //glPopMatrix(); 959 981 960 982 glViewport(0, 0, winWidth, winHeight); … … 991 1013 void CleanUp() 992 1014 { 993 CLEAR_CONTAINER(sceneEntities);994 1015 DEL_PTR(traverser); 995 996 1016 DEL_PTR(bvh); 997 1017 DEL_PTR(visualization); 998 1018 DEL_PTR(camera); 999 1000 1019 DEL_PTR(loader); 1001 1020 } … … 1040 1059 char msg6[200]; 1041 1060 char msg7[200]; 1061 char msg8[200]; 1042 1062 1043 1063 … … 1084 1104 sprintf_s(msg6, "issued queries: %5d, state changes: %5d", issuedQueries, stateChanges); 1085 1105 1106 sprintf_s(msg8, "triangles per virtual leaf: %5d", trianglesPerVirtualLeaf); 1107 1086 1108 sprintf_s(msg7, "fps: %6.1f", fps); 1087 1109 … … 1111 1133 Output(20, 150, msg2); 1112 1134 Output(20, 180, msg3); 1135 Output(20, 210, msg8); 1113 1136 } 1114 1137 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.h
r2784 r2795 145 145 146 146 147 // delete a pointer and set to NULL 148 #ifndef DEL_ARRAY_PTR 149 #define DEL_ARRAY_PTR(ptr) do {if (ptr) { \ 150 delete [] (ptr); \ 151 (ptr) = 0;}} \ 152 while (0) 153 #endif 154 155 147 156 // Clears a container (i.e., a vector of pointers) and deletes the pointers 148 157 #ifndef CLEAR_CONTAINER
Note: See TracChangeset
for help on using the changeset viewer.