Browse Source

OctreeQuery micro-optimizations.

Lasse Öörni 14 years ago
parent
commit
b9d7839d94
2 changed files with 19 additions and 24 deletions
  1. 11 11
      Engine/Graphics/Octree.cpp
  2. 8 13
      Engine/Graphics/View.cpp

+ 11 - 11
Engine/Graphics/Octree.cpp

@@ -170,23 +170,23 @@ void Octant::DrawDebugGeometry(DebugRenderer* debug, bool depthTest)
 
 
 void Octant::GetDrawablesInternal(OctreeQuery& query, bool inside) const
 void Octant::GetDrawablesInternal(OctreeQuery& query, bool inside) const
 {
 {
-    if (!numDrawables_)
-        return;
-    
-    Intersection res = query.TestOctant(cullingBox_, inside);
-    if (res == OUTSIDE && this != root_)
-        // Fully outside, so cull this octant, its children & drawables
-        return;
-    if (res == INSIDE)
-        inside = true;
+    if (this != root_)
+    {
+        Intersection res = query.TestOctant(cullingBox_, inside);
+        if (res == OUTSIDE)
+            // Fully outside, so cull this octant, its children & drawables
+            return;
+        if (res == INSIDE)
+            inside = true;
+    }
     
     
     for (PODVector<Drawable*>::ConstIterator i = drawables_.Begin(); i != drawables_.End(); ++i)
     for (PODVector<Drawable*>::ConstIterator i = drawables_.Begin(); i != drawables_.End(); ++i)
     {
     {
         Drawable* drawable = *i;
         Drawable* drawable = *i;
         
         
         if (!(drawable->GetDrawableFlags() & query.drawableFlags_) || !(drawable->GetViewMask() & query.viewMask_) ||
         if (!(drawable->GetDrawableFlags() & query.drawableFlags_) || !(drawable->GetViewMask() & query.viewMask_) ||
-            !drawable->IsVisible() || (query.occludersOnly_ && !drawable->IsOccluder()) || (query.shadowCastersOnly_ &&
-            !drawable->GetCastShadows()))
+            (query.occludersOnly_ && !drawable->IsOccluder()) || (query.shadowCastersOnly_ && !drawable->GetCastShadows()) ||
+            !drawable->IsVisible())
             continue;
             continue;
         
         
         if (query.TestDrawable(drawable->GetWorldBoundingBox(), inside) != OUTSIDE)
         if (query.TestDrawable(drawable->GetWorldBoundingBox(), inside) != OUTSIDE)

+ 8 - 13
Engine/Graphics/View.cpp

@@ -283,14 +283,13 @@ void View::GetDrawables()
     Vector3 cameraPos = camera_->GetWorldPosition();
     Vector3 cameraPos = camera_->GetWorldPosition();
     
     
     // Get zones & find the zone camera is in
     // Get zones & find the zone camera is in
-    PODVector<Zone*> zones;
-    PointOctreeQuery query(reinterpret_cast<PODVector<Drawable*>& >(zones), cameraPos, DRAWABLE_ZONE, camera_->GetViewMask());
+    PointOctreeQuery query(tempDrawables_, cameraPos, DRAWABLE_ZONE, camera_->GetViewMask());
     octree_->GetDrawables(query);
     octree_->GetDrawables(query);
     
     
     int highestZonePriority = M_MIN_INT;
     int highestZonePriority = M_MIN_INT;
-    for (unsigned i = 0; i < zones.Size(); ++i)
+    for (unsigned i = 0; i < tempDrawables_.Size(); ++i)
     {
     {
-        Zone* zone = zones[i];
+        Zone* zone = static_cast<Zone*>(tempDrawables_[i]);
         if (zone->IsInside(cameraPos) && zone->GetPriority() > highestZonePriority)
         if (zone->IsInside(cameraPos) && zone->GetPriority() > highestZonePriority)
         {
         {
             zone_ = zone;
             zone_ = zone;
@@ -299,27 +298,23 @@ void View::GetDrawables()
     }
     }
     
     
     // If occlusion in use, get & render the occluders, then build the depth buffer hierarchy
     // If occlusion in use, get & render the occluders, then build the depth buffer hierarchy
-    bool useOcclusion = false;
     OcclusionBuffer* buffer = 0;
     OcclusionBuffer* buffer = 0;
     
     
     if (maxOccluderTriangles_ > 0)
     if (maxOccluderTriangles_ > 0)
     {
     {
         FrustumOctreeQuery query(occluders_, camera_->GetFrustum(), DRAWABLE_GEOMETRY, camera_->GetViewMask(), true, false);
         FrustumOctreeQuery query(occluders_, camera_->GetFrustum(), DRAWABLE_GEOMETRY, camera_->GetViewMask(), true, false);
-        
         octree_->GetDrawables(query);
         octree_->GetDrawables(query);
         UpdateOccluders(occluders_, camera_);
         UpdateOccluders(occluders_, camera_);
         
         
         if (occluders_.Size())
         if (occluders_.Size())
         {
         {
             buffer = renderer_->GetOrCreateOcclusionBuffer(camera_, maxOccluderTriangles_);
             buffer = renderer_->GetOrCreateOcclusionBuffer(camera_, maxOccluderTriangles_);
-            
             DrawOccluders(buffer, occluders_);
             DrawOccluders(buffer, occluders_);
             buffer->BuildDepthHierarchy();
             buffer->BuildDepthHierarchy();
-            useOcclusion = true;
         }
         }
     }
     }
     
     
-    if (!useOcclusion)
+    if (!buffer)
     {
     {
         // Get geometries & lights without occlusion
         // Get geometries & lights without occlusion
         FrustumOctreeQuery query(tempDrawables_, camera_->GetFrustum(), DRAWABLE_GEOMETRY | DRAWABLE_LIGHT);
         FrustumOctreeQuery query(tempDrawables_, camera_->GetFrustum(), DRAWABLE_GEOMETRY | DRAWABLE_LIGHT);
@@ -359,14 +354,14 @@ void View::GetDrawables()
             
             
             // Expand the scene bounding boxes
             // Expand the scene bounding boxes
             const BoundingBox& geomBox = drawable->GetWorldBoundingBox();
             const BoundingBox& geomBox = drawable->GetWorldBoundingBox();
-            BoundingBox geoview_Box = geomBox.Transformed(view);
+            BoundingBox geomViewBox = geomBox.Transformed(view);
             sceneBox_.Merge(geomBox);
             sceneBox_.Merge(geomBox);
-            sceneViewBox_.Merge(geoview_Box);
+            sceneViewBox_.Merge(geomViewBox);
             
             
             // Store depth info to speed up split directional light queries
             // Store depth info to speed up split directional light queries
             GeometryDepthBounds bounds;
             GeometryDepthBounds bounds;
-            bounds.min_ = geoview_Box.min_.z_;
-            bounds.max_ = geoview_Box.max_.z_;
+            bounds.min_ = geomViewBox.min_.z_;
+            bounds.max_ = geomViewBox.max_.z_;
             
             
             geometryDepthBounds_.Push(bounds);
             geometryDepthBounds_.Push(bounds);
             geometries_.Push(drawable);
             geometries_.Push(drawable);