Cleanup: Use const pointers in attribute API

This commit is contained in:
Hans Goudey 2022-06-07 18:55:56 +02:00
parent d39e0f9616
commit 9fda233897
15 changed files with 61 additions and 56 deletions

View File

@ -50,7 +50,7 @@ typedef enum eAttrDomainMask {
/* Attributes. */
bool BKE_id_attributes_supported(struct ID *id);
bool BKE_id_attributes_supported(const struct ID *id);
bool BKE_attribute_allow_procedural_access(const char *attribute_name);
/**
@ -74,7 +74,7 @@ struct CustomDataLayer *BKE_id_attribute_search(const struct ID *id,
eAttrDomain BKE_id_attribute_domain(const struct ID *id, const struct CustomDataLayer *layer);
int BKE_id_attribute_data_length(struct ID *id, struct CustomDataLayer *layer);
bool BKE_id_attribute_required(struct ID *id, struct CustomDataLayer *layer);
bool BKE_id_attribute_required(const struct ID *id, struct CustomDataLayer *layer);
bool BKE_id_attribute_rename(struct ID *id,
struct CustomDataLayer *layer,
const char *new_name,

View File

@ -25,7 +25,7 @@ void *BKE_curves_add(struct Main *bmain, const char *name);
struct BoundBox *BKE_curves_boundbox_get(struct Object *ob);
bool BKE_curves_customdata_required(struct Curves *curves, struct CustomDataLayer *layer);
bool BKE_curves_customdata_required(const struct Curves *curves, struct CustomDataLayer *layer);
/* Depsgraph */

View File

@ -30,7 +30,7 @@ struct BoundBox *BKE_pointcloud_boundbox_get(struct Object *ob);
bool BKE_pointcloud_minmax(const struct PointCloud *pointcloud, float r_min[3], float r_max[3]);
void BKE_pointcloud_update_customdata_pointers(struct PointCloud *pointcloud);
bool BKE_pointcloud_customdata_required(struct PointCloud *pointcloud,
bool BKE_pointcloud_customdata_required(const struct PointCloud *pointcloud,
struct CustomDataLayer *layer);
/* Dependency Graph */

View File

@ -105,7 +105,7 @@ static CustomData *attribute_customdata_find(ID *id, CustomDataLayer *layer)
return nullptr;
}
bool BKE_id_attributes_supported(ID *id)
bool BKE_id_attributes_supported(const ID *id)
{
DomainInfo info[ATTR_DOMAIN_NUM];
get_domains(id, info);
@ -382,14 +382,14 @@ int BKE_id_attribute_data_length(ID *id, CustomDataLayer *layer)
return 0;
}
bool BKE_id_attribute_required(ID *id, CustomDataLayer *layer)
bool BKE_id_attribute_required(const ID *id, CustomDataLayer *layer)
{
switch (GS(id->name)) {
case ID_PT: {
return BKE_pointcloud_customdata_required((PointCloud *)id, layer);
return BKE_pointcloud_customdata_required((const PointCloud *)id, layer);
}
case ID_CV: {
return BKE_curves_customdata_required((Curves *)id, layer);
return BKE_curves_customdata_required((const Curves *)id, layer);
}
default:
return false;

View File

@ -273,7 +273,7 @@ BoundBox *BKE_curves_boundbox_get(Object *ob)
return ob->runtime.bb;
}
bool BKE_curves_customdata_required(Curves *UNUSED(curves), CustomDataLayer *layer)
bool BKE_curves_customdata_required(const Curves *UNUSED(curves), CustomDataLayer *layer)
{
return layer->type == CD_PROP_FLOAT3 && STREQ(layer->name, ATTR_POSITION);
}

View File

@ -1448,7 +1448,7 @@ static bool fill_texpaint_slots_cb(bNode *node, void *userdata)
slot->attribute_name = storage->name;
if (storage->type == SHD_ATTRIBUTE_GEOMETRY) {
const Mesh *mesh = (const Mesh *)fill_data->ob->data;
CustomDataLayer *layer = BKE_id_attributes_color_find(&mesh->id, storage->name);
const CustomDataLayer *layer = BKE_id_attributes_color_find(&mesh->id, storage->name);
slot->valid = layer != NULL;
}

View File

@ -315,7 +315,8 @@ void BKE_pointcloud_update_customdata_pointers(PointCloud *pointcloud)
CustomData_get_layer_named(&pointcloud->pdata, CD_PROP_FLOAT, POINTCLOUD_ATTR_RADIUS));
}
bool BKE_pointcloud_customdata_required(PointCloud *UNUSED(pointcloud), CustomDataLayer *layer)
bool BKE_pointcloud_customdata_required(const PointCloud *UNUSED(pointcloud),
CustomDataLayer *layer)
{
return layer->type == CD_PROP_FLOAT3 && STREQ(layer->name, POINTCLOUD_ATTR_POSITION);
}

