[Bf-blender-cvs] [e4774c0b2d0] blender2.8: Metaball: pointers used in `DRW_shgroup_call_dynamic_add` don't need to hold the reference.

Germano noreply at git.blender.org
Thu May 3 02:26:53 CEST 2018


Commit: e4774c0b2d02d3231c1bdc0097d879b77daa5651
Author: Germano
Date:   Wed May 2 21:26:43 2018 -0300
Branches: blender2.8
https://developer.blender.org/rBe4774c0b2d02d3231c1bdc0097d879b77daa5651

Metaball: pointers used in `DRW_shgroup_call_dynamic_add` don't need to hold the reference.

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

M	source/blender/blenkernel/BKE_mball.h
M	source/blender/blenkernel/intern/mball.c
M	source/blender/draw/intern/draw_common.c
M	source/blender/draw/intern/draw_common.h
M	source/blender/draw/modes/edit_metaball_mode.c
M	source/blender/draw/modes/object_mode.c
M	source/blender/makesdna/DNA_meta_types.h

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

diff --git a/source/blender/blenkernel/BKE_mball.h b/source/blender/blenkernel/BKE_mball.h
index b05a35e614f..a486e8319c6 100644
--- a/source/blender/blenkernel/BKE_mball.h
+++ b/source/blender/blenkernel/BKE_mball.h
@@ -78,10 +78,6 @@ void BKE_mball_eval_geometry(struct Depsgraph *depsgraph,
                              struct MetaBall *mball);
 /* Draw Cache */
 
-void BKE_mball_element_calc_scale_xform(float r_scale_xform[3][4],
-                                        const float obmat[4][4],
-                                        const float local_pos[3]);
-
 enum {
 	BKE_MBALL_BATCH_DIRTY_ALL = 0,
 };
diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c
index 47f15e99b5f..d7fb2d0a17b 100644
--- a/source/blender/blenkernel/intern/mball.c
+++ b/source/blender/blenkernel/intern/mball.c
@@ -550,32 +550,6 @@ void BKE_mball_eval_geometry(struct Depsgraph *UNUSED(depsgraph),
 
 /* Draw Engine */
 
-/* use for draw-manager only. */
-void BKE_mball_element_calc_scale_xform(float r_scale_xform[3][4],
-                                        const float obmat[4][4],
-                                        const float local_pos[3])
-{
-	float world_pos[3], scamat[3][3];
-	mul_v3_m4v3(world_pos, obmat, local_pos);
-	copy_m3_m4(scamat, obmat);
-	{
-		/* Get the normalized inverse matrix to extract only
-		 * the scale of Scamat */
-		float iscamat[3][3];
-		invert_m3_m3(iscamat, scamat);
-		normalize_m3(iscamat);
-		mul_m3_m3_post(scamat, iscamat);
-	}
-
-	copy_v3_v3(r_scale_xform[0], scamat[0]);
-	copy_v3_v3(r_scale_xform[1], scamat[1]);
-	copy_v3_v3(r_scale_xform[2], scamat[2]);
-
-	r_scale_xform[0][3] = world_pos[0];
-	r_scale_xform[1][3] = world_pos[1];
-	r_scale_xform[2][3] = world_pos[2];
-}
-
 void (*BKE_mball_batch_cache_dirty_cb)(MetaBall *mb, int mode) = NULL;
 void (*BKE_mball_batch_cache_free_cb)(MetaBall *mb) = NULL;
 
diff --git a/source/blender/draw/intern/draw_common.c b/source/blender/draw/intern/draw_common.c
index 5019f28e4cf..eaccd1b68b6 100644
--- a/source/blender/draw/intern/draw_common.c
+++ b/source/blender/draw/intern/draw_common.c
@@ -493,7 +493,7 @@ DRWShadingGroup *shgroup_instance_bone_envelope_solid(DRWPass *pass)
 	return grp;
 }
 
-DRWShadingGroup *shgroup_instance_mball_handles(DRWPass *pass, struct Gwn_Batch *geom)
+DRWShadingGroup *shgroup_instance_mball_handles(DRWPass *pass)
 {
 	GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_INSTANCE_MBALL_HANDLES);
 
@@ -503,7 +503,8 @@ DRWShadingGroup *shgroup_instance_mball_handles(DRWPass *pass, struct Gwn_Batch
 		{"color"                  , DRW_ATTRIB_FLOAT, 3}
 	});
 
-	DRWShadingGroup *grp = DRW_shgroup_instance_create(sh, pass, geom, g_formats.instance_mball_handles);
+	DRWShadingGroup *grp = DRW_shgroup_instance_create(sh, pass, DRW_cache_screenspace_circle_get(),
+	                                                   g_formats.instance_mball_handles);
 	DRW_shgroup_uniform_vec3(grp, "screen_vecs[0]", DRW_viewport_screenvecs_get(), 2);
 
 	return grp;
