[Bf-blender-cvs] [7c9235d0e01] temp_bmesh_multires: * Sculpt color layers are now properly handle by pbvh bmesh draw code. Before only the active layer was uploaded to the GPU, now all of them (except the autogenerated original color layer) are.

Joseph Eagar noreply at git.blender.org
Fri Mar 26 01:18:41 CET 2021


Commit: 7c9235d0e01aaa23d4f24039275ea46d531df57f
Author: Joseph Eagar
Date:   Thu Mar 25 17:17:42 2021 -0700
Branches: temp_bmesh_multires
https://developer.blender.org/rB7c9235d0e01aaa23d4f24039275ea46d531df57f

* Sculpt color layers are now properly handle by pbvh bmesh draw code.
  Before only the active layer was uploaded to the GPU, now all of them
  (except the autogenerated original color layer) are.

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

M	source/blender/blenkernel/intern/collection.c
M	source/blender/blenkernel/intern/lib_id.c
M	source/blender/draw/intern/draw_cache_extract_mesh.c
M	source/blender/editors/sculpt_paint/sculpt_dyntopo.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/editors/sculpt_paint/sculpt_undo.c
M	source/blender/gpu/intern/gpu_buffers.c

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

diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index 178a762fd40..5b3989d3459 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -688,10 +688,11 @@ static Collection *collection_duplicate_recursive(Main *bmain,
 Collection *BKE_collection_duplicate(Main *bmain,
                                      Collection *parent,
                                      Collection *collection,
-                                     eDupli_ID_Flags duplicate_flags,
-                                     eLibIDDuplicateFlags duplicate_options)
+                                     const uint duplicate_flags_in, //it's not const!! - joeedh
+                                     const uint duplicate_options)
 {
   const bool is_subprocess = (duplicate_options & LIB_ID_DUPLICATE_IS_SUBPROCESS) != 0;
+  uint duplicate_flags = duplicate_flags_in; 
 
   if (!is_subprocess) {
     BKE_main_id_tag_all(bmain, LIB_TAG_NEW, false);
diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c
index af921307bfb..ff0993f9def 100644
--- a/source/blender/blenkernel/intern/lib_id.c
+++ b/source/blender/blenkernel/intern/lib_id.c
@@ -638,7 +638,7 @@ ID *BKE_id_copy(Main *bmain, const ID *id)
  * Invokes the appropriate copy method for the block and returns the result in
  * newid, unless test. Returns true if the block can be copied.
  */
-ID *BKE_id_copy_for_duplicate(Main *bmain, ID *id, const eDupli_ID_Flags duplicate_flags)
+ID *BKE_id_copy_for_duplicate(Main *bmain, ID *id, const uint duplicate_flags)
 {
   if (id == NULL) {
     return id;
diff --git a/source/blender/draw/intern/draw_cache_extract_mesh.c b/source/blender/draw/intern/draw_cache_extract_mesh.c
index f167ea3d540..9062315c63b 100644
--- a/source/blender/draw/intern/draw_cache_extract_mesh.c
+++ b/source/blender/draw/intern/draw_cache_extract_mesh.c
@@ -2903,10 +2903,19 @@ static void *extract_vcol_init(const MeshRenderData *mr, struct MeshBatchCache *
 
   /* Sculpt Vertex Colors */
   if (U.experimental.use_sculpt_vertex_colors) {
+    const int totlayers = CustomData_number_of_layers(cd_vdata, CD_PROP_COLOR);
+
     for (int i = 0; i < 8; i++) {
       if (svcol_layers & (1 << i)) {
+        if (i >= totlayers) {
+          svcol_layers &= ~(1 << i);
+          cache->cd_used.sculpt_vcol = svcol_layers;
+          break;
+        }
+
         char attr_name[32], attr_safe_name[GPU_MAX_SAFE_ATTR_NAME];
         const char *layer_name = CustomData_get_layer_name(cd_vdata, CD_PROP_COLOR, i);
+
         GPU_vertformat_safe_attr_name(layer_name, attr_safe_name, GPU_MAX_SAFE_ATTR_NAME);
 
         BLI_snprintf(attr_name, sizeof(attr_name), "c%s", attr_safe_name);
diff --git a/source/blender/editors/sculpt_paint/sculpt_dyntopo.c b/source/blender/editors/sculpt_paint/sculpt_dyntopo.c
index d3d764e0780..60801026131 100644
--- a/source/blender/editors/sculpt_paint/sculpt_dyntopo.c
+++ b/source/blender/editors/sculpt_paint/sculpt_dyntopo.c
@@ -234,8 +234,6 @@ void SCULPT_dyntopo_node_layers_add(SculptSession *ss)
 
   ss->bm->pdata.layers[cd_face_node_layer_index].flag |= CD_FLAG_TEMPORARY;
   ss->cd_faceset_offset = CustomData_get_offset(&ss->bm->pdata, CD_SCULPT_FACE_SETS);
-
-  SCULPT_dyntopo_save_origverts(ss);
 }
 
 /**
@@ -266,6 +264,7 @@ void SCULPT_dynamic_topology_sync_layers(Object *ob, Mesh *me)
     CustomData *data2 = cd2[i];
 
     if (!data1->layers) {
+      modified |= data2->layers != NULL;
       continue;
     }
 
@@ -276,6 +275,15 @@ void SCULPT_dynamic_topology_sync_layers(Object *ob, Mesh *me)
         continue;
       }
 
+      modified = modified || CustomData_get_active_layer_index(data1, cl1->type) !=
+                                 CustomData_get_active_layer_index(data2, cl1->type);
+      modified = modified || CustomData_get_render_layer_index(data1, cl1->type) !=
+                                 CustomData_get_render_layer_index(data2, cl1->type);
+      modified = modified || CustomData_get_stencil_layer_index(data1, cl1->type) !=
+                                 CustomData_get_stencil_layer_index(data2, cl1->type);
+      modified = modified || CustomData_get_clone_layer_index(data1, cl1->type) !=
+                                 CustomData_get_clone_layer_index(data2, cl1->type);
+
       int idx = CustomData_get_named_layer_index(data2, cl1->type, cl1->name);
       if (idx < 0) {
         BLI_array_append(newlayers, cl1);
@@ -362,7 +370,9 @@ void SCULPT_dynamic_topology_enable_ex(Main *bmain, Depsgraph *depsgraph, Scene
                      }));
   SCULPT_dynamic_topology_triangulate(ss->bm);
   BM_data_layer_add(ss->bm, &ss->bm->vdata, CD_PAINT_MASK);
+
   SCULPT_dyntopo_node_layers_add(ss);
+  SCULPT_dyntopo_save_origverts(ss);
 
   BMIter iter;
   BMVert *v;
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index 973623ea1d9..91fc4956dd9 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -344,6 +344,7 @@ bool SCULPT_stroke_is_dynamic_topology(const SculptSession *ss, const Brush *bru
 
 void SCULPT_dynamic_topology_triangulate(struct BMesh *bm);
 void SCULPT_dyntopo_node_layers_add(struct SculptSession *ss);
+void SCULPT_dyntopo_save_origverts(struct SculptSession *ss);
 
 enum eDynTopoWarnFlag SCULPT_dynamic_topology_check(Scene *scene, Object *ob);
 
diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c
index b27a2520a7c..134766c84cd 100644
--- a/source/blender/editors/sculpt_paint/sculpt_undo.c
+++ b/source/blender/editors/sculpt_paint/sculpt_undo.c
@@ -459,6 +459,9 @@ static void sculpt_undo_bmesh_enable(Object *ob, SculptUndoNode *unode)
                           }));
   BM_data_layer_add(ss->bm, &ss->bm->vdata, CD_PAINT_MASK);
   SCULPT_dyntopo_node_layers_add(ss);
+  SCULPT_dyntopo_save_origverts(ss);
+
+
   me->flag |= ME_SCULPT_DYNAMIC_TOPOLOGY;
 
   /* Restore the BMLog using saved entries. */
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index 9670f5c5c18..25accf2bf2f 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -103,7 +103,9 @@ struct GPU_PBVH_Buffers {
 
 static struct {
   GPUVertFormat format;
-  uint pos, nor, msk, col, fset, uv;
+  uint pos, nor, msk, fset, uv;
+  uint col[MAX_MCOL];
+  int totcol;
 } g_vbo_id = {{0}};
 
 /** \} */
@@ -229,7 +231,7 @@ void GPU_pbvh_mesh_buffers_update(GPU_PBVH_Buffers *buffers,
       GPU_vertbuf_attr_get_raw_data(buffers->vert_buf, g_vbo_id.msk, &msk_step);
       GPU_vertbuf_attr_get_raw_data(buffers->vert_buf, g_vbo_id.fset, &fset_step);
       if (show_vcol) {
-        GPU_vertbuf_attr_get_raw_data(buffers->vert_buf, g_vbo_id.col, &col_step);
+        GPU_vertbuf_attr_get_raw_data(buffers->vert_buf, g_vbo_id.col[0], &col_step);
       }
 
       /* calculate normal for each polygon only once */
@@ -669,7 +671,7 @@ void GPU_pbvh_grid_buffers_update(GPU_PBVH_Buffers *buffers,
 
             if (show_vcol) {
               const ushort vcol[4] = {USHRT_MAX, USHRT_MAX, USHRT_MAX, USHRT_MAX};
-              GPU_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.col, vbo_index, &vcol);
+              GPU_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.col[0], vbo_index, &vcol);
             }
 
             GPU_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.fset, vbo_index, &face_set_color);
@@ -723,10 +725,10 @@ void GPU_pbvh_grid_buffers_update(GPU_PBVH_Buffers *buffers,
             }
 
             const ushort vcol[4] = {USHRT_MAX, USHRT_MAX, USHRT_MAX, USHRT_MAX};
-            GPU_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.col, vbo_index + 0, &vcol);
-            GPU_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.col, vbo_index + 1, &vcol);
-            GPU_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.col, vbo_index + 2, &vcol);
-            GPU_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.col, vbo_index + 3, &vcol);
+            GPU_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.col[0], vbo_index + 0, &vcol);
+            GPU_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.col[0], vbo_index + 1, &vcol);
+            GPU_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.col[0], vbo_index + 2, &vcol);
+            GPU_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.col[0], vbo_index + 3, &vcol);
 
             GPU_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.fset, vbo_index + 0, &face_set_color);
             GPU_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.fset, vbo_index + 1, &face_set_color);
