[Bf-blender-cvs] [2ba2efc2969] master: Cleanup: Simplify arguments to sculpt draw functions

Hans Goudey noreply at git.blender.org
Tue Aug 2 20:33:16 CEST 2022


Commit: 2ba2efc29691762d3fb2002f54adafd536b2c37b
Author: Hans Goudey
Date:   Tue Aug 2 13:32:25 2022 -0500
Branches: master
https://developer.blender.org/rB2ba2efc29691762d3fb2002f54adafd536b2c37b

Cleanup: Simplify arguments to sculpt draw functions

Instead of passing pointers to specific mesh data, rely on
retrieving that data from the mesh internally. This makes
it easier to support retrieving additional data from Mesh
(like active attribute names in D15101 or D15169). It also makes
the functions simpler conceptually, because they're drawing
a mesh with an acceleration strcture on top.

The BKE_id_attribute_copy_domains_temp call was unnecessary
because the GPU_pbvh_mesh_buffers_update function was only
called when Mesh/PBVH_FACES is used in the first place.

Differential Revision: https://developer.blender.org/D15197

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

M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/gpu/GPU_buffers.h
M	source/blender/gpu/intern/gpu_buffers.c

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

diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index ac3eac70c39..dae9788d21c 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -1303,17 +1303,6 @@ static void pbvh_update_draw_buffer_cb(void *__restrict userdata,
   PBVH *pbvh = data->pbvh;
   PBVHNode *node = data->nodes[n];
 
-  CustomData *vdata, *ldata;
-
-  if (!pbvh->header.bm) {
-    vdata = pbvh->vdata;
-    ldata = pbvh->ldata;
-  }
-  else {
-    vdata = &pbvh->header.bm->vdata;
-    ldata = &pbvh->header.bm->ldata;
-  }
-
   if (node->flag & PBVH_RebuildDrawBuffers) {
     switch (pbvh->header.type) {
       case PBVH_GRIDS: {
@@ -1326,14 +1315,12 @@ static void pbvh_update_draw_buffer_cb(void *__restrict userdata,
       }
       case PBVH_FACES:
         node->draw_buffers = GPU_pbvh_mesh_buffers_build(
-            pbvh->mpoly,
-            pbvh->mloop,
-            pbvh->looptri,
+            pbvh->mesh,
             pbvh->verts,
-            node->prim_indices,
+            pbvh->looptri,
             CustomData_get_layer(pbvh->pdata, CD_SCULPT_FACE_SETS),
-            node->totprim,
-            pbvh->mesh);
+            node->prim_indices,
+            node->totprim);
         break;
       case PBVH_BMESH:
         node->draw_buffers = GPU_pbvh_bmesh_buffers_build(pbvh->flags &
@@ -1360,11 +1347,12 @@ static void pbvh_update_draw_buffer_cb(void *__restrict userdata,
                                      update_flags);
         break;
       case PBVH_FACES: {
+        /* Pass vertices separately because they may be not be the same as the mesh's vertices,
+         * and pass normals separately because they are managed by the PBVH. */
         GPU_pbvh_mesh_buffers_update(pbvh->vbo_id,
                                      node->draw_buffers,
+                                     pbvh->mesh,
                                      pbvh->verts,
-                                     vdata,
-                                     ldata,
                                      CustomData_get_layer(pbvh->vdata, CD_PAINT_MASK),
                                      CustomData_get_layer(pbvh->pdata, CD_SCULPT_FACE_SETS),
                                      pbvh->face_sets_color_seed,
diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h
index 89473ac0fe0..6dc49ff494d 100644
--- a/source/blender/gpu/GPU_buffers.h
+++ b/source/blender/gpu/GPU_buffers.h
@@ -22,6 +22,7 @@ struct CCGKey;
 struct DMFlagMat;
 struct GSet;
 struct TableGSet;
+struct Mesh;
 struct MLoop;
 struct MLoopCol;
 struct MLoopTri;
@@ -46,14 +47,12 @@ typedef struct GPU_PBVH_Buffers GPU_PBVH_Buffers;
  *
  * Threaded: do not call any functions that use OpenGL calls!
  */
-GPU_PBVH_Buffers *GPU_pbvh_mesh_buffers_build(const struct MPoly *mpoly,
-                                              const struct MLoop *mloop,
+GPU_PBVH_Buffers *GPU_pbvh_mesh_buffers_build(const struct Mesh *mesh,
+                                              const struct MVert *vertices,
                                               const struct MLoopTri *looptri,
-                                              const struct MVert *mvert,
-                                              const int *face_indices,
                                               const int *sculpt_face_sets,
-                                              int face_indices_len,
-                                              const struct Mesh *mesh);
+                                              const int *face_indices,
+                                              int face_indices_len);
 
 /**
  * Threaded: do not call any functions that use OpenGL calls!
@@ -91,9 +90,8 @@ enum {
  */
 void GPU_pbvh_mesh_buffers_update(PBVHGPUFormat *vbo_id,
                                   GPU_PBVH_Buffers *buffers,
+                                  const struct Mesh *mesh,
                                   const struct MVert *mvert,
-                                  const CustomData *vdata,
-                                  const CustomData *ldata,
                                   const float *vmask,
                                   const int *sculpt_face_sets,
                                   const int face_sets_color_seed,
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index 14bbd82c282..9e8e75be23b 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -221,9 +221,8 @@ static bool gpu_pbvh_is_looptri_visible(const MLoopTri *lt,
 
 void GPU_pbvh_mesh_buffers_update(PBVHGPUFormat *vbo_id,
                                   GPU_PBVH_Buffers *buffers,
+                                  const Mesh *mesh,
                                   const MVert *mvert,
-                                  const CustomData *vdata,
-                                  const CustomData *ldata,
                                   const float *vmask,
                                   const int *sculpt_face_sets,
                                   int face_sets_color_seed,
@@ -234,23 +233,20 @@ void GPU_pbvh_mesh_buffers_update(PBVHGPUFormat *vbo_id,
   GPUAttrRef vcol_refs[MAX_GPU_ATTR];
   GPUAttrRef cd_uvs[MAX_GPU_ATTR];
 
-  Mesh me_query;
-  BKE_id_attribute_copy_domains_temp(ID_ME, vdata, NULL, ldata, NULL, NULL, &me_query.id);
-
-  CustomDataLayer *actcol = BKE_id_attributes_active_color_get(&me_query.id);
-  eAttrDomain actcol_domain = actcol ? BKE_id_attribute_domain(&me_query.id, actcol) :
+  const CustomDataLayer *actcol = BKE_id_attributes_active_color_get(&mesh->id);
+  eAttrDomain actcol_domain = actcol ? BKE_id_attribute_domain(&mesh->id, actcol) :
                                        ATTR_DOMAIN_AUTO;
 
-  CustomDataLayer *rendercol = BKE_id_attributes_render_color_get(&me_query.id);
+  const CustomDataLayer *rendercol = BKE_id_attributes_render_color_get(&mesh->id);
 
   int totcol;
 
   if (update_flags & GPU_PBVH_BUFFERS_SHOW_VCOL) {
     totcol = gpu_pbvh_make_attr_offs(ATTR_DOMAIN_MASK_COLOR,
                                      CD_MASK_COLOR_ALL,
-                                     vdata,
+                                     &mesh->vdata,
                                      NULL,
-                                     ldata,
+                                     &mesh->ldata,
                                      NULL,
                                      vcol_refs,
                                      vbo_id->active_attrs_only,
@@ -267,14 +263,14 @@ void GPU_pbvh_mesh_buffers_update(PBVHGPUFormat *vbo_id,
                                       CD_MASK_MLOOPUV,
                                       NULL,
                                       NULL,
-                                      ldata,
+                                      &mesh->ldata,
                                       NULL,
                                       cd_uvs,
                                       vbo_id->active_attrs_only,
                                       CD_MLOOPUV,
                                       ATTR_DOMAIN_CORNER,
-                                      get_active_layer(ldata, CD_MLOOPUV),
-                                      get_render_layer(ldata, CD_MLOOPUV));
+                                      get_active_layer(&mesh->ldata, CD_MLOOPUV),
+                                      get_render_layer(&mesh->ldata, CD_MLOOPUV));
 
   const bool show_mask = vmask && (update_flags & GPU_PBVH_BUFFERS_SHOW_MASK) != 0;
   const bool show_face_sets = sculpt_face_sets &&
@@ -308,7 +304,7 @@ void GPU_pbvh_mesh_buffers_update(PBVHGPUFormat *vbo_id,
           GPU_vertbuf_attr_get_raw_data(buffers->vert_buf, vbo_id->uv[uv_i], &uv_step);
 
           GPUAttrRef *ref = cd_uvs + uv_i;
-          CustomDataLayer *layer = ldata->layers + ref->layer_idx;
+          CustomDataLayer *layer = mesh->ldata.layers + ref->layer_idx;
           MLoopUV *muv = layer->data;
 
           for (uint i = 0; i < buffers->face_indices_len; i++) {
@@ -334,7 +330,7 @@ void GPU_pbvh_mesh_buffers_update(PBVHGPUFormat *vbo_id,
         MLoopCol *mcol = NULL;
 
         GPUAttrRef *ref = vcol_refs + col_i;
-        const CustomData *cdata = ref->domain == ATTR_DOMAIN_POINT ? vdata : ldata;
+        const CustomData *cdata = ref->domain == ATTR_DOMAIN_POINT ? &mesh->vdata : &mesh->ldata;
         CustomDataLayer *layer = cdata->layers + ref->layer_idx;
 
         bool color_loops = ref->domain == ATTR_DOMAIN_CORNER;
@@ -457,19 +453,20 @@ void GPU_pbvh_mesh_buffers_update(PBVHGPUFormat *vbo_id,
   buffers->mvert = mvert;
 }
 
-GPU_PBVH_Buffers *GPU_pbvh_mesh_buffers_build(const MPoly *mpoly,
-                                              const MLoop *mloop,
+GPU_PBVH_Buffers *GPU_pbvh_mesh_buffers_build(const Mesh *mesh,
+                                              const MVert *vertices,
                                               const MLoopTri *looptri,
-                                              const MVert *mvert,
-                                              const int *face_indices,
                                               const int *sculpt_face_sets,
-                                              const int face_indices_len,
-                                              const struct Mesh *mesh)
+                                              const int *face_indices,
+                                              const int face_indices_len)
 {
   GPU_PBVH_Buffers *buffers;
   int i, tottri;
   int tot_real_edges = 0;
 
+  const MPoly *mpoly = mesh->mpoly;
+  const MLoop *mloop = mesh->mloop;
+
   buffers = MEM_callocN(sizeof(GPU_PBVH_Buffers), "GPU_Buffers");
 
   /* smooth or flat for all */
@@ -480,7 +477,7 @@ GPU_PBVH_Buffers *GPU_pbvh_mesh_buffers_build(const MPoly *mpoly,
   /* Count the number of visible triangles */
   for (i = 0, tottri = 0; i < face_indices_len; i++) {
     const MLoopTri *lt = &looptri[face_indices[i]];
-    if (gpu_pbvh_is_looptri_visible(lt, mvert, mloop, sculpt_face_sets)) {
+    if (gpu_pbvh_is_looptri_visible(lt, vertices, mloop, sculpt_face_sets)) {
       int r_edges[3];
       BKE_mesh_looptri_get_real_edges(mesh, lt, r_edges);
       for (

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list