Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2022-08-30 22:54:53 +0300
committerHans Goudey <h.goudey@me.com>2022-08-30 22:56:05 +0300
commit25237d2625078c6d14d744f288776299efd3c7c8 (patch)
tree17d11451a5b816b15905e34402aa1b046d666c7a /source/blender/blenkernel/intern/data_transfer.c
parentd81e947c591ec6f3de2bc407b9f837b2efa36890 (diff)
Attributes: Improve custom data initialization options
When allocating new `CustomData` layers, often we do redundant initialization of arrays. For example, it's common that values are allocated, set to their default value, and then set to some other value. This is wasteful, and it negates the benefits of optimizations to the allocator like D15082. There are two reasons for this. The first is array-of-structs storage that makes it annoying to initialize values manually, and the second is confusing options in the Custom Data API. This patch addresses the latter. The `CustomData` "alloc type" options are rearranged. Now, besides the options that use existing layers, there are two remaining: * `CD_SET_DEFAULT` sets the default value. * Usually zeroes, but for colors this is white (how it was before). * Should be used when you add the layer but don't set all values. * `CD_CONSTRUCT` refers to the "default construct" C++ term. * Only necessary or defined for non-trivial types like vertex groups. * Doesn't do anything for trivial types like `int` or `float3`. * Should be used every other time, when all values will be set. The attribute API's `AttributeInit` types are updated as well. To update code, replace `CD_CALLOC` with `CD_SET_DEFAULT` and `CD_DEFAULT` with `CD_CONSTRUCT`. This doesn't cause any functional changes yet. Follow-up commits will change to avoid initializing new layers where the correctness is clear. Differential Revision: https://developer.blender.org/D15617
Diffstat (limited to 'source/blender/blenkernel/intern/data_transfer.c')
-rw-r--r--source/blender/blenkernel/intern/data_transfer.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/source/blender/blenkernel/intern/data_transfer.c b/source/blender/blenkernel/intern/data_transfer.c
index be686635d3e..02b5175f65f 100644
--- a/source/blender/blenkernel/intern/data_transfer.c
+++ b/source/blender/blenkernel/intern/data_transfer.c
@@ -280,7 +280,8 @@ static void data_transfer_dtdata_type_preprocess(Mesh *me_src,
loop_nors_dst = CustomData_get_layer(ldata_dst, CD_NORMAL);
const bool do_loop_nors_dst = (loop_nors_dst == NULL);
if (do_loop_nors_dst) {
- loop_nors_dst = CustomData_add_layer(ldata_dst, CD_NORMAL, CD_CALLOC, NULL, num_loops_dst);
+ loop_nors_dst = CustomData_add_layer(
+ ldata_dst, CD_NORMAL, CD_SET_DEFAULT, NULL, num_loops_dst);
CustomData_set_layer_flag(ldata_dst, CD_NORMAL, CD_FLAG_TEMPORARY);
}
if (dirty_nors_dst || do_loop_nors_dst) {
@@ -333,7 +334,7 @@ static void data_transfer_dtdata_type_postprocess(Object *UNUSED(ob_src),
if (!custom_nors_dst) {
custom_nors_dst = CustomData_add_layer(
- ldata_dst, CD_CUSTOMLOOPNORMAL, CD_CALLOC, NULL, num_loops_dst);
+ ldata_dst, CD_CUSTOMLOOPNORMAL, CD_SET_DEFAULT, NULL, num_loops_dst);
}
/* Note loop_nors_dst contains our custom normals as transferred from source... */
@@ -561,7 +562,7 @@ static bool data_transfer_layersmapping_cdlayers_multisrc_to_dst(ListBase *r_map
if (use_create) {
/* Create as much data layers as necessary! */
for (; idx_dst < idx_src; idx_dst++) {
- CustomData_add_layer(cd_dst, cddata_type, CD_CALLOC, NULL, num_elem_dst);
+ CustomData_add_layer(cd_dst, cddata_type, CD_SET_DEFAULT, NULL, num_elem_dst);
}
}
else {
@@ -622,7 +623,8 @@ static bool data_transfer_layersmapping_cdlayers_multisrc_to_dst(ListBase *r_map
if ((idx_dst = CustomData_get_named_layer(cd_dst, cddata_type, name)) == -1) {
if (use_create) {
- CustomData_add_layer_named(cd_dst, cddata_type, CD_CALLOC, NULL, num_elem_dst, name);
+ CustomData_add_layer_named(
+ cd_dst, cddata_type, CD_SET_DEFAULT, NULL, num_elem_dst, name);
idx_dst = CustomData_get_named_layer(cd_dst, cddata_type, name);
}
else {
@@ -710,7 +712,7 @@ static bool data_transfer_layersmapping_cdlayers(ListBase *r_map,
if (!use_create) {
return true;
}
- data_dst = CustomData_add_layer(cd_dst, cddata_type, CD_CALLOC, NULL, num_elem_dst);
+ data_dst = CustomData_add_layer(cd_dst, cddata_type, CD_SET_DEFAULT, NULL, num_elem_dst);
}
else if (use_dupref_dst && r_map) {
/* If dest is a evaluated mesh (from modifier),
@@ -763,7 +765,7 @@ static bool data_transfer_layersmapping_cdlayers(ListBase *r_map,
if (!use_create) {
return true;
}
- data_dst = CustomData_add_layer(cd_dst, cddata_type, CD_CALLOC, NULL, num_elem_dst);
+ data_dst = CustomData_add_layer(cd_dst, cddata_type, CD_SET_DEFAULT, NULL, num_elem_dst);
}
else {
/* If dest is a evaluated mesh (from modifier),
@@ -786,7 +788,7 @@ static bool data_transfer_layersmapping_cdlayers(ListBase *r_map,
}
/* Create as much data layers as necessary! */
for (; num <= idx_dst; num++) {
- CustomData_add_layer(cd_dst, cddata_type, CD_CALLOC, NULL, num_elem_dst);
+ CustomData_add_layer(cd_dst, cddata_type, CD_SET_DEFAULT, NULL, num_elem_dst);
}
}
/* If dest is a evaluated mesh (from modifier),
@@ -805,7 +807,7 @@ static bool data_transfer_layersmapping_cdlayers(ListBase *r_map,
if (!use_create) {
return true;
}
- CustomData_add_layer_named(cd_dst, cddata_type, CD_CALLOC, NULL, num_elem_dst, name);
+ CustomData_add_layer_named(cd_dst, cddata_type, CD_SET_DEFAULT, NULL, num_elem_dst, name);
idx_dst = CustomData_get_named_layer(cd_dst, cddata_type, name);
}
/* If dest is a evaluated mesh (from modifier),