Armature: Cleanup: Remove unused function and use less silly wire drawing.
authorClément Foucault <foucault.clem@gmail.com>
Wed, 16 May 2018 16:01:32 +0000 (18:01 +0200)
committerClément Foucault <foucault.clem@gmail.com>
Wed, 16 May 2018 16:46:35 +0000 (18:46 +0200)
source/blender/draw/intern/DRW_render.h
source/blender/draw/intern/draw_armature.c
source/blender/draw/intern/draw_cache.c
source/blender/draw/intern/draw_cache.h
source/blender/draw/intern/draw_common.c
source/blender/draw/intern/draw_common.h
source/blender/draw/intern/draw_manager_data.c

index 827ac4701e558494697827bd9c87da5dc3441a02..574eb245d1b09dd4faf1f040a6a13bb2f02b5ea4 100644 (file)
@@ -315,6 +315,7 @@ DRWShadingGroup *DRW_shgroup_material_empty_tri_batch_create(struct GPUMaterial
 DRWShadingGroup *DRW_shgroup_instance_create(
         struct GPUShader *shader, DRWPass *pass, struct Gwn_Batch *geom, struct Gwn_VertFormat *format);
 DRWShadingGroup *DRW_shgroup_point_batch_create(struct GPUShader *shader, DRWPass *pass);
+DRWShadingGroup *DRW_shgroup_line_batch_create_with_format(struct GPUShader *shader, DRWPass *pass, struct Gwn_VertFormat *format);
 DRWShadingGroup *DRW_shgroup_line_batch_create(struct GPUShader *shader, DRWPass *pass);
 DRWShadingGroup *DRW_shgroup_empty_tri_batch_create(struct GPUShader *shader, DRWPass *pass, int size);
 DRWShadingGroup *DRW_shgroup_transform_feedback_create(struct GPUShader *shader, DRWPass *pass, struct Gwn_VertBuf *tf_target);
index 214513c1b4731f410611a8520e5fae1fe2d04eb5..b4c4b010b0805bdbe7bb2b1603ded12d76606f51 100644 (file)
@@ -81,7 +81,7 @@ static struct {
        DRWShadingGroup *bone_box_solid;
        DRWShadingGroup *bone_box_wire;
        DRWShadingGroup *bone_box_outline;
-       DRWShadingGroup *bone_wire_wire;
+       DRWShadingGroup *bone_wire;
        DRWShadingGroup *bone_stick;
        DRWShadingGroup *bone_envelope_solid;
        DRWShadingGroup *bone_envelope_distance;
@@ -171,17 +171,21 @@ static void drw_shgroup_bone_box(
 }
 
 /* Wire */
-static void drw_shgroup_bone_wire_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])
 {
-       if (g_data.bone_wire_wire == NULL) {
-               struct Gwn_Batch *geom = DRW_cache_bone_wire_wire_outline_get();
-               g_data.bone_wire_wire = shgroup_instance_wire(g_data.passes.bone_wire, geom);
+       if (g_data.bone_wire == NULL) {
+               g_data.bone_wire = shgroup_dynlines_flat_color(g_data.passes.bone_wire);
        }
-       float final_bonemat[4][4];
-       mul_m4_m4m4(final_bonemat, g_data.ob->obmat, bone_mat);
-       DRW_shgroup_call_dynamic_add(g_data.bone_wire_wire, final_bonemat, color);
+       float head[3], tail[3];
+       mul_v3_m4v3(head, g_data.ob->obmat, bone_mat[3]);
+       DRW_shgroup_call_dynamic_add(g_data.bone_wire, head, color);
+
+       add_v3_v3v3(tail, bone_mat[3], bone_mat[1]);
+       mul_m4_v3(g_data.ob->obmat, tail);
+       DRW_shgroup_call_dynamic_add(g_data.bone_wire, tail, 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])
@@ -1287,12 +1291,12 @@ static void draw_bone_wire(
                BLI_assert(bbones_mat != NULL);
 
                for (int i = pchan->bone->segments; i--; bbones_mat++) {
-                       drw_shgroup_bone_wire_wire(bbones_mat->mat, col_wire);
+                       drw_shgroup_bone_wire(bbones_mat->mat, col_wire);
                }
        }
        else if (eBone) {
                for (int i = 0; i < eBone->segments; i++) {
-                       drw_shgroup_bone_wire_wire(eBone->disp_bbone_mat[i], col_wire);
+                       drw_shgroup_bone_wire(eBone->disp_bbone_mat[i], col_wire);
                }
        }
 
index 639e4edb32f01de1eead322f7578a6c5464aba7c..7fa21cb209b45004582fa181207d1c15d64d4b41 100644 (file)
@@ -1650,37 +1650,6 @@ Gwn_Batch *DRW_cache_bone_octahedral_get(void)
        return SHC.drw_bone_octahedral;
 }
 
