From b11a463e4fcd98f2fff6e05a03e97e71b93b8274 Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Mon, 21 Jun 2021 16:25:53 -0300 Subject: Refactor: Do not keep a copy of depth buffer in RegionView3D The depth cache (located in `RegionView3D::depths`) is used for quick and simple occlusion testing in: - particle selection, - "Draw Curve" operator and - "Interactive Light Track to Cursor" operator, However, keeping a texture buffer in cache is not a recommended practice. For displays with high resolution like 8k this represents something around 132MB. Also, currently, each call to `ED_view3d_depth_override` invalidates the depth cache. So that depth is never reused in multiple calls from an operator (this was not the case in blender 2.79). This commit allows to create a depth cache and release it in the same operator. Thus, the buffer is kept in cache for a short time, freeing up space. No functional changes. --- source/blender/editors/space_view3d/view3d_utils.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'source/blender/editors/space_view3d/view3d_utils.c') diff --git a/source/blender/editors/space_view3d/view3d_utils.c b/source/blender/editors/space_view3d/view3d_utils.c index 8ae5d4a29e9..c7da3378ae3 100644 --- a/source/blender/editors/space_view3d/view3d_utils.c +++ b/source/blender/editors/space_view3d/view3d_utils.c @@ -1017,9 +1017,9 @@ static float view_autodist_depth_margin(ARegion *region, const int mval[2], int } ViewDepths depth_temp = {0}; - view3d_update_depths_rect(region, &depth_temp, &rect); + view3d_depths_rect_create(region, &rect, &depth_temp); float depth_close = view3d_depth_near(&depth_temp); - MEM_SAFE_FREE(depth_temp.depths); + ED_view3d_depths_free(&depth_temp); return depth_close; } @@ -1044,7 +1044,7 @@ bool ED_view3d_autodist(Depsgraph *depsgraph, bool depth_ok = false; /* Get Z Depths, needed for perspective, nice for ortho */ - ED_view3d_depth_override(depsgraph, region, v3d, NULL, V3D_DEPTH_NO_GPENCIL, false); + ED_view3d_depth_override(depsgraph, region, v3d, NULL, V3D_DEPTH_NO_GPENCIL, NULL); /* Attempt with low margin's first */ int i = 0; @@ -1694,7 +1694,8 @@ bool ED_view3d_depth_read_cached(const ViewDepths *vd, return false; } -bool ED_view3d_depth_read_cached_normal(const ViewContext *vc, +bool ED_view3d_depth_read_cached_normal(const ARegion *region, + const ViewDepths *depths, const int mval[2], float r_normal[3]) { @@ -1705,9 +1706,6 @@ bool ED_view3d_depth_read_cached_normal(const ViewContext *vc, bool depths_valid[9] = {false}; float coords[9][3] = {{0}}; - ARegion *region = vc->region; - const ViewDepths *depths = vc->rv3d->depths; - for (int x = 0, i = 0; x < 2; x++) { for (int y = 0; y < 2; y++) { const int mval_ofs[2] = {mval[0] + (x - 1), mval[1] + (y - 1)}; @@ -1761,11 +1759,4 @@ bool ED_view3d_depth_unproject_v3(const ARegion *region, return ED_view3d_unproject_v3(region, centx, centy, depth, r_location_world); } -void ED_view3d_depth_tag_update(RegionView3D *rv3d) -{ - if (rv3d->depths) { - rv3d->depths->damaged = true; - } -} - /** \} */ -- cgit v1.2.3