- Timestamp:
- 07/16/08 17:19:25 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
r2839 r2842 152 152 { 153 153 mGeometry[i] = (*it); 154 mBox.Include((*it)->GetBoundingBox());154 //mBox.Include((*it)->GetBoundingBox()); 155 155 } 156 156 … … 799 799 for (int i = node->mFirst; i <= node->mLast; ++ i) 800 800 { 801 #ifdef TODO 802 numTriangles += mGeometry[i]->GetGeometry()->GetNumTriangles(); 803 #endif 801 numTriangles += mGeometry[i]->CountNumTriangles(); 804 802 } 805 803 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.h
r2840 r2842 35 35 36 36 inline bool HasTexture() const { return mHasTexture; } 37 37 38 const AxisAlignedBox3& GetBoundingBox() const; 38 39 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp
r2841 r2842 14 14 { 15 15 16 static Camera *sCam = NULL;17 18 19 inline static bool CompDist(SceneEntity *e1, SceneEntity *e2)20 {21 return22 (SqrMagnitude(e1->GetBoundingBox().Center() - sCam->GetPosition()) <23 SqrMagnitude(e2->GetBoundingBox().Center() - sCam->GetPosition()));24 }25 26 16 27 17 inline static bool CompDist2(RenderQueueBucket *b1, RenderQueueBucket *b2) … … 29 19 return (b1->mMinDistance < b2->mMinDistance); 30 20 } 21 31 22 32 23 … … 46 37 mSize(0) 47 38 { 48 sCam = cam;49 39 } 50 40 … … 91 81 shapes.clear(); 92 82 93 entity->GetCurrentLODLevel(shapes) 83 entity->GetCurrentLODLevel(shapes); 94 84 95 85 ShapeContainer::const_iterator sit, sit_end = shapes.end(); … … 107 97 ++ mSize; 108 98 109 if ( entity->mRenderQueueBucket)110 { 111 bucket = entity->mRenderQueueBucket;99 if (shape->mRenderQueueBucket) 100 { 101 bucket = shape->mRenderQueueBucket; 112 102 } 113 103 else … … 119 109 for (; i < mBuckets.size(); ++ i) 120 110 { 121 if (bucketFound = FitsInBucket( entity, i))111 if (bucketFound = FitsInBucket(shape, i)) 122 112 break; 123 113 } … … 128 118 RenderQueueBucket *bucket = new RenderQueueBucket(); 129 119 130 Material *mat = entity->GetMaterial();120 Material *mat = shape->GetMaterial(); 131 121 132 122 bucket->mAlphaTestEnabled = mat->IsAlphaTestEnabled(); … … 143 133 // assume that the incoming nodes are ordered by distance => set min dist 144 134 // on first incoming node 145 float dist = SqrMagnitude(entity->GetBoundingBox().Center() - mCamera->GetPosition()); 135 Vector3 v = shape->GetTransformedBoundingBox().Center() - mCamera->GetPosition(); 136 const float dist = SqrMagnitude(v); 146 137 mBuckets[i]->mMinDistance = dist; 147 138 … … 150 141 151 142 bucket = mBuckets[i]; 152 entity->mRenderQueueBucket = bucket;153 } 154 155 bucket->m Entities.push_back(entity);143 shape->mRenderQueueBucket = bucket; 144 } 145 146 bucket->mShapes.push_back(shape); 156 147 } 157 148 … … 174 165 void RenderQueue::Render() 175 166 { 167 // sort the buckets 176 168 Sort(); 177 169 178 170 // render all buckets 179 171 for (size_t i = 0; i < mBuckets.size(); ++ i) … … 215 207 216 208 209 void RenderQueue::Sort() 210 { 211 // sort buckets itself 212 sort(mBuckets.begin(), mBuckets.end(), CompDist2); 213 } 214 215 217 216 void RenderQueue::Apply() 218 217 { … … 222 221 223 222 224 void RenderQueue::Sort() 225 { 226 // sort buckets itself 227 sort(mBuckets.begin(), mBuckets.end(), CompDist2); 228 } 229 230 231 } 223 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.h
r2841 r2842 70 70 protected: 71 71 72 void Sort(); 73 72 74 void Enqueue(Shape *shape); 73 75 74 76 inline bool FitsInBucket(Shape *shape, size_t idx) const; 75 76 /** Sorts the render queue by materials / textures.77 */78 void Sort();79 77 /** Clears the render queue 80 78 */ -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp
r2839 r2842 109 109 { 110 110 SceneEntity *ent = entities[i]; 111 #ifdef TODO 112 mStats.mNumRenderedTriangles += ent-> GetGeometry()->GetNumTriangles();113 #endif 111 112 mStats.mNumRenderedTriangles += ent->CountNumTriangles(); 113 114 114 if (mUseRenderQueue) 115 115 mRenderQueue->Enqueue(ent); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
r2840 r2842 9 9 #include "Vector3.h" 10 10 #include "Transform3.h" 11 #include "Shape.h" 11 12 12 13 … … 26 27 CLEAR_CONTAINER(mTextures); 27 28 CLEAR_CONTAINER(mTrafos); 29 CLEAR_CONTAINER(mShapes); 28 30 } 29 31 … … 62 64 sceneGeom = new SceneEntity(trafo); 63 65 66 // create shape 67 Shape *shape = new Shape(geom, mat, sceneGeom); 68 mShapes.push_back(shape); 69 70 sceneGeom->AddShape(shape); 71 64 72 return sceneGeom; 65 73 } … … 104 112 105 113 mGeometryTable[i] = geom; 106 mMaterialTable[i] = mat; 114 mMaterialTable[i] = mat; 107 115 108 116 mGeometry.push_back(geom); … … 199 207 SceneEntity *ent = LoadSceneEntity(str); 200 208 entities[i] = ent; 209 201 210 mSceneEntities.push_back(ent); 202 211 } … … 232 241 mGeometryTable.clear(); 233 242 mMaterialTable.clear(); 243 //mShapesTable.clear(); 234 244 235 245 return true; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h
r2840 r2842 48 48 std::map<int, Material *> mMaterialTable; 49 49 std::map<int, Geometry *> mGeometryTable; 50 //std::map<int, Shape *> mShapesTable; 50 51 51 52 // these are kept to be able to delete these resources afterwards … … 53 54 std::vector<Material *> mMaterials; 54 55 std::vector<Geometry *> mGeometry; 55 std::vector<SceneEntity *> mSceneEntities;56 56 std::vector<Transform3 *> mTrafos; 57 58 SceneEntityContainer mSceneEntities; 59 ShapeContainer mShapes; 57 60 }; 58 61 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp
r2841 r2842 9 9 10 10 11 using namespace std; 12 13 11 14 namespace CHCDemoEngine 12 15 { 16 13 17 14 18 SceneEntity::SceneEntity(Transform3 *trafo): mTransform(trafo) … … 26 30 ShapeContainer::const_iterator sit, sit_end; 27 31 28 if (mLODInfos ->empty())32 if (mLODInfos.empty()) 29 33 { 30 34 sit = mShapes.begin(); sit_end = mShapes.end(); … … 35 39 int i = 0; 36 40 37 LODInfo *info;38 39 41 LODInfoContainer::const_iterator lid, lid_end = mLODInfos.end(); 40 42 41 43 for (lid = mLODInfos.begin(); lid != lid_end; ++ lid) 42 44 { 43 info = *lid;45 LODInfo *lodInfo = *lid; 44 46 45 if ( info->mDistance > mDistance)47 if (lodInfo->mSquaredDistance > mDistance) 46 48 { 47 sit = info->mShapes.begin();48 sit_end = info->mShapes.end();49 sit = lodInfo->mShapes.begin(); 50 sit_end = lodInfo->mShapes.end(); 49 51 break; 50 52 } … … 70 72 ShapeContainer::const_iterator sit, sit_end = shapes.end(); 71 73 72 for ( ; sit != sit_end; ++ sit)74 for (sit = shapes.begin(); sit != sit_end; ++ sit) 73 75 { 74 76 (*sit)->Render(state); … … 101 103 102 104 103 AxisAlignedBox3 SceneEntity::GetBoundingBox() const 105 int SceneEntity::CountNumTriangles() 104 106 { 105 #ifdef TODO 106 AxisAlignedBox3 box = mGeometry->GetBoundingBox(); 107 if (mTransform) Transform(box, *mTransform); 108 #else 109 AxisAlignedBox3 box; 110 #endif 111 107 int numTriangles = 0; 108 static ShapeContainer shapes; 109 shapes.clear(); 112 110 113 return box; 111 GetCurrentLODLevel(shapes); 112 113 ShapeContainer::const_iterator sit, sit_end = shapes.end(); 114 115 for (sit = shapes.begin(); sit != sit_end; ++ sit) 116 { 117 numTriangles += (*sit)->GetGeometry()->GetNumTriangles(); 118 } 119 120 return numTriangles; 114 121 } 115 122 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h
r2841 r2842 51 51 /** Returns the transformed bounding box. 52 52 */ 53 AxisAlignedBox3 GetBoundingBox() const;53 //AxisAlignedBox3 GetBoundingBox() const; 54 54 /** set frame where we last rendered this node 55 55 */ … … 62 62 inline Transform3 *GetTransform() const { return mTransform; } 63 63 64 void GetCurrentLODLevel(ShapeContainer &shapes); 64 65 65 void GetCurrentLODLevel(ShapeContainer &shapes); 66 int CountNumTriangles(); 67 66 68 67 69 protected: -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.cpp
r2840 r2842 4 4 #include "Geometry.h" 5 5 #include "SceneEntity.h" 6 7 #include "glInterface.h" 8 #include <Cg/cg.h> 9 #include <Cg/cgGL.h> 6 #include "Transform3.h" 10 7 11 8 … … 30 27 if (mMaterial) mMaterial->Render(state); 31 28 29 mParent->GetTransform()->Load(state); 32 30 mGeometry->Render(state); 31 mParent->GetTransform()->Unload(state); 32 33 33 } 34 34 … … 46 46 47 47 48 49 AxisAlignedBox3 Shape::GetBoundingBox() const 50 { 51 return mGeometry->GetBoundingBox(); 48 52 } 53 54 55 AxisAlignedBox3 Shape::GetTransformedBoundingBox() const 56 { 57 AxisAlignedBox3 box = mGeometry->GetBoundingBox(); 58 Matrix4x4 *mat = mParent->GetTransform()->GetMatrix(); 59 60 if (mat) Transform(box, *mat); 61 62 return box; 63 } 64 65 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.h
r2840 r2842 12 12 13 13 14 15 14 class Material; 16 15 class Geometry; 17 16 class RenderState; 17 class AxisAlignedBox3; 18 18 19 struct RenderQueueBucket; 20 19 21 20 22 /** Class representing a shape. … … 43 45 */ 44 46 void SetMaterial(Material *mat); 45 47 /** Returns the transformed bounding box. 48 */ 49 AxisAlignedBox3 GetBoundingBox() const; 50 /** Returns bounding box transformed with the parent transform. 51 */ 52 AxisAlignedBox3 GetTransformedBoundingBox() const; 53 46 54 inline Material *GetMaterial() const { return mMaterial; } 47 55
Note: See TracChangeset
for help on using the changeset viewer.