-Gwn_Batch *DRW_cache_bone_octahedral_wire_outline_get(void)
-{
-       if (!SHC.drw_bone_octahedral_wire) {
-               uint v_idx = 0;
-
-               static Gwn_VertFormat format = { 0 };
-               static struct { uint pos, n1, n2; } attr_id;
-               if (format.attrib_ct == 0) {
-                       attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
-                       attr_id.n1 = GWN_vertformat_attr_add(&format, "N1", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
-                       attr_id.n2 = GWN_vertformat_attr_add(&format, "N2", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
-               }
-
-               /* Vertices */
-               Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
-               GWN_vertbuf_data_alloc(vbo, 12 * 2);
-
-               for (int i = 0; i < 12; i++) {
-                       const float *co1 = bone_octahedral_verts[bone_octahedral_wire[i * 2]];
-                       const float *co2 = bone_octahedral_verts[bone_octahedral_wire[i * 2 + 1]];
-                       const float *n1 = bone_octahedral_solid_normals[bone_octahedral_wire_adjacent_face[i * 2]];
-                       const float *n2 = bone_octahedral_solid_normals[bone_octahedral_wire_adjacent_face[i * 2 + 1]];
-                       add_fancy_edge(vbo, attr_id.pos, attr_id.n1, attr_id.n2, &v_idx, co1, co2, n1, n2);
-               }
-
-               SHC.drw_bone_octahedral_wire = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
-       }
-       return SHC.drw_bone_octahedral_wire;
-}
-
-
 /* XXX TODO move that 1 unit cube to more common/generic place? */
 static const float bone_box_verts[8][3] = {
        { 1.0f, 0.0f,  1.0f},
@@ -1820,64 +1789,6 @@ Gwn_Batch *DRW_cache_bone_box_get(void)
        return SHC.drw_bone_box;
 }
 
-Gwn_Batch *DRW_cache_bone_box_wire_outline_get(void)
-{
-       if (!SHC.drw_bone_box_wire) {
-               uint v_idx = 0;
-
-               static Gwn_VertFormat format = { 0 };
-               static struct { uint pos, n1, n2; } attr_id;
-               if (format.attrib_ct == 0) {
-                       attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
-                       attr_id.n1 = GWN_vertformat_attr_add(&format, "N1", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
-                       attr_id.n2 = GWN_vertformat_attr_add(&format, "N2", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
-               }
-
-               /* Vertices */
-               Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
-               GWN_vertbuf_data_alloc(vbo, 12 * 2);
-
-               for (int i = 0; i < 12; i++) {
-                       const float *co1 = bone_box_verts[bone_box_wire[i * 2]];
-                       const float *co2 = bone_box_verts[bone_box_wire[i * 2 + 1]];
-                       const float *n1 = bone_box_solid_normals[bone_box_wire_adjacent_face[i * 2]];
-                       const float *n2 = bone_box_solid_normals[bone_box_wire_adjacent_face[i * 2 + 1]];
-                       add_fancy_edge(vbo, attr_id.pos, attr_id.n1, attr_id.n2, &v_idx, co1, co2, n1, n2);
-               }
-
-               SHC.drw_bone_box_wire = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
-       }
-       return SHC.drw_bone_box_wire;
-}
-
-
-Gwn_Batch *DRW_cache_bone_wire_wire_outline_get(void)
-{
-       if (!SHC.drw_bone_wire_wire) {
-               uint v_idx = 0;
-
-               static Gwn_VertFormat format = { 0 };
-               static struct { uint pos, n1, n2; } attr_id;
-               if (format.attrib_ct == 0) {
-                       attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
-                       attr_id.n1 = GWN_vertformat_attr_add(&format, "N1", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
-                       attr_id.n2 = GWN_vertformat_attr_add(&format, "N2", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
-               }
-
-               /* Vertices */
-               Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
-               GWN_vertbuf_data_alloc(vbo, 2);
-
-               const float co1[3] = {0.0f, 0.0f, 0.0f};
-               const float co2[3] = {0.0f, 1.0f, 0.0f};
-               const float n[3] = {1.0f, 0.0f, 0.0f};
-               add_fancy_edge(vbo, attr_id.pos, attr_id.n1, attr_id.n2, &v_idx, co1, co2, n, n);
-
-               SHC.drw_bone_wire_wire = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
-       }
-       return SHC.drw_bone_wire_wire;
-}
-
 /* Helpers for envelope bone's solid sphere-with-hidden-equatorial-cylinder.
  * Note that here we only encode head/tail in forth component of the vector. */
 static void benv_lat_lon_to_co(const float lat, const float lon, float r_nor[3])
index 6848285706a5772270be8f1ebe74c91a72f385d3..b9a569b3aceb0438abf07039ed70e126ef18e5fc 100644 (file)
@@ -97,10 +97,7 @@ struct Gwn_Batch *DRW_cache_lightprobe_planar_get(void);
 
 /* Bones */
 struct Gwn_Batch *DRW_cache_bone_octahedral_get(void);
-struct Gwn_Batch *DRW_cache_bone_octahedral_wire_outline_get(void);
 struct Gwn_Batch *DRW_cache_bone_box_get(void);
-struct Gwn_Batch *DRW_cache_bone_box_wire_outline_get(void);
-struct Gwn_Batch *DRW_cache_bone_wire_wire_outline_get(void);
 struct Gwn_Batch *DRW_cache_bone_envelope_solid_get(void);
 struct Gwn_Batch *DRW_cache_bone_envelope_outline_get(void);
 struct Gwn_Batch *DRW_cache_bone_envelope_head_wire_outline_get(void);
index ba5e04df512b0a2e63a50495dd7a08f82e1d8beb..b51b15b20ed733c5194e79b6b15cb6905593ca91 100644 (file)
@@ -203,6 +203,7 @@ static struct {
        struct Gwn_VertFormat *instance_bone_envelope_distance;
        struct Gwn_VertFormat *instance_bone_envelope_outline;
        struct Gwn_VertFormat *instance_mball_handles;
+       struct Gwn_VertFormat *dynlines_color;
 } g_formats = {NULL};
 
 void DRW_globals_free(void)
@@ -218,6 +219,20 @@ void DRW_globals_free(void)
        }
 }
 
+DRWShadingGroup *shgroup_dynlines_flat_color(DRWPass *pass)
+{
+       GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_FLAT_COLOR);
+
+       DRW_shgroup_instance_format(g_formats.dynlines_color, {
+               {"pos"      , DRW_ATTRIB_FLOAT, 3},
+               {"color"    , DRW_ATTRIB_FLOAT, 4}
+       });
+
+       DRWShadingGroup *grp = DRW_shgroup_line_batch_create_with_format(sh, pass, g_formats.dynlines_color);
+
+       return grp;
+}
+
 DRWShadingGroup *shgroup_dynlines_dashed_uniform_color(DRWPass *pass, float color[4])
 {
        GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR);
index 9c36ecd995cad214cbbb9ff097c27b7b641360f4..11cff02d6c9161464a4df44ea3b41ab6cf223586 100644 (file)
@@ -99,6 +99,7 @@ typedef struct GlobalsUboStorage {
 void DRW_globals_update(void);
 void DRW_globals_free(void);
 
+struct DRWShadingGroup *shgroup_dynlines_flat_color(struct DRWPass *pass);
 struct DRWShadingGroup *shgroup_dynlines_dashed_uniform_color(struct DRWPass *pass, float color[4]);
 struct DRWShadingGroup *shgroup_dynpoints_uniform_color(struct DRWPass *pass, float color[4], float *size);
 struct DRWShadingGroup *shgroup_groundlines_uniform_color(struct DRWPass *pass, float color[4]);
index 6f4de3bb02bc751649fa737f2ae918125f0e3b50..1e2036714bf082887e5632cb26ded938c9766480 100644 (file)
@@ -797,18 +797,23 @@ DRWShadingGroup *DRW_shgroup_point_batch_create(struct GPUShader *shader, DRWPas
        return shgroup;
 }
 
-DRWShadingGroup *DRW_shgroup_line_batch_create(struct GPUShader *shader, DRWPass *pass)
+DRWShadingGroup *DRW_shgroup_line_batch_create_with_format(struct GPUShader *shader, DRWPass *pass, Gwn_VertFormat *format)
 {
-       DRW_shgroup_instance_format(g_pos_format, {{"pos", DRW_ATTRIB_FLOAT, 3}});
-
        DRWShadingGroup *shgroup = drw_shgroup_create_ex(shader, pass);
        shgroup->type = DRW_SHG_LINE_BATCH;
 
-       drw_shgroup_batching_init(shgroup, shader, g_pos_format);
+       drw_shgroup_batching_init(shgroup, shader, format);
 
        return shgroup;
 }
 
+DRWShadingGroup *DRW_shgroup_line_batch_create(struct GPUShader *shader, DRWPass *pass)
+{
+       DRW_shgroup_instance_format(g_pos_format, {{"pos", DRW_ATTRIB_FLOAT, 3}});
+
+       return DRW_shgroup_line_batch_create_with_format(shader, pass, g_pos_format);
+}
+
 /* Very special batch. Use this if you position
  * your vertices with the vertex shader
  * and dont need any VBO attrib */