diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-03-20 07:05:25 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-03-20 07:05:25 +0300 |
commit | 4e2aea5efea31262ce46240baa0511e85a021332 (patch) | |
tree | bb79830062714cb04410f8b6c72b28920b1eb033 /source/blender | |
parent | 47ba487e05daf73018f7fd3af0a44d46228e9fd6 (diff) |
DRW: minor optimization for edit-mesh conversion
Finding visible connected elements is often a direct lookup
when they're not connected to hidden geometry.
Add inline wrappers that avoid a function call,
gives minor speedup creating GPU edit-mesh data.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl_mesh.c | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c index 3e1b6b6c020..4e064111245 100644 --- a/source/blender/draw/intern/draw_cache_impl_mesh.c +++ b/source/blender/draw/intern/draw_cache_impl_mesh.c @@ -85,6 +85,40 @@ enum { }; /* ---------------------------------------------------------------------- */ +/** \name BMesh Inline Wrappers + * \{ */ + +/** + * Wrapper for #BM_vert_find_first_loop_visible + * since most of the time this can be accessed directly without a function call. + */ +BLI_INLINE BMLoop *bm_vert_find_first_loop_visible_inline(BMVert *v) +{ + if (v->e) { + BMLoop *l = v->e->l; + if (l && !BM_elem_flag_test(l->f, BM_ELEM_HIDDEN)) { + return l->v == v ? l : l->next; + } + return BM_vert_find_first_loop_visible(v); + } + return NULL; +} + +BLI_INLINE BMLoop *bm_edge_find_first_loop_visible_inline(BMEdge *e) +{ + if (e->l) { + BMLoop *l = e->l; + if (!BM_elem_flag_test(l->f, BM_ELEM_HIDDEN)) { + return l; + } + return BM_edge_find_first_loop_visible(e); + } + return NULL; +} + +/** \} */ + +/* ---------------------------------------------------------------------- */ /** \name Mesh/BMesh Interface (direct access to basic data). * \{ */ @@ -3426,8 +3460,8 @@ static void mesh_create_loops_lines( if (!BM_elem_flag_test(bm_edge, BM_ELEM_HIDDEN) && bm_edge->l != NULL) { - BMLoop *bm_loop1 = BM_vert_find_first_loop_visible(bm_edge->v1); - BMLoop *bm_loop2 = BM_vert_find_first_loop_visible(bm_edge->v2); + BMLoop *bm_loop1 = bm_vert_find_first_loop_visible_inline(bm_edge->v1); + BMLoop *bm_loop2 = bm_vert_find_first_loop_visible_inline(bm_edge->v2); int v1 = BM_elem_index_get(bm_loop1); int v2 = BM_elem_index_get(bm_loop2); if (v1 > v2) { @@ -3669,7 +3703,7 @@ static void mesh_create_edit_loops_points_lines(MeshRenderData *rdata, GPUIndexB BMEdge *eed; BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) { if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) { - BMLoop *l = BM_edge_find_first_loop_visible(eed); + BMLoop *l = bm_edge_find_first_loop_visible_inline(eed); if (l != NULL) { int v1 = BM_elem_index_get(eed->l); int v2 = BM_elem_index_get(eed->l->next); @@ -3683,7 +3717,7 @@ static void mesh_create_edit_loops_points_lines(MeshRenderData *rdata, GPUIndexB BMVert *eve; BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) { if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) { - BMLoop *l = BM_vert_find_first_loop_visible(eve); + BMLoop *l = bm_vert_find_first_loop_visible_inline(eve); if (l != NULL) { int v = BM_elem_index_get(l); GPU_indexbuf_add_generic_vert(&elb_vert, v); |