[Bf-blender-cvs] [c2022d6d369] tmp-worbench-rewrite2-optimizations: Skip bbox allocation by retrieving bounds min/max

Miguel Pozo noreply at git.blender.org
Tue Jan 17 16:15:31 CET 2023


Commit: c2022d6d3691ddcced42c24488344393249ba631
Author: Miguel Pozo
Date:   Tue Jan 17 16:13:17 2023 +0100
Branches: tmp-worbench-rewrite2-optimizations
https://developer.blender.org/rBc2022d6d3691ddcced42c24488344393249ba631

Skip bbox allocation by retrieving bounds min/max

===================================================================

M	source/blender/blenkernel/intern/object.cc
M	source/blender/draw/intern/draw_manager_data.cc
M	source/blender/draw/intern/draw_resource.hh

===================================================================

diff --git a/source/blender/blenkernel/intern/object.cc b/source/blender/blenkernel/intern/object.cc
index d33f8fe5de7..817bc50cba4 100644
--- a/source/blender/blenkernel/intern/object.cc
+++ b/source/blender/blenkernel/intern/object.cc
@@ -3882,8 +3882,12 @@ void BKE_object_minmax(Object *ob, float r_min[3], float r_max[3], const bool us
       break;
     }
     case OB_MESH: {
-      const BoundBox bb = *BKE_mesh_boundbox_get(ob);
-      BKE_boundbox_minmax(&bb, ob->object_to_world, r_min, r_max);
+      Mesh *me = (Mesh *)ob->data;
+      INIT_MINMAX(r_min, r_max);
+      if (!BKE_mesh_wrapper_minmax(me, r_min, r_max)) {
+        r_min[0] = r_min[1] = r_min[2] = -1.0f;
+        r_max[0] = r_max[1] = r_max[2] = 1.0f;
+      }
       changed = true;
       break;
     }
diff --git a/source/blender/draw/intern/draw_manager_data.cc b/source/blender/draw/intern/draw_manager_data.cc
index 5b4e0792577..5c06233054d 100644
--- a/source/blender/draw/intern/draw_manager_data.cc
+++ b/source/blender/draw/intern/draw_manager_data.cc
@@ -719,12 +719,16 @@ static void drw_call_obinfos_init(DRWObjectInfos *ob_infos, Object *ob)
 
 static void drw_call_culling_init(DRWCullingState *cull, Object *ob)
 {
-  const BoundBox *bbox;
-  if (ob != nullptr && (bbox = BKE_object_boundbox_get(ob))) {
+  if (ob != nullptr) {
+    float3 min, max;
+    BKE_object_minmax(ob, min, max, false);
+    BoundBox bbox;
+    BKE_boundbox_init_from_minmax(&bbox, min, max);
+
     float corner[3];
     /* Get BoundSphere center and radius from the BoundBox. */
-    mid_v3_v3v3(cull->bsphere.center, bbox->vec[0], bbox->vec[6]);
-    mul_v3_m4v3(corner, ob->object_to_world, bbox->vec[0]);
+    mid_v3_v3v3(cull->bsphere.center, bbox.vec[0], bbox.vec[6]);
+    mul_v3_m4v3(corner, ob->object_to_world, bbox.vec[0]);
     mul_m4_v3(ob->object_to_world, cull->bsphere.center);
     cull->bsphere.radius = len_v3v3(cull->bsphere.center, corner);
 
diff --git a/source/blender/draw/intern/draw_resource.hh b/source/blender/draw/intern/draw_resource.hh
index a2de084b900..69e7c3a0687 100644
--- a/source/blender/draw/intern/draw_resource.hh
+++ b/source/blender/draw/intern/draw_resource.hh
@@ -151,15 +151,15 @@ inline void ObjectBounds::sync()
 
 inline void ObjectBounds::sync(Object &ob)
 {
-  const BoundBox *bbox = BKE_object_boundbox_get(&ob);
-  if (bbox == nullptr) {
-    bounding_sphere.w = -1.0f; /* Disable test. */
-    return;
-  }
-  *reinterpret_cast<float3 *>(&bounding_corners[0]) = bbox->vec[0];
-  *reinterpret_cast<float3 *>(&bounding_corners[1]) = bbox->vec[4];
-  *reinterpret_cast<float3 *>(&bounding_corners[2]) = bbox->vec[3];
-  *reinterpret_cast<float3 *>(&bounding_corners[3]) = bbox->vec[1];
+  float3 min, max;
+  BKE_object_minmax(&ob, min, max, false);
+  BoundBox bbox;
+  BKE_boundbox_init_from_minmax(&bbox, min, max);
+
+  *reinterpret_cast<float3 *>(&bounding_corners[0]) = bbox.vec[0];
+  *reinterpret_cast<float3 *>(&bounding_corners[1]) = bbox.vec[4];
+  *reinterpret_cast<float3 *>(&bounding_corners[2]) = bbox.vec[3];
+  *reinterpret_cast<float3 *>(&bounding_corners[3]) = bbox.vec[1];
   bounding_sphere.w = 0.0f; /* Enable test. */
 }



More information about the Bf-blender-cvs mailing list