diff options
author | Hans Goudey <h.goudey@me.com> | 2022-10-06 04:51:05 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-10-06 18:49:24 +0300 |
commit | 0f224ceedba8575a7373938987c7ed18f3e565de (patch) | |
tree | e358a2e739e3b2dc70a63761155038f90e6d9444 /source/blender | |
parent | dc93235797d12f3793646570ef61e07eb4ec1c2b (diff) |
Cleanup: Move multires.c to C++
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_modifier.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_multires.h | 5 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_subsurf.h | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/multires.cc (renamed from source/blender/blenkernel/intern/multires.c) | 258 |
5 files changed, 141 insertions, 129 deletions
diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h index f46672a5033..ce2f9e878f8 100644 --- a/source/blender/blenkernel/BKE_modifier.h +++ b/source/blender/blenkernel/BKE_modifier.h @@ -127,6 +127,7 @@ typedef enum ModifierApplyFlag { * See `OBJECT_OT_modifier_apply` operator. */ MOD_APPLY_TO_BASE_MESH = 1 << 4, } ModifierApplyFlag; +ENUM_OPERATORS(ModifierApplyFlag, MOD_APPLY_TO_BASE_MESH); typedef struct ModifierUpdateDepsgraphContext { struct Scene *scene; diff --git a/source/blender/blenkernel/BKE_multires.h b/source/blender/blenkernel/BKE_multires.h index dfa330ff508..53dfaf953ea 100644 --- a/source/blender/blenkernel/BKE_multires.h +++ b/source/blender/blenkernel/BKE_multires.h @@ -8,7 +8,7 @@ */ #include "BKE_subsurf.h" -#include "BLI_compiler_compat.h" +#include "BLI_utildefines.h" #ifdef __cplusplus extern "C" { @@ -53,12 +53,13 @@ void multires_modifier_update_hidden(struct DerivedMesh *dm); */ void multiresModifier_set_levels_from_disps(struct MultiresModifierData *mmd, struct Object *ob); -typedef enum { +typedef enum MultiresFlags { MULTIRES_USE_LOCAL_MMD = 1, MULTIRES_USE_RENDER_PARAMS = 2, MULTIRES_ALLOC_PAINT_MASK = 4, MULTIRES_IGNORE_SIMPLIFY = 8, } MultiresFlags; +ENUM_OPERATORS(MultiresFlags, MULTIRES_IGNORE_SIMPLIFY); struct DerivedMesh *multires_make_derived_from_derived(struct DerivedMesh *dm, struct MultiresModifierData *mmd, diff --git a/source/blender/blenkernel/BKE_subsurf.h b/source/blender/blenkernel/BKE_subsurf.h index f32a78c3015..557a71fd06b 100644 --- a/source/blender/blenkernel/BKE_subsurf.h +++ b/source/blender/blenkernel/BKE_subsurf.h @@ -11,6 +11,7 @@ /* Thread sync primitives used directly. */ #include "BLI_threads.h" +#include "BLI_utildefines.h" #ifdef __cplusplus extern "C" { @@ -32,7 +33,7 @@ struct SubsurfModifierData; /**************************** External *****************************/ -typedef enum { +typedef enum SubsurfFlags { SUBSURF_USE_RENDER_PARAMS = 1, SUBSURF_IS_FINAL_CALC = 2, SUBSURF_FOR_EDIT_MODE = 4, @@ -41,6 +42,7 @@ typedef enum { SUBSURF_USE_GPU_BACKEND = 32, SUBSURF_IGNORE_SIMPLIFY = 64, } SubsurfFlags; +ENUM_OPERATORS(SubsurfFlags, SUBSURF_IGNORE_SIMPLIFY); struct DerivedMesh *subsurf_make_derived_from_derived(struct DerivedMesh *dm, struct SubsurfModifierData *smd, diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index d0e2d945c2f..192acbf8338 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -216,7 +216,7 @@ set(SRC intern/mesh_wrapper.cc intern/modifier.cc intern/movieclip.c - intern/multires.c + intern/multires.cc intern/multires_reshape.c intern/multires_reshape_apply_base.c intern/multires_reshape_ccg.c diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.cc index ce61ca483e9..83189adfcdb 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.cc @@ -43,8 +43,8 @@ #include "multires_reshape.h" -#include <math.h> -#include <string.h> +#include <cmath> +#include <cstring> /* MULTIRES MODIFIER */ static const int multires_grid_tot[] = { @@ -53,11 +53,11 @@ static const int multires_side_tot[] = { 0, 2, 3, 5, 9, 17, 33, 65, 129, 257, 513, 1025, 2049, 4097}; /* See multiresModifier_disp_run for description of each operation */ -typedef enum { +enum DispOp { APPLY_DISPLACEMENTS, CALC_DISPLACEMENTS, ADD_DISPLACEMENTS, -} DispOp; +}; static void multiresModifier_disp_run( DerivedMesh *dm, Mesh *me, DerivedMesh *dm2, DispOp op, CCGElem **oldGridData, int totlvl); @@ -107,7 +107,7 @@ static BLI_bitmap *multires_mdisps_upsample_hidden(BLI_bitmap *lo_hidden, /* fast case */ if (lo_level == hi_level) { - return MEM_dupallocN(lo_hidden); + return static_cast<BLI_bitmap *>(MEM_dupallocN(lo_hidden)); } subd = BLI_BITMAP_NEW(square_i(hi_gridsize), "MDisps.hidden upsample"); @@ -184,7 +184,7 @@ static BLI_bitmap *multires_mdisps_downsample_hidden(const BLI_bitmap *old_hidde static void multires_output_hidden_to_ccgdm(CCGDerivedMesh *ccgdm, Mesh *me, int level) { const MPoly *polys = BKE_mesh_polys(me); - const MDisps *mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS); + const MDisps *mdisps = static_cast<const MDisps *>(CustomData_get_layer(&me->ldata, CD_MDISPS)); BLI_bitmap **grid_hidden = ccgdm->gridHidden; int *gridOffset; int i, j; @@ -217,7 +217,7 @@ static void multires_mdisps_subdivide_hidden(MDisps *md, int new_level) return; } - subd = multires_mdisps_upsample_hidden(md->hidden, md->level, new_level, NULL); + subd = multires_mdisps_upsample_hidden(md->hidden, md->level, new_level, nullptr); /* swap in the subdivided data */ MEM_freeN(md->hidden); @@ -232,13 +232,12 @@ Mesh *BKE_multires_create_mesh(struct Depsgraph *depsgraph, Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); Mesh *deformed_mesh = mesh_get_eval_deform( depsgraph, scene_eval, object_eval, &CD_MASK_BAREMESH); - ModifierEvalContext modifier_ctx = { - .depsgraph = depsgraph, - .object = object_eval, - .flag = MOD_APPLY_USECACHE | MOD_APPLY_IGNORE_SIMPLIFY, - }; + ModifierEvalContext modifier_ctx{}; + modifier_ctx.depsgraph = depsgraph; + modifier_ctx.object = object_eval; + modifier_ctx.flag = MOD_APPLY_USECACHE | MOD_APPLY_IGNORE_SIMPLIFY; - const ModifierTypeInfo *mti = BKE_modifier_get_info(mmd->modifier.type); + const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(mmd->modifier.type)); Mesh *result = mti->modifyMesh(&mmd->modifier, &modifier_ctx, deformed_mesh); if (result == deformed_mesh) { @@ -255,12 +254,12 @@ float (*BKE_multires_create_deformed_base_mesh_vert_coords(struct Depsgraph *dep Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); Object *object_eval = DEG_get_evaluated_object(depsgraph, object); - Object object_for_eval = *object_eval; + Object object_for_eval = blender::dna::shallow_copy(*object_eval); object_for_eval.data = object->data; - object_for_eval.sculpt = NULL; + object_for_eval.sculpt = nullptr; const bool use_render = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER); - ModifierEvalContext mesh_eval_context = {depsgraph, &object_for_eval, 0}; + ModifierEvalContext mesh_eval_context = {depsgraph, &object_for_eval, ModifierApplyFlag(0)}; if (use_render) { mesh_eval_context.flag |= MOD_APPLY_RENDER; } @@ -270,13 +269,13 @@ float (*BKE_multires_create_deformed_base_mesh_vert_coords(struct Depsgraph *dep ModifierData *first_md = BKE_modifiers_get_virtual_modifierlist(&object_for_eval, &virtual_modifier_data); - Mesh *base_mesh = object->data; + Mesh *base_mesh = static_cast<Mesh *>(object->data); int num_deformed_verts; float(*deformed_verts)[3] = BKE_mesh_vert_coords_alloc(base_mesh, &num_deformed_verts); - for (ModifierData *md = first_md; md != NULL; md = md->next) { - const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type); + for (ModifierData *md = first_md; md != nullptr; md = md->next) { + const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type)); if (md == &mmd->modifier) { break; @@ -294,7 +293,7 @@ float (*BKE_multires_create_deformed_base_mesh_vert_coords(struct Depsgraph *dep md, &mesh_eval_context, base_mesh, deformed_verts, num_deformed_verts); } - if (r_num_deformed_verts != NULL) { + if (r_num_deformed_verts != nullptr) { *r_num_deformed_verts = num_deformed_verts; } return deformed_verts; @@ -312,16 +311,15 @@ MultiresModifierData *find_multires_modifier_before(Scene *scene, ModifierData * } } - return NULL; + return nullptr; } MultiresModifierData *get_multires_modifier(Scene *scene, Object *ob, bool use_first) { - ModifierData *md; - MultiresModifierData *mmd = NULL, *firstmmd = NULL; + MultiresModifierData *mmd = nullptr, *firstmmd = nullptr; /* find first active multires modifier */ - for (md = ob->modifiers.first; md; md = md->next) { + LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) { if (md->type == eModifierType_Multires) { if (!firstmmd) { firstmmd = (MultiresModifierData *)md; @@ -350,8 +348,8 @@ int multires_get_level(const Scene *scene, bool ignore_simplify) { if (render) { - return (scene != NULL) ? get_render_subsurf_level(&scene->r, mmd->renderlvl, true) : - mmd->renderlvl; + return (scene != nullptr) ? get_render_subsurf_level(&scene->r, mmd->renderlvl, true) : + mmd->renderlvl; } if (ob->mode == OB_MODE_SCULPT) { return mmd->sculptlvl; @@ -360,7 +358,7 @@ int multires_get_level(const Scene *scene, return mmd->lvl; } - return (scene != NULL) ? get_render_subsurf_level(&scene->r, mmd->lvl, false) : mmd->lvl; + return (scene != nullptr) ? get_render_subsurf_level(&scene->r, mmd->lvl, false) : mmd->lvl; } void multires_set_tot_level(Object *ob, MultiresModifierData *mmd, int lvl) @@ -387,7 +385,7 @@ static void multires_ccg_mark_as_modified(SubdivCCG *subdiv_ccg, MultiresModifie void multires_mark_as_modified(Depsgraph *depsgraph, Object *object, MultiresModifiedFlags flags) { - if (object == NULL) { + if (object == nullptr) { return; } /* NOTE: CCG live inside of evaluated object. @@ -398,9 +396,9 @@ void multires_mark_as_modified(Depsgraph *depsgraph, Object *object, MultiresMod * * In a longer term maybe special dependency graph tag can help sanitizing this a bit. */ Object *object_eval = DEG_get_evaluated_object(depsgraph, object); - Mesh *mesh = object_eval->data; + Mesh *mesh = static_cast<Mesh *>(object_eval->data); SubdivCCG *subdiv_ccg = mesh->runtime.subdiv_ccg; - if (subdiv_ccg == NULL) { + if (subdiv_ccg == nullptr) { return; } multires_ccg_mark_as_modified(subdiv_ccg, flags); @@ -408,18 +406,18 @@ void multires_mark_as_modified(Depsgraph *depsgraph, Object *object, MultiresMod void multires_flush_sculpt_updates(Object *object) { - if (object == NULL || object->sculpt == NULL || object->sculpt->pbvh == NULL) { + if (object == nullptr || object->sculpt == nullptr || object->sculpt->pbvh == nullptr) { return; } SculptSession *sculpt_session = object->sculpt; if (BKE_pbvh_type(sculpt_session->pbvh) != PBVH_GRIDS || !sculpt_session->multires.active || - sculpt_session->multires.modifier == NULL) { + sculpt_session->multires.modifier == nullptr) { return; } SubdivCCG *subdiv_ccg = sculpt_session->subdiv_ccg; - if (subdiv_ccg == NULL) { + if (subdiv_ccg == nullptr) { return; } @@ -427,7 +425,7 @@ void multires_flush_sculpt_updates(Object *object) return; } - Mesh *mesh = object->data; + Mesh *mesh = static_cast<Mesh *>(object->data); multiresModifier_reshapeFromCCG( sculpt_session->multires.modifier->totlvl, mesh, sculpt_session->subdiv_ccg); @@ -439,15 +437,15 @@ void multires_force_sculpt_rebuild(Object *object) { multires_flush_sculpt_updates(object); - if (object == NULL || object->sculpt == NULL) { + if (object == nullptr || object->sculpt == nullptr) { return; } SculptSession *ss = object->sculpt; - if (ss->pbvh != NULL) { + if (ss->pbvh != nullptr) { BKE_pbvh_free(ss->pbvh); - object->sculpt->pbvh = NULL; + object->sculpt->pbvh = nullptr; } MEM_SAFE_FREE(ss->pmap); @@ -466,15 +464,14 @@ void multires_force_external_reload(Object *object) /* reset the multires levels to match the number of mdisps */ static int get_levels_from_disps(Object *ob) { - Mesh *me = ob->data; + Mesh *me = static_cast<Mesh *>(ob->data); const MPoly *polys = BKE_mesh_polys(me); - MDisps *mdisp, *md; int i, j, totlvl = 0; - mdisp = CustomData_get_layer(&me->ldata, CD_MDISPS); + const MDisps *mdisp = static_cast<const MDisps *>(CustomData_get_layer(&me->ldata, CD_MDISPS)); for (i = 0; i < me->totpoly; i++) { - md = mdisp + polys[i].loopstart; + const MDisps *md = mdisp + polys[i].loopstart; for (j = 0; j < polys[i].totloop; j++, md++) { if (md->totdisp == 0) { @@ -504,14 +501,15 @@ static int get_levels_from_disps(Object *ob) void multiresModifier_set_levels_from_disps(MultiresModifierData *mmd, Object *ob) { - Mesh *me = ob->data; - MDisps *mdisp; + Mesh *me = static_cast<Mesh *>(ob->data); + const MDisps *mdisp; if (me->edit_mesh) { - mdisp = CustomData_get_layer(&me->edit_mesh->bm->ldata, CD_MDISPS); + mdisp = static_cast<const MDisps *>( + CustomData_get_layer(&me->edit_mesh->bm->ldata, CD_MDISPS)); } else { - mdisp = CustomData_get_layer(&me->ldata, CD_MDISPS); + mdisp = static_cast<const MDisps *>(CustomData_get_layer(&me->ldata, CD_MDISPS)); } if (mdisp) { @@ -524,7 +522,7 @@ void multiresModifier_set_levels_from_disps(MultiresModifierData *mmd, Object *o static void multires_set_tot_mdisps(Mesh *me, int lvl) { - MDisps *mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS); + MDisps *mdisps = static_cast<MDisps *>(CustomData_get_layer(&me->ldata, CD_MDISPS)); int i; if (mdisps) { @@ -542,7 +540,8 @@ static void multires_reallocate_mdisps(int totloop, MDisps *mdisps, int lvl) /* reallocate displacements to be filled in */ for (i = 0; i < totloop; i++) { int totdisp = multires_grid_tot[lvl]; - float(*disps)[3] = MEM_calloc_arrayN(totdisp, sizeof(float[3]), "multires disps"); + float(*disps)[3] = static_cast<float(*)[3]>( + MEM_calloc_arrayN(totdisp, sizeof(float[3]), __func__)); if (mdisps[i].disps) { MEM_freeN(mdisps[i].disps); @@ -616,8 +615,8 @@ static void multires_grid_paint_mask_downsample(GridPaintMask *gpm, int level) { if (level < gpm->level) { int gridsize = BKE_ccg_gridsize(level); - float *data = MEM_calloc_arrayN( - square_i(gridsize), sizeof(float), "multires_grid_paint_mask_downsample"); + float *data = static_cast<float *>( + MEM_calloc_arrayN(square_i(gridsize), sizeof(float), __func__)); int x, y; for (y = 0; y < gridsize; y++) { @@ -642,8 +641,8 @@ static void multires_del_higher(MultiresModifierData *mmd, Object *ob, int lvl) multires_set_tot_mdisps(me, mmd->totlvl); multiresModifier_ensure_external_read(me, mmd); - mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS); - gpm = CustomData_get_layer(&me->ldata, CD_GRID_PAINT_MASK); + mdisps = static_cast<MDisps *>(CustomData_get_layer(&me->ldata, CD_MDISPS)); + gpm = static_cast<GridPaintMask *>(CustomData_get_layer(&me->ldata, CD_GRID_PAINT_MASK)); multires_force_sculpt_rebuild(ob); @@ -661,9 +660,10 @@ static void multires_del_higher(MultiresModifierData *mmd, Object *ob, int lvl) float(*disps)[3], (*ndisps)[3], (*hdisps)[3]; int totdisp = multires_grid_tot[lvl]; - disps = MEM_calloc_arrayN(totdisp, sizeof(float[3]), "multires disps"); + disps = static_cast<float(*)[3]>( + MEM_calloc_arrayN(totdisp, sizeof(float[3]), "multires disps")); - if (mdisp->disps != NULL) { + if (mdisp->disps != nullptr) { ndisps = disps; hdisps = mdisp->disps; @@ -703,11 +703,10 @@ void multiresModifier_del_levels(MultiresModifierData *mmd, Mesh *me = BKE_mesh_from_object(ob); int lvl = multires_get_level(scene, ob, mmd, false, true); int levels = mmd->totlvl - lvl; - MDisps *mdisps; multires_set_tot_mdisps(me, mmd->totlvl); multiresModifier_ensure_external_read(me, mmd); - mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS); + MDisps *mdisps = static_cast<MDisps *>(CustomData_get_layer(&me->ldata, CD_MDISPS)); multires_force_sculpt_rebuild(ob); @@ -724,9 +723,9 @@ static DerivedMesh *multires_dm_create_local(Scene *scene, int lvl, int totlvl, bool alloc_paint_mask, - int flags) + MultiresFlags flags) { - MultiresModifierData mmd = {{NULL}}; + MultiresModifierData mmd = {{nullptr}}; mmd.lvl = lvl; mmd.sculptlvl = lvl; @@ -752,7 +751,7 @@ static DerivedMesh *subsurf_dm_create_local(Scene *scene, bool for_render, SubsurfFlags flags) { - SubsurfModifierData smd = {{NULL}}; + SubsurfModifierData smd = {{nullptr}}; smd.levels = smd.renderLevels = lvl; smd.quality = 3; @@ -779,7 +778,7 @@ static DerivedMesh *subsurf_dm_create_local(Scene *scene, flags |= SUBSURF_USE_RENDER_PARAMS; } - return subsurf_make_derived_from_derived(dm, &smd, scene, NULL, flags); + return subsurf_make_derived_from_derived(dm, &smd, scene, nullptr, flags); } static void grid_tangent(const CCGKey *key, int x, int y, int axis, CCGElem *grid, float t[3]) @@ -826,7 +825,7 @@ static void grid_tangent_matrix(float mat[3][3], const CCGKey *key, int x, int y copy_v3_v3(mat[2], CCG_grid_elem_no(key, grid, x, y)); } -typedef struct MultiresThreadedData { +struct MultiresThreadedData { DispOp op; CCGElem **gridData, **subGridData; CCGKey *key; @@ -837,13 +836,13 @@ typedef struct MultiresThreadedData { int *gridOffset; int gridSize, dGridSize, dSkip; float (*smat)[3]; -} MultiresThreadedData; +}; static void multires_disp_run_cb(void *__restrict userdata, const int pidx, - const TaskParallelTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict /*tls*/) { - MultiresThreadedData *tdata = userdata; + MultiresThreadedData *tdata = static_cast<MultiresThreadedData *>(userdata); DispOp op = tdata->op; CCGElem **gridData = tdata->gridData; @@ -861,11 +860,11 @@ static void multires_disp_run_cb(void *__restrict userdata, int S, x, y, gIndex = gridOffset[pidx]; for (S = 0; S < numVerts; S++, gIndex++) { - GridPaintMask *gpm = grid_paint_mask ? &grid_paint_mask[gIndex] : NULL; + GridPaintMask *gpm = grid_paint_mask ? &grid_paint_mask[gIndex] : nullptr; MDisps *mdisp = &mdisps[mpoly[pidx].loopstart + S]; CCGElem *grid = gridData[gIndex]; CCGElem *subgrid = subGridData[gIndex]; - float(*dispgrid)[3] = NULL; + float(*dispgrid)[3] = nullptr; dispgrid = mdisp->disps; @@ -875,7 +874,8 @@ static void multires_disp_run_cb(void *__restrict userdata, if (gpm->data) { MEM_freeN(gpm->data); } - gpm->data = MEM_calloc_arrayN(key->grid_area, sizeof(float), "gpm.data"); + gpm->data = static_cast<float *>( + MEM_calloc_arrayN(key->grid_area, sizeof(float), "gpm.data")); } for (y = 0; y < gridSize; y++) { @@ -943,16 +943,16 @@ static void multiresModifier_disp_run( CCGElem **gridData, **subGridData; CCGKey key; const MPoly *mpoly = BKE_mesh_polys(me); - MDisps *mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS); - GridPaintMask *grid_paint_mask = NULL; + MDisps *mdisps = static_cast<MDisps *>(CustomData_get_layer(&me->ldata, CD_MDISPS)); + GridPaintMask *grid_paint_mask = nullptr; int *gridOffset; int i, gridSize, dGridSize, dSkip; int totloop, totpoly; /* this happens in the dm made by bmesh_mdisps_space_set */ if (dm2 && CustomData_has_layer(&dm2->loopData, CD_MDISPS)) { - mpoly = CustomData_get_layer(&dm2->polyData, CD_MPOLY); - mdisps = CustomData_get_layer(&dm2->loopData, CD_MDISPS); + mpoly = static_cast<const MPoly *>(CustomData_get_layer(&dm2->polyData, CD_MPOLY)); + mdisps = static_cast<MDisps *>(CustomData_get_layer(&dm2->loopData, CD_MDISPS)); totloop = dm2->numLoopData; totpoly = dm2->numPolyData; } @@ -963,7 +963,8 @@ static void multiresModifier_disp_run( if (!mdisps) { if (op == CALC_DISPLACEMENTS) { - mdisps = CustomData_add_layer(&me->ldata, CD_MDISPS, CD_SET_DEFAULT, NULL, me->totloop); + mdisps = static_cast<MDisps *>( + CustomData_add_layer(&me->ldata, CD_MDISPS, CD_SET_DEFAULT, nullptr, me->totloop)); } else { return; @@ -982,12 +983,13 @@ static void multiresModifier_disp_run( /* multires paint masks */ if (key.has_mask) { - grid_paint_mask = CustomData_get_layer(&me->ldata, CD_GRID_PAINT_MASK); + grid_paint_mask = static_cast<GridPaintMask *>( + CustomData_get_layer(&me->ldata, CD_GRID_PAINT_MASK)); } /* when adding new faces in edit mode, need to allocate disps */ for (i = 0; i < totloop; i++) { - if (mdisps[i].disps == NULL) { + if (mdisps[i].disps == nullptr) { multires_reallocate_mdisps(totloop, mdisps, totlvl); break; } @@ -997,25 +999,24 @@ static void multiresModifier_disp_run( BLI_parallel_range_settings_defaults(&settings); settings.min_iter_per_thread = CCG_TASK_LIMIT; - MultiresThreadedData data = { - .op = op, - .gridData = gridData, - .subGridData = subGridData, - .key = &key, - .mpoly = mpoly, - .mdisps = mdisps, - .grid_paint_mask = grid_paint_mask, - .gridOffset = gridOffset, - .gridSize = gridSize, - .dGridSize = dGridSize, - .dSkip = dSkip, - }; + MultiresThreadedData data{}; + data.op = op; + data.gridData = gridData; + data.subGridData = subGridData; + data.key = &key; + data.mpoly = mpoly; + data.mdisps = mdisps; + data.grid_paint_mask = grid_paint_mask; + data.gridOffset = gridOffset; + data.gridSize = gridSize; + data.dGridSize = dGridSize; + data.dSkip = dSkip; BLI_task_parallel_range(0, totpoly, &data, multires_disp_run_cb, &settings); if (op == APPLY_DISPLACEMENTS) { - ccgSubSurf_stitchFaces(ccgdm->ss, 0, NULL, 0); - ccgSubSurf_updateNormals(ccgdm->ss, NULL, 0); + ccgSubSurf_stitchFaces(ccgdm->ss, 0, nullptr, 0); + ccgSubSurf_updateNormals(ccgdm->ss, nullptr, 0); } } @@ -1028,11 +1029,11 @@ void multires_modifier_update_mdisps(struct DerivedMesh *dm, Scene *scene) MultiresModifierData *mmd; ob = ccgdm->multires.ob; - me = ccgdm->multires.ob->data; + me = static_cast<Mesh *>(ccgdm->multires.ob->data); mmd = ccgdm->multires.mmd; multires_set_tot_mdisps(me, mmd->totlvl); multiresModifier_ensure_external_read(me, mmd); - mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS); + mdisps = static_cast<const MDisps *>(CustomData_get_layer(&me->ldata, CD_MDISPS)); if (mdisps) { int lvl = ccgdm->multires.lvl; @@ -1080,13 +1081,15 @@ void multires_modifier_update_mdisps(struct DerivedMesh *dm, Scene *scene) BLI_assert(highGridKey.elem_size == lowGridKey.elem_size); - subGridData = MEM_calloc_arrayN(numGrids, sizeof(CCGElem *), "subGridData*"); - diffGrid = MEM_calloc_arrayN(lowGridKey.elem_size, lowGridSize * lowGridSize, "diff"); + subGridData = static_cast<CCGElem **>( + MEM_calloc_arrayN(numGrids, sizeof(CCGElem *), "subGridData*")); + diffGrid = static_cast<CCGElem *>( + MEM_calloc_arrayN(lowGridKey.elem_size, lowGridSize * lowGridSize, "diff")); for (i = 0; i < numGrids; i++) { /* backup subsurf grids */ - subGridData[i] = MEM_calloc_arrayN( - highGridKey.elem_size, highGridSize * highGridSize, "subGridData"); + subGridData[i] = static_cast<CCGElem *>( + MEM_calloc_arrayN(highGridKey.elem_size, highGridSize * highGridSize, "subGridData")); memcpy( subGridData[i], highGridData[i], highGridKey.elem_size * highGridSize * highGridSize); @@ -1105,11 +1108,11 @@ void multires_modifier_update_mdisps(struct DerivedMesh *dm, Scene *scene) lowdm->release(lowdm); /* subsurf higher levels again with difference of coordinates */ - ccgSubSurf_updateFromFaces(ss, lvl, NULL, 0); - ccgSubSurf_updateLevels(ss, lvl, NULL, 0); + ccgSubSurf_updateFromFaces(ss, lvl, nullptr, 0); + ccgSubSurf_updateLevels(ss, lvl, nullptr, 0); /* add to displacements */ - multiresModifier_disp_run(highdm, me, NULL, ADD_DISPLACEMENTS, subGridData, mmd->totlvl); + multiresModifier_disp_run(highdm, me, nullptr, ADD_DISPLACEMENTS, subGridData, mmd->totlvl); /* free */ highdm->release(highdm); @@ -1139,7 +1142,7 @@ void multires_modifier_update_mdisps(struct DerivedMesh *dm, Scene *scene) cddm->release(cddm); multiresModifier_disp_run( - dm, me, NULL, CALC_DISPLACEMENTS, subdm->getGridData(subdm), mmd->totlvl); + dm, me, nullptr, CALC_DISPLACEMENTS, subdm->getGridData(subdm), mmd->totlvl); subdm->release(subdm); } @@ -1150,8 +1153,8 @@ void multires_modifier_update_hidden(DerivedMesh *dm) { CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm; BLI_bitmap **grid_hidden = ccgdm->gridHidden; - Mesh *me = ccgdm->multires.ob->data; - MDisps *mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS); + Mesh *me = static_cast<Mesh *>(ccgdm->multires.ob->data); + MDisps *mdisps = static_cast<MDisps *>(CustomData_get_layer(&me->ldata, CD_MDISPS)); int totlvl = ccgdm->multires.totlvl; int lvl = ccgdm->multires.lvl; @@ -1164,7 +1167,7 @@ void multires_modifier_update_hidden(DerivedMesh *dm) if (!gh && md->hidden) { MEM_freeN(md->hidden); - md->hidden = NULL; + md->hidden = nullptr; } else if (gh) { gh = multires_mdisps_upsample_hidden(gh, lvl, totlvl, md->hidden); @@ -1180,16 +1183,16 @@ void multires_modifier_update_hidden(DerivedMesh *dm) void multires_stitch_grids(Object *ob) { - if (ob == NULL) { + if (ob == nullptr) { return; } SculptSession *sculpt_session = ob->sculpt; - if (sculpt_session == NULL) { + if (sculpt_session == nullptr) { return; } PBVH *pbvh = sculpt_session->pbvh; SubdivCCG *subdiv_ccg = sculpt_session->subdiv_ccg; - if (pbvh == NULL || subdiv_ccg == NULL) { + if (pbvh == nullptr || subdiv_ccg == nullptr) { return; } BLI_assert(BKE_pbvh_type(pbvh) == PBVH_GRIDS); @@ -1208,9 +1211,9 @@ void multires_stitch_grids(Object *ob) DerivedMesh *multires_make_derived_from_derived( DerivedMesh *dm, MultiresModifierData *mmd, Scene *scene, Object *ob, MultiresFlags flags) { - Mesh *me = ob->data; + Mesh *me = static_cast<Mesh *>(ob->data); DerivedMesh *result; - CCGDerivedMesh *ccgdm = NULL; + CCGDerivedMesh *ccgdm = nullptr; CCGElem **gridData, **subGridData; CCGKey key; const bool render = (flags & MULTIRES_USE_RENDER_PARAMS) != 0; @@ -1222,7 +1225,7 @@ DerivedMesh *multires_make_derived_from_derived( return dm; } - const int subsurf_flags = ignore_simplify ? SUBSURF_IGNORE_SIMPLIFY : 0; + const SubsurfFlags subsurf_flags = ignore_simplify ? SUBSURF_IGNORE_SIMPLIFY : SubsurfFlags(0); result = subsurf_dm_create_local(scene, ob, @@ -1243,7 +1246,7 @@ DerivedMesh *multires_make_derived_from_derived( ccgdm->multires.local_mmd = 0; ccgdm->multires.lvl = lvl; ccgdm->multires.totlvl = mmd->totlvl; - ccgdm->multires.modified_flags = 0; + ccgdm->multires.modified_flags = MultiresModifiedFlags(0); } numGrids = result->getNumGrids(result); @@ -1251,10 +1254,12 @@ DerivedMesh *multires_make_derived_from_derived( gridData = result->getGridData(result); result->getGridKey(result, &key); - subGridData = MEM_malloc_arrayN(numGrids, sizeof(CCGElem *), "subGridData*"); + subGridData = static_cast<CCGElem **>( + MEM_malloc_arrayN(numGrids, sizeof(CCGElem *), "subGridData*")); for (i = 0; i < numGrids; i++) { - subGridData[i] = MEM_malloc_arrayN(key.elem_size, gridSize * gridSize, "subGridData"); + subGridData[i] = static_cast<CCGElem *>( + MEM_malloc_arrayN(key.elem_size, gridSize * gridSize, "subGridData")); memcpy(subGridData[i], gridData[i], key.elem_size * gridSize * gridSize); } @@ -1262,7 +1267,8 @@ DerivedMesh *multires_make_derived_from_derived( multiresModifier_ensure_external_read(me, mmd); /* Run displacement. */ - multiresModifier_disp_run(result, ob->data, dm, APPLY_DISPLACEMENTS, subGridData, mmd->totlvl); + multiresModifier_disp_run( + result, static_cast<Mesh *>(ob->data), dm, APPLY_DISPLACEMENTS, subGridData, mmd->totlvl); /* copy hidden elements for this level */ if (ccgdm) { @@ -1358,7 +1364,7 @@ static void multires_sync_levels(Scene *scene, Object *ob_src, Object *ob_dst) * up-sampled correct without modifier data. * just remove mdisps if no multires present (nazgul) */ - multires_customdata_delete(ob_src->data); + multires_customdata_delete(static_cast<Mesh *>(ob_src->data)); } if (mmd_src && mmd_dst) { @@ -1369,7 +1375,7 @@ static void multires_sync_levels(Scene *scene, Object *ob_src, Object *ob_dst) static void multires_apply_uniform_scale(Object *object, const float scale) { Mesh *mesh = (Mesh *)object->data; - MDisps *mdisps = CustomData_get_layer(&mesh->ldata, CD_MDISPS); + MDisps *mdisps = static_cast<MDisps *>(CustomData_get_layer(&mesh->ldata, CD_MDISPS)); for (int i = 0; i < mesh->totloop; i++) { MDisps *grid = &mdisps[i]; for (int j = 0; j < grid->totdisp; j++) { @@ -1378,13 +1384,13 @@ static void multires_apply_uniform_scale(Object *object, const float scale) } } -static void multires_apply_smat(struct Depsgraph *UNUSED(depsgraph), +static void multires_apply_smat(struct Depsgraph * /*depsgraph*/, Scene *scene, Object *object, const float smat[3][3]) { const MultiresModifierData *mmd = get_multires_modifier(scene, object, true); - if (mmd == NULL || mmd->totlvl == 0) { + if (mmd == nullptr || mmd->totlvl == 0) { return; } /* Make sure layer present. */ @@ -1450,11 +1456,11 @@ void multiresModifier_prepare_join(struct Depsgraph *depsgraph, void multires_topology_changed(Mesh *me) { - MDisps *mdisp = NULL, *cur = NULL; + MDisps *mdisp = nullptr, *cur = nullptr; int i, grid = 0; CustomData_external_read(&me->ldata, &me->id, CD_MASK_MDISPS, me->totloop); - mdisp = CustomData_get_layer(&me->ldata, CD_MDISPS); + mdisp = static_cast<MDisps *>(CustomData_get_layer(&me->ldata, CD_MDISPS)); if (!mdisp) { return; @@ -1474,7 +1480,8 @@ void multires_topology_changed(Mesh *me) if (!mdisp->totdisp || !mdisp->disps) { if (grid) { mdisp->totdisp = grid; - mdisp->disps = MEM_calloc_arrayN(mdisp->totdisp, sizeof(float[3]), "mdisp topology"); + mdisp->disps = static_cast<float(*)[3]>( + MEM_calloc_arrayN(mdisp->totdisp, sizeof(float[3]), "mdisp topology")); } continue; @@ -1488,9 +1495,10 @@ void multires_ensure_external_read(struct Mesh *mesh, int top_level) return; } - MDisps *mdisps = CustomData_get_layer(&mesh->ldata, CD_MDISPS); - if (mdisps == NULL) { - mdisps = CustomData_add_layer(&mesh->ldata, CD_MDISPS, CD_SET_DEFAULT, NULL, mesh->totloop); + MDisps *mdisps = static_cast<MDisps *>(CustomData_get_layer(&mesh->ldata, CD_MDISPS)); + if (mdisps == nullptr) { + mdisps = static_cast<MDisps *>( + CustomData_add_layer(&mesh->ldata, CD_MDISPS, CD_SET_DEFAULT, nullptr, mesh->totloop)); } const int totloop = mesh->totloop; @@ -1517,10 +1525,10 @@ void multiresModifier_ensure_external_read(struct Mesh *mesh, const MultiresModi /***************** Multires interpolation stuff *****************/ -int mdisp_rot_face_to_crn(struct MVert *UNUSED(mvert), +int mdisp_rot_face_to_crn(struct MVert * /*mvert*/, struct MPoly *mpoly, - struct MLoop *UNUSED(mloop), - const struct MLoopTri *UNUSED(lt), + struct MLoop * /*mloop*/, + const struct MLoopTri * /*lt*/, const int face_side, const float u, const float v, @@ -1598,7 +1606,7 @@ int mdisp_rot_face_to_crn(struct MVert *UNUSED(mvert), float mindist = FLT_MAX; for (i = 0; i < mpoly->totloop; i++) { - float len = len_v3v3(NULL, mvert[mloop[mpoly->loopstart + i].v].co); + float len = len_v3v3(nullptr, mvert[mloop[mpoly->loopstart + i].v].co); if (len < mindist) { mindist = len; minS = i; |