[Bf-blender-cvs] [19018d25fdd] temp-vert-normals-cleanup: Merge branch 'master' into temp-vert-normals-cleanup

Hans Goudey noreply at git.blender.org
Wed Nov 10 20:33:43 CET 2021


Commit: 19018d25fdd44eef6317bf35b3ce9e6ab239343b
Author: Hans Goudey
Date:   Wed Nov 10 12:33:18 2021 -0600
Branches: temp-vert-normals-cleanup
https://developer.blender.org/rB19018d25fdd44eef6317bf35b3ce9e6ab239343b

Merge branch 'master' into temp-vert-normals-cleanup

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



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

diff --cc source/blender/blenkernel/intern/mesh.cc
index bd81f24e11e,73e0c2cfa74..8f19180a6d4
--- a/source/blender/blenkernel/intern/mesh.cc
+++ b/source/blender/blenkernel/intern/mesh.cc
@@@ -88,13 -88,8 +88,13 @@@ static void mesh_init_data(ID *id
    CustomData_reset(&mesh->pdata);
    CustomData_reset(&mesh->ldata);
  
-   BKE_mesh_runtime_reset(mesh);
+   BKE_mesh_runtime_init_data(mesh);
  
 +  /* A newly created mesh does not have normals, so tag them dirty. This will be cleared by
 +   * retrieving the normal layer for manually writing to it, or calling functions like
 +   * #BKE_mesh_ensure_face_normals. */
 +  BKE_mesh_normals_tag_dirty(mesh);
 +
    mesh->face_sets_color_seed = BLI_hash_int(PIL_check_seconds_timer_i() & UINT_MAX);
  }
  
