[Bf-blender-cvs] [4ddf3215a7d] blender-v2.81-release: Fix T68380 Skin modifier root not displayed

Clément Foucault noreply at git.blender.org
Wed Oct 16 19:03:39 CEST 2019


Commit: 4ddf3215a7df3ac4a0cfceccb283414510078ba5
Author: Clément Foucault
Date:   Tue Oct 15 01:49:53 2019 +0200
Branches: blender-v2.81-release
https://developer.blender.org/rB4ddf3215a7df3ac4a0cfceccb283414510078ba5

Fix T68380 Skin modifier root not displayed

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

M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/intern/draw_cache_extract.h
M	source/blender/draw/intern/draw_cache_extract_mesh.c
M	source/blender/draw/intern/draw_cache_impl.h
M	source/blender/draw/intern/draw_cache_impl_mesh.c
M	source/blender/draw/intern/draw_common.c
M	source/blender/draw/intern/draw_common.h
M	source/blender/draw/modes/edit_mesh_mode.c
M	source/blender/draw/modes/shaders/common_globals_lib.glsl
A	source/blender/draw/modes/shaders/edit_mesh_skin_root_vert.glsl

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

diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 64a5caf80d4..950adf3ddc5 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -293,6 +293,7 @@ data_to_c_simple(modes/shaders/edit_mesh_overlay_facefill_vert.glsl SRC)
 data_to_c_simple(modes/shaders/edit_mesh_overlay_facefill_frag.glsl SRC)
 data_to_c_simple(modes/shaders/edit_mesh_overlay_mesh_analysis_frag.glsl SRC)
 data_to_c_simple(modes/shaders/edit_mesh_overlay_mesh_analysis_vert.glsl SRC)
+data_to_c_simple(modes/shaders/edit_mesh_skin_root_vert.glsl SRC)
 data_to_c_simple(modes/shaders/edit_curve_overlay_handle_vert.glsl SRC)
 data_to_c_simple(modes/shaders/edit_curve_overlay_handle_geom.glsl SRC)
 data_to_c_simple(modes/shaders/edit_curve_overlay_loosevert_vert.glsl SRC)
