Browse Source

gobj: Compute nested vertices separate from internal bounds in Geom

This prevents having to recalculate the internal bounds (which may be quite slow to compute, but not actually necessary if there are user bounds present) to get the nested vertices
rdb 3 years ago
parent
commit
833c3d37f7
3 changed files with 25 additions and 3 deletions
  1. 3 0
      panda/src/gobj/geom.I
  2. 20 3
      panda/src/gobj/geom.cxx
  3. 2 0
      panda/src/gobj/geom.h

+ 3 - 0
panda/src/gobj/geom.I

@@ -379,6 +379,7 @@ calc_tight_bounds(LPoint3 &min_point, LPoint3 &max_point,
  */
 INLINE void Geom::
 mark_internal_bounds_stale(CData *cdata) {
+  cdata->_nested_vertices_stale = true;
   cdata->_internal_bounds_stale = true;
 }
 
@@ -512,6 +513,7 @@ CData() :
   _shade_model(SM_uniform),
   _geom_rendering(0),
   _nested_vertices(0),
+  _nested_vertices_stale(true),
   _internal_bounds_stale(true),
   _bounds_type(BoundingVolume::BT_default)
 {
@@ -527,6 +529,7 @@ CData(GeomVertexData *data) :
   _shade_model(SM_uniform),
   _geom_rendering(0),
   _nested_vertices(0),
+  _nested_vertices_stale(true),
   _internal_bounds_stale(true),
   _bounds_type(BoundingVolume::BT_default)
 {

+ 20 - 3
panda/src/gobj/geom.cxx

@@ -1098,9 +1098,9 @@ get_bounds(Thread *current_thread) const {
 int Geom::
 get_nested_vertices(Thread *current_thread) const {
   CDLockedReader cdata(_cycler, current_thread);
-  if (cdata->_internal_bounds_stale) {
+  if (cdata->_nested_vertices_stale) {
     CDWriter cdataw(((Geom *)this)->_cycler, cdata, false);
-    compute_internal_bounds(cdataw, current_thread);
+    compute_nested_vertices(cdataw, current_thread);
     return cdataw->_nested_vertices;
   }
   return cdata->_nested_vertices;
@@ -1468,9 +1468,26 @@ compute_internal_bounds(Geom::CData *cdata, Thread *current_thread) const {
       cdata->_internal_bounds = new BoundingBox;
     }
   }
+  cdata->_internal_bounds_stale = false;
+}
+
+/**
+ * Recomputes the number of nested vertices in this Geom.
+ */
+void Geom::
+compute_nested_vertices(Geom::CData *cdata, Thread *current_thread) const {
+  int num_vertices = 0;
+
+  Primitives::const_iterator pi;
+  for (pi = cdata->_primitives.begin();
+       pi != cdata->_primitives.end();
+       ++pi) {
+    GeomPrimitivePipelineReader reader((*pi).get_read_pointer(current_thread), current_thread);
+    num_vertices += reader.get_num_vertices();
+  }
 
   cdata->_nested_vertices = num_vertices;
-  cdata->_internal_bounds_stale = false;
+  cdata->_nested_vertices_stale = false;
 }
 
 /**

+ 2 - 0
panda/src/gobj/geom.h

@@ -185,6 +185,7 @@ private:
 
   INLINE void mark_internal_bounds_stale(CData *cdata);
   void compute_internal_bounds(CData *cdata, Thread *current_thread) const;
+  void compute_nested_vertices(CData *cdata, Thread *current_thread) const;
 
   void do_calc_tight_bounds(LPoint3 &min_point, LPoint3 &max_point,
                             PN_stdfloat &sq_center_dist, bool &found_any,
@@ -327,6 +328,7 @@ private:
 
     CPT(BoundingVolume) _internal_bounds;
     int _nested_vertices;
+    bool _nested_vertices_stale;
     bool _internal_bounds_stale;
     BoundingVolume::BoundsType _bounds_type;
     CPT(BoundingVolume) _user_bounds;