From 142541124976af41f08fb5479886350c2d803710 Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Tue, 30 Mar 2021 16:23:58 -0300 Subject: Cleanup/Refactor: Unify functions that redraw the depth buffer Now `ED_view3d_backbuf_depth_validate`, `ED_view3d_draw_depth` and `ED_view3d_draw_depth_gpencil` are unified in `ED_view3d_depth_override`. This new function replaces `ED_view3d_autodist_init`. Also, since `ED_view3d_depth_update` depends on the render context, and changing the context is a slow operation, that function also was removed, and the depth buffer cached is now updated inside the new unified drawing function when the "bool update_cache" parameter is true. Finally `V3D_INVALID_BACKBUF` flag has been renamed and moved to `runtime.flag`. Differential revision: https://developer.blender.org/D10678 --- source/blender/editors/gpencil/annotate_paint.c | 24 +++++++++++++++------- source/blender/editors/gpencil/gpencil_fill.c | 3 ++- source/blender/editors/gpencil/gpencil_paint.c | 12 ++++++++--- source/blender/editors/gpencil/gpencil_primitive.c | 12 +++++++---- source/blender/editors/gpencil/gpencil_utils.c | 2 +- 5 files changed, 37 insertions(+), 16 deletions(-) (limited to 'source/blender/editors/gpencil') diff --git a/source/blender/editors/gpencil/annotate_paint.c b/source/blender/editors/gpencil/annotate_paint.c index e9817f82090..5c40bc8e418 100644 --- a/source/blender/editors/gpencil/annotate_paint.c +++ b/source/blender/editors/gpencil/annotate_paint.c @@ -660,10 +660,14 @@ static short annotation_stroke_addpoint(tGPsdata *p, View3D *v3d = p->area->spacedata.first; view3d_region_operator_needs_opengl(p->win, p->region); - ED_view3d_autodist_init(p->depsgraph, - p->region, - v3d, - (ts->annotate_v3d_align & GP_PROJECT_DEPTH_STROKE) ? 1 : 0); + ED_view3d_depth_override(p->depsgraph, + p->region, + v3d, + NULL, + (ts->annotate_v3d_align & GP_PROJECT_DEPTH_STROKE) ? + V3D_DEPTH_GPENCIL_ONLY : + V3D_DEPTH_NO_GPENCIL, + false); } /* convert screen-coordinates to appropriate coordinates (and store them) */ @@ -1222,7 +1226,7 @@ static void annotation_stroke_doeraser(tGPsdata *p) if (p->flags & GP_PAINTFLAG_V3D_ERASER_DEPTH) { View3D *v3d = p->area->spacedata.first; view3d_region_operator_needs_opengl(p->win, p->region); - ED_view3d_autodist_init(p->depsgraph, p->region, v3d, 0); + ED_view3d_depth_override(p->depsgraph, p->region, v3d, NULL, V3D_DEPTH_NO_GPENCIL, false); } } @@ -1695,8 +1699,14 @@ static void annotation_paint_strokeend(tGPsdata *p) /* need to restore the original projection settings before packing up */ view3d_region_operator_needs_opengl(p->win, p->region); - ED_view3d_autodist_init( - p->depsgraph, p->region, v3d, (ts->annotate_v3d_align & GP_PROJECT_DEPTH_STROKE) ? 1 : 0); + ED_view3d_depth_override(p->depsgraph, + p->region, + v3d, + NULL, + (ts->annotate_v3d_align & GP_PROJECT_DEPTH_STROKE) ? + V3D_DEPTH_GPENCIL_ONLY : + V3D_DEPTH_NO_GPENCIL, + false); } /* check if doing eraser or not */ diff --git a/source/blender/editors/gpencil/gpencil_fill.c b/source/blender/editors/gpencil/gpencil_fill.c index 4749f40fac5..3f86e5474c5 100644 --- a/source/blender/editors/gpencil/gpencil_fill.c +++ b/source/blender/editors/gpencil/gpencil_fill.c @@ -1363,7 +1363,8 @@ static void gpencil_get_depth_array(tGPDfill *tgpf) if (ts->gpencil_v3d_align & GP_PROJECT_DEPTH_VIEW) { /* need to restore the original projection settings before packing up */ view3d_region_operator_needs_opengl(tgpf->win, tgpf->region); - ED_view3d_autodist_init(tgpf->depsgraph, tgpf->region, tgpf->v3d, 0); + ED_view3d_depth_override( + tgpf->depsgraph, tgpf->region, tgpf->v3d, NULL, V3D_DEPTH_NO_GPENCIL, false); /* Since strokes are so fine, when using their depth we need a margin * otherwise they might get missed. */ diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index beaa5f9b64f..d072d8a35df 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -1722,7 +1722,7 @@ static void gpencil_stroke_doeraser(tGPsdata *p) if ((gp_settings != NULL) && (gp_settings->flag & GP_BRUSH_OCCLUDE_ERASER)) { View3D *v3d = p->area->spacedata.first; view3d_region_operator_needs_opengl(p->win, p->region); - ED_view3d_autodist_init(p->depsgraph, p->region, v3d, 0); + ED_view3d_depth_override(p->depsgraph, p->region, v3d, NULL, V3D_DEPTH_NO_GPENCIL, false); } } @@ -2305,8 +2305,14 @@ static void gpencil_paint_strokeend(tGPsdata *p) /* need to restore the original projection settings before packing up */ view3d_region_operator_needs_opengl(p->win, p->region); - ED_view3d_autodist_init( - p->depsgraph, p->region, v3d, (ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE) ? 1 : 0); + ED_view3d_depth_override(p->depsgraph, + p->region, + v3d, + NULL, + (ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE) ? + V3D_DEPTH_GPENCIL_ONLY : + V3D_DEPTH_NO_GPENCIL, + false); } /* check if doing eraser or not */ diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c index dfff0ce639e..3d20e32ed49 100644 --- a/source/blender/editors/gpencil/gpencil_primitive.c +++ b/source/blender/editors/gpencil/gpencil_primitive.c @@ -785,10 +785,14 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) /* need to restore the original projection settings before packing up */ view3d_region_operator_needs_opengl(tgpi->win, tgpi->region); - ED_view3d_autodist_init(tgpi->depsgraph, - tgpi->region, - tgpi->v3d, - (ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE) ? 1 : 0); + ED_view3d_depth_override(tgpi->depsgraph, + tgpi->region, + tgpi->v3d, + NULL, + (ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE) ? + V3D_DEPTH_GPENCIL_ONLY : + V3D_DEPTH_NO_GPENCIL, + false); depth_arr = MEM_mallocN(sizeof(float) * gps->totpoints, "depth_points"); tGPspoint *ptc = &points2D[0]; diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c index 574670de7ca..8d42024a518 100644 --- a/source/blender/editors/gpencil/gpencil_utils.c +++ b/source/blender/editors/gpencil/gpencil_utils.c @@ -648,7 +648,7 @@ void gpencil_point_conversion_init(bContext *C, GP_SpaceConversion *r_gsc) view3d_operator_needs_opengl(C); view3d_region_operator_needs_opengl(win, region); - ED_view3d_autodist_init(depsgraph, region, v3d, 0); + ED_view3d_depth_override(depsgraph, region, v3d, NULL, V3D_DEPTH_NO_GPENCIL, false); /* for camera view set the subrect */ if (rv3d->persp == RV3D_CAMOB) { -- cgit v1.2.3