diff options
author | Pablo Dobarro <pablodp606> | 2020-03-12 19:51:39 +0300 |
---|---|---|
committer | Pablo Dobarro <pablodp606@gmail.com> | 2020-04-02 19:00:51 +0300 |
commit | b8d9b5e3315232bb157de43713ec2a54433cf9a6 (patch) | |
tree | 8f14c626a0742b1e4539966348d847c8ba314dda /source/blender/blenkernel | |
parent | 34465a7fb091664b07611353d99dcaa0862d4a4c (diff) |
Sculpt: Delay Viewport Updates
In Blender 2.81 we update and draw all nodes inside the view planes.
When navigating with a pen tablet after an operation that tags the whole
mesh to update (like undo or inverting the mask), this introduces some
lag as nodes are updating when they enter the view. The viewport is not
fully responsive again until all nodes have entered the view after the
operation.
This commit delays nodes updates until the view navigation stops, so the
viewport navigation is always fully responsive. This introduces some
artifacts while navigating, so it can be disabled if you don't want to
see them.
I'm storing the update planes in the PBVH. This way I can add support
for some tools to update in real-time only the nodes inside this plane
while running the operator, like the mesh filter.
Reviewed By: jbakker
Differential Revision: https://developer.blender.org/D6269
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_pbvh.h | 6 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/pbvh.c | 29 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/pbvh_intern.h | 3 |
3 files changed, 35 insertions, 3 deletions
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h index 2020d45ae86..a59ce816e26 100644 --- a/source/blender/blenkernel/BKE_pbvh.h +++ b/source/blender/blenkernel/BKE_pbvh.h @@ -81,6 +81,9 @@ typedef struct PBVHFrustumPlanes { int num_planes; } PBVHFrustumPlanes; +void BKE_pbvh_set_frustum_planes(PBVH *bvh, PBVHFrustumPlanes *planes); +void BKE_pbvh_get_frustum_planes(PBVH *bvh, PBVHFrustumPlanes *planes); + /* Callbacks */ /* returns 1 if the search should continue from this node, 0 otherwise */ @@ -190,7 +193,8 @@ bool BKE_pbvh_node_find_nearest_to_ray(PBVH *bvh, void BKE_pbvh_draw_cb(PBVH *bvh, bool show_vcol, bool update_only_visible, - PBVHFrustumPlanes *frustum, + PBVHFrustumPlanes *update_frustum, + PBVHFrustumPlanes *draw_frustum, void (*draw_fn)(void *user_data, struct GPU_PBVH_Buffers *buffers), void *user_data); diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c index 879f1e507ba..06622f0d009 100644 --- a/source/blender/blenkernel/intern/pbvh.c +++ b/source/blender/blenkernel/intern/pbvh.c @@ -2683,7 +2683,8 @@ static bool pbvh_draw_search_cb(PBVHNode *node, void *data_v) void BKE_pbvh_draw_cb(PBVH *bvh, bool show_vcol, bool update_only_visible, - PBVHFrustumPlanes *frustum, + PBVHFrustumPlanes *update_frustum, + PBVHFrustumPlanes *draw_frustum, void (*draw_fn)(void *user_data, GPU_PBVH_Buffers *buffers), void *user_data) { @@ -2704,7 +2705,7 @@ void BKE_pbvh_draw_cb(PBVH *bvh, } /* Gather visible nodes. */ - PBVHDrawSearchData data = {.frustum = frustum, .accum_update_flag = 0}; + PBVHDrawSearchData data = {.frustum = update_frustum, .accum_update_flag = 0}; BKE_pbvh_search_gather(bvh, pbvh_draw_search_cb, &data, &nodes, &totnode); if (update_only_visible && (data.accum_update_flag & update_flag)) { @@ -2722,7 +2723,15 @@ void BKE_pbvh_draw_cb(PBVH *bvh, } node->flag &= ~(PBVH_RebuildDrawBuffers | PBVH_UpdateDrawBuffers); + } + + MEM_SAFE_FREE(nodes); + + PBVHDrawSearchData draw_data = {.frustum = draw_frustum, .accum_update_flag = 0}; + BKE_pbvh_search_gather(bvh, pbvh_draw_search_cb, &draw_data, &nodes, &totnode); + for (int a = 0; a < totnode; a++) { + PBVHNode *node = nodes[a]; if (!(node->flag & PBVH_FullyHidden)) { draw_fn(user_data, node->draw_buffers); } @@ -2998,6 +3007,22 @@ void pbvh_show_face_sets_set(PBVH *bvh, bool show_face_sets) bvh->show_face_sets = show_face_sets; } +void BKE_pbvh_set_frustum_planes(PBVH *bvh, PBVHFrustumPlanes *planes) +{ + bvh->num_planes = planes->num_planes; + for (int i = 0; i < bvh->num_planes; i++) { + copy_v4_v4(bvh->planes[i], planes->planes[i]); + } +} + +void BKE_pbvh_get_frustum_planes(PBVH *bvh, PBVHFrustumPlanes *planes) +{ + planes->num_planes = bvh->num_planes; + for (int i = 0; i < planes->num_planes; i++) { + copy_v4_v4(planes->planes[i], bvh->planes[i]); + } +} + void BKE_pbvh_parallel_range_settings(PBVHParallelSettings *settings, bool use_threading, int totnode) diff --git a/source/blender/blenkernel/intern/pbvh_intern.h b/source/blender/blenkernel/intern/pbvh_intern.h index 21cb5649330..d3e42ac7705 100644 --- a/source/blender/blenkernel/intern/pbvh_intern.h +++ b/source/blender/blenkernel/intern/pbvh_intern.h @@ -168,6 +168,9 @@ struct PBVH { int cd_vert_node_offset; int cd_face_node_offset; + float planes[6][4]; + int num_planes; + struct BMLog *bm_log; struct SubdivCCG *subdiv_ccg; }; |