Merge branch 'master' into blender2.8
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 15 Jan 2018 12:55:52 +0000 (13:55 +0100)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 15 Jan 2018 12:55:52 +0000 (13:55 +0100)
12 files changed:
1  2 
release/scripts/startup/bl_ui/space_view3d.py
release/scripts/startup/bl_ui/space_view3d_toolbar.py
source/blender/blenkernel/BKE_paint.h
source/blender/blenkernel/BKE_pbvh.h
source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/blenkernel/intern/paint.c
source/blender/blenkernel/intern/pbvh.c
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/gpu/GPU_buffers.h
source/blender/gpu/intern/gpu_buffers.c
source/blender/makesdna/DNA_scene_types.h
source/blender/makesrna/intern/rna_sculpt_paint.c

Simple merge
index 9aea5dc95a03408fb8ed538de67f3fd299dda11a,f619133ee4bc5ea7ddaeb83f2bc7b0d8752f7f08..5f37aa25de770b755ec6c2023075ae1a5ecf46f6
@@@ -373,7 -369,7 +373,8 @@@ bool BKE_pbvh_node_vert_update_check_an
  //void BKE_pbvh_node_BB_reset(PBVHNode *node);
  //void BKE_pbvh_node_BB_expand(PBVHNode *node, float co[3]);
  
 +bool pbvh_has_mask(PBVH *bvh);
  void pbvh_show_diffuse_color_set(PBVH *bvh, bool show_diffuse_color);
+ void pbvh_show_mask_set(PBVH *bvh, bool show_mask);
  
  #endif /* __BKE_PBVH_H__ */
index 37fdfd68dab7bda2a0a291efe5814ef443774dd5,d926c96c0d871ae273e927af743c4614356aa373..63f2c7e54526270fcf966b1a0f1842a745aed210
@@@ -2385,22 -2361,27 +2406,27 @@@ void pbvh_vertex_iter_init(PBVH *bvh, P
                vi->vmask = CustomData_get_layer(bvh->vdata, CD_PAINT_MASK);
  }
  
 -void pbvh_show_diffuse_color_set(PBVH *bvh, bool show_diffuse_color)
 +bool pbvh_has_mask(PBVH *bvh)
  {
 -      bool has_mask = false;
 -
        switch (bvh->type) {
                case PBVH_GRIDS:
 -                      has_mask = (bvh->gridkey.has_mask != 0);
 -                      break;
 +                      return (bvh->gridkey.has_mask != 0);
                case PBVH_FACES:
 -                      has_mask = (bvh->vdata && CustomData_get_layer(bvh->vdata,
 -                                                      CD_PAINT_MASK));
 -                      break;
 +                      return (bvh->vdata && CustomData_get_layer(bvh->vdata,
 +                                            CD_PAINT_MASK));
                case PBVH_BMESH:
 -                      has_mask = (bvh->bm && (CustomData_get_offset(&bvh->bm->vdata, CD_PAINT_MASK) != -1));
 -                      break;
 +                      return (bvh->bm && (CustomData_get_offset(&bvh->bm->vdata, CD_PAINT_MASK) != -1));
        }
  
 -      bvh->show_diffuse_color = !has_mask || show_diffuse_color;
 +      return false;
 +}
 +
 +void pbvh_show_diffuse_color_set(PBVH *bvh, bool show_diffuse_color)
 +{
 +      bvh->show_diffuse_color = !pbvh_has_mask(bvh) || show_diffuse_color;
  }
