[Bf-blender-cvs] [abd02da4bd5] master: Cleanup: Move three mesh files to C++
Hans Goudey
noreply at git.blender.org
Thu Apr 14 00:51:12 CEST 2022
Commit: abd02da4bd5ca5fac4aca2bc1868da0827aa74c2
Author: Hans Goudey
Date: Wed Apr 13 17:51:05 2022 -0500
Branches: master
https://developer.blender.org/rBabd02da4bd5ca5fac4aca2bc1868da0827aa74c2
Cleanup: Move three mesh files to C++
This will allow easier interaction with other areas also using C++
features, and a potential optimization to edit mesh bounding box
calculation.
===================================================================
M source/blender/blenkernel/CMakeLists.txt
R091 source/blender/blenkernel/intern/editmesh_cache.c source/blender/blenkernel/intern/editmesh_cache.cc
R075 source/blender/blenkernel/intern/mesh_runtime.c source/blender/blenkernel/intern/mesh_runtime.cc
R080 source/blender/blenkernel/intern/mesh_wrapper.c source/blender/blenkernel/intern/mesh_wrapper.cc
===================================================================
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index c8af4bb69b8..ce4131a0627 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -126,7 +126,7 @@ set(SRC
intern/editlattice.c
intern/editmesh.c
intern/editmesh_bvh.c
- intern/editmesh_cache.c
+ intern/editmesh_cache.cc
intern/editmesh_tangent.c
intern/effect.c
intern/fcurve.c
@@ -203,12 +203,12 @@ set(SRC
intern/mesh_normals.cc
intern/mesh_remap.c
intern/mesh_remesh_voxel.cc
- intern/mesh_runtime.c
+ intern/mesh_runtime.cc
intern/mesh_sample.cc
intern/mesh_tangent.c
intern/mesh_tessellate.c
intern/mesh_validate.cc
- intern/mesh_wrapper.c
+ intern/mesh_wrapper.cc
intern/modifier.c
intern/movieclip.c
intern/multires.c
diff --git a/source/blender/blenkernel/intern/editmesh_cache.c b/source/blender/blenkernel/intern/editmesh_cache.cc
similarity index 91%
rename from source/blender/blenkernel/intern/editmesh_cache.c
rename to source/blender/blenkernel/intern/editmesh_cache.cc
index f80f300d149..1ea2f38ce27 100644
--- a/source/blender/blenkernel/intern/editmesh_cache.c
+++ b/source/blender/blenkernel/intern/editmesh_cache.cc
@@ -35,7 +35,7 @@ void BKE_editmesh_cache_ensure_poly_normals(BMEditMesh *em, EditMeshData *emd)
BM_mesh_elem_index_ensure(bm, BM_VERT);
- polyNos = MEM_mallocN(sizeof(*polyNos) * bm->totface, __func__);
+ polyNos = static_cast<float(*)[3]>(MEM_mallocN(sizeof(*polyNos) * bm->totface, __func__));
vertexCos = emd->vertexCos;
@@ -65,7 +65,7 @@ void BKE_editmesh_cache_ensure_vert_normals(BMEditMesh *em, EditMeshData *emd)
polyNos = emd->polyNos;
vertexCos = emd->vertexCos;
- vertexNos = MEM_callocN(sizeof(*vertexNos) * bm->totvert, __func__);
+ vertexNos = static_cast<float(*)[3]>(MEM_callocN(sizeof(*vertexNos) * bm->totvert, __func__));
BM_verts_calc_normal_vcos(bm, polyNos, vertexCos, vertexNos);
@@ -84,7 +84,7 @@ void BKE_editmesh_cache_ensure_poly_centers(BMEditMesh *em, EditMeshData *emd)
BMIter fiter;
int i;
- polyCos = MEM_mallocN(sizeof(*polyCos) * bm->totface, __func__);
+ polyCos = static_cast<float(*)[3]>(MEM_mallocN(sizeof(*polyCos) * bm->totface, __func__));
if (emd->vertexCos) {
const float(*vertexCos)[3];
diff --git a/source/blender/blenkernel/intern/mesh_runtime.c b/source/blender/blenkernel/intern/mesh_runtime.cc
similarity index 75%
rename from source/blender/blenkernel/intern/mesh_runtime.c
rename to source/blender/blenkernel/intern/mesh_runtime.cc
index 7bd52abeb0d..b06e867cf37 100644
--- a/source/blender/blenkernel/intern/mesh_runtime.c
+++ b/source/blender/blenkernel/intern/mesh_runtime.cc
@@ -14,8 +14,7 @@
#include "DNA_object_types.h"
#include "BLI_math_geom.h"
-#include "BLI_task.h"
-#include "BLI_threads.h"
+#include "BLI_task.hh"
#include "BKE_bvhutils.h"
#include "BKE_lib_id.h"
@@ -35,12 +34,12 @@
*/
static void mesh_runtime_init_mutexes(Mesh *mesh)
{
- mesh->runtime.eval_mutex = MEM_mallocN(sizeof(ThreadMutex), "mesh runtime eval_mutex");
- BLI_mutex_init(mesh->runtime.eval_mutex);
- mesh->runtime.normals_mutex = MEM_mallocN(sizeof(ThreadMutex), "mesh runtime normals_mutex");
- BLI_mutex_init(mesh->runtime.normals_mutex);
- mesh->runtime.render_mutex = MEM_mallocN(sizeof(ThreadMutex), "mesh runtime render_mutex");
- BLI_mutex_init(mesh->runtime.render_mutex);
+ mesh->runtime.eval_mutex = MEM_new<ThreadMutex>("mesh runtime eval_mutex");
+ BLI_mutex_init(static_cast<ThreadMutex *>(mesh->runtime.eval_mutex));
+ mesh->runtime.normals_mutex = MEM_new<ThreadMutex>("mesh runtime normals_mutex");
+ BLI_mutex_init(static_cast<ThreadMutex *>(mesh->runtime.normals_mutex));
+ mesh->runtime.render_mutex = MEM_new<ThreadMutex>("mesh runtime render_mutex");
+ BLI_mutex_init(static_cast<ThreadMutex *>(mesh->runtime.render_mutex));
}
/**
@@ -48,20 +47,20 @@ static void mesh_runtime_init_mutexes(Mesh *mesh)
*/
static void mesh_runtime_free_mutexes(Mesh *mesh)
{
- if (mesh->runtime.eval_mutex != NULL) {
- BLI_mutex_end(mesh->runtime.eval_mutex);
+ if (mesh->runtime.eval_mutex != nullptr) {
+ BLI_mutex_end(static_cast<ThreadMutex *>(mesh->runtime.eval_mutex));
MEM_freeN(mesh->runtime.eval_mutex);
- mesh->runtime.eval_mutex = NULL;
+ mesh->runtime.eval_mutex = nullptr;
}
- if (mesh->runtime.normals_mutex != NULL) {
- BLI_mutex_end(mesh->runtime.normals_mutex);
+ if (mesh->runtime.normals_mutex != nullptr) {
+ BLI_mutex_end(static_cast<ThreadMutex *>(mesh->runtime.normals_mutex));
MEM_freeN(mesh->runtime.normals_mutex);
- mesh->runtime.normals_mutex = NULL;
+ mesh->runtime.normals_mutex = nullptr;
}
- if (mesh->runtime.render_mutex != NULL) {
- BLI_mutex_end(mesh->runtime.render_mutex);
+ if (mesh->runtime.render_mutex != nullptr) {
+ BLI_mutex_end(static_cast<ThreadMutex *>(mesh->runtime.render_mutex));
MEM_freeN(mesh->runtime.render_mutex);
- mesh->runtime.render_mutex = NULL;
+ mesh->runtime.render_mutex = nullptr;
}
}
@@ -80,28 +79,28 @@ void BKE_mesh_runtime_reset_on_copy(Mesh *mesh, const int UNUSED(flag))
{
Mesh_Runtime *runtime = &mesh->runtime;
- runtime->mesh_eval = NULL;
- runtime->edit_data = NULL;
- runtime->batch_cache = NULL;
- runtime->subdiv_ccg = NULL;
- memset(&runtime->looptris, 0, sizeof(runtime->looptris));
- runtime->bvh_cache = NULL;
- runtime->shrinkwrap_data = NULL;
+ runtime->mesh_eval = nullptr;
+ runtime->edit_data = nullptr;
+ runtime->batch_cache = nullptr;
+ runtime->subdiv_ccg = nullptr;
+ runtime->looptris = blender::dna::shallow_zero_initialize();
+ runtime->bvh_cache = nullptr;
+ runtime->shrinkwrap_data = nullptr;
runtime->vert_normals_dirty = true;
runtime->poly_normals_dirty = true;
- runtime->vert_normals = NULL;
- runtime->poly_normals = NULL;
+ runtime->vert_normals = nullptr;
+ runtime->poly_normals = nullptr;
mesh_runtime_init_mutexes(mesh);
}
void BKE_mesh_runtime_clear_cache(Mesh *mesh)
{
- if (mesh->runtime.mesh_eval != NULL) {
- mesh->runtime.mesh_eval->edit_mesh = NULL;
- BKE_id_free(NULL, mesh->runtime.mesh_eval);
- mesh->runtime.mesh_eval = NULL;
+ if (mesh->runtime.mesh_eval != nullptr) {
+ mesh->runtime.mesh_eval->edit_mesh = nullptr;
+ BKE_id_free(nullptr, mesh->runtime.mesh_eval);
+ mesh->runtime.mesh_eval = nullptr;
}
BKE_mesh_runtime_clear_geometry(mesh);
BKE_mesh_batch_cache_free(mesh);
@@ -121,7 +120,7 @@ static void mesh_ensure_looptri_data(Mesh *mesh)
const uint totpoly = mesh->totpoly;
const int looptris_len = poly_to_tri_count(totpoly, mesh->totloop);
- BLI_assert(mesh->runtime.looptris.array_wip == NULL);
+ BLI_assert(mesh->runtime.looptris.array_wip == nullptr);
SWAP(MLoopTri *, mesh->runtime.looptris.array, mesh->runtime.looptris.array_wip);
@@ -133,9 +132,9 @@ static void mesh_ensure_looptri_data(Mesh *mesh)
}
if (totpoly) {
- if (mesh->runtime.looptris.array_wip == NULL) {
- mesh->runtime.looptris.array_wip = MEM_malloc_arrayN(
- looptris_len, sizeof(*mesh->runtime.looptris.array_wip), __func__);
+ if (mesh->runtime.looptris.array_wip == nullptr) {
+ mesh->runtime.looptris.array_wip = static_cast<MLoopTri *>(
+ MEM_malloc_arrayN(looptris_len, sizeof(*mesh->runtime.looptris.array_wip), __func__));
mesh->runtime.looptris.len_alloc = looptris_len;
}
@@ -146,7 +145,7 @@ static void mesh_ensure_looptri_data(Mesh *mesh)
void BKE_mesh_runtime_looptri_recalc(Mesh *mesh)
{
mesh_ensure_looptri_data(mesh);
- BLI_assert(mesh->totpoly == 0 || mesh->runtime.looptris.array_wip != NULL);
+ BLI_assert(mesh->totpoly == 0 || mesh->runtime.looptris.array_wip != nullptr);
BKE_mesh_recalc_looptri(mesh->mloop,
mesh->mpoly,
@@ -155,11 +154,11 @@ void BKE_mesh_runtime_looptri_recalc(Mesh *mesh)
mesh->totpoly,
mesh->runtime.looptris.array_wip);
- BLI_assert(mesh->runtime.looptris.array == NULL);
+ BLI_assert(mesh->runtime.looptris.array == nullptr);
atomic_cas_ptr((void **)&mesh->runtime.looptris.array,
mesh->runtime.looptris.array,
mesh->runtime.looptris.array_wip);
- mesh->runtime.looptris.array_wip = NULL;
+ mesh->runtime.looptris.array_wip = nullptr;
}
int BKE_mesh_runtime_looptri_len(const Mesh *mesh)
@@ -170,12 +169,6 @@ int BKE_mesh_runtime_looptri_len(const Mesh *mesh)
return looptri_len;
}
-static void mesh_runtime_looptri_recalc_isolated(void *userdata)
-{
- Mesh *mesh = userdata;
- BKE_mesh_runtime_looptri_recalc(mesh);
-}
-
const MLoopTri *BKE_mesh_runtime_looptri_ensure(const Mesh *mesh)
{
ThreadMutex *mesh_eval_mutex = (ThreadMutex *)mesh->runtime.eval_mutex;
@@ -183,12 +176,13 @@ const MLoopTri *BKE_mesh_runtime_looptri_ensure(const Mesh *mesh)
MLoopTri *looptri = mesh->runtime.looptris.array;
- if (looptri != NULL) {
+ if (looptri != nullptr) {
BLI_assert(BKE_mesh_runtime_looptri_len(mesh) == mesh->runtime.looptris.len);
}
else {
/* Must isolate multithreaded tasks while holding a mutex lock. */
- BLI_task_isolate(mesh_runtime_looptri_recalc_isolated, (void *)mesh);
+ blender::threading::isolate_task(
+ [&]() { BKE_mesh_runtime_looptri_recalc(const_cast<Mesh *>(mesh)); });
looptri = mesh->runtime.looptris.array;
}
@@ -211,18 +205,18 @@ void BKE_mesh_runtime_verttri_from_looptri(MVertTri *r_verttri,
bool BKE_mesh_runtime_ensure_edit_data(struct Mesh *mesh)
{
- if (mesh->runtime.edit_data != NULL) {
+ if (mesh->runtime.edit_data != nullptr) {
return false;
}
- mesh->runtime.edit_data = MEM_callocN(sizeof(EditMeshData), "EditMeshData");
+ mesh->runtime.edit_data = MEM_cnew<EditMeshData>(__func__);
return true;
}
bool BKE_mesh_runtime_reset_edit_data(Mesh *mesh)
{
EditMeshData *edit_data = mesh->runtime.edit_data;
- if (edit_data == NULL) {
+ if (edit_data == nullptr) {
return false;
}
@@ -236,13 +230,13 @@ bool BKE_mesh_runtime_reset_edit_data(Mesh *mesh)
bool BKE_mesh_runtime_clear_edit_data(Mesh *mesh)
{
- if (mesh->runtime.edit_dat
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list