From 6292b60a3f5b1c224ec78301c7830045560fa3b4 Mon Sep 17 00:00:00 2001 From: Antony Riakiotakis Date: Thu, 10 Apr 2014 22:31:39 +0300 Subject: Dyntopo: Minor display optimization. While hiding, flush the hidden flags to the faces. This avoids iterating through all the loops while updating the GPU buffers. --- source/blender/blenkernel/BKE_pbvh.h | 1 + source/blender/blenkernel/intern/pbvh_bmesh.c | 5 +++++ source/blender/editors/sculpt_paint/paint_hide.c | 20 +++++++++++++++++++- source/blender/gpu/intern/gpu_buffers.c | 2 +- 4 files changed, 26 insertions(+), 2 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h index 73ca60d40b9..79a41f06c3a 100644 --- a/source/blender/blenkernel/BKE_pbvh.h +++ b/source/blender/blenkernel/BKE_pbvh.h @@ -185,6 +185,7 @@ bool BKE_pbvh_node_planes_exclude_AABB(PBVHNode *node, void *data); struct GSet *BKE_pbvh_bmesh_node_unique_verts(PBVHNode *node); struct GSet *BKE_pbvh_bmesh_node_other_verts(PBVHNode *node); +struct GSet *BKE_pbvh_bmesh_node_faces(PBVHNode *node); void BKE_pbvh_bmesh_node_save_orig(PBVHNode *node); void BKE_pbvh_bmesh_after_stroke(PBVH *bvh); diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c index 432694f75f9..ba383279900 100644 --- a/source/blender/blenkernel/intern/pbvh_bmesh.c +++ b/source/blender/blenkernel/intern/pbvh_bmesh.c @@ -1338,6 +1338,11 @@ GSet *BKE_pbvh_bmesh_node_other_verts(PBVHNode *node) return node->bm_other_verts; } +struct GSet *BKE_pbvh_bmesh_node_faces(PBVHNode *node) +{ + return node->bm_faces; +} + /****************************** Debugging *****************************/ #if 0 diff --git a/source/blender/editors/sculpt_paint/paint_hide.c b/source/blender/editors/sculpt_paint/paint_hide.c index 6542bb2ca9b..fb3fd10a5f1 100644 --- a/source/blender/editors/sculpt_paint/paint_hide.c +++ b/source/blender/editors/sculpt_paint/paint_hide.c @@ -253,6 +253,20 @@ static void partialvis_update_bmesh_verts(BMesh *bm, } } +static void partialvis_update_bmesh_faces(GSet *faces, PartialVisAction action) +{ + GSetIterator gs_iter; + + GSET_ITER (gs_iter, faces) { + BMFace *f = BLI_gsetIterator_getKey(&gs_iter); + + if ((action == PARTIALVIS_HIDE) && paint_is_bmesh_face_hidden(f)) + BM_elem_flag_enable(f, BM_ELEM_HIDDEN); + else + BM_elem_flag_disable(f, BM_ELEM_HIDDEN); + } +} + static void partialvis_update_bmesh(Object *ob, PBVH *pbvh, PBVHNode *node, @@ -261,12 +275,13 @@ static void partialvis_update_bmesh(Object *ob, float planes[4][4]) { BMesh *bm; - GSet *unique, *other; + GSet *unique, *other, *faces; bool any_changed = false, any_visible = false; bm = BKE_pbvh_get_bmesh(pbvh); unique = BKE_pbvh_bmesh_node_unique_verts(node); other = BKE_pbvh_bmesh_node_other_verts(node); + faces = BKE_pbvh_bmesh_node_faces(node); sculpt_undo_push_node(ob, node, SCULPT_UNDO_HIDDEN); @@ -286,6 +301,9 @@ static void partialvis_update_bmesh(Object *ob, &any_changed, &any_visible); + /* finally loop over node faces and tag the ones that are fully hidden */ + partialvis_update_bmesh_faces(faces, action); + if (any_changed) { BKE_pbvh_node_mark_rebuild_draw(node); BKE_pbvh_node_fully_hidden_set(node, !any_visible); diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c index 82c14695fec..e1db9b6f83a 100644 --- a/source/blender/gpu/intern/gpu_buffers.c +++ b/source/blender/gpu/intern/gpu_buffers.c @@ -2056,7 +2056,7 @@ static int gpu_bmesh_face_visible_count(GSet *bm_faces) GSET_ITER (gh_iter, bm_faces) { BMFace *f = BLI_gsetIterator_getKey(&gh_iter); - if (!paint_is_bmesh_face_hidden(f)) + if (!BM_elem_flag_test(f, BM_ELEM_HIDDEN)) totface++; } -- cgit v1.2.3