[Bf-blender-cvs] [9ca1abe0421] master: Fix T101100: missing smooth shading with linked subdivision surface in editmode

Brecht Van Lommel noreply at git.blender.org
Fri Sep 16 16:50:53 CEST 2022


Commit: 9ca1abe0421726c2240139e58198b591080ba9a6
Author: Brecht Van Lommel
Date:   Fri Sep 16 16:46:32 2022 +0200
Branches: master
https://developer.blender.org/rB9ca1abe0421726c2240139e58198b591080ba9a6

Fix T101100: missing smooth shading with linked subdivision surface in editmode

Smooth flag should come from the evaluated mesh, only selection and hidding
state should be mapped to the original bmesh.

Pre-existing issue revealed by refactor in b247588dc0f4.

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

M	source/blender/draw/intern/draw_cache_impl_subdivision.cc

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

diff --git a/source/blender/draw/intern/draw_cache_impl_subdivision.cc b/source/blender/draw/intern/draw_cache_impl_subdivision.cc
index ab935809f96..c57406fe460 100644
--- a/source/blender/draw/intern/draw_cache_impl_subdivision.cc
+++ b/source/blender/draw/intern/draw_cache_impl_subdivision.cc
@@ -635,17 +635,9 @@ void draw_subdiv_cache_free(DRWSubdivCache *cache)
      SUBDIV_COARSE_FACE_FLAG_ACTIVE | SUBDIV_COARSE_FACE_FLAG_HIDDEN) \
     << SUBDIV_COARSE_FACE_FLAG_OFFSET)
 
-static uint32_t compute_coarse_face_flag(BMFace *f, BMFace *efa_act)
+static uint32_t compute_coarse_face_flag_bm(BMFace *f, BMFace *efa_act)
 {
-  if (f == nullptr) {
-    /* May happen during mapped extraction. */
-    return 0;
-  }
-
   uint32_t flag = 0;
-  if (BM_elem_flag_test(f, BM_ELEM_SMOOTH)) {
-    flag |= SUBDIV_COARSE_FACE_FLAG_SMOOTH;
-  }
   if (BM_elem_flag_test(f, BM_ELEM_SELECT)) {
     flag |= SUBDIV_COARSE_FACE_FLAG_SELECT;
   }
@@ -655,8 +647,7 @@ static uint32_t compute_coarse_face_flag(BMFace *f, BMFace *efa_act)
   if (f == efa_act) {
     flag |= SUBDIV_COARSE_FACE_FLAG_ACTIVE;
   }
-  const int loopstart = BM_elem_index_get(f->l_first);
-  return (uint)(loopstart) | (flag << SUBDIV_COARSE_FACE_FLAG_OFFSET);
+  return flag;
 }
 
 static void draw_subdiv_cache_extra_coarse_face_data_bm(BMesh *bm,
@@ -668,7 +659,12 @@ static void draw_subdiv_cache_extra_coarse_face_data_bm(BMesh *bm,
 
   BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
     const int index = BM_elem_index_get(f);
-    flags_data[index] = compute_coarse_face_flag(f, efa_act);
+    uint32_t flag = compute_coarse_face_flag_bm(f, efa_act);
+    if (BM_elem_flag_test(f, BM_ELEM_SMOOTH)) {
+      flag |= SUBDIV_COARSE_FACE_FLAG_SMOOTH;
+    }
+    const int loopstart = BM_elem_index_get(f->l_first);
+    flags_data[index] = (uint)(loopstart) | (flag << SUBDIV_COARSE_FACE_FLAG_OFFSET);
   }
 }
 
@@ -702,9 +698,16 @@ static void draw_subdiv_cache_extra_coarse_face_data_mapped(Mesh *mesh,
     return;
   }
 
-  for (int i = 0; i < mesh->totpoly; i++) {
+  const Span<MPoly> polys = mesh->polys();
+  for (const int i : polys.index_range()) {
     BMFace *f = bm_original_face_get(mr, i);
-    flags_data[i] = compute_coarse_face_flag(f, mr->efa_act);
+    /* Selection and hiding from bmesh. */
+    uint32_t flag = (f) ? compute_coarse_face_flag_bm(f, mr->efa_act) : 0;
+    /* Smooth from mesh. */
+    if ((polys[i].flag & ME_SMOOTH) != 0) {
+      flag |= SUBDIV_COARSE_FACE_FLAG_SMOOTH;
+    }
+    flags_data[i] = (uint)(polys[i].loopstart) | (flag << SUBDIV_COARSE_FACE_FLAG_OFFSET);
   }
 }



More information about the Bf-blender-cvs mailing list