Explorar el Código

Speed up collecting visible drawables.

Lasse Öörni hace 11 años
padre
commit
5753a90b57

+ 2 - 8
Source/Urho3D/Graphics/Drawable.cpp

@@ -292,12 +292,6 @@ void Drawable::SetSortValue(float value)
     sortValue_ = value;
     sortValue_ = value;
 }
 }
 
 
-void Drawable::SetMinMaxZ(float minZ, float maxZ)
-{
-    minZ_ = minZ;
-    maxZ_ = maxZ;
-}
-
 void Drawable::MarkInView(const FrameInfo& frame)
 void Drawable::MarkInView(const FrameInfo& frame)
 {
 {
     if (frame.frameNumber_ != viewFrameNumber_)
     if (frame.frameNumber_ != viewFrameNumber_)
@@ -306,7 +300,7 @@ void Drawable::MarkInView(const FrameInfo& frame)
         viewCameras_.Clear();
         viewCameras_.Clear();
     }
     }
     
     
-    viewCameras_.Insert(frame.camera_);
+    viewCameras_.Push(frame.camera_);
 }
 }
 
 
 void Drawable::MarkInView(unsigned frameNumber, Camera* camera)
 void Drawable::MarkInView(unsigned frameNumber, Camera* camera)
@@ -318,7 +312,7 @@ void Drawable::MarkInView(unsigned frameNumber, Camera* camera)
     }
     }
     
     
     if (camera)
     if (camera)
-        viewCameras_.Insert(camera);
+        viewCameras_.Push(camera);
 }
 }
 
 
 void Drawable::LimitLights()
 void Drawable::LimitLights()

+ 3 - 4
Source/Urho3D/Graphics/Drawable.h

@@ -25,7 +25,6 @@
 #include "../Math/BoundingBox.h"
 #include "../Math/BoundingBox.h"
 #include "../Scene/Component.h"
 #include "../Scene/Component.h"
 #include "../Graphics/GraphicsDefs.h"
 #include "../Graphics/GraphicsDefs.h"
-#include "../Container/HashSet.h"
 
 
 namespace Urho3D
 namespace Urho3D
 {
 {
@@ -199,7 +198,7 @@ public:
     /// Set sorting value.
     /// Set sorting value.
     void SetSortValue(float value);
     void SetSortValue(float value);
     /// Set view-space depth bounds.
     /// Set view-space depth bounds.
-    void SetMinMaxZ(float minZ, float maxZ);
+    void SetMinMaxZ(float minZ, float maxZ) { minZ_ = minZ; maxZ_ = maxZ; }
     /// Mark in view.
     /// Mark in view.
     void MarkInView(const FrameInfo& frame);
     void MarkInView(const FrameInfo& frame);
     /// Mark in view of a specific camera. Specify null camera to update just the frame number.
     /// Mark in view of a specific camera. Specify null camera to update just the frame number.
@@ -336,8 +335,8 @@ protected:
     Zone* zone_;
     Zone* zone_;
     /// Zone inconclusive or dirtied flag.
     /// Zone inconclusive or dirtied flag.
     bool zoneDirty_;
     bool zoneDirty_;
-    /// Set of cameras from which is seen on the current frame.
-    HashSet<Camera*> viewCameras_;
+    /// List of cameras from which is seen on the current frame.
+    PODVector<Camera*> viewCameras_;
 };
 };
 
 
 inline bool CompareDrawables(Drawable* lhs, Drawable* rhs)
 inline bool CompareDrawables(Drawable* lhs, Drawable* rhs)

+ 10 - 14
Source/Urho3D/Graphics/View.cpp

@@ -180,22 +180,18 @@ void CheckVisibilityWork(const WorkItem* item, unsigned threadIndex)
     while (start != end)
     while (start != end)
     {
     {
         Drawable* drawable = *start++;
         Drawable* drawable = *start++;
-        bool batchesUpdated = false;
-        
-        // If draw distance non-zero, update and check it
-        float maxDistance = drawable->GetDrawDistance();
-        if (maxDistance > 0.0f)
-        {
-            drawable->UpdateBatches(view->frame_);
-            batchesUpdated = true;
-            if (drawable->GetDistance() > maxDistance)
-                continue;
-        }
-        
+
         if (!buffer || !drawable->IsOccludee() || buffer->IsVisible(drawable->GetWorldBoundingBox()))
         if (!buffer || !drawable->IsOccludee() || buffer->IsVisible(drawable->GetWorldBoundingBox()))
         {
         {
-            if (!batchesUpdated)
-                drawable->UpdateBatches(view->frame_);
+            drawable->UpdateBatches(view->frame_);
+            // If draw distance non-zero, update and check it
+            float maxDistance = drawable->GetDrawDistance();
+            if (maxDistance > 0.0f)
+            {
+                if (drawable->GetDistance() > maxDistance)
+                    continue;
+            }
+
             drawable->MarkInView(view->frame_);
             drawable->MarkInView(view->frame_);
             
             
             // For geometries, find zone, clear lights and calculate view space Z range
             // For geometries, find zone, clear lights and calculate view space Z range