[Bf-blender-cvs] [741ed1029e5] blender2.8: Cleanup: naming of DRW mesh weight API

Campbell Barton noreply at git.blender.org
Wed Sep 26 02:02:55 CEST 2018


Commit: 741ed1029e57f4b5d3fc0f85c25ac5791d582e9a
Author: Campbell Barton
Date:   Wed Sep 26 10:16:17 2018 +1000
Branches: blender2.8
https://developer.blender.org/rB741ed1029e57f4b5d3fc0f85c25ac5791d582e9a

Cleanup: naming of DRW mesh weight API

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

M	source/blender/draw/intern/draw_cache.c
M	source/blender/draw/intern/draw_cache_impl.h
M	source/blender/draw/intern/draw_cache_impl_mesh.c

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

diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
index 716ad93223a..301aa7c9970 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -2962,37 +2962,38 @@ GPUBatch *DRW_cache_mesh_surface_weights_get(Object *ob, ToolSettings *ts, bool
 	Mesh *me = ob->data;
 
 	/* Extract complete vertex weight group selection state and mode flags. */
-	VertexWeightSelection vwsel;
-	memset(&vwsel, 0, sizeof(vwsel));
+	struct DRW_MeshWeightState wstate;
+	memset(&wstate, 0, sizeof(wstate));
 
-	vwsel.defgroup_active = ob->actdef - 1;
-	vwsel.defgroup_tot = BLI_listbase_count(&ob->defbase);
+	wstate.defgroup_active = ob->actdef - 1;
+	wstate.defgroup_len = BLI_listbase_count(&ob->defbase);
 
-	vwsel.alert_mode = ts->weightuser;
+	wstate.alert_mode = ts->weightuser;
 
 	if (paint_mode && ts->multipaint) {
 		/* Multipaint needs to know all selected bones, not just the active group.
 		 * This is actually a relatively expensive operation, but caching would be difficult. */
-		vwsel.defgroup_sel = BKE_object_defgroup_selected_get(ob, vwsel.defgroup_tot, &vwsel.defgroup_sel_tot);
+		wstate.defgroup_sel = BKE_object_defgroup_selected_get(ob, wstate.defgroup_len, &wstate.defgroup_sel_len);
 
-		if (vwsel.defgroup_sel_tot > 1) {
-			vwsel.flags |= VWEIGHT_MULTIPAINT | (ts->auto_normalize ? VWEIGHT_AUTO_NORMALIZE : 0);
+		if (wstate.defgroup_sel_len > 1) {
+			wstate.flags |= DRW_MESH_WEIGHT_STATE_MULTIPAINT | (ts->auto_normalize ? DRW_MESH_WEIGHT_STATE_AUTO_NORMALIZE : 0);
 
 			if (me->editflag & ME_EDIT_MIRROR_X) {
-				BKE_object_defgroup_mirror_selection(ob, vwsel.defgroup_tot, vwsel.defgroup_sel, vwsel.defgroup_sel, &vwsel.defgroup_sel_tot);
+				BKE_object_defgroup_mirror_selection(
+				        ob, wstate.defgroup_len, wstate.defgroup_sel, wstate.defgroup_sel, &wstate.defgroup_sel_len);
 			}
 		}
 		/* With only one selected bone Multipaint reverts to regular mode. */
 		else {
-			vwsel.defgroup_sel_tot = 0;
-			MEM_SAFE_FREE(vwsel.defgroup_sel);
+			wstate.defgroup_sel_len = 0;
+			MEM_SAFE_FREE(wstate.defgroup_sel);
 		}
 	}
 
 	/* Generate the weight data using the selection. */
-	GPUBatch *batch = DRW_mesh_batch_cache_get_triangles_with_normals_and_weights(me, &vwsel);
+	GPUBatch *batch = DRW_mesh_batch_cache_get_triangles_with_normals_and_weights(me, &wstate);
 
-	DRW_vweight_selection_clear(&vwsel);
+	DRW_mesh_weight_state_clear(&wstate);
 
 	return batch;
 }
diff --git a/source/blender/draw/intern/draw_cache_impl.h b/source/blender/draw/intern/draw_cache_impl.h
index 372ec6cdf6c..ca14d6ae3cc 100644
--- a/source/blender/draw/intern/draw_cache_impl.h
+++ b/source/blender/draw/intern/draw_cache_impl.h
@@ -97,26 +97,27 @@ struct GPUBatch *DRW_lattice_batch_cache_get_all_verts(struct Lattice *lt);
 struct GPUBatch *DRW_lattice_batch_cache_get_overlay_verts(struct Lattice *lt);
 
 /* Vertex Group Selection and display options */
-typedef struct VertexWeightSelection {
+struct DRW_MeshWeightState {
 	int defgroup_active;
-	int defgroup_tot;
+	int defgroup_len;
 
 	short flags;
 	char alert_mode;
 
 	/* Set of all selected bones for Multipaint. */
-	int defgroup_sel_tot;
 	bool *defgroup_sel;
-} VertexWeightSelection;
+	int   defgroup_sel_len;
+};
 
+/* DRW_MeshWeightState.flags */
 enum {
-	VWEIGHT_MULTIPAINT          = (1 << 0),
-	VWEIGHT_AUTO_NORMALIZE      = (1 << 1),
+	DRW_MESH_WEIGHT_STATE_MULTIPAINT          = (1 << 0),
+	DRW_MESH_WEIGHT_STATE_AUTO_NORMALIZE      = (1 << 1),
 };
 
-void DRW_vweight_selection_clear(struct VertexWeightSelection *sel);
-void DRW_vweight_selection_copy(struct VertexWeightSelection *sel, const struct VertexWeightSelection *src);
-bool DRW_vweight_selection_compare(const struct VertexWeightSelection *a, const struct VertexWeightSelection *b);
+void DRW_mesh_weight_state_clear(struct DRW_MeshWeightState *wstate);
+void DRW_mesh_weight_state_copy(struct DRW_MeshWeightState *wstate_dst, const struct DRW_MeshWeightState *wstate_src);
+bool DRW_mesh_weight_state_compare(const struct DRW_MeshWeightState *a, const struct DRW_MeshWeightState *b);
 
 /* Mesh */
 struct GPUBatch **DRW_mesh_batch_cache_get_surface_shaded(
@@ -130,7 +131,7 @@ struct GPUBatch *DRW_mesh_batch_cache_get_weight_overlay_verts(struct Mesh *me);
 struct GPUBatch *DRW_mesh_batch_cache_get_all_edges(struct Mesh *me);
 struct GPUBatch *DRW_mesh_batch_cache_get_all_triangles(struct Mesh *me);
 struct GPUBatch *DRW_mesh_batch_cache_get_triangles_with_normals(struct Mesh *me);
-struct GPUBatch *DRW_mesh_batch_cache_get_triangles_with_normals_and_weights(struct Mesh *me, const struct VertexWeightSelection *vwsel);
+struct GPUBatch *DRW_mesh_batch_cache_get_triangles_with_normals_and_weights(struct Mesh *me, const struct DRW_MeshWeightState *wstate);
 struct GPUBatch *DRW_mesh_batch_cache_get_triangles_with_normals_and_vert_colors(struct Mesh *me);
 struct GPUBatch *DRW_mesh_batch_cache_get_triangles_with_select_id(struct Mesh *me, bool use_hide, uint select_id_offset);
 struct GPUBatch *DRW_mesh_batch_cache_get_triangles_with_select_mask(struct Mesh *me, bool use_hide);
diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c
index f00eb084665..cc3360d76e9 100644
--- a/source/blender/draw/intern/draw_cache_impl_mesh.c
+++ b/source/blender/draw/intern/draw_cache_impl_mesh.c
@@ -1119,16 +1119,16 @@ static void vertex_weight_color(float vweight[3], float weight, bool show_alert_
 	}
 }
 
-static void evaluate_vertex_weight(float vweight[3], const MDeformVert *dvert, const VertexWeightSelection *vwsel)
+static void evaluate_vertex_weight(float vweight[3], const MDeformVert *dvert, const struct DRW_MeshWeightState *wstate)
 {
 	float input = 0.0f;
 	bool show_alert_color = false;
 
-	if (vwsel->flags & VWEIGHT_MULTIPAINT) {
+	if (wstate->flags & DRW_MESH_WEIGHT_STATE_MULTIPAINT) {
 		/* Multi-Paint feature */
 		input = BKE_defvert_multipaint_collective_weight(
-		        dvert, vwsel->defgroup_tot, vwsel->defgroup_sel, vwsel->defgroup_sel_tot,
-		        (vwsel->flags & VWEIGHT_AUTO_NORMALIZE) != 0);
+		        dvert, wstate->defgroup_len, wstate->defgroup_sel, wstate->defgroup_sel_len,
+		        (wstate->flags & DRW_MESH_WEIGHT_STATE_AUTO_NORMALIZE) != 0);
 
 		/* make it black if the selected groups have no weight on a vertex */
 		if (input == 0.0f) {
@@ -1137,16 +1137,16 @@ static void evaluate_vertex_weight(float vweight[3], const MDeformVert *dvert, c
 	}
 	else {
 		/* default, non tricky behavior */
-		input = defvert_find_weight(dvert, vwsel->defgroup_active);
+		input = defvert_find_weight(dvert, wstate->defgroup_active);
 
 		if (input == 0.0f) {
-			switch (vwsel->alert_mode) {
+			switch (wstate->alert_mode) {
 				case OB_DRAW_GROUPUSER_ACTIVE:
 					show_alert_color = true;
 					break;
 
 				case OB_DRAW_GROUPUSER_ALL:
-					show_alert_color = defvert_is_weight_zero(dvert, vwsel->defgroup_tot);
+					show_alert_color = defvert_is_weight_zero(dvert, wstate->defgroup_len);
 					break;
 			}
 		}
@@ -1159,11 +1159,11 @@ static void evaluate_vertex_weight(float vweight[3], const MDeformVert *dvert, c
 static const unsigned char missing_weight_color[3] = { 0xa0, 0x00, 0xa0 };
 
 /** Ensure #MeshRenderData.vert_weight_color */
-static void mesh_render_data_ensure_vert_weight_color(MeshRenderData *rdata, const VertexWeightSelection *vwsel)
+static void mesh_render_data_ensure_vert_weight_color(MeshRenderData *rdata, const struct DRW_MeshWeightState *wstate)
 {
 	float (*vweight)[3] = rdata->vert_weight_color;
 	if (vweight == NULL) {
-		if (vwsel->defgroup_active == -1) {
+		if (wstate->defgroup_active == -1) {
 			goto fallback;
 		}
 
@@ -1181,7 +1181,7 @@ static void mesh_render_data_ensure_vert_weight_color(MeshRenderData *rdata, con
 			vweight = rdata->vert_weight_color = MEM_mallocN(sizeof(*vweight) * rdata->vert_len, __func__);
 			BM_ITER_MESH_INDEX(eve, &viter, bm, BM_VERT, i) {
 				const MDeformVert *dvert = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset);
-				evaluate_vertex_weight(vweight[i], dvert, vwsel);
+				evaluate_vertex_weight(vweight[i], dvert, wstate);
 			}
 		}
 		else {
@@ -1191,7 +1191,7 @@ static void mesh_render_data_ensure_vert_weight_color(MeshRenderData *rdata, con
 
 			vweight = rdata->vert_weight_color = MEM_mallocN(sizeof(*vweight) * rdata->vert_len, __func__);
 			for (int i = 0; i < rdata->vert_len; i++) {
-				evaluate_vertex_weight(vweight[i], &rdata->dvert[i], vwsel);
+				evaluate_vertex_weight(vweight[i], &rdata->dvert[i], wstate);
 			}
 		}
 	}
@@ -1202,11 +1202,11 @@ fallback:
 
 	float error_color[3];
 
-	if ((vwsel->defgroup_active < 0) && (vwsel->defgroup_tot > 0)) {
+	if ((wstate->defgroup_active < 0) && (wstate->defgroup_len > 0)) {
 		rgb_uchar_to_float(error_color, missing_weight_color);
 	}
 	else {
-		vertex_weight_color(error_color, 0.0f, vwsel->alert_mode != OB_DRAW_GROUPUSER_NONE);
+		vertex_weight_color(error_color, 0.0f, wstate->alert_mode != OB_DRAW_GROUPUSER_NONE);
 	}
 
 	for (int i = 0; i < rdata->vert_len; i++) {
@@ -1596,38 +1596,38 @@ static void add_overlay_loose_vert(
  * \{ */
 
 /** Reset the selection structure, deallocating heap memory as appropriate. */
-void DRW_vweight_selection_clear(struct VertexWeightSelection *sel)
+void DRW_mesh_weight_state_clear(struct DRW_MeshWeightState *wstate)
 {
-	MEM_SAFE_FREE(sel->defgroup_sel);
+	MEM_SAFE_FREE(wstate->defgroup_sel);
 
-	memset(sel, 0, sizeof(VertexWeightSelection));
+	memset(wstate, 0, sizeof(*wstate));
 
-	sel->defgroup_active = -1;
+	wstate->defgroup_active = -1;
 }
 
 /** Copy selection data from one structure to another, including heap memory. */
-void DRW_vweight_selection_copy(struct VertexWeightSelection *sel, const struct VertexWeightSelection *src)
+void DRW_mesh_weight_state_copy(struct DRW_MeshWeightState *wstate_dst, const struct DRW_MeshWeightState *wstate_src)
 {
-	MEM_SAFE_FREE(sel->defgroup_sel);
+	MEM_SAFE_FREE(wstate_dst->defgroup_sel);
 
-	memcpy(sel, src, sizeof(VertexWeightSelection));
+	memcpy(wstate_dst, wstate_src, sizeof(*wstate_dst));
 
-	if (src->defgroup_sel) {
-		sel->defgroup_sel = MEM_dupallocN(src->defgroup_sel);
+	if (wstate_src->defgroup_sel) {
+		wstate_dst

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list