From 47239b40419750f0ad8284ba1de1012a638660fb Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 3 May 2017 00:05:57 +1000 Subject: Cleanup: use depsgraph for scene/layer access --- source/blender/draw/DRW_engine.h | 6 ++--- source/blender/draw/intern/draw_manager.c | 27 +++++++++++++--------- source/blender/editors/curve/editcurve_paint.c | 2 +- source/blender/editors/gpencil/gpencil_edit.c | 2 +- source/blender/editors/gpencil/gpencil_paint.c | 6 ++--- source/blender/editors/gpencil/gpencil_utils.c | 2 +- source/blender/editors/include/ED_view3d.h | 4 ++-- .../editors/interface/interface_eyedropper.c | 2 +- .../editors/sculpt_paint/paint_image_proj.c | 3 ++- source/blender/editors/space_view3d/view3d_draw.c | 7 ++++-- source/blender/editors/space_view3d/view3d_edit.c | 25 +++++++++++--------- .../blender/editors/space_view3d/view3d_intern.h | 2 +- source/blender/editors/space_view3d/view3d_view.c | 5 ++-- 13 files changed, 52 insertions(+), 41 deletions(-) diff --git a/source/blender/draw/DRW_engine.h b/source/blender/draw/DRW_engine.h index dbb25796050..62dae9b3e7b 100644 --- a/source/blender/draw/DRW_engine.h +++ b/source/blender/draw/DRW_engine.h @@ -64,12 +64,12 @@ void DRW_engine_viewport_data_size_get( void DRW_draw_view(const struct bContext *C); void DRW_draw_select_loop( - struct ViewContext *vc, struct Depsgraph *graph, - struct Scene *scene, struct SceneLayer *sl, struct View3D *v3d, struct ARegion *ar, + struct Depsgraph *graph, + struct View3D *v3d, struct ARegion *ar, bool use_obedit_skip, bool use_nearest, const struct rcti *rect); void DRW_draw_depth_loop( struct Depsgraph *graph, - struct Scene *scene, struct ARegion *ar, struct View3D *v3d); + struct ARegion *ar, struct View3D *v3d); void DRW_object_engine_data_free(struct Object *ob); diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index 00937b55f92..d6c86d82291 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -2253,29 +2253,32 @@ void DRW_draw_view(const bContext *C) * object mode select-loop, see: ED_view3d_draw_select_loop (legacy drawing). */ void DRW_draw_select_loop( - struct ViewContext *vc, Depsgraph *graph, - Scene *scene, struct SceneLayer *sl, View3D *v3d, ARegion *ar, + struct Depsgraph *graph, + View3D *v3d, ARegion *ar, bool UNUSED(use_obedit_skip), bool UNUSED(use_nearest), const rcti *rect) { + Scene *scene = DAG_get_scene(graph); + SceneLayer *sl = DAG_get_scene_layer(graph); #ifndef USE_GPU_SELECT UNUSED_VARS(vc, scene, sl, v3d, ar, rect); #else - RegionView3D *rv3d = vc->rv3d; + RegionView3D *rv3d = ar->regiondata; /* backup (_never_ use rv3d->viewport) */ - void *backup_viewport = vc->rv3d->viewport; + void *backup_viewport = rv3d->viewport; rv3d->viewport = NULL; bool use_obedit = false; int obedit_mode = 0; - if (vc->obedit && vc->obedit->type == OB_MBALL) { + if (scene->obedit && scene->obedit->type == OB_MBALL) { use_obedit = true; - DRW_engines_cache_populate(vc->obedit); + DRW_engines_cache_populate(scene->obedit); obedit_mode = CTX_MODE_EDIT_METABALL; } - else if ((vc->obedit && vc->obedit->type == OB_ARMATURE)) { + else if ((scene->obedit && scene->obedit->type == OB_ARMATURE)) { /* if not drawing sketch, draw bones */ - if (!BDR_drawSketchNames(vc)) { + // if (!BDR_drawSketchNames(vc)) + { use_obedit = true; obedit_mode = CTX_MODE_EDIT_ARMATURE; } @@ -2323,7 +2326,7 @@ void DRW_draw_select_loop( DRW_engines_cache_init(); if (use_obedit) { - DRW_engines_cache_populate(vc->obedit); + DRW_engines_cache_populate(scene->obedit); } else { DEG_OBJECT_ITER(graph, ob) @@ -2364,8 +2367,10 @@ void DRW_draw_select_loop( */ void DRW_draw_depth_loop( Depsgraph *graph, - Scene *scene, ARegion *ar, View3D *v3d) + ARegion *ar, View3D *v3d) { + Scene *scene = DAG_get_scene(graph); + SceneLayer *sl = DAG_get_scene_layer(graph); RegionView3D *rv3d = ar->regiondata; /* backup (_never_ use rv3d->viewport) */ @@ -2392,7 +2397,7 @@ void DRW_draw_depth_loop( /* Instead of 'DRW_context_state_init(C, &DST.draw_ctx)', assign from args */ DST.draw_ctx = (DRWContextState){ - ar, rv3d, v3d, scene, BKE_scene_layer_context_active(scene), (bContext *)NULL, + ar, rv3d, v3d, scene, sl, (bContext *)NULL, }; DRW_viewport_var_init(); diff --git a/source/blender/editors/curve/editcurve_paint.c b/source/blender/editors/curve/editcurve_paint.c index aee479da173..867aec61922 100644 --- a/source/blender/editors/curve/editcurve_paint.c +++ b/source/blender/editors/curve/editcurve_paint.c @@ -1181,7 +1181,7 @@ static int curve_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event) /* needed or else the draw matrix can be incorrect */ view3d_operator_needs_opengl(C); - ED_view3d_autodist_init(cdd->vc.depsgraph, cdd->vc.scene, cdd->vc.ar, cdd->vc.v3d, 0); + ED_view3d_autodist_init(cdd->vc.depsgraph, cdd->vc.ar, cdd->vc.v3d, 0); if (cdd->vc.rv3d->depths) { cdd->vc.rv3d->depths->damaged = true; diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c index 5286302ddad..546f5e4208a 100644 --- a/source/blender/editors/gpencil/gpencil_edit.c +++ b/source/blender/editors/gpencil/gpencil_edit.c @@ -2012,7 +2012,7 @@ static int gp_strokes_reproject_exec(bContext *C, wmOperator *op) if (mode == GP_REPROJECT_SURFACE) { struct Depsgraph *graph = CTX_data_depsgraph(C); view3d_region_operator_needs_opengl(CTX_wm_window(C), gsc.ar); - ED_view3d_autodist_init(graph, scene, gsc.ar, CTX_wm_view3d(C), 0); + ED_view3d_autodist_init(graph, gsc.ar, CTX_wm_view3d(C), 0); } // TODO: For deforming geometry workflow, create new frames? diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index 6659510c6cc..d794e6b8760 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -641,7 +641,7 @@ static short gp_stroke_addpoint(tGPsdata *p, const int mval[2], float pressure, view3d_region_operator_needs_opengl(p->win, p->ar); ED_view3d_autodist_init( - p->graph, p->scene, p->ar, v3d, (ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE) ? 1 : 0); + p->graph, p->ar, v3d, (ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE) ? 1 : 0); } /* convert screen-coordinates to appropriate coordinates (and store them) */ @@ -1242,7 +1242,7 @@ static void gp_stroke_doeraser(tGPsdata *p) if (p->flags & GP_PAINTFLAG_V3D_ERASER_DEPTH) { View3D *v3d = p->sa->spacedata.first; view3d_region_operator_needs_opengl(p->win, p->ar); - ED_view3d_autodist_init(p->graph, p->scene, p->ar, v3d, 0); + ED_view3d_autodist_init(p->graph, p->ar, v3d, 0); } } @@ -1809,7 +1809,7 @@ static void gp_paint_strokeend(tGPsdata *p) /* need to restore the original projection settings before packing up */ view3d_region_operator_needs_opengl(p->win, p->ar); - ED_view3d_autodist_init(p->graph, p->scene, p->ar, v3d, (ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE) ? 1 : 0); + ED_view3d_autodist_init(p->graph, p->ar, v3d, (ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE) ? 1 : 0); } /* check if doing eraser or not */ diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c index 9ed5cf57eec..05b45a2f2eb 100644 --- a/source/blender/editors/gpencil/gpencil_utils.c +++ b/source/blender/editors/gpencil/gpencil_utils.c @@ -529,7 +529,7 @@ void gp_point_conversion_init(bContext *C, GP_SpaceConversion *r_gsc) view3d_operator_needs_opengl(C); view3d_region_operator_needs_opengl(win, ar); - ED_view3d_autodist_init(graph, scene, ar, v3d, 0); + ED_view3d_autodist_init(graph, ar, v3d, 0); /* for camera view set the subrect */ if (rv3d->persp == RV3D_CAMOB) { diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index 0cb6f054f12..24a1b06d940 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -295,12 +295,12 @@ int ED_view3d_backbuf_sample_size_clamp(struct ARegion *ar, const float unsigned int ED_view3d_backbuf_sample(struct ViewContext *vc, int x, int y); bool ED_view3d_autodist( - struct Depsgraph *graph, struct Scene *scene, struct ARegion *ar, struct View3D *v3d, + struct Depsgraph *graph, struct ARegion *ar, struct View3D *v3d, const int mval[2], float mouse_worldloc[3], const bool alphaoverride, const float fallback_depth_pt[3]); /* only draw so ED_view3d_autodist_simple can be called many times after */ -void ED_view3d_autodist_init(struct Depsgraph *graph, struct Scene *scene, struct ARegion *ar, struct View3D *v3d, int mode); +void ED_view3d_autodist_init(struct Depsgraph *graph, struct ARegion *ar, struct View3D *v3d, int mode); bool ED_view3d_autodist_simple(struct ARegion *ar, const int mval[2], float mouse_worldloc[3], int margin, float *force_depth); bool ED_view3d_autodist_depth(struct ARegion *ar, const int mval[2], int margin, float *depth); bool ED_view3d_autodist_depth_seg(struct ARegion *ar, const int mval_sta[2], const int mval_end[2], int margin, float *depth); diff --git a/source/blender/editors/interface/interface_eyedropper.c b/source/blender/editors/interface/interface_eyedropper.c index ea13e67e600..bad47512d12 100644 --- a/source/blender/editors/interface/interface_eyedropper.c +++ b/source/blender/editors/interface/interface_eyedropper.c @@ -920,7 +920,7 @@ static void depthdropper_depth_sample_pt(bContext *C, DepthDropper *ddr, int mx, view3d_operator_needs_opengl(C); - if (ED_view3d_autodist(graph, scene, ar, v3d, mval, co, true, NULL)) { + if (ED_view3d_autodist(graph, ar, v3d, mval, co, true, NULL)) { const float mval_center_fl[2] = { (float)ar->winx / 2, (float)ar->winy / 2}; diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c index 16d81c6e923..901f24844e4 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.c +++ b/source/blender/editors/sculpt_paint/paint_image_proj.c @@ -5025,8 +5025,9 @@ void paint_proj_stroke( view3d_operator_needs_opengl(C); - if (!ED_view3d_autodist(graph, scene, ar, v3d, mval_i, cursor, false, NULL)) + if (!ED_view3d_autodist(graph, ar, v3d, mval_i, cursor, false, NULL)) { return; + } ED_region_tag_redraw(ar); diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 7e2789de33d..1f46a891e76 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -70,6 +70,8 @@ #include "ED_transform.h" #include "ED_gpencil.h" +#include "DEG_depsgraph_query.h" + #include "GPU_matrix.h" #include "GPU_immediate.h" #include "GPU_immediate_util.h" @@ -755,8 +757,9 @@ static void drawrenderborder(ARegion *ar, View3D *v3d) void ED_view3d_draw_depth( struct Depsgraph *graph, - Scene *scene, ARegion *ar, View3D *v3d, bool alphaoverride) + ARegion *ar, View3D *v3d, bool alphaoverride) { + Scene *scene = DAG_get_scene(graph); RegionView3D *rv3d = ar->regiondata; short zbuf = v3d->zbuf; @@ -797,7 +800,7 @@ void ED_view3d_draw_depth( else #endif /* WITH_OPENGL_LEGACY */ { - DRW_draw_depth_loop(graph, scene, ar, v3d); + DRW_draw_depth_loop(graph, ar, v3d); } if (rv3d->rflag & RV3D_CLIPPING) { diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 63024b489e1..156905cf681 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -77,6 +77,8 @@ #include "ED_gpencil.h" #include "ED_view3d.h" +#include "DEG_depsgraph_query.h" + #include "UI_resources.h" #include "PIL_time.h" /* smoothview */ @@ -742,7 +744,7 @@ static void viewops_data_create_ex( negate_v3_v3(fallback_depth_pt, rv3d->ofs); vod->use_dyn_ofs = ED_view3d_autodist( - graph, vod->scene, vod->ar, vod->v3d, + graph, vod->ar, vod->v3d, event->mval, vod->dyn_ofs, true, fallback_depth_pt); } else { @@ -3310,7 +3312,6 @@ static int viewcenter_pick_invoke(bContext *C, wmOperator *op, const wmEvent *ev { View3D *v3d = CTX_wm_view3d(C); RegionView3D *rv3d = CTX_wm_region_view3d(C); - Scene *scene = CTX_data_scene(C); ARegion *ar = CTX_wm_region(C); if (rv3d) { @@ -3322,7 +3323,7 @@ static int viewcenter_pick_invoke(bContext *C, wmOperator *op, const wmEvent *ev view3d_operator_needs_opengl(C); - if (ED_view3d_autodist(graph, scene, ar, v3d, event->mval, new_ofs, false, NULL)) { + if (ED_view3d_autodist(graph, ar, v3d, event->mval, new_ofs, false, NULL)) { /* pass */ } else { @@ -3580,7 +3581,6 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op) ARegion *ar = CTX_wm_region(C); View3D *v3d = CTX_wm_view3d(C); RegionView3D *rv3d = CTX_wm_region_view3d(C); - Scene *scene = CTX_data_scene(C); int gesture_mode; const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); @@ -3609,7 +3609,7 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op) ED_view3d_dist_range_get(v3d, dist_range); /* Get Z Depths, needed for perspective, nice for ortho */ - ED_view3d_draw_depth(CTX_data_depsgraph(C), scene, ar, v3d, true); + ED_view3d_draw_depth(CTX_data_depsgraph(C), ar, v3d, true); { /* avoid allocating the whole depth buffer */ @@ -4688,7 +4688,6 @@ void VIEW3D_OT_clip_border(wmOperatorType *ot) /* note: cannot use event->mval here (called by object_add() */ void ED_view3d_cursor3d_position(bContext *C, float fp[3], const int mval[2]) { - Scene *scene = CTX_data_scene(C); ARegion *ar = CTX_wm_region(C); View3D *v3d = CTX_wm_view3d(C); RegionView3D *rv3d = ar->regiondata; @@ -4712,8 +4711,9 @@ void ED_view3d_cursor3d_position(bContext *C, float fp[3], const int mval[2]) if (U.uiflag & USER_ZBUF_CURSOR) { /* maybe this should be accessed some other way */ struct Depsgraph *graph = CTX_data_depsgraph(C); view3d_operator_needs_opengl(C); - if (ED_view3d_autodist(graph, scene, ar, v3d, mval, fp, true, NULL)) + if (ED_view3d_autodist(graph, ar, v3d, mval, fp, true, NULL)) { depth_used = true; + } } if (depth_used == false) { @@ -4888,7 +4888,7 @@ static float view_autodist_depth_margin(ARegion *ar, const int mval[2], int marg * \param fallback_depth_pt: Use this points depth when no depth can be found. */ bool ED_view3d_autodist( - struct Depsgraph *graph, Scene *scene, ARegion *ar, View3D *v3d, + struct Depsgraph *graph, ARegion *ar, View3D *v3d, const int mval[2], float mouse_worldloc[3], const bool alphaoverride, const float fallback_depth_pt[3]) { @@ -4898,7 +4898,7 @@ bool ED_view3d_autodist( bool depth_ok = false; /* Get Z Depths, needed for perspective, nice for ortho */ - ED_view3d_draw_depth(graph, scene, ar, v3d, alphaoverride); + ED_view3d_draw_depth(graph, ar, v3d, alphaoverride); /* Attempt with low margin's first */ i = 0; @@ -4928,16 +4928,19 @@ bool ED_view3d_autodist( void ED_view3d_autodist_init( struct Depsgraph *graph, - Scene *scene, ARegion *ar, View3D *v3d, int mode) + ARegion *ar, View3D *v3d, int mode) { /* Get Z Depths, needed for perspective, nice for ortho */ switch (mode) { case 0: - ED_view3d_draw_depth(graph, scene, ar, v3d, true); + ED_view3d_draw_depth(graph, ar, v3d, true); break; case 1: + { + Scene *scene = DAG_get_scene(graph); ED_view3d_draw_depth_gpencil(scene, ar, v3d); break; + } } } diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h index dd9570eb656..f1b9fb575de 100644 --- a/source/blender/editors/space_view3d/view3d_intern.h +++ b/source/blender/editors/space_view3d/view3d_intern.h @@ -213,7 +213,7 @@ void view3d_draw_region_info(const struct bContext *C, struct ARegion *ar); void ED_view3d_draw_depth( struct Depsgraph *graph, - Scene *scene, struct ARegion *ar, View3D *v3d, bool alphaoverride); + struct ARegion *ar, View3D *v3d, bool alphaoverride); /* view3d_draw_legacy.c */ void view3d_main_region_draw_legacy(const struct bContext *C, struct ARegion *ar); diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index b92431e6370..a1dcdd3abcf 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -1117,7 +1117,6 @@ int view3d_opengl_select( { Depsgraph *graph = vc->depsgraph; Scene *scene = vc->scene; - SceneLayer *sl = vc->scene_layer; View3D *v3d = vc->v3d; ARegion *ar = vc->ar; rcti rect; @@ -1192,7 +1191,7 @@ int view3d_opengl_select( else #else { - DRW_draw_select_loop(vc, graph, scene, sl, v3d, ar, use_obedit_skip, use_nearest, &rect); + DRW_draw_select_loop(graph, v3d, ar, use_obedit_skip, use_nearest, &rect); } #endif /* WITH_OPENGL_LEGACY */ @@ -1209,7 +1208,7 @@ int view3d_opengl_select( else #else { - DRW_draw_select_loop(vc, graph, scene, sl, v3d, ar, use_obedit_skip, use_nearest, &rect); + DRW_draw_select_loop(graph, v3d, ar, use_obedit_skip, use_nearest, &rect); } #endif /* WITH_OPENGL_LEGACY */ -- cgit v1.2.3