diff --git a/source/blender/draw/intern/draw_common.h b/source/blender/draw/intern/draw_common.h
index 7b40596ad10..052cbc7bee9 100644
--- a/source/blender/draw/intern/draw_common.h
+++ b/source/blender/draw/intern/draw_common.h
@@ -121,7 +121,7 @@ struct DRWShadingGroup *shgroup_spot_instance(struct DRWPass *pass, struct Gwn_B
 struct DRWShadingGroup *shgroup_instance_bone_envelope_distance(struct DRWPass *pass);
 struct DRWShadingGroup *shgroup_instance_bone_envelope_outline(struct DRWPass *pass);
 struct DRWShadingGroup *shgroup_instance_bone_envelope_solid(struct DRWPass *pass);
-struct DRWShadingGroup *shgroup_instance_mball_handles(struct DRWPass *pass, struct Gwn_Batch *geom);
+struct DRWShadingGroup *shgroup_instance_mball_handles(struct DRWPass *pass);
 struct DRWShadingGroup *shgroup_instance_bone_shape_outline(struct DRWPass *pass, struct Gwn_Batch *geom);
 struct DRWShadingGroup *shgroup_instance_bone_sphere(struct DRWPass *pass);
 struct DRWShadingGroup *shgroup_instance_bone_sphere_outline(struct DRWPass *pass);
diff --git a/source/blender/draw/modes/edit_metaball_mode.c b/source/blender/draw/modes/edit_metaball_mode.c
index f7b7113a4d6..e7b07c36882 100644
--- a/source/blender/draw/modes/edit_metaball_mode.c
+++ b/source/blender/draw/modes/edit_metaball_mode.c
@@ -120,48 +120,10 @@ static void EDIT_METABALL_cache_init(void *vedata)
 		psl->pass = DRW_pass_create("My Pass", state);
 
 		/* Create a shadingGroup using a function in draw_common.c or custom one */
-		stl->g_data->group = shgroup_instance_mball_handles(psl->pass, DRW_cache_screenspace_circle_get());
+		stl->g_data->group = shgroup_instance_mball_handles(psl->pass);
 	}
 }
 