@@ -844,11 +846,11 @@ static void gpu_bmesh_vert_to_buffer_copy(BMVert *v,
       // printf("%d %d %d %d   %d\n", vcol[0], vcol[1], vcol[2], vcol[3], tot);
     }
     // const ushort vcol[4] = {USHRT_MAX, USHRT_MAX, USHRT_MAX, USHRT_MAX};
-    GPU_vertbuf_attr_set(vert_buf, g_vbo_id.col, v_index, vcol);
+    GPU_vertbuf_attr_set(vert_buf, g_vbo_id.col[0], v_index, vcol);
   }
   else if (show_vcol) {
     const ushort vcol[4] = {USHRT_MAX, USHRT_MAX, USHRT_MAX, USHRT_MAX};
-    GPU_vertbuf_attr_set(vert_buf, g_vbo_id.col, v_index, vcol);
+    GPU_vertbuf_attr_set(vert_buf, g_vbo_id.col[0], v_index, vcol);
   }
 
   /* Add default face sets color to avoid artifacts. */
@@ -923,16 +925,41 @@ void GPU_pbvh_update_attribute_names(CustomData *vdata, CustomData *ldata)
     /* TODO: Do not allocate these `.msk` and `.col` when they are not used. */
     g_vbo_id.msk = GPU_vertformat_attr_add(
         &g_vbo_id.format, "msk", GPU_COMP_U8, 1, GPU_FETCH_INT_TO_FLOAT_UNIT);
-    g_vbo_id.col = GPU_vertformat_attr_add(
+
+    g_vbo_id.col[0] = GPU_vertformat_attr_add(
         &g_vbo_id.format, "c", GPU_COMP_U16, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
+    g_vbo_id.totcol = 1;
 
     if (vdata && CustomData_has_layer(vdata, CD_PROP_COLOR)) {
+      for (int i = 0; i < vdata->totlayer; i++) {
+      }
       const int cd_vcol_index = CustomData_get_layer_index(vdata, CD_PROP_COLOR);
-      CustomDataLayer *cl = vdata->layers + cd_vcol_index;
-      cl += cl->active;
+      const int act = CustomData_get_act

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list