Metaball: pointers used in `DRW_shgroup_call_dynamic_add` don't need to hold the...
authorGermano <germano.costa@ig.com.br>
Thu, 3 May 2018 00:26:43 +0000 (21:26 -0300)
committerGermano <germano.costa@ig.com.br>
Thu, 3 May 2018 00:26:43 +0000 (21:26 -0300)
source/blender/blenkernel/BKE_mball.h
source/blender/blenkernel/intern/mball.c
source/blender/draw/intern/draw_common.c
source/blender/draw/intern/draw_common.h
source/blender/draw/modes/edit_metaball_mode.c
source/blender/draw/modes/object_mode.c
source/blender/makesdna/DNA_meta_types.h

index b05a35e614f36618538ddfa42ab364a39a9b54b9..a486e8319c6fc78fcb8cb07e73178b5c8ced8e59 100644 (file)
@@ -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,
 };
index 47f15e99b5f2510ca31cebedeca2b388bfbdeea9..d7fb2d0a17b59388391761d5309a1f538e486b3a 100644 (file)
@@ -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;
 
index 5019f28e4cfa9f48b8062814f076c9f86eaf969f..eaccd1b68b6fbf3785e209f41a569a8602c110dd 100644 (file)
@@ -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;
index 7b40596ad10615fd0ae4a51e94f6723a7e7d83e4..052cbc7bee99874a5fe76ec89b94dde61960cec3 100644 (file)
@@ -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);
index f7b7113a4d63cfe20d0c68db42c6936c0e664969..e7b07c36882f6c18e50c78b3431516f3b34e6b87 100644 (file)
@@ -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);
                        }
                }
        }
index 8b86fe8c9a238f49aa282f0bd90fdac2cdd0d074..4830aa3334e27f963522984d02a25733672ee63d 100644 (file)
@@ -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, color);
+               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];
+
+               DRW_shgroup_call_dynamic_add(stl->g_data->mball_handle, draw_scale_xform, &ml->rad, color);
        }
 }
 
index d1f001fccc4f91d2f5f55b9ada5e0f60878635d3..fade313e29e938bbcb819834e2a3b9876b06cdc8 100644 (file)
@@ -59,11 +59,6 @@ typedef struct MetaElem {
        float len;              /* old, only used for backwards compat. use dimensions now */
        
        float *mat, *imat;      /* matrix and inverted matrix */
-
-       /* Draw_Data: stores pointers used for shader attributes */
-       float draw_scale_xform[3][4]; /* Matrix of Scale and Translation */
-       float draw_stiffness_radius; /* radius of the stiffness circle (only in edit mode) */
-       float pad;
 } MetaElem;
 
 typedef struct MetaBall {