-static void EDIT_METABALL_cache_populate_radius(
-        DRWShadingGroup *group, MetaElem *ml, const float scale_xform[3][4],
-        const float *radius, const int selection_id)
-{
-	const float *color;
-	static const float col_radius[3] =        {0.63, 0.19, 0.19}; /* 0x3030A0 */
-	static const float col_radius_select[3] = {0.94, 0.63, 0.63}; /* 0xA0A0F0 */
-
-	if ((ml->flag & SELECT) && (ml->flag & MB_SCALE_RAD)) color = col_radius_select;
-	else color = col_radius;
-
-	if (selection_id != -1) {
-		ml->selcol1 = selection_id;
-		DRW_select_load_id(selection_id);
-	}
-
-	DRW_shgroup_call_dynamic_add(group, scale_xform, radius, color);
-}
-
-static void EDIT_METABALL_cache_populate_stiffness(
-        DRWShadingGroup *group, MetaElem *ml, const float scale_xform[3][4],
-        const float *radius, const int selection_id)
-{
-	const float *color;
-	static const float col_stiffness[3] =        {0.19, 0.63, 0.19}; /* 0x30A030 */
-	static const float col_stiffness_select[3] = {0.63, 0.94, 0.63}; /* 0xA0F0A0 */
-
-	if ((ml->flag & SELECT) && !(ml->flag & MB_SCALE_RAD)) color = col_stiffness_select;
-	else color = col_stiffness;
-
-	if (selection_id != -1) {
-		ml->selcol2 = selection_id;
-		DRW_select_load_id(selection_id);
-	}
-
-	DRW_shgroup_call_dynamic_add(group, scale_xform, radius, color);
-}
-
 /* Add geometry to shadingGroups. Execute for each objects */
 static void EDIT_METABALL_cache_populate(void *vedata, Object *ob)
 {
@@ -175,19 +137,60 @@ static void EDIT_METABALL_cache_populate(void *vedata, Object *ob)
 		if ((ob == draw_ctx->object_edit) || BKE_object_is_in_editmode_and_selected(ob)) {
 			MetaBall *mb = ob->data;
 
+			const float *color;
+			const float col_radius[3]           = {0.63, 0.19, 0.19}; /* 0x3030A0 */
+			const float col_radius_select[3]    = {0.94, 0.63, 0.63}; /* 0xA0A0F0 */
+			const float col_stiffness[3]        = {0.19, 0.63, 0.19}; /* 0x30A030 */
+			const float col_stiffness_select[3] = {0.63, 0.94, 0.63}; /* 0xA0F0A0 */
+
 			const bool is_select = DRW_state_is_select();
 
 			int selection_id = 0;
 
+			float draw_scale_xform[3][4]; /* Matrix of Scale and Translation */
+			{
+				float scamat[3][3];
+				copy_m3_m4(scamat, ob->obmat);
+				/* Get the normalized inverse matrix to extract only
+				* the scale of Scamat */
+				float iscamat[3][3];
+				invert_m3_m3(iscamat, scamat);
+				normalize_m3(iscamat);
+				mul_m3_m3_post(scamat, iscamat);
+
+				copy_v3_v3(draw_scale_xform[0], scamat[0]);
+				copy_v3_v3(draw_scale_xform[1], scamat[1]);
+				copy_v3_v3(draw_scale_xform[2], scamat[2]);
+			}
+
 			for (MetaElem *ml = mb->editelems->first; ml != NULL; ml = ml->next) {
-				BKE_mball_element_calc_scale_xform(ml->draw_scale_xform, ob->obmat, &ml->x);
-				ml->draw_stiffness_radius = ml->rad * atanf(ml->s) / (float)M_PI_2;
+				float world_pos[3];
+				mul_v3_m4v3(world_pos, ob->obmat, &ml->x);
+				draw_scale_xform[0][3] = world_pos[0];
+				draw_scale_xform[1][3] = world_pos[1];
+				draw_scale_xform[2][3] = world_pos[2];
+
+				float draw_stiffness_radius = ml->rad * atanf(ml->s) / (float)M_PI_2;
+
+				if ((ml->flag & SELECT) && (ml->flag & MB_SCALE_RAD)) color = col_radius_select;
+				else color = col_radius;
+
+				if (is_select) {
+					ml->selcol1 = ++selection_id;
+					DRW_select_load_id(selection_id);
+				}
+
+				DRW_shgroup_call_dynamic_add(group, draw_scale_xform, &ml->rad, color);
+
+				if ((ml->flag & SELECT) && !(ml->flag & MB_SCALE_RAD)) color = col_stiffness_select;
+				else color = col_stiffness;
 
-				EDIT_METABALL_cache_populate_radius(
-				        group, ml, ml->draw_scale_xform, &ml->rad, is_select ? ++selection_id : -1);
+				if (is_select) {
+					ml->selcol2 = ++selection_id;
+					DRW_select_load_id(selection_id);
+				}
 
-				EDIT_METABALL_cache_populate_stiffness(
-				        group, ml, ml->draw_scale_xform, &ml->draw_stiffness_radius, is_select ? ++selection_id : -1);
+				DRW_shgroup_call_dynamic_add(group, draw_scale_xform, &draw_stiffness_radius, color);
 			}
 		}
 	}
diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c
index 8b86fe8c9a2..4830aa3334e 100644
--- a/source/blender/draw/modes/object_mode.c
+++ b/source/blender/draw/modes/object_mode.c
@@ -1188,9 +1188,7 @@ static void OBJECT_cache_init(void *vedata)
 
 	{
 		/* Metaballs Handles */
-		struct Gwn_Batch *geom;
-		geom = DRW_cache_screenspace_circle_get();
-		stl->g_data->mball_handle = shgroup_instance_mball_handles(psl->non_meshes, geom);
+		stl->g_data->mball_handle = shgroup_instance_mball_handles(psl->non_meshes);
 	}
 
 	{
@@ -1329,10 +1327,31 @@ static void DRW_shgroup_mball_handles(OBJECT_StorageList *stl, Object *ob, ViewL
 	float *color;
 	DRW_object_wire_theme_get(ob, view_layer, &color);
 
+	float draw_scale_xform[3][4]; /* Matrix of Scale and Translation */
+	{
+		float scamat[3][3];
+		copy_m3_m4(scamat, ob->obmat);
+		/* Get the normalized inverse matrix to extract only
+		* the scale of Scamat */
+		float iscamat[3][3];
+		invert_m3_m3(iscamat, scamat);
+		normalize_m3(iscamat);
+		mul_m3_m3_post(scamat, iscamat);
+
+		copy_v3_v3(draw_scale_xform[0], scamat[0]);
+		copy_v3_v3(draw_scale_xform[1], scamat[1]);
+		copy_v3_v3(draw_scale_xform[2], scamat[2]);
+	}
+
 	for (MetaElem *ml = mb->elems.first; ml != NULL; ml = ml->next) {
 		/* draw radius */
-		BKE_mball_element_calc_scale_xform(ml->draw_scale_xform, ob->obmat, &ml->x);
-		DRW_shgroup_call_dynamic_add(stl->g_data->mball_handle, ml->draw_scale_xform, &ml->rad, col

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list