Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGermano Cavalcante <mano-wii>2021-06-21 22:25:53 +0300
committerGermano Cavalcante <germano.costa@ig.com.br>2021-06-21 22:41:50 +0300
commitb11a463e4fcd98f2fff6e05a03e97e71b93b8274 (patch)
tree6d6e3a294e19c75f3dfe2f9a1d06ab96875be04f
parentb665ad8621a0db265fd666542d26aed463025db1 (diff)
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.
-rw-r--r--source/blender/blenkernel/intern/screen.c1
-rw-r--r--source/blender/editors/curve/editcurve_paint.c22
-rw-r--r--source/blender/editors/gpencil/annotate_paint.c6
-rw-r--r--source/blender/editors/gpencil/gpencil_fill.c2
-rw-r--r--source/blender/editors/gpencil/gpencil_paint.c4
-rw-r--r--source/blender/editors/gpencil/gpencil_primitive.c2
-rw-r--r--source/blender/editors/gpencil/gpencil_utils.c2
-rw-r--r--source/blender/editors/include/ED_particle.h7
-rw-r--r--source/blender/editors/include/ED_view3d.h9
-rw-r--r--source/blender/editors/object/object_transform.c18
-rw-r--r--source/blender/editors/physics/particle_edit.c87
-rw-r--r--source/blender/editors/space_view3d/space_view3d.c7
-rw-r--r--source/blender/editors/space_view3d/view3d_draw.c93
-rw-r--r--source/blender/editors/space_view3d/view3d_edit.c20
-rw-r--r--source/blender/editors/space_view3d/view3d_intern.h2
-rw-r--r--source/blender/editors/space_view3d/view3d_select.c2
-rw-r--r--source/blender/editors/space_view3d/view3d_utils.c19
-rw-r--r--source/blender/makesdna/DNA_view3d_types.h1
18 files changed, 151 insertions, 153 deletions
diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c
index 269aeaebe82..7a5892baaf6 100644
--- a/source/blender/blenkernel/intern/screen.c
+++ b/source/blender/blenkernel/intern/screen.c
@@ -1467,7 +1467,6 @@ static void direct_link_region(BlendDataReader *reader, ARegion *region, int spa
BLO_read_data_address(reader, &rv3d->localvd);
BLO_read_data_address(reader, &rv3d->clipbb);
- rv3d->depths = NULL;
rv3d->render_engine = NULL;
rv3d->sms = NULL;
rv3d->smooth_timer = NULL;
diff --git a/source/blender/editors/curve/editcurve_paint.c b/source/blender/editors/curve/editcurve_paint.c
index 03c120df28b..94c227dfa75 100644
--- a/source/blender/editors/curve/editcurve_paint.c
+++ b/source/blender/editors/curve/editcurve_paint.c
@@ -128,6 +128,7 @@ struct CurveDrawData {
} prev;
ViewContext vc;
+ ViewDepths *depths;
enum {
CURVE_DRAW_IDLE = 0,
CURVE_DRAW_PAINTING = 1,
@@ -188,7 +189,6 @@ static bool stroke_elem_project(const struct CurveDrawData *cdd,
float r_normal_world[3])
{
ARegion *region = cdd->vc.region;
- RegionView3D *rv3d = cdd->vc.rv3d;
bool is_location_world_set = false;
@@ -204,7 +204,7 @@ static bool stroke_elem_project(const struct CurveDrawData *cdd,
}
}
else {
- const ViewDepths *depths = rv3d->depths;
+ const ViewDepths *depths = cdd->depths;
if (depths && ((uint)mval_i[0] < depths->w) && ((uint)mval_i[1] < depths->h)) {
float depth_fl = 1.0f;
ED_view3d_depth_read_cached(depths, mval_i, 0, &depth_fl);
@@ -219,7 +219,7 @@ static bool stroke_elem_project(const struct CurveDrawData *cdd,
if (surface_offset != 0.0f) {
const float offset = cdd->project.use_surface_offset_absolute ? 1.0f : radius;
float normal[3];
- if (ED_view3d_depth_read_cached_normal(&cdd->vc, mval_i, normal)) {
+ if (ED_view3d_depth_read_cached_normal(region, depths, mval_i, normal)) {
madd_v3_v3fl(r_location_world, normal, offset * surface_offset);
if (r_normal_world) {
copy_v3_v3(r_normal_world, normal);
@@ -528,7 +528,7 @@ static void curve_draw_event_add_first(wmOperator *op, const wmEvent *event)
if (ELEM(cps->surface_plane,
CURVE_PAINT_SURFACE_PLANE_NORMAL_VIEW,
CURVE_PAINT_SURFACE_PLANE_NORMAL_SURFACE)) {
- if (ED_view3d_depth_read_cached_normal(&cdd->vc, event->mval, normal)) {
+ if (ED_view3d_depth_read_cached_normal(cdd->vc.region, cdd->depths, event->mval, normal)) {
if (cps->surface_plane == CURVE_PAINT_SURFACE_PLANE_NORMAL_VIEW) {
float cross_a[3], cross_b[3];
cross_v3_v3v3(cross_a, rv3d->viewinv[2], normal);
@@ -622,6 +622,10 @@ static void curve_draw_exit(wmOperator *op)
BLI_mempool_destroy(cdd->stroke_elem_pool);
}
+ if (cdd->depths) {
+ ED_view3d_depths_free(cdd->depths);
+ MEM_freeN(cdd->depths);
+ }
MEM_freeN(cdd);
op->customdata = NULL;
}
@@ -1084,10 +1088,14 @@ 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_depth_override(
- cdd->vc.depsgraph, cdd->vc.region, cdd->vc.v3d, NULL, V3D_DEPTH_NO_GPENCIL, true);
+ ED_view3d_depth_override(cdd->vc.depsgraph,
+ cdd->vc.region,
+ cdd->vc.v3d,
+ NULL,
+ V3D_DEPTH_NO_GPENCIL,
+ &cdd->depths);
- if (cdd->vc.rv3d->depths != NULL) {
+ if (cdd->depths != NULL) {
cdd->project.use_depth = true;
}
else {
diff --git a/source/blender/editors/gpencil/annotate_paint.c b/source/blender/editors/gpencil/annotate_paint.c
index c155587e95a..e3c6fd8f878 100644
--- a/source/blender/editors/gpencil/annotate_paint.c
+++ b/source/blender/editors/gpencil/annotate_paint.c
@@ -667,7 +667,7 @@ static short annotation_stroke_addpoint(tGPsdata *p,
(ts->annotate_v3d_align & GP_PROJECT_DEPTH_STROKE) ?
V3D_DEPTH_GPENCIL_ONLY :
V3D_DEPTH_NO_GPENCIL,
- false);
+ NULL);
}
/* convert screen-coordinates to appropriate coordinates (and store them) */
@@ -1226,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_depth_override(p->depsgraph, p->region, v3d, NULL, V3D_DEPTH_NO_GPENCIL, false);
+ ED_view3d_depth_override(p->depsgraph, p->region, v3d, NULL, V3D_DEPTH_NO_GPENCIL, NULL);
}
}
@@ -1706,7 +1706,7 @@ static void annotation_paint_strokeend(tGPsdata *p)
(ts->annotate_v3d_align & GP_PROJECT_DEPTH_STROKE) ?
V3D_DEPTH_GPENCIL_ONLY :
V3D_DEPTH_NO_GPENCIL,
- false);
+ NULL);
}
/* 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 f74e211dd65..5c4e2de6aa8 100644
--- a/source/blender/editors/gpencil/gpencil_fill.c
+++ b/source/blender/editors/gpencil/gpencil_fill.c
@@ -1373,7 +1373,7 @@ static void gpencil_get_depth_array(tGPDfill *tgpf)
/* need to restore the original projection settings before packing up */
view3d_region_operator_needs_opengl(tgpf->win, tgpf->region);
ED_view3d_depth_override(
- tgpf->depsgraph, tgpf->region, tgpf->v3d, NULL, V3D_DEPTH_NO_GPENCIL, false);
+ tgpf->depsgraph, tgpf->region, tgpf->v3d, NULL, V3D_DEPTH_NO_GPENCIL, NULL);
/* 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 e40748e5f6e..638994bbc2a 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -1744,7 +1744,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_depth_override(p->depsgraph, p->region, v3d, NULL, V3D_DEPTH_NO_GPENCIL, false);
+ ED_view3d_depth_override(p->depsgraph, p->region, v3d, NULL, V3D_DEPTH_NO_GPENCIL, NULL);
}
}
@@ -2334,7 +2334,7 @@ static void gpencil_paint_strokeend(tGPsdata *p)
(ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE) ?
V3D_DEPTH_GPENCIL_ONLY :
V3D_DEPTH_NO_GPENCIL,
- false);
+ NULL);
}
/* 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 5f02bbf0a77..a2b4e5dee64 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -792,7 +792,7 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
(ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE) ?
V3D_DEPTH_GPENCIL_ONLY :
V3D_DEPTH_NO_GPENCIL,
- false);
+ NULL);
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 c9ef340b9d3..4da21bd05ee 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -680,7 +680,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_depth_override(depsgraph, region, v3d, NULL, V3D_DEPTH_NO_GPENCIL, false);
+ ED_view3d_depth_override(depsgraph, region, v3d, NULL, V3D_DEPTH_NO_GPENCIL, NULL);
/* for camera view set the subrect */
if (rv3d->persp == RV3D_CAMOB) {
diff --git a/source/blender/editors/include/ED_particle.h b/source/blender/editors/include/ED_particle.h
index e84298bd9c2..6d0172e724a 100644
--- a/source/blender/editors/include/ED_particle.h
+++ b/source/blender/editors/include/ED_particle.h
@@ -34,6 +34,7 @@ struct ParticleSystem;
struct Scene;
struct UndoType;
struct ViewLayer;
+struct wmGenericUserData;
struct bContext;
struct rcti;
@@ -68,7 +69,11 @@ void PE_update_object(struct Depsgraph *depsgraph,
bool PE_mouse_particles(
struct bContext *C, const int mval[2], bool extend, bool deselect, bool toggle);
bool PE_box_select(struct bContext *C, const struct rcti *rect, const int sel_op);
-bool PE_circle_select(struct bContext *C, const int sel_op, const int mval[2], float rad);
+bool PE_circle_select(struct bContext *C,
+ struct wmGenericUserData *wm_userdata,
+ const int sel_op,
+ const int mval[2],
+ float rad);
int PE_lasso_select(struct bContext *C,
const int mcoords[][2],
const int mcoords_len,
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index d86041aa6e8..64883ed5f1d 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -90,8 +90,6 @@ typedef struct ViewDepths {
short x, y; /* only for temp use for sub-rects, added to region->winx/y */
float *depths;
double depth_range[2];
-
- bool damaged;
} ViewDepths;
/* Rotate 3D cursor on placement. */
@@ -154,19 +152,20 @@ void ED_view3d_depth_override(struct Depsgraph *depsgraph,
struct View3D *v3d,
struct Object *obact,
eV3DDepthOverrideMode mode,
- bool update_cache);
+ struct ViewDepths **r_depths);
+void ED_view3d_depths_free(ViewDepths *depths);
bool ED_view3d_depth_read_cached(const ViewDepths *vd,
const int mval[2],
int margin,
float *r_depth);
-bool ED_view3d_depth_read_cached_normal(const ViewContext *vc,
+bool ED_view3d_depth_read_cached_normal(const struct ARegion *region,
+ const ViewDepths *depths,
const int mval[2],
float r_normal[3]);
bool ED_view3d_depth_unproject_v3(const struct ARegion *region,
const int mval[2],
const double depth,
float r_location_world[3]);
-void ED_view3d_depth_tag_update(struct RegionView3D *rv3d);
/* Projection */
#define IS_CLIPPED 12000
diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c
index b9a3bc87e19..dbeaf829b7d 100644
--- a/source/blender/editors/object/object_transform.c
+++ b/source/blender/editors/object/object_transform.c
@@ -1615,6 +1615,7 @@ struct XFormAxisItem {
struct XFormAxisData {
ViewContext vc;
+ ViewDepths *depths;
struct {
float depth;
float normal[3];
@@ -1684,8 +1685,9 @@ static void object_transform_axis_target_free_data(wmOperator *op)
struct XFormAxisItem *item = xfd->object_data;
#ifdef USE_RENDER_OVERRIDE
- if (xfd->vc.rv3d->depths) {
- xfd->vc.rv3d->depths->damaged = true;
+ if (xfd->depths) {
+ ED_view3d_depths_free(xfd->depths);
+ MEM_freeN(xfd->depths);
}
#endif
@@ -1782,13 +1784,14 @@ static int object_transform_axis_target_invoke(bContext *C, wmOperator *op, cons
vc.v3d->flag2 |= V3D_HIDE_OVERLAYS;
#endif
- ED_view3d_depth_override(vc.depsgraph, vc.region, vc.v3d, NULL, V3D_DEPTH_NO_GPENCIL, true);
+ ViewDepths *depths = NULL;
+ ED_view3d_depth_override(vc.depsgraph, vc.region, vc.v3d, NULL, V3D_DEPTH_NO_GPENCIL, &depths);
#ifdef USE_RENDER_OVERRIDE
vc.v3d->flag2 = flag2_prev;
#endif
- if (vc.rv3d->depths == NULL) {
+ if (depths == NULL) {
BKE_report(op->reports, RPT_WARNING, "Unable to access depth buffer, using view plane");
return OPERATOR_CANCELLED;
}
@@ -1800,6 +1803,7 @@ static int object_transform_axis_target_invoke(bContext *C, wmOperator *op, cons
/* Don't change this at runtime. */
xfd->vc = vc;
+ xfd->depths = depths;
xfd->vc.mval[0] = event->mval[0];
xfd->vc.mval[1] = event->mval[1];
@@ -1863,7 +1867,7 @@ static int object_transform_axis_target_modal(bContext *C, wmOperator *op, const
const bool is_translate_init = is_translate && (xfd->is_translate != is_translate);
if (event->type == MOUSEMOVE || is_translate_init) {
- const ViewDepths *depths = xfd->vc.rv3d->depths;
+ const ViewDepths *depths = xfd->depths;
if (depths && ((uint)event->mval[0] < depths->w) && ((uint)event->mval[1] < depths->h)) {
float depth_fl = 1.0f;
ED_view3d_depth_read_cached(depths, event->mval, 0, &depth_fl);
@@ -1895,7 +1899,7 @@ static int object_transform_axis_target_modal(bContext *C, wmOperator *op, const
float normal[3];
bool normal_found = false;
- if (ED_view3d_depth_read_cached_normal(&xfd->vc, event->mval, normal)) {
+ if (ED_view3d_depth_read_cached_normal(region, depths, event->mval, normal)) {
normal_found = true;
/* cheap attempt to smooth normals out a bit! */
@@ -1905,7 +1909,7 @@ static int object_transform_axis_target_modal(bContext *C, wmOperator *op, const
if (x != 0 && y != 0) {
const int mval_ofs[2] = {event->mval[0] + x, event->mval[1] + y};
float n[3];
- if (ED_view3d_depth_read_cached_normal(&xfd->vc, mval_ofs, n)) {
+ if (ED_view3d_depth_read_cached_normal(region, depths, mval_ofs, n)) {
add_v3_v3(normal, n);
}
}
diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c
index 97994b65f40..c0d035f36cf 100644
--- a/source/blender/editors/physics/particle_edit.c
+++ b/source/blender/editors/physics/particle_edit.c
@@ -466,6 +466,7 @@ static int pe_x_mirror(Object *ob)
typedef struct PEData {
ViewContext vc;
+ ViewDepths *depths;
const bContext *context;
Main *bmain;
@@ -530,7 +531,7 @@ static void PE_set_view3d_data(bContext *C, PEData *data)
data->vc.v3d,
data->vc.obact,
V3D_DEPTH_OBJECT_ONLY,
- true);
+ &data->depths);
}
}
}
@@ -570,6 +571,17 @@ static void PE_free_random_generator(PEData *data)
}
}
+static void PE_data_free(PEData *data)
+{
+ PE_free_random_generator(data);
+ PE_free_shape_tree(data);
+ if (data->depths) {
+ ED_view3d_depths_free(data->depths);
+ MEM_freeN(data->depths);
+ data->depths = NULL;
+ }
+}
+
/** \} */
/* -------------------------------------------------------------------- */
@@ -579,7 +591,7 @@ static void PE_free_random_generator(PEData *data)
static bool key_test_depth(const PEData *data, const float co[3], const int screen_co[2])
{
View3D *v3d = data->vc.v3d;
- ViewDepths *vd = data->vc.rv3d->depths;
+ ViewDepths *vd = data->depths;
float depth;
/* nothing to do */
@@ -1871,15 +1883,13 @@ void PARTICLE_OT_select_all(wmOperatorType *ot)
bool PE_mouse_particles(bContext *C, const int mval[2], bool extend, bool deselect, bool toggle)
{
- PEData data;
+ Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
Scene *scene = CTX_data_scene(C);
Object *ob = CTX_data_active_object(C);
POINT_P;
KEY_K;
- PE_set_view3d_data(C, &data);
-
- PTCacheEdit *edit = PE_get_current(data.depsgraph, scene, ob);
+ PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob);
if (!PE_start_edit(edit)) {
return false;
@@ -1894,6 +1904,8 @@ bool PE_mouse_particles(bContext *C, const int mval[2], bool extend, bool desele
}
}
+ PEData data;
+ PE_set_view3d_data(C, &data);
data.mval = mval;
data.rad = ED_view3d_select_dist_px();
@@ -1913,6 +1925,8 @@ bool PE_mouse_particles(bContext *C, const int mval[2], bool extend, bool desele
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_SELECTED, data.ob);
}
+ PE_data_free(&data);
+
return true;
}
@@ -2204,6 +2218,7 @@ static int select_linked_pick_exec(bContext *C, wmOperator *op)
for_mouse_hit_keys(&data, select_keys, PSEL_NEAREST);
PE_update_selection(data.depsgraph, data.scene, data.ob, 1);
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_SELECTED, data.ob);
+ PE_data_free(&data);
return OPERATOR_FINISHED;
}
@@ -2298,11 +2313,14 @@ bool PE_box_select(bContext *C, const rcti *rect, const int sel_op)
for_mouse_hit_keys(&data, select_key_op, PSEL_ALL_KEYS);
}
- if (data.is_changed) {
- PE_update_selection(data.depsgraph, scene, ob, 1);
+ bool is_changed = data.is_changed;
+ PE_data_free(&data);
+
+ if (is_changed) {
+ PE_update_selection(depsgraph, scene, ob, 1);
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_SELECTED, ob);
}
- return data.is_changed;
+ return is_changed;
}
/** \} */
@@ -2311,35 +2329,53 @@ bool PE_box_select(bContext *C, const rcti *rect, const int sel_op)
/** \name Circle Select Operator
* \{ */
-bool PE_circle_select(bContext *C, const int sel_op, const int mval[2], float rad)
+static void pe_select_cache_free_generic_userdata(void *data)
+{
+ PE_data_free(data);
+ MEM_freeN(data);
+}
+
+static void pe_select_cache_init_with_generic_userdata(bContext *C, wmGenericUserData *wm_userdata)
+{
+ struct PEData *data = MEM_callocN(sizeof(*data), __func__);
+ wm_userdata->data = data;
+ wm_userdata->free_fn = pe_select_cache_free_generic_userdata;
+ wm_userdata->use_free = true;
+ PE_set_view3d_data(C, data);
+}
+
+bool PE_circle_select(
+ bContext *C, wmGenericUserData *wm_userdata, const int sel_op, const int mval[2], float rad)
{
BLI_assert(ELEM(sel_op, SEL_OP_SET, SEL_OP_ADD, SEL_OP_SUB));
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
Scene *scene = CTX_data_scene(C);
Object *ob = CTX_data_active_object(C);
PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob);
- PEData data;
if (!PE_start_edit(edit)) {
return false;
}
- const bool select = (sel_op != SEL_OP_SUB);
+ if (wm_userdata->data == NULL) {
+ pe_select_cache_init_with_generic_userdata(C, wm_userdata);
+ }
- PE_set_view3d_data(C, &data);
- data.mval = mval;
- data.rad = rad;
- data.select = select;
+ PEData *data = wm_userdata->data;
+ data->mval = mval;
+ data->rad = rad;
+ data->select = (sel_op != SEL_OP_SUB);
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
- data.is_changed = PE_deselect_all_visible_ex(edit);
+ data->is_changed = PE_deselect_all_visible_ex(edit);
}
- for_mouse_hit_keys(&data, select_key, 0);
- if (data.is_changed) {
- PE_update_selection(data.depsgraph, scene, ob, 1);
+ for_mouse_hit_keys(data, select_key, 0);
+
+ if (data->is_changed) {
+ PE_update_selection(depsgraph, scene, ob, 1);
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_SELECTED, ob);
}
- return data.is_changed;
+ return data->is_changed;
}
/** \} */
@@ -2425,8 +2461,11 @@ int PE_lasso_select(bContext *C, const int mcoords[][2], const int mcoords_len,
}
}
- if (data.is_changed) {
- PE_update_selection(data.depsgraph, scene, ob, 1);
+ bool is_changed = data.is_changed;
+ PE_data_free(&data);
+
+ if (is_changed) {
+ PE_update_selection(depsgraph, scene, ob, 1);
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_SELECTED, ob);
return OPERATOR_FINISHED;
}
@@ -4921,7 +4960,7 @@ static void brush_edit_exit(wmOperator *op)
{
BrushEdit *bedit = op->customdata;
- PE_free_random_generator(&bedit->data);
+ PE_data_free(&bedit->data);
MEM_freeN(bedit);
}
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index 8c356bc1600..c9f345b3123 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -786,12 +786,6 @@ static void view3d_main_region_free(ARegion *region)
RE_engine_free(rv3d->render_engine);
}
- if (rv3d->depths) {
- if (rv3d->depths->depths) {
- MEM_freeN(rv3d->depths->depths);
- }
- MEM_freeN(rv3d->depths);
- }
if (rv3d->sms) {
MEM_freeN(rv3d->sms);
}
@@ -815,7 +809,6 @@ static void *view3d_main_region_duplicate(void *poin)
new->clipbb = MEM_dupallocN(rv3d->clipbb);
}
- new->depths = NULL;
new->render_engine = NULL;
new->sms = NULL;
new->smooth_timer = NULL;
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 0bc19887118..c024bab355d 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -2221,7 +2221,7 @@ int ED_view3d_backbuf_sample_size_clamp(ARegion *region, const float dist)
/** \name Z-Depth Utilities
* \{ */
-void view3d_update_depths_rect(ARegion *region, ViewDepths *d, rcti *rect)
+void view3d_depths_rect_create(ARegion *region, rcti *rect, ViewDepths *r_d)
{
/* clamp rect by region */
rcti r = {
@@ -2242,70 +2242,44 @@ void view3d_update_depths_rect(ARegion *region, ViewDepths *d, rcti *rect)
int h = BLI_rcti_size_y(rect);
if (w <= 0 || h <= 0) {
- if (d->depths) {
- MEM_freeN(d->depths);
- }
- d->depths = NULL;
-
- d->damaged = false;
+ r_d->depths = NULL;
+ return;
}
- else if (d->w != w || d->h != h || d->x != x || d->y != y || d->depths == NULL) {
- d->x = x;
- d->y = y;
- d->w = w;
- d->h = h;
- if (d->depths) {
- MEM_freeN(d->depths);
- }
-
- d->depths = MEM_mallocN(sizeof(float) * d->w * d->h, "View depths Subset");
+ r_d->x = x;
+ r_d->y = y;
+ r_d->w = w;
+ r_d->h = h;
- d->damaged = true;
- }
+ r_d->depths = MEM_mallocN(sizeof(float) * w * h, "View depths Subset");
- if (d->damaged) {
+ {
GPUViewport *viewport = WM_draw_region_get_viewport(region);
- view3d_opengl_read_Z_pixels(viewport, rect, d->depths);
+ view3d_opengl_read_Z_pixels(viewport, rect, r_d->depths);
/* Range is assumed to be this as they are never changed. */
- d->depth_range[0] = 0.0;
- d->depth_range[1] = 1.0;
- d->damaged = false;
+ r_d->depth_range[0] = 0.0;
+ r_d->depth_range[1] = 1.0;
}
}
/* Note, with nouveau drivers the glReadPixels() is very slow. T24339. */
-static void view3d_depth_cache_update(ARegion *region)
+static ViewDepths *view3d_depths_create(ARegion *region)
{
- RegionView3D *rv3d = region->regiondata;
+ ViewDepths *d = MEM_callocN(sizeof(ViewDepths), "ViewDepths");
+ d->w = region->winx;
+ d->h = region->winy;
+ d->depths = MEM_mallocN(sizeof(float) * d->w * d->h, "View depths");
- /* Create storage for, and, if necessary, copy depth buffer. */
- if (!rv3d->depths) {
- rv3d->depths = MEM_callocN(sizeof(ViewDepths), "ViewDepths");
- }
- if (rv3d->depths) {
- ViewDepths *d = rv3d->depths;
- if (d->w != region->winx || d->h != region->winy || !d->depths) {
- d->w = region->winx;
- d->h = region->winy;
- if (d->depths) {
- MEM_freeN(d->depths);
- }
- d->depths = MEM_mallocN(sizeof(float) * d->w * d->h, "View depths");
- d->damaged = true;
- }
-
- if (d->damaged) {
- GPUViewport *viewport = WM_draw_region_get_viewport(region);
- DefaultFramebufferList *fbl = GPU_viewport_framebuffer_list_get(viewport);
- GPU_framebuffer_read_depth(fbl->depth_only_fb, 0, 0, d->w, d->h, GPU_DATA_FLOAT, d->depths);
+ {
+ GPUViewport *viewport = WM_draw_region_get_viewport(region);
+ DefaultFramebufferList *fbl = GPU_viewport_framebuffer_list_get(viewport);
+ GPU_framebuffer_read_depth(fbl->depth_only_fb, 0, 0, d->w, d->h, GPU_DATA_FLOAT, d->depths);
- /* Assumed to be this as they are never changed. */
- d->depth_range[0] = 0.0;
- d->depth_range[1] = 1.0;
- d->damaged = false;
- }
+ /* Assumed to be this as they are never changed. */
+ d->depth_range[0] = 0.0;
+ d->depth_range[1] = 1.0;
}
+ return d;
}
/* Utility function to find the closest Z value, use for auto-depth. */
@@ -2345,7 +2319,7 @@ void ED_view3d_depth_override(Depsgraph *depsgraph,
View3D *v3d,
Object *obact,
eV3DDepthOverrideMode mode,
- bool update_cache)
+ ViewDepths **r_depths)
{
if (v3d->runtime.flag & V3D_RUNTIME_DEPTHBUF_OVERRIDDEN) {
return;
@@ -2390,12 +2364,8 @@ void ED_view3d_depth_override(Depsgraph *depsgraph,
break;
}
- if (rv3d->depths != NULL) {
- rv3d->depths->damaged = true;
- /* TODO: Clear cache? */
- }
- if (update_cache) {
- view3d_depth_cache_update(region);
+ if (r_depths) {
+ *r_depths = view3d_depths_create(region);
}
}
@@ -2409,6 +2379,13 @@ void ED_view3d_depth_override(Depsgraph *depsgraph,
UI_Theme_Restore(&theme_state);
}
+void ED_view3d_depths_free(ViewDepths *depths)
+{
+ if (depths->depths) {
+ MEM_freeN(depths->depths);
+ }
+}
+
/** \} */
/* -------------------------------------------------------------------- */
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index 8b6d0e9ee04..ab0683644c3 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -953,7 +953,6 @@ static int viewrotate_modal(bContext *C, wmOperator *op, const wmEvent *event)
}
}
else if (event_code == VIEW_CONFIRM) {
- ED_view3d_depth_tag_update(vod->rv3d);
use_autokey = true;
ret = OPERATOR_FINISHED;
}
@@ -1014,7 +1013,6 @@ static int viewrotate_invoke(bContext *C, wmOperator *op, const wmEvent *event)
}
viewrotate_apply(vod, event_xy);
- ED_view3d_depth_tag_update(vod->rv3d);
viewops_data_free(C, op);
@@ -1799,7 +1797,6 @@ static int viewmove_modal(bContext *C, wmOperator *op, const wmEvent *event)
}
}
else if (event_code == VIEW_CONFIRM) {
- ED_view3d_depth_tag_update(vod->rv3d);
use_autokey = true;
ret = OPERATOR_FINISHED;
}
@@ -1840,7 +1837,6 @@ static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event)
if (event->type == MOUSEPAN) {
/* invert it, trackpad scroll follows same principle as 2d windows this way */
viewmove_apply(vod, 2 * event->x - event->prevx, 2 * event->y - event->prevy);
- ED_view3d_depth_tag_update(vod->rv3d);
viewops_data_free(C, op);
@@ -2254,7 +2250,6 @@ static int viewzoom_modal(bContext *C, wmOperator *op, const wmEvent *event)
}
}
else if (event_code == VIEW_CONFIRM) {
- ED_view3d_depth_tag_update(vod->rv3d);
use_autokey = true;
ret = OPERATOR_FINISHED;
}
@@ -2341,8 +2336,6 @@ static int viewzoom_exec(bContext *C, wmOperator *op)
view3d_boxview_sync(area, region);
}
- ED_view3d_depth_tag_update(rv3d);
-
ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d);
ED_view3d_camera_lock_autokey(v3d, rv3d, C, false, true);
@@ -2398,8 +2391,6 @@ static int viewzoom_invoke(bContext *C, wmOperator *op, const wmEvent *event)
(use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)));
ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true);
- ED_view3d_depth_tag_update(vod->rv3d);
-
viewops_data_free(C, op);
return OPERATOR_FINISHED;
}
@@ -2579,7 +2570,6 @@ static int viewdolly_modal(bContext *C, wmOperator *op, const wmEvent *event)
}
}
else if (event_code == VIEW_CONFIRM) {
- ED_view3d_depth_tag_update(vod->rv3d);
use_autokey = true;
ret = OPERATOR_FINISHED;
}
@@ -2636,8 +2626,6 @@ static int viewdolly_exec(bContext *C, wmOperator *op)
view3d_boxview_sync(area, region);
}
- ED_view3d_depth_tag_update(rv3d);
-
ED_view3d_camera_lock_sync(CTX_data_ensure_evaluated_depsgraph(C), v3d, rv3d);
ED_region_tag_redraw(region);
@@ -2718,7 +2706,6 @@ static int viewdolly_invoke(bContext *C, wmOperator *op, const wmEvent *event)
event->prevx;
}
viewdolly_apply(vod, &event->prevx, (U.uiflag & USER_ZOOM_INVERT) == 0);
- ED_view3d_depth_tag_update(vod->rv3d);
viewops_data_free(C, op);
return OPERATOR_FINISHED;
@@ -3629,13 +3616,13 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
ED_view3d_dist_range_get(v3d, dist_range);
ED_view3d_depth_override(
- CTX_data_ensure_evaluated_depsgraph(C), region, v3d, NULL, V3D_DEPTH_NO_GPENCIL, false);
+ CTX_data_ensure_evaluated_depsgraph(C), region, v3d, NULL, V3D_DEPTH_NO_GPENCIL, NULL);
{
/* avoid allocating the whole depth buffer */
ViewDepths depth_temp = {0};
/* avoid view3d_update_depths() for speed. */
- view3d_update_depths_rect(region, &depth_temp, &rect);
+ view3d_depths_rect_create(region, &rect, &depth_temp);
/* find the closest Z pixel */
depth_close = view3d_depth_near(&depth_temp);
@@ -4433,7 +4420,6 @@ static int viewroll_modal(bContext *C, wmOperator *op, const wmEvent *event)
}
}
else if (event_code == VIEW_CONFIRM) {
- ED_view3d_depth_tag_update(vod->rv3d);
use_autokey = true;
ret = OPERATOR_FINISHED;
}
@@ -4541,7 +4527,6 @@ static int viewroll_invoke(bContext *C, wmOperator *op, const wmEvent *event)
if (event->type == MOUSEROTATE) {
vod->init.event_xy[0] = vod->prev.event_xy[0] = event->x;
viewroll_apply(vod, event->prevx, event->prevy);
- ED_view3d_depth_tag_update(vod->rv3d);
viewops_data_free(C, op);
return OPERATOR_FINISHED;
@@ -4638,7 +4623,6 @@ static int viewpan_invoke(bContext *C, wmOperator *op, const wmEvent *event)
viewmove_apply(vod, vod->prev.event_xy[0] + x, vod->prev.event_xy[1] + y);
- ED_view3d_depth_tag_update(vod->rv3d);
viewops_data_free(C, op);
return OPERATOR_FINISHED;
diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h
index 6f07cb8b44d..0964c2dcbcc 100644
--- a/source/blender/editors/space_view3d/view3d_intern.h
+++ b/source/blender/editors/space_view3d/view3d_intern.h
@@ -137,7 +137,7 @@ void ED_view3d_draw_depth_loop(struct Depsgraph *depsgraph,
struct ARegion *region,
View3D *v3d);
-void view3d_update_depths_rect(struct ARegion *region, struct ViewDepths *d, struct rcti *rect);
+void view3d_depths_rect_create(struct ARegion *region, struct rcti *rect, struct ViewDepths *r_d);
float view3d_depth_near(struct ViewDepths *d);
/* view3d_select.c */
diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index 5bdeb2cb35f..f768d7faf63 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -4385,7 +4385,7 @@ static int view3d_circle_select_exec(bContext *C, wmOperator *op)
FOREACH_OBJECT_IN_MODE_END;
}
else if (obact && (obact->mode & OB_MODE_PARTICLE_EDIT)) {
- if (PE_circle_select(C, sel_op, mval, (float)radius)) {
+ if (PE_circle_select(C, wm_userdata, sel_op, mval, (float)radius)) {
return OPERATOR_FINISHED;
}
return OPERATOR_CANCELLED;
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;
- }
-}
-
/** \} */
diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h
index fa738c647bb..41350c128ae 100644
--- a/source/blender/makesdna/DNA_view3d_types.h
+++ b/source/blender/makesdna/DNA_view3d_types.h
@@ -72,7 +72,6 @@ typedef struct RegionView3D {
/** Allocated backup of its self while in localview. */
struct RegionView3D *localvd;
struct RenderEngine *render_engine;
- struct ViewDepths *depths;
/** Animated smooth view. */
struct SmoothView3DStore *sms;