+ void pbvh_show_mask_set(PBVH *bvh, bool show_mask)
+ {
+       bvh->show_mask = show_mask;
+ }
index 30fd4bd30b8dd1db5294d3b8f5df157dc13d6db0,6ffaa29ead63ef45b73a09abec9c1f28c4b778c0..0d8a7a45ee98849a8c8e4af19dfe4f6204756ee5
@@@ -261,12 -266,14 +267,13 @@@ void GPU_pbvh_grid_buffers_update
  void GPU_pbvh_buffers_draw(
          GPU_PBVH_Buffers *buffers, DMSetMaterial setMaterial,
          bool wireframe, bool fast);
 +struct Gwn_Batch *GPU_pbvh_buffers_batch_get(GPU_PBVH_Buffers *buffers, bool fast);
  
 -/* debug PBVH draw*/
 -void GPU_pbvh_BB_draw(float min[3], float max[3], bool leaf);
 -void GPU_pbvh_BB_draw_init(void);
 -void GPU_pbvh_BB_draw_end(void);
 +/* debug PBVH draw */
 +void GPU_pbvh_BB_draw(float min[3], float max[3], bool leaf, unsigned int pos);
  
  bool GPU_pbvh_buffers_diffuse_changed(GPU_PBVH_Buffers *buffers, struct GSet *bm_faces, bool show_diffuse_color);
+ bool GPU_pbvh_buffers_mask_changed(GPU_PBVH_Buffers *buffers, bool show_mask);
  
  void GPU_pbvh_buffers_free(GPU_PBVH_Buffers *buffers);
  void GPU_pbvh_multires_buffers_free(struct GridCommonGPUBuffer **grid_common_gpu_buffer);