diff --git a/source/blender/draw/intern/draw_cache_extract.h b/source/blender/draw/intern/draw_cache_extract.h
index 46193e255b5..b1eab3c73ae 100644
--- a/source/blender/draw/intern/draw_cache_extract.h
+++ b/source/blender/draw/intern/draw_cache_extract.h
@@ -81,7 +81,7 @@ BLI_INLINE int mesh_render_mat_len_get(Mesh *me)
 
 typedef struct MeshBufferCache {
   /* Every VBO below contains at least enough
-   * data for every loops in the mesh (except fdots).
+   * data for every loops in the mesh (except fdots and skin roots).
    * For some VBOs, it extends to (in this exact order) :
    * loops + loose_edges*2 + loose_verts */
   struct {
@@ -104,6 +104,7 @@ typedef struct MeshBufferCache {
     GPUVertBuf *fdots_uv;
     // GPUVertBuf *fdots_edit_data; /* inside fdots_nor for now. */
     GPUVertBuf *fdots_edituv_data;
+    GPUVertBuf *skin_roots;
     /* Selection */
     GPUVertBuf *vert_idx; /* extend */
     GPUVertBuf *edge_idx; /* extend */
@@ -157,6 +158,7 @@ typedef enum DRWBatchFlag {
   MBC_WIRE_LOOPS = (1 << 24),
   MBC_WIRE_LOOPS_UVS = (1 << 25),
   MBC_SURF_PER_MAT = (1 << 26),
+  MBC_SKIN_ROOTS = (1 << 27),
 } DRWBatchFlag;
 
 #define MBC_EDITUV \
@@ -185,6 +187,7 @@ typedef struct MeshBatchCache {
     GPUBatch *edit_lnor;
     GPUBatch *edit_fdots;
     GPUBatch *edit_mesh_analysis;
+    GPUBatch *edit_skin_roots;
     /* Edit UVs */
     GPUBatch *edituv_faces_stretch_area;
     GPUBatch *edituv_faces_stretch_angle;
diff --git a/source/blender/draw/intern/draw_cache_extract_mesh.c b/source/blender/draw/intern/draw_cache_extract_mesh.c
index 2ac97196b99..0479bdd4de7 100644
--- a/source/blender/draw/intern/draw_cache_extract_mesh.c
+++ b/source/blender/draw/intern/draw_cache_extract_mesh.c
@@ -3859,6 +3859,69 @@ static const MeshExtract extract_fdots_edituv_data = {
 };
 /** \} */
 
+/* ---------------------------------------------------------------------- */
+/** \name Extract Skin Modifier Roots
+ * \{ */
+
+typedef struct SkinRootData {
+  float size;
+  float local_pos[3];
+} SkinRootData;
+
+static void *extract_skin_roots_init(const MeshRenderData *mr, void *buf)
+{
+  /* Exclusively for edit mode. */
+  BLI_assert(mr->bm);
+
+  static GPUVertFormat format = {0};
+  if (format.attr_len == 0) {
+    GPU_vertformat_attr_add(&format, "size", GPU_COMP_F32, 1, GPU_FETCH_FLOAT);
+    GPU_vertformat_attr_add(&format, "local_pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+  }
+  GPUVertBuf *vbo = buf;
+  GPU_vertbuf_init_with_format(vbo, &format);
+  GPU_vertbuf_data_alloc(vbo, mr->bm->totvert);
+
+  SkinRootData *vbo_data = (SkinRootData *)vbo->data;
+
+  int root_len = 0;
+  int cd_ofs = CustomData_get_offset(&mr->bm->vdata, CD_MVERT_SKIN);
+
+  BMIter iter;
+  BMVert *eve;
+  BM_ITER_MESH (eve, &iter, mr->bm, BM_VERTS_OF_MESH) {
+    const MVertSkin *vs = BM_ELEM_CD_GET_VOID_P(eve, cd_ofs);
+    if (vs->flag & MVERT_SKIN_ROOT) {
+      vbo_data->size = (vs->radius[0] + vs->radius[1]) * 0.5f;
+      copy_v3_v3(vbo_data->local_pos, eve->co);
+      vbo_data++;
+      root_len++;
+    }
+  }
+
+  /* It's really unlikely that all verts will be roots. Resize to avoid loosing VRAM. */
+  GPU_vertbuf_data_len_set(vbo, root_len);
+
+  return NULL;
+}
+
+static const MeshExtract extract_skin_roots = {
+    extract_skin_roots_init,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    0,
+    false,
+};
+
+/** \} */
+
 /* ---------------------------------------------------------------------- */
 /** \name Extract Selection Index
  * \{ */
@@ -4358,6 +4421,7 @@ void mesh_buffer_cache_create_requested(MeshBatchCache *cache,
   EXTRACT(vbo, edge_idx);
   EXTRACT(vbo, vert_idx);
   EXTRACT(vbo, fdot_idx);
+  EXTRACT(vbo, skin_roots);
 
   EXTRACT(ibo, tris);
   EXTRACT(ibo, lines);
diff --git a/source/blender/draw/intern/draw_cache_impl.h b/source/blender/draw/intern/draw_cache_impl.h
index cdc1791b153..8cb318bd0bb 100644
--- a/source/blender/draw/intern/draw_cache_impl.h
+++ b/source/blender/draw/intern/draw_cache_impl.h
@@ -142,6 +142,7 @@ struct GPUBatch *DRW_mesh_batch_cache_get_edit_edges(struct Mesh *me);
 struct GPUBatch *DRW_mesh_batch_cache_get_edit_vnors(struct Mesh *me);
 struct GPUBatch *DRW_mesh_batch_cache_get_edit_lnors(struct Mesh *me);
 struct GPUBatch *DRW_mesh_batch_cache_get_edit_facedots(struct Mesh *me);
+struct GPUBatch *DRW_mesh_batch_cache_get_edit_skin_roots(struct Mesh *me);
 /* edit-mesh selection */
 struct GPUBatch *DRW_mesh_batch_cache_get_triangles_with_select_id(struct Mesh *me);
 struct GPUBatch *DRW_mesh_batch_cache_get_facedots_with_select_id(struct Mesh *me);
diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c
index b8b657354b2..49db8bd9765 100644
--- a/source/blender/draw/intern/draw_cache_impl_mesh.c
+++ b/source/blender/draw/intern/draw_cache_impl_mesh.c
@@ -879,6 +879,13 @@ GPUBatch *DRW_mesh_batch_cache_get_edit_facedots(Mesh *me)
   return DRW_batch_request(&cache->batch.edit_fdots);
 }
 
+GPUBatch *DRW_mesh_batch_cache_get_edit_skin_roots(Mesh *me)
+{
+  MeshBatchCache *cache = mesh_batch_cache_get(me);
+  mesh_batch_cache_add_request(cache, MBC_SKIN_ROOTS);
+  return DRW_batch_request(&cache->batch.edit_skin_roots);
+}
+
 /** \} */
 
 /* ---------------------------------------------------------------------- */
@@ -1319,6 +1326,18 @@ void DRW_mesh_batch_cache_create_requested(
     DRW_vbo_request(cache->batch.edit_fdots, &mbufcache->vbo.fdots_pos);
     DRW_vbo_request(cache->batch.edit_fdots, &mbufcache->vbo.fdots_nor);
   }
+  if (DRW_batch_requested(cache->batch.edit_skin_roots, GPU_PRIM_LINES)) {
+    DRW_vbo_request(cache->batch.edit_skin_roots, &mbufcache->vbo.skin_roots);
+    /* HACK(fclem): This is a workaround the deferred batch init
+     * that prevent drawing using DRW_shgroup_call_instances_with_attribs.
+     * So we instead create the whole instancing batch here.
+     * Note that we use GPU_PRIM_LINES instead of expected GPU_PRIM_LINE_STRIP
+     * in order to mimic the old stipple pattern. */
+    cache->batch.edit_skin_roots->inst = cache->batch.edit_skin_roots->verts[0];
+    cache->batch.edit_skin_roots->verts[0] = NULL;
+    GPUBatch *circle = DRW_cache_screenspace_circle_get();
+    GPU_batch_vertbuf_add(cache->batch.edit_skin_roots, circle->verts[0]);
+  }
 
   /* Selection */
   if (DRW_batch_requested(cache->batch.edit_selection_verts, GPU_PRIM_POINTS)) {
diff --git a/source/blender/draw/intern/draw_common.c b/source/blender/draw/intern/draw_common.c
index 988859c64a5..c04425ded3f 100644
--- a/source/blender/draw/intern/draw_common.c
+++ b/source/blender/draw/intern/draw_common.c
@@ -83,6 +83,7 @@ void DRW_globals_update(void)
   UI_GetThemeColor4fv(TH_VNORMAL, gb->colorVNormal);
   UI_GetThemeColor4fv(TH_LNORMAL, gb->colorLNormal);
   UI_GetThemeColor4fv(TH_FACE_DOT, gb->colorFaceDot);
+  UI_GetThemeColor4fv(TH_SKIN_ROOT, gb->colorSkinRoot);
   UI_GetThemeColor4fv(TH_BACK, gb->colorBackground);
 
   /* Custom median color to slightly affect the edit mesh colors. */
diff --git a/source/blender/draw/intern/draw_common.h b/source/blender/draw/intern/draw_common.h
index 9899b6c0194..01c0946247a 100644
--- a/source/blender/draw/intern/draw_common.h
+++ b/source/blender/draw/intern/draw_common.h
@@ -73,6 +73,7 @@ typedef struct GlobalsUboStorage {
   float colorVNormal[4];
   float colorLNormal[4];
   float colorFaceDot[4];
+  float colorSkinRoot[4];
 
   float colorDeselect[4];
   float colorOutline[4];
diff --git a/source/blender/draw/modes/edit_mesh_mode.c b/source/blender/draw/modes/edit_mesh_mode.c
index 30fb6c9845c..623a4a52aed 100644
--- a/source/blender/draw/modes/edit_mesh_mode.c
+++ b/source/blender/draw/modes/edit_mesh_mode.c
@@ -55,6 +55,7 @@ extern char datatoc_edit_mesh_overlay_mesh_analysis_frag_glsl[];
 extern char datatoc_edit_mesh_overlay_mesh_analysis_vert_glsl[];
 extern char datatoc_edit_normals_vert_glsl[];
 extern char datatoc_edit_normals_geom_glsl[];
+extern char datatoc_edit_mesh_skin_root_vert_glsl[];
 extern char datatoc_common_globals_lib_glsl[];
 extern char datatoc_common_view_lib_glsl[];
 
@@ -114,6 +115,7 @@ typedef struct EDIT_MESH_Shaders {
   GPUShader *overlay_edge_flat;
   GPUShader *overlay_face;
   GPUShader *overlay_facedot;
+  GPUShader *overlay_skin_root;
 
   GPUShader *overlay_mix;
   GPUShader *overlay_facefill;
@@ -141,6 +143,7 @@ typedef struct EDIT_MESH_ComponentShadingGroupList {
   DRWShadingGroup *faces;
   DRWShadingGroup *faces_cage;
   DRWShadingGroup *facedots;
+  DRWShadingGroup *skin_roots;
 } EDIT_MESH_ComponentShadingGroupList;
 
 typedef struct EDIT_MESH_PrivateData {
@@ -266,6 +269,12 @@ static void EDIT_MESH_engine_init(void *vedata)
         .frag = (const char *[]){lib, datatoc_edit_mesh_overlay_facefill_frag_glsl, NULL},
         .defs = (const char *[]){sh_cfg_data->def, NULL},
     });
+    sh_data->overlay_skin_root = GPU_shader_create_from_arrays({
+        .vert = (const char *[]){lib, datatoc_edit_mesh_skin_root_vert_glsl, NULL},
+        .frag = (const char *[]){datatoc_gpu_shader_flat_color_frag_glsl, NULL},
+        .defs = (const char *[]){sh_cfg_data->def, NULL},
+    });
+
     MEM_freeN(lib);
 
     sh_data->overlay_mix = DRW_shader_create_fullscreen(datatoc_edit_mesh_overlay_mix_frag_glsl,
@@ -341,6 +350,7 @@ static void edit_mesh_create_overlay_passes(float face_alpha,
   GPUShader *edge_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list