View File

@ -353,7 +353,7 @@ static void mesh_cd_calc_active_mloopcol_layer(const Object *object,
BKE_id_attribute_copy_domains_temp(ID_ME, cd_vdata, NULL, cd_ldata, NULL, NULL, &me_query.id);
CustomDataLayer *layer = BKE_id_attributes_active_color_get(&me_query.id);
const CustomDataLayer *layer = BKE_id_attributes_active_color_get(&me_query.id);
int layer_i = BKE_id_attribute_to_index(
&me_query.id, layer, ATTR_DOMAIN_MASK_COLOR, CD_MASK_COLOR_ALL);
@ -367,7 +367,7 @@ static uint mesh_cd_calc_gpu_layers_vcol_used(const Mesh *me_query,
const CustomData *cd_ldata,
const char name[])
{
CustomDataLayer *layer = NULL;
const CustomDataLayer *layer = NULL;
eAttrDomain domain;
if (name[0]) {
@ -1089,8 +1089,8 @@ static void sculpt_request_active_vcol(MeshBatchCache *cache, Object *object, Me
Mesh me_query = blender::dna::shallow_zero_initialize();
BKE_id_attribute_copy_domains_temp(ID_ME, cd_vdata, NULL, cd_ldata, NULL, NULL, &me_query.id);
CustomDataLayer *active = BKE_id_attributes_active_color_get(&me_query.id);
CustomDataLayer *render = BKE_id_attributes_render_color_get(&me_query.id);
const CustomDataLayer *active = BKE_id_attributes_active_color_get(&me_query.id);
const CustomDataLayer *render = BKE_id_attributes_render_color_get(&me_query.id);
int active_i = BKE_id_attribute_to_index(
&me_query.id, active, ATTR_DOMAIN_MASK_COLOR, CD_MASK_COLOR_ALL);

View File

@ -73,10 +73,10 @@ namespace blender::draw {
/* Initialize the common vertex format for vcol for coarse and subdivided meshes. */
static void init_vcol_format(GPUVertFormat *format,
const MeshBatchCache *cache,
CustomData *cd_vdata,
CustomData *cd_ldata,
CustomDataLayer *active,
CustomDataLayer *render)
const CustomData *cd_vdata,
const CustomData *cd_ldata,
const CustomDataLayer *active,
const CustomDataLayer *render)
{
GPU_vertformat_deinterleave(format);
@ -130,16 +130,18 @@ static void extract_vcol_init(const MeshRenderData *mr,
GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buf);
GPUVertFormat format = {0};
CustomData *cd_vdata = (mr->extract_type == MR_EXTRACT_BMESH) ? &mr->bm->vdata : &mr->me->vdata;
CustomData *cd_ldata = (mr->extract_type == MR_EXTRACT_BMESH) ? &mr->bm->ldata : &mr->me->ldata;
const CustomData *cd_vdata = (mr->extract_type == MR_EXTRACT_BMESH) ? &mr->bm->vdata :
&mr->me->vdata;
const CustomData *cd_ldata = (mr->extract_type == MR_EXTRACT_BMESH) ? &mr->bm->ldata :
&mr->me->ldata;
Mesh me_query = blender::dna::shallow_zero_initialize();
BKE_id_attribute_copy_domains_temp(
ID_ME, cd_vdata, nullptr, cd_ldata, nullptr, nullptr, &me_query.id);
CustomDataLayer *active_color = BKE_id_attributes_active_color_get(&me_query.id);
CustomDataLayer *render_color = BKE_id_attributes_render_color_get(&me_query.id);
const CustomDataLayer *active_color = BKE_id_attributes_active_color_get(&me_query.id);
const CustomDataLayer *render_color = BKE_id_attributes_render_color_get(&me_query.id);
const uint32_t vcol_layers = cache->cd_used.vcol;
init_vcol_format(&format, cache, cd_vdata, cd_ldata, active_color, render_color);
@ -152,7 +154,7 @@ static void extract_vcol_init(const MeshRenderData *mr,
blender::Vector<VColRef> refs = get_vcol_refs(cd_vdata, cd_ldata, vcol_layers);
for (const VColRef &ref : refs) {
CustomData *cdata = ref.domain == ATTR_DOMAIN_POINT ? cd_vdata : cd_ldata;
const CustomData *cdata = ref.domain == ATTR_DOMAIN_POINT ? cd_vdata : cd_ldata;
if (mr->extract_type == MR_EXTRACT_BMESH) {
int cd_ofs = ref.layer->offset;
@ -168,10 +170,10 @@ static void extract_vcol_init(const MeshRenderData *mr,
BMFace *f;
BM_ITER_MESH (f, &iter, mr->bm, BM_FACES_OF_MESH) {
BMLoop *l_iter = f->l_first;
const BMLoop *l_iter = f->l_first;
do {
BMElem *elem = is_point ? reinterpret_cast<BMElem *>(l_iter->v) :
reinterpret_cast<BMElem *>(l_iter);
const BMElem *elem = is_point ? reinterpret_cast<const BMElem *>(l_iter->v) :
reinterpret_cast<const BMElem *>(l_iter);
if (is_byte) {
const MLoopCol *mloopcol = (const MLoopCol *)BM_ELEM_CD_GET_VOID_P(elem, cd_ofs);
vcol_data->r = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[mloopcol->r]);
@ -193,17 +195,17 @@ static void extract_vcol_init(const MeshRenderData *mr,
}
else {
int totloop = mr->loop_len;
int idx = CustomData_get_named_layer_index(cdata, ref.layer->type, ref.layer->name);
const int idx = CustomData_get_named_layer_index(cdata, ref.layer->type, ref.layer->name);
MLoopCol *mcol = nullptr;
MPropCol *pcol = nullptr;
const MLoopCol *mcol = nullptr;
const MPropCol *pcol = nullptr;
const MLoop *mloop = mr->mloop;
if (ref.layer->type == CD_PROP_COLOR) {
pcol = static_cast<MPropCol *>(cdata->layers[idx].data);
pcol = static_cast<const MPropCol *>(cdata->layers[idx].data);
}
else {
mcol = static_cast<MLoopCol *>(cdata->layers[idx].data);
mcol = static_cast<const MLoopCol *>(cdata->layers[idx].data);
}
const bool is_corner = ref.domain == ATTR_DOMAIN_CORNER;
@ -251,8 +253,8 @@ static void extract_vcol_init_subdiv(const DRWSubdivCache *subdiv_cache,
BKE_id_attribute_copy_domains_temp(
ID_ME, cd_vdata, nullptr, cd_ldata, nullptr, nullptr, &me_query.id);
CustomDataLayer *active_color = BKE_id_attributes_active_color_get(&me_query.id);
CustomDataLayer *render_color = BKE_id_attributes_render_color_get(&me_query.id);
const CustomDataLayer *active_color = BKE_id_attributes_active_color_get(&me_query.id);
const CustomDataLayer *render_color = BKE_id_attributes_render_color_get(&me_query.id);
GPUVertFormat format = {0};
init_vcol_format(
@ -299,14 +301,15 @@ static void extract_vcol_init_subdiv(const DRWSubdivCache *subdiv_cache,
const bool is_byte = ref.layer->type == CD_PROP_BYTE_COLOR;
BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
BMLoop *l_iter = f->l_first;
const BMLoop *l_iter = f->l_first;
do {
BMElem *elem = is_vert ? reinterpret_cast<BMElem *>(l_iter->v) :
reinterpret_cast<BMElem *>(l_iter);
const BMElem *elem = is_vert ? reinterpret_cast<const BMElem *>(l_iter->v) :
reinterpret_cast<const BMElem *>(l_iter);
if (is_byte) {
MLoopCol *mcol2 = static_cast<MLoopCol *>(BM_ELEM_CD_GET_VOID_P(elem, cd_ofs));
const MLoopCol *mcol2 = static_cast<const MLoopCol *>(
BM_ELEM_CD_GET_VOID_P(elem, cd_ofs));
vcol->r = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[mcol2->r]);
vcol->g = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[mcol2->g]);
@ -314,7 +317,8 @@ static void extract_vcol_init_subdiv(const DRWSubdivCache *subdiv_cache,
vcol->a = unit_float_to_ushort_clamp(mcol2->a * (1.0f / 255.0f));
}
else {
MPropCol *pcol2 = static_cast<MPropCol *>(BM_ELEM_CD_GET_VOID_P(elem, cd_ofs));
const MPropCol *pcol2 = static_cast<const MPropCol *>(
BM_ELEM_CD_GET_VOID_P(elem, cd_ofs));
vcol->r = unit_float_to_ushort_clamp(pcol2->color[0]);
vcol->g = unit_float_to_ushort_clamp(pcol2->color[1]);
@ -328,14 +332,14 @@ static void extract_vcol_init_subdiv(const DRWSubdivCache *subdiv_cache,
}
else {
const MLoop *ml = coarse_mesh->mloop;
MLoopCol *mcol = nullptr;
MPropCol *pcol = nullptr;
const MLoopCol *mcol = nullptr;
const MPropCol *pcol = nullptr;
if (ref.layer->type == CD_PROP_COLOR) {
pcol = static_cast<MPropCol *>(cdata->layers[layer_i].data);
pcol = static_cast<const MPropCol *>(cdata->layers[layer_i].data);
}
else {
mcol = static_cast<MLoopCol *>(cdata->layers[layer_i].data);
mcol = static_cast<const MLoopCol *>(cdata->layers[layer_i].data);
}
for (int ml_index = 0; ml_index < coarse_mesh->totloop; ml_index++, vcol++, ml++) {

View File

@ -44,9 +44,9 @@ namespace blender::ed::geometry {
static bool geometry_attributes_poll(bContext *C)
{
Object *ob = ED_object_context(C);
Main *bmain = CTX_data_main(C);
ID *data = (ob) ? static_cast<ID *>(ob->data) : nullptr;
const Object *ob = ED_object_context(C);
const Main *bmain = CTX_data_main(C);
const ID *data = (ob) ? static_cast<ID *>(ob->data) : nullptr;
return (ob && BKE_id_is_editable(bmain, &ob->id) && data && BKE_id_is_editable(bmain, data)) &&
BKE_id_attributes_supported(data);
}
@ -106,7 +106,7 @@ static int geometry_attribute_add_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
static void next_color_attribute(struct ID *id, CustomDataLayer *layer, bool is_render)
static void next_color_attribute(ID *id, CustomDataLayer *layer, bool is_render)
{
int index = BKE_id_attribute_to_index(id, layer, ATTR_DOMAIN_MASK_COLOR, CD_MASK_COLOR_ALL);
@ -129,7 +129,7 @@ static void next_color_attribute(struct ID *id, CustomDataLayer *layer, bool is_
}
}
static void next_color_attributes(struct ID *id, CustomDataLayer *layer)
static void next_color_attributes(ID *id, CustomDataLayer *layer)
{
next_color_attribute(id, layer, false); /* active */
next_color_attribute(id, layer, true); /* render */

View File

@ -3092,8 +3092,8 @@ static int edbm_rotate_colors_exec(bContext *C, wmOperator *op)
BMOperator bmop;
Mesh *me = BKE_object_get_original_mesh(ob);
CustomDataLayer *layer = BKE_id_attributes_active_color_get(&me->id);
const Mesh *me = BKE_object_get_original_mesh(ob);
const CustomDataLayer *layer = BKE_id_attributes_active_color_get(&me->id);
if (!layer || BKE_id_attribute_domain(&me->id, layer) != ATTR_DOMAIN_CORNER) {
continue;
@ -3144,8 +3144,8 @@ static int edbm_reverse_colors_exec(bContext *C, wmOperator *op)
continue;
}
Mesh *me = BKE_object_get_original_mesh(obedit);
CustomDataLayer *layer = BKE_id_attributes_active_color_get(&me->id);
const Mesh *me = BKE_object_get_original_mesh(obedit);
const CustomDataLayer *layer = BKE_id_attributes_active_color_get(&me->id);
if (!layer || BKE_id_attribute_domain(&me->id, layer) != ATTR_DOMAIN_CORNER) {
continue;

View File

@ -139,7 +139,7 @@ struct NormalAnglePrecalc {
/* Returns number of elements. */
static int get_vcol_elements(Mesh *me, size_t *r_elem_size)
{
CustomDataLayer *layer = BKE_id_attributes_active_color_get(&me->id);
const CustomDataLayer *layer = BKE_id_attributes_active_color_get(&me->id);
eAttrDomain domain = BKE_id_attribute_domain(&me->id, layer);
if (r_elem_size) {

View File

@ -148,7 +148,7 @@ const float *SCULPT_vertex_co_get(SculptSession *ss, int index)
bool SCULPT_has_loop_colors(const Object *ob)
{
Mesh *me = BKE_object_get_original_mesh(ob);
CustomDataLayer *layer = BKE_id_attributes_active_color_get(&me->id);
const CustomDataLayer *layer = BKE_id_attributes_active_color_get(&me->id);
return layer && BKE_id_attribute_domain(&me->id, layer) == ATTR_DOMAIN_CORNER;
}

View File

@ -1465,7 +1465,7 @@ static bool sculpt_attribute_ref_equals(SculptAttrRef *a, SculptAttrRef *b)
static void sculpt_save_active_attribute(Object *ob, SculptAttrRef *attr)
{
Mesh *me = BKE_object_get_original_mesh(ob);
CustomDataLayer *layer;
const CustomDataLayer *layer;
if (ob && me && (layer = BKE_id_attributes_active_color_get((ID *)me))) {
attr->domain = BKE_id_attribute_domain((ID *)me, layer);

View File

@ -538,7 +538,7 @@ static void rna_AttributeGroup_active_color_set(PointerRNA *ptr,
static int rna_AttributeGroup_active_color_index_get(PointerRNA *ptr)
{
CustomDataLayer *layer = BKE_id_attributes_active_color_get(ptr->owner_id);
const CustomDataLayer *layer = BKE_id_attributes_active_color_get(ptr->owner_id);
return BKE_id_attribute_to_index(
ptr->owner_id, layer, ATTR_DOMAIN_MASK_COLOR, CD_MASK_COLOR_ALL);