index 3a6b0a2a72d0264366498f4ed4c4baa9e955d466,afe7a4c4d2784046cfbadcbd425b1990166c0dcb..095021c12d8d768cbd9d39d07789ec9fd4a2b701
@@@ -1053,10 -1035,17 +1055,15 @@@ static void gpu_color_from_mask_quad_co
  void GPU_pbvh_mesh_buffers_update(
          GPU_PBVH_Buffers *buffers, const MVert *mvert,
          const int *vert_indices, int totvert, const float *vmask,
-         const int (*face_vert_indices)[3], bool show_diffuse_color)
+         const int (*face_vert_indices)[3],
+         const int update_flags)
  {
 -      VertexBufferFormat *vert_data;
 -      int i;
+       const bool show_diffuse_color = (update_flags & GPU_PBVH_BUFFERS_SHOW_DIFFUSE_COLOR) != 0;
+       const bool show_mask = (update_flags & GPU_PBVH_BUFFERS_SHOW_MASK) != 0;
        buffers->vmask = vmask;
        buffers->show_diffuse_color = show_diffuse_color;
+       buffers->show_mask = show_mask;
        buffers->use_matcaps = GPU_material_use_matcaps_get();
  
        {
                         * copies are made for flat shading because normals
                         * shouldn't be shared. */
                        if (buffers->smooth) {
 -                              for (i = 0; i < totvert; ++i) {
 +                              for (uint i = 0; i < totvert; ++i) {
                                        const MVert *v = &mvert[vert_indices[i]];
 -                                      VertexBufferFormat *out = vert_data + i;
 -
 -                                      copy_v3_v3(out->co, v->co);
 -                                      memcpy(out->no, v->no, sizeof(short) * 3);
 +                                      GWN_vertbuf_attr_set(buffers->vert_buf, vbo_id.pos, i, v->co);
 +                                      GWN_vertbuf_attr_set(buffers->vert_buf, vbo_id.nor, i, v->no);
                                }
  
 -                              for (i = 0; i < buffers->face_indices_len; i++) {
 +                              for (uint i = 0; i < buffers->face_indices_len; i++) {
                                        const MLoopTri *lt = &buffers->looptri[buffers->face_indices[i]];
                                        for (uint j = 0; j < 3; j++) {
 -                                              VertexBufferFormat *out = vert_data + face_vert_indices[i][j];
 -
 +                                              int vidx = face_vert_indices[i][j];
-                                               if (vmask) {
+                                               if (vmask && show_mask) {
 -                                                      uint v_index = buffers->mloop[lt->tri[j]].v;
 -                                                      gpu_color_from_mask_copy(vmask[v_index], diffuse_color, out->color);
 +                                                      int v_index = buffers->mloop[lt->tri[j]].v;
 +                                                      uchar color_ub[3];
 +                                                      gpu_color_from_mask_copy(vmask[v_index], diffuse_color, color_ub);
 +                                                      GWN_vertbuf_attr_set(buffers->vert_buf, vbo_id.col, vidx, color_ub);
                                                }
                                                else {
 -                                                      copy_v3_v3_uchar(out->color, diffuse_color_ub);
 +                                                      GWN_vertbuf_attr_set(buffers->vert_buf, vbo_id.col, vidx, diffuse_color_ub);
                                                }
                                        }
                                }
@@@ -1180,19 -1166,15 +1187,20 @@@ GPU_PBVH_Buffers *GPU_pbvh_mesh_buffers
          const int  face_indices_len)
  {
        GPU_PBVH_Buffers *buffers;
 -      unsigned short *tri_data;
 -      int i, j, tottri;
 +      int i, tottri;
  
        buffers = MEM_callocN(sizeof(GPU_PBVH_Buffers), "GPU_Buffers");
 -      buffers->index_type = GL_UNSIGNED_SHORT;
 +
 +      /* smooth or flat for all */
 +#if 0
        buffers->smooth = mpoly[looptri[face_indices[0]].poly].flag & ME_SMOOTH;
 +#else
 +      /* for DrawManager we dont support mixed smooth/flat */
 +      buffers->smooth = (mpoly[0].flag & ME_SMOOTH) != 0;
 +#endif
  
        buffers->show_diffuse_color = false;
+       buffers->show_mask = true;
        buffers->use_matcaps = false;
  
        /* Count the number of visible triangles */
  void GPU_pbvh_grid_buffers_update(
          GPU_PBVH_Buffers *buffers, CCGElem **grids,
          const DMFlagMat *grid_flag_mats, int *grid_indices,
-         int totgrid, const CCGKey *key, bool show_diffuse_color)
+         int totgrid, const CCGKey *key,
+         const int update_flags)
  {
 -      VertexBufferFormat *vert_data;
+       const bool show_diffuse_color = (update_flags & GPU_PBVH_BUFFERS_SHOW_DIFFUSE_COLOR) != 0;
+       const bool show_mask = (update_flags & GPU_PBVH_BUFFERS_SHOW_MASK) != 0;
        int i, j, k, x, y;
  
        buffers->show_diffuse_color = show_diffuse_color;
                                for (y = 0; y < key->grid_size; y++) {
                                        for (x = 0; x < key->grid_size; x++) {
                                                CCGElem *elem = CCG_grid_elem(key, grid, x, y);
 -                                              
 -                                              copy_v3_v3(vd->co, CCG_elem_co(key, elem));
 +                                              GWN_vertbuf_attr_set(buffers->vert_buf, vbo_id.pos, vbo_index, CCG_elem_co(key, elem));
 +
                                                if (buffers->smooth) {
 -                                                      normal_float_to_short_v3(vd->no, CCG_elem_no(key, elem));
 +                                                      short no_short[3];
 +                                                      normal_float_to_short_v3(no_short, CCG_elem_no(key, elem));
 +                                                      GWN_vertbuf_attr_set(buffers->vert_buf, vbo_id.nor, vbo_index, no_short);
  
-                                                       if (has_mask) {
+                                                       if (has_mask && show_mask) {
 +                                                              uchar color_ub[3];
                                                                gpu_color_from_mask_copy(*CCG_elem_mask(key, elem),
 -                                                                                       diffuse_color, vd->color);
 +                                                                                           diffuse_color, color_ub);
 +                                                              GWN_vertbuf_attr_set(buffers->vert_buf, vbo_id.col, vbo_index, color_ub);
                                                        }
                                                }
 -                                              vd++;
 +                                              vbo_index += 1;
                                        }
                                }
                                
@@@ -1536,36 -1549,32 +1549,45 @@@ GPU_PBVH_Buffers *GPU_pbvh_grid_buffers
   * index '*v_index' in the 'vert_data' array and '*v_index' is
   * incremented.
   */
 -static void gpu_bmesh_vert_to_buffer_copy(BMVert *v,
 -                                          VertexBufferFormat *vert_data,
 -                                          int *v_index,
 -                                          const float fno[3],
 -                                          const float *fmask,
 -                                          const int cd_vert_mask_offset,
 -                                          const float diffuse_color[4],
 -                                          const bool show_mask)
 +static void gpu_bmesh_vert_to_buffer_copy__gwn(
 +        BMVert *v,
 +        Gwn_VertBuf *vert_buf,
 +        const VertexBufferAttrID *vbo_id,
 +        int *v_index,
 +        const float fno[3],
 +        const float *fmask,
 +        const int cd_vert_mask_offset,
-         const float diffuse_color[4])
++        const float diffuse_color[4],
++        const bool show_mask)
  {
        if (!BM_elem_flag_test(v, BM_ELEM_HIDDEN)) {
 -              VertexBufferFormat *vd = &vert_data[*v_index];
  
                /* Set coord, normal, and mask */
 -              copy_v3_v3(vd->co, v->co);
 -              normal_float_to_short_v3(vd->no, fno ? fno : v->no);
 +              GWN_vertbuf_attr_set(vert_buf, vbo_id->pos, *v_index, v->co);
  
 -              float effective_mask;
 -              if (show_mask) {
 -                      effective_mask = fmask ? *fmask
 -                                             : BM_ELEM_CD_GET_FLOAT(v, cd_vert_mask_offset);
 -              }
 -              else {
 -                      effective_mask = 0.0f;
 +              {
 +                      short no_short[3];
 +                      normal_float_to_short_v3(no_short, fno ? fno : v->no);
 +                      GWN_vertbuf_attr_set(vert_buf, vbo_id->nor, *v_index, no_short);
                }
  
 -              gpu_color_from_mask_copy(effective_mask, diffuse_color, vd->color);
 +              {
 +                      uchar color_ub[3];
++                      float effective_mask;
++                      if (show_mask) {
++                              effective_mask = fmask ? *fmask
++                                                     : BM_ELEM_CD_GET_FLOAT(v, cd_vert_mask_offset);
++                      }
++                      else {
++                              effective_mask = 0.0f;
++                      }
++
 +                      gpu_color_from_mask_copy(
-                               fmask ? *fmask :
-                                       BM_ELEM_CD_GET_FLOAT(v, cd_vert_mask_offset),
++                              effective_mask,
 +                              diffuse_color,
 +                              color_ub);
 +                      GWN_vertbuf_attr_set(vert_buf, vbo_id->col, *v_index, color_ub);
 +              }
  
                /* Assign index for use in the triangle index buffer */
                /* note: caller must set:  bm->elem_index_dirty |= BM_VERT; */
@@@ -1620,8 -1629,12 +1642,10 @@@ void GPU_pbvh_bmesh_buffers_update
          GSet *bm_faces,
          GSet *bm_unique_verts,
          GSet *bm_other_verts,
-         bool show_diffuse_color)
+         const int update_flags)
  {
 -      VertexBufferFormat *vert_data;
 -      void *tri_data;
+       const bool show_diffuse_color = (update_flags & GPU_PBVH_BUFFERS_SHOW_DIFFUSE_COLOR) != 0;
+       const bool show_mask = (update_flags & GPU_PBVH_BUFFERS_SHOW_MASK) != 0;
        int tottri, totvert, maxvert = 0;
        float diffuse_color[4] = {0.8f, 0.8f, 0.8f, 1.0f};
  
                        bm->elem_index_dirty |= BM_VERT;
  
                        GSET_ITER (gs_iter, bm_unique_verts) {
 -                              gpu_bmesh_vert_to_buffer_copy(BLI_gsetIterator_getKey(&gs_iter),
 -                                                            vert_data, &v_index, NULL, NULL,
 -                                                            cd_vert_mask_offset, diffuse_color,
 -                                                            show_mask);
 +                              gpu_bmesh_vert_to_buffer_copy__gwn(
 +                                      BLI_gsetIterator_getKey(&gs_iter),
 +                                      buffers->vert_buf, &vbo_id, &v_index, NULL, NULL,
-                                       cd_vert_mask_offset, diffuse_color);
++                                      cd_vert_mask_offset, diffuse_color,
++                                      show_mask);
                        }
  
                        GSET_ITER (gs_iter, bm_other_verts) {
 -                              gpu_bmesh_vert_to_buffer_copy(BLI_gsetIterator_getKey(&gs_iter),
 -                                                            vert_data, &v_index, NULL, NULL,
 -                                                            cd_vert_mask_offset, diffuse_color,
 -                                                            show_mask);
 +                              gpu_bmesh_vert_to_buffer_copy__gwn(
 +                                      BLI_gsetIterator_getKey(&gs_iter),
 +                                      buffers->vert_buf, &vbo_id, &v_index, NULL, NULL,
-                                       cd_vert_mask_offset, diffuse_color);
++                                      cd_vert_mask_offset, diffuse_color,
++                                      show_mask);
                        }
  
                        maxvert = v_index;
                                        fmask /= 3.0f;
                                        
                                        for (i = 0; i < 3; i++) {
 -                                              gpu_bmesh_vert_to_buffer_copy(v[i], vert_data,
 -                                                                            &v_index, f->no, &fmask,
 -                                                                            cd_vert_mask_offset, diffuse_color,
 -                                                                            show_mask);
 +                                              gpu_bmesh_vert_to_buffer_copy__gwn(
 +                                                      v[i], buffers->vert_buf, &vbo_id,
 +                                                      &v_index, f->no, &fmask,
-                                                       cd_vert_mask_offset, diffuse_color);
++                                                      cd_vert_mask_offset, diffuse_color,
++                                                      show_mask);
                                        }
                                }
                        }
index ddcf525c3c87e857a7a8645491c877c1cd2f43e3,6dbfc3634b250916a92901626116f3bcedbdf050..cc447f2a0282e2dfdfa08ad449c9b8a69d9e5e7b
@@@ -297,6 -287,20 +297,22 @@@ static void rna_Sculpt_ShowDiffuseColor
        }
  }
  
 -static void rna_Sculpt_ShowMask_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr))