@@@ -1907,11 -1897,13 +1913,11 @@@ void BKE_mesh_vert_coords_apply_with_ma
  void BKE_mesh_calc_normals_split_ex(Mesh *mesh, MLoopNorSpaceArray *r_lnors_spacearr)
  {
    float(*r_loopnors)[3];
 -  float(*polynors)[3];
 -  short(*clnors)[2] = nullptr;
 -  bool free_polynors = false;
 +  short(*clnors)[2] = NULL;
  
    /* Note that we enforce computing clnors when the clnor space array is requested by caller here.
-    * However, we obviously only use the autosmooth angle threshold
-    * only in case autosmooth is enabled. */
+    * However, we obviously only use the auto-smooth angle threshold
+    * only in case auto-smooth is enabled. */
    const bool use_split_normals = (r_lnors_spacearr != nullptr) ||
                                   ((mesh->flag & ME_AUTOSMOOTH) != 0);
    const float split_angle = (mesh->flag & ME_AUTOSMOOTH) != 0 ? mesh->smoothresh : (float)M_PI;
diff --cc source/blender/blenkernel/intern/mesh_runtime.c
index 61236764550,ce89c723a61..fa914f62e82
--- a/source/blender/blenkernel/intern/mesh_runtime.c
+++ b/source/blender/blenkernel/intern/mesh_runtime.c
@@@ -45,19 -45,54 +45,61 @@@
   * \{ */
  
  /**
-  * Default values defined at read time.
+  * \brief Initialize the runtime mutexes of the given mesh.
+  *
+  * Any existing mutexes will be overridden.
   */
- void BKE_mesh_runtime_reset(Mesh *mesh)
+ static void mesh_runtime_init_mutexes(Mesh *mesh)
  {
-   memset(&mesh->runtime, 0, sizeof(mesh->runtime));
    mesh->runtime.eval_mutex = MEM_mallocN(sizeof(ThreadMutex), "mesh runtime eval_mutex");
-   mesh->runtime.normals_mutex = MEM_mallocN(sizeof(ThreadMutex), __func__);
 -  BLI_mutex_init(mesh->runtime.eval_mutex);
++  mesh->runtime.normals_mutex = MEM_mallocN(sizeof(ThreadMutex), "mesh runtime normals_mutex");
    mesh->runtime.render_mutex = MEM_mallocN(sizeof(ThreadMutex), "mesh runtime render_mutex");
 +  BLI_mutex_init(mesh->runtime.eval_mutex);
 +  BLI_mutex_init(mesh->runtime.normals_mutex);
    BLI_mutex_init(mesh->runtime.render_mutex);
  }
  
+ /**
+  * \brief free the mutexes of the given mesh runtime.
+  */
+ static void mesh_runtime_free_mutexes(Mesh *mesh)
+ {
+   if (mesh->runtime.eval_mutex != NULL) {
+     BLI_mutex_end(mesh->runtime.eval_mutex);
+     MEM_freeN(mesh->runtime.eval_mutex);
+     mesh->runtime.eval_mutex = NULL;
+   }
++  if (mesh->runtime.normals_mutex != NULL) {
++    BLI_mutex_end(mesh->runtime.normals_mutex);
++    MEM_freeN(mesh->runtime.normals_mutex);
++    mesh->runtime.normals_mutex = NULL;
++  }
+   if (mesh->runtime.render_mutex != NULL) {
+     BLI_mutex_end(mesh->runtime.render_mutex);
+     MEM_freeN(mesh->runtime.render_mutex);
+     mesh->runtime.render_mutex = NULL;
+   }
+ }
+ 
+ /**
+  * \brief Initialize the runtime of the given mesh.
+  *
+  * Function expects that the runtime is already cleared.
+  */
+ void BKE_mesh_runtime_init_data(Mesh *mesh)
+ {
+   mesh_runtime_init_mutexes(mesh);
+ }
+ 
+ /**
+  * \brief Free all data (and mutexes) inside the runtime of the given mesh.
+  */
+ void BKE_mesh_runtime_free_data(Mesh *mesh)
+ {
+   BKE_mesh_runtime_clear_cache(mesh);
+   mesh_runtime_free_mutexes(mesh);
+ }
+ 
  /* Clear all pointers which we don't want to be shared on copying the datablock.
   * However, keep all the flags which defines what the mesh is (for example, that
   * it's deformed only, or that its custom data layers are out of date.) */
@@@ -73,31 -108,16 +115,16 @@@ void BKE_mesh_runtime_reset_on_copy(Mes
    runtime->bvh_cache = NULL;
    runtime->shrinkwrap_data = NULL;
  
-   mesh->runtime.eval_mutex = MEM_mallocN(sizeof(ThreadMutex), "mesh runtime eval_mutex");
-   mesh->runtime.normals_mutex = MEM_mallocN(sizeof(ThreadMutex), __func__);
-   mesh->runtime.render_mutex = MEM_mallocN(sizeof(ThreadMutex), "mesh runtime render_mutex");
-   BLI_mutex_init(mesh->runtime.eval_mutex);
-   BLI_mutex_init(mesh->runtime.normals_mutex);
-   BLI_mutex_init(mesh->runtime.render_mutex);
+   mesh_runtime_init_mutexes(mesh);
  }
  
+ /**
+  * \brief This function clears runtime cache of the given mesh.
 - * 
++ *
+  * Call this function to recalculate runtime data when used.
+  */
  void BKE_mesh_runtime_clear_cache(Mesh *mesh)
  {
-   if (mesh->runtime.eval_mutex != NULL) {
-     BLI_mutex_end(mesh->runtime.eval_mutex);
-     MEM_freeN(mesh->runtime.eval_mutex);
-     mesh->runtime.eval_mutex = NULL;
-   }
-   if (mesh->runtime.normals_mutex != NULL) {
-     BLI_mutex_end(mesh->runtime.normals_mutex);
-     MEM_freeN(mesh->runtime.normals_mutex);
-     mesh->runtime.normals_mutex = NULL;
-   }
-   if (mesh->runtime.render_mutex != NULL) {
-     BLI_mutex_end(mesh->runtime.render_mutex);
-     MEM_freeN(mesh->runtime.render_mutex);
-     mesh->runtime.render_mutex = NULL;
-   }
    if (mesh->runtime.mesh_eval != NULL) {
      mesh->runtime.mesh_eval->edit_mesh = NULL;
      BKE_id_free(NULL, mesh->runtime.mesh_eval);



More information about the Bf-blender-cvs mailing list