Merge branch 'blender2.7'
[blender.git] / source / blender / draw / intern / draw_armature.c
index 4b9a1cef9ba780933e331f815d3c0fe26beb89f4..f22350113e7890e90b16d1fd6990e875abbc4b67 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  * Copyright 2016, Blender Foundation.
- * Contributor(s): Blender Institute
- *
- * ***** END GPL LICENSE BLOCK *****
- *
  */
 
-/** \file draw_armature.c
- *  \ingroup draw
+/** \file
+ * \ingroup draw
  */
 
 #include <stdlib.h>
@@ -124,16 +118,18 @@ static struct {
 /* Octahedral */
 static void drw_shgroup_bone_octahedral(
         const float (*bone_mat)[4],
-        const float bone_color[4], const float hint_color[4], const float outline_color[4])
+        const float bone_color[4], const float hint_color[4], const float outline_color[4],
+        const eGPUShaderConfig sh_cfg)
 {
        if (g_data.bone_octahedral_outline == NULL) {
                struct GPUBatch *geom = DRW_cache_bone_octahedral_wire_get();
-               g_data.bone_octahedral_outline = shgroup_instance_bone_shape_outline(g_data.passes.bone_outline, geom);
+               g_data.bone_octahedral_outline = shgroup_instance_bone_shape_outline(
+                       g_data.passes.bone_outline, geom, sh_cfg);
        }
        if (g_data.bone_octahedral_solid == NULL) {
                struct GPUBatch *geom = DRW_cache_bone_octahedral_get();
-               g_data.bone_octahedral_solid = shgroup_instance_bone_shape_solid(g_data.passes.bone_solid, geom,
-                                                                                g_data.transparent);
+               g_data.bone_octahedral_solid = shgroup_instance_bone_shape_solid(
+                       g_data.passes.bone_solid, geom, g_data.transparent, sh_cfg);
        }
        float final_bonemat[4][4];
        mul_m4_m4m4(final_bonemat, g_data.ob->obmat, bone_mat);
@@ -146,15 +142,18 @@ static void drw_shgroup_bone_octahedral(
 /* Box / B-Bone */
 static void drw_shgroup_bone_box(
         const float (*bone_mat)[4],
-        const float bone_color[4], const float hint_color[4], const float outline_color[4])
+        const float bone_color[4], const float hint_color[4], const float outline_color[4],
+        const eGPUShaderConfig sh_cfg)
 {
        if (g_data.bone_box_wire == NULL) {
                struct GPUBatch *geom = DRW_cache_bone_box_wire_get();
-               g_data.bone_box_outline = shgroup_instance_bone_shape_outline(g_data.passes.bone_outline, geom);
+               g_data.bone_box_outline = shgroup_instance_bone_shape_outline(
+                       g_data.passes.bone_outline, geom, sh_cfg);
        }
        if (g_data.bone_box_solid == NULL) {
                struct GPUBatch *geom = DRW_cache_bone_box_get();
-               g_data.bone_box_solid = shgroup_instance_bone_shape_solid(g_data.passes.bone_solid, geom, g_data.transparent);
+               g_data.bone_box_solid = shgroup_instance_bone_shape_solid(
+                       g_data.passes.bone_solid, geom, g_data.transparent, sh_cfg);
        }
        float final_bonemat[4][4];
        mul_m4_m4m4(final_bonemat, g_data.ob->obmat, bone_mat);
@@ -165,10 +164,12 @@ static void drw_shgroup_bone_box(
 }
 
 /* Wire */
-static void drw_shgroup_bone_wire(const float (*bone_mat)[4], const float color[4])
+static void drw_shgroup_bone_wire(
+        const float (*bone_mat)[4], const float color[4],
+        const eGPUShaderConfig sh_cfg)
 {
        if (g_data.bone_wire == NULL) {
-               g_data.bone_wire = shgroup_dynlines_flat_color(g_data.passes.bone_wire);
+               g_data.bone_wire = shgroup_dynlines_flat_color(g_data.passes.bone_wire, sh_cfg);
        }
        float head[3], tail[3];
        mul_v3_m4v3(head, g_data.ob->obmat, bone_mat[3]);
@@ -182,10 +183,11 @@ static void drw_shgroup_bone_wire(const float (*bone_mat)[4], const float color[
 /* Stick */
 static void drw_shgroup_bone_stick(
         const float (*bone_mat)[4],
-        const float col_wire[4], const float col_bone[4], const float col_head[4], const float col_tail[4])
+        const float col_wire[4], const float col_bone[4], const float col_head[4], const float col_tail[4],
+        const eGPUShaderConfig sh_cfg)
 {
        if (g_data.bone_stick == NULL) {
-               g_data.bone_stick = shgroup_instance_bone_stick(g_data.passes.bone_wire);
+               g_data.bone_stick = shgroup_instance_bone_stick(g_data.passes.bone_wire, sh_cfg);
        }
        float final_bonemat[4][4], tail[4];
        mul_m4_m4m4(final_bonemat, g_data.ob->obmat, bone_mat);
@@ -312,7 +314,7 @@ extern void drw_batch_cache_generate_requested(Object *custom);
 static void drw_shgroup_bone_custom_solid(
         const float (*bone_mat)[4],
         const float bone_color[4], const float hint_color[4], const float outline_color[4],
-        Object *custom)
+        const eGPUShaderConfig sh_cfg, Object *custom)
 {
        /* grr, not re-using instances! */
        struct GPUBatch *surf = DRW_cache_object_surface_get(custom);
@@ -328,13 +330,14 @@ static void drw_shgroup_bone_custom_solid(
        }
 
        if (surf) {
-               DRWShadingGroup *shgrp_geom_solid = shgroup_instance_bone_shape_solid(g_data.passes.bone_solid, surf,
-                                                                                     g_data.transparent);
+               DRWShadingGroup *shgrp_geom_solid = shgroup_instance_bone_shape_solid(
+                       g_data.passes.bone_solid, surf, g_data.transparent, sh_cfg);
                DRW_shgroup_call_dynamic_add(shgrp_geom_solid, final_bonemat, bone_color, hint_color);
        }
 
        if (edges && outline_color[3] > 0.0f) {
-               DRWShadingGroup *shgrp_geom_wire = shgroup_instance_bone_shape_outline(g_data.passes.bone_outline, edges);
+               DRWShadingGroup *shgrp_geom_wire = shgroup_instance_bone_shape_outline(
+                       g_data.passes.bone_outline, edges, sh_cfg);
                DRW_shgroup_call_dynamic_add(shgrp_geom_wire, final_bonemat, outline_color);
        }
 
@@ -1255,7 +1258,7 @@ static void draw_points(
 static void draw_bone_custom_shape(
         EditBone *eBone, bPoseChannel *pchan, bArmature *arm,
         const int boneflag, const short constflag,
-        const int select_id)
+        const eGPUShaderConfig sh_cfg, const int select_id)
 {
        const float *col_solid = get_bone_solid_color(eBone, pchan, arm, boneflag, constflag);
        const float *col_wire = get_bone_wire_color(eBone, pchan, arm, boneflag, constflag);
@@ -1267,7 +1270,7 @@ static void draw_bone_custom_shape(
        }
 
        if ((boneflag & BONE_DRAWWIRE) == 0) {
-               drw_shgroup_bone_custom_solid(disp_mat, col_solid, col_hint, col_wire, pchan->custom);
+               drw_shgroup_bone_custom_solid(disp_mat, col_solid, col_hint, col_wire, sh_cfg, pchan->custom);
        }
        else {
                drw_shgroup_bone_custom_wire(disp_mat, col_wire, pchan->custom);
@@ -1323,7 +1326,8 @@ static void draw_bone_envelope(
 
 static void draw_bone_line(
         EditBone *eBone, bPoseChannel *pchan, bArmature *arm,
-        const int boneflag, const short constflag, const int select_id)
+        const int boneflag, const short constflag,
+        const eGPUShaderConfig sh_cfg, const int select_id)
 {
        const float *col_bone = get_bone_solid_with_consts_color(eBone, pchan, arm, boneflag, constflag);
        const float *col_wire = get_bone_wire_color(eBone, pchan, arm, boneflag, constflag);
@@ -1361,20 +1365,20 @@ static void draw_bone_line(
 
        if (select_id == -1) {
                /* Not in selection mode, draw everything at once. */
-               drw_shgroup_bone_stick(BONE_VAR(eBone, pchan, disp_mat), col_wire, col_bone, col_head, col_tail);
+               drw_shgroup_bone_stick(BONE_VAR(eBone, pchan, disp_mat), col_wire, col_bone, col_head, col_tail, sh_cfg);
        }
        else {
                /* In selection mode, draw bone, root and tip separately. */
                DRW_select_load_id(select_id | BONESEL_BONE);
-               drw_shgroup_bone_stick(BONE_VAR(eBone, pchan, disp_mat), col_wire, col_bone, no_display, no_display);
+               drw_shgroup_bone_stick(BONE_VAR(eBone, pchan, disp_mat), col_wire, col_bone, no_display, no_display, sh_cfg);
 
                if (col_head[3] > 0.0f) {
                        DRW_select_load_id(select_id | BONESEL_ROOT);
-                       drw_shgroup_bone_stick(BONE_VAR(eBone, pchan, disp_mat), col_wire, no_display, col_head, no_display);
+                       drw_shgroup_bone_stick(BONE_VAR(eBone, pchan, disp_mat), col_wire, no_display, col_head, no_display, sh_cfg);
                }
 
                DRW_select_load_id(select_id | BONESEL_TIP);
-               drw_shgroup_bone_stick(BONE_VAR(eBone, pchan, disp_mat), col_wire, no_display, no_display, col_tail);
+               drw_shgroup_bone_stick(BONE_VAR(eBone, pchan, disp_mat), col_wire, no_display, no_display, col_tail, sh_cfg);
 
                DRW_select_load_id(-1);
        }
@@ -1383,7 +1387,7 @@ static void draw_bone_line(
 static void draw_bone_wire(
         EditBone *eBone, bPoseChannel *pchan, bArmature *arm,
         const int boneflag, const short constflag,
-        const int select_id)
+        const eGPUShaderConfig sh_cfg, const int select_id)
 {
        const float *col_wire = get_bone_wire_color(eBone, pchan, arm, boneflag, constflag);
 
@@ -1396,12 +1400,12 @@ static void draw_bone_wire(
                BLI_assert(bbones_mat != NULL);
 
                for (int i = pchan->bone->segments; i--; bbones_mat++) {
-                       drw_shgroup_bone_wire(bbones_mat->mat, col_wire);
+                       drw_shgroup_bone_wire(bbones_mat->mat, col_wire, sh_cfg);
                }
        }
        else if (eBone) {
                for (int i = 0; i < eBone->segments; i++) {
-                       drw_shgroup_bone_wire(eBone->disp_bbone_mat[i], col_wire);
+                       drw_shgroup_bone_wire(eBone->disp_bbone_mat[i], col_wire, sh_cfg);
                }
        }
 
@@ -1417,7 +1421,7 @@ static void draw_bone_wire(
 static void draw_bone_box(
         EditBone *eBone, bPoseChannel *pchan, bArmature *arm,
         const int boneflag, const short constflag,
-        const int select_id)
+        const eGPUShaderConfig sh_cfg, const int select_id)
 {
        const float *col_solid = get_bone_solid_with_consts_color(eBone, pchan, arm, boneflag, constflag);
        const float *col_wire = get_bone_wire_color(eBone, pchan, arm, boneflag, constflag);
@@ -1432,12 +1436,12 @@ static void draw_bone_box(
                BLI_assert(bbones_mat != NULL);
 
                for (int i = pchan->bone->segments; i--; bbones_mat++) {
-                       drw_shgroup_bone_box(bbones_mat->mat, col_solid, col_hint, col_wire);
+                       drw_shgroup_bone_box(bbones_mat->mat, col_solid, col_hint, col_wire, sh_cfg);
                }
        }
        else if (eBone) {
                for (int i = 0; i < eBone->segments; i++) {
-                       drw_shgroup_bone_box(eBone->disp_bbone_mat[i], col_solid, col_hint, col_wire);
+                       drw_shgroup_bone_box(eBone->disp_bbone_mat[i], col_solid, col_hint, col_wire, sh_cfg);
                }
        }
 
@@ -1453,7 +1457,7 @@ static void draw_bone_box(
 static void draw_bone_octahedral(
         EditBone *eBone, bPoseChannel *pchan, bArmature *arm,
         const int boneflag, const short constflag,
-        const int select_id)
+        const eGPUShaderConfig sh_cfg, const int select_id)
 {
        const float *col_solid = get_bone_solid_with_consts_color(eBone, pchan, arm, boneflag, constflag);
        const float *col_wire = get_bone_wire_color(eBone, pchan, arm, boneflag, constflag);
@@ -1463,7 +1467,7 @@ static void draw_bone_octahedral(
                DRW_select_load_id(select_id | BONESEL_BONE);
        }
 
-       drw_shgroup_bone_octahedral(BONE_VAR(eBone, pchan, disp_mat), col_solid, col_hint, col_wire);
+       drw_shgroup_bone_octahedral(BONE_VAR(eBone, pchan, disp_mat), col_solid, col_hint, col_wire, sh_cfg);
 
        if (select_id != -1) {
                DRW_select_load_id(-1);
@@ -1691,7 +1695,7 @@ static void draw_armature_edit(Object *ob)
        const bool show_text = DRW_state_show_text();
        const bool show_relations = ((draw_ctx->v3d->flag & V3D_HIDE_HELPLINES) == 0);
 
-       for (eBone = arm->edbo->first, index = ob->select_color; eBone; eBone = eBone->next, index += 0x10000) {
+       for (eBone = arm->edbo->first, index = ob->select_id; eBone; eBone = eBone->next, index += 0x10000) {
                if (eBone->layer & arm->layer) {
                        if ((eBone->flag & BONE_HIDDEN_A) == 0) {
                                const int select_id = is_select ? index : (uint)-1;
@@ -1717,19 +1721,19 @@ static void draw_armature_edit(Object *ob)
                                }
                                else if (arm->drawtype == ARM_LINE) {
                                        draw_bone_update_disp_matrix_default(eBone, NULL);
-                                       draw_bone_line(eBone, NULL, arm, boneflag, constflag, select_id);
+                                       draw_bone_line(eBone, NULL, arm, boneflag, constflag, draw_ctx->sh_cfg, select_id);
                                }
                                else if (arm->drawtype == ARM_WIRE) {
                                        draw_bone_update_disp_matrix_bbone(eBone, NULL);
-                                       draw_bone_wire(eBone, NULL, arm, boneflag, constflag, select_id);
+                                       draw_bone_wire(eBone, NULL, arm, boneflag, constflag, draw_ctx->sh_cfg, select_id);
                                }
                                else if (arm->drawtype == ARM_B_BONE) {
                                        draw_bone_update_disp_matrix_bbone(eBone, NULL);
-                                       draw_bone_box(eBone, NULL, arm, boneflag, constflag, select_id);
+                                       draw_bone_box(eBone, NULL, arm, boneflag, constflag, draw_ctx->sh_cfg, select_id);
                                }
                                else {
                                        draw_bone_update_disp_matrix_default(eBone, NULL);
-                                       draw_bone_octahedral(eBone, NULL, arm, boneflag, constflag, select_id);
+                                       draw_bone_octahedral(eBone, NULL, arm, boneflag, constflag, draw_ctx->sh_cfg, select_id);
                                }
 
                                /* Draw names of bone */
@@ -1779,7 +1783,7 @@ static void draw_armature_pose(Object *ob, const float const_color[4])
                }
 
                if (arm->flag & ARM_POSEMODE) {
-                       index = ob->select_color;
+                       index = ob->select_id;
                }
        }
 
@@ -1824,7 +1828,7 @@ static void draw_armature_pose(Object *ob, const float const_color[4])
 
                                if ((pchan->custom) && !(arm->flag & ARM_NO_CUSTOM)) {
                                        draw_bone_update_disp_matrix_custom(pchan);
-                                       draw_bone_custom_shape(NULL, pchan, arm, boneflag, constflag, select_id);
+                                       draw_bone_custom_shape(NULL, pchan, arm, boneflag, constflag, draw_ctx->sh_cfg, select_id);
                                }
                                else if (arm->drawtype == ARM_ENVELOPE) {
                                        draw_bone_update_disp_matrix_default(NULL, pchan);
@@ -1832,19 +1836,19 @@ static void draw_armature_pose(Object *ob, const float const_color[4])
                                }
                                else if (arm->drawtype == ARM_LINE) {
                                        draw_bone_update_disp_matrix_default(NULL, pchan);
-                                       draw_bone_line(NULL, pchan, arm, boneflag, constflag, select_id);
+                                       draw_bone_line(NULL, pchan, arm, boneflag, constflag, draw_ctx->sh_cfg, select_id);
                                }
                                else if (arm->drawtype == ARM_WIRE) {
                                        draw_bone_update_disp_matrix_bbone(NULL, pchan);
-                                       draw_bone_wire(NULL, pchan, arm, boneflag, constflag, select_id);
+                                       draw_bone_wire(NULL, pchan, arm, boneflag, constflag, draw_ctx->sh_cfg, select_id);
                                }
                                else if (arm->drawtype == ARM_B_BONE) {
                                        draw_bone_update_disp_matrix_bbone(NULL, pchan);
-                                       draw_bone_box(NULL, pchan, arm, boneflag, constflag, select_id);
+                                       draw_bone_box(NULL, pchan, arm, boneflag, constflag, draw_ctx->sh_cfg, select_id);
                                }
                                else {
                                        draw_bone_update_disp_matrix_default(NULL, pchan);
-                                       draw_bone_octahedral(NULL, pchan, arm, boneflag, constflag, select_id);
+                                       draw_bone_octahedral(NULL, pchan, arm, boneflag, constflag, draw_ctx->sh_cfg, select_id);
                                }
 
                                if (!is_pose_select && show_relations &&