++static void rna_Sculpt_ShowMask_update(bContext *C, PointerRNA *UNUSED(ptr))
+ {
 -      Object *object = (scene->basact) ? scene->basact->object : NULL;
++      ViewLayer *view_layer = CTX_data_view_layer(C);
++      Object *object = OBACT(view_layer);
+       if (object == NULL || object->sculpt == NULL) {
+               return;
+       }
++      Scene *scene = CTX_data_scene(C);
+       Sculpt *sd = scene->toolsettings->sculpt;
+       object->sculpt->show_mask = ((sd->flags & SCULPT_HIDE_MASK) == 0);
+       if (object->sculpt->pbvh != NULL) {
+               pbvh_show_mask_set(object->sculpt->pbvh, object->sculpt->show_mask);
+       }
+       WM_main_add_notifier(NC_OBJECT | ND_DRAW, object);
+ }
  static char *rna_Sculpt_path(PointerRNA *UNUSED(ptr))
  {
        return BLI_strdup("tool_settings.sculpt");
@@@ -610,9 -606,13 +626,15 @@@ static void rna_def_sculpt(BlenderRNA  
        RNA_def_property_boolean_sdna(prop, NULL, "flags", SCULPT_SHOW_DIFFUSE);
        RNA_def_property_ui_text(prop, "Show Diffuse Color",
                                 "Show diffuse color of object and overlay sculpt mask on top of it");
 +      RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
        RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Sculpt_ShowDiffuseColor_update");
  
+       prop = RNA_def_property(srna, "show_mask", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_negative_sdna(prop, NULL, "flags", SCULPT_HIDE_MASK);
+       RNA_def_property_ui_text(prop, "Show Mask", "Show mask as overlay on object");
++      RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+       RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Sculpt_ShowMask_update");
        prop = RNA_def_property(srna, "detail_size", PROP_FLOAT, PROP_PIXEL);
        RNA_def_property_ui_range(prop, 0.5, 40.0, 10, 2);
        RNA_def_property_ui_text(prop, "Detail Size", "Maximum edge length for dynamic topology sculpting (in pixels)");