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.
This commit is contained in:
Germano Cavalcante 2021-06-21 16:25:53 -03:00 committed by Germano Cavalcante
parent b665ad8621
commit b11a463e4f
Notes: blender-bot 2023-02-14 07:53:51 +01:00
Referenced by issue #89345, Non-planar faces cause assertion failure when decimating
Referenced by issue #89347, Make Planar Faces operator causes assertion failure with non-planar faces
18 changed files with 154 additions and 156 deletions

View File

@ -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;

View File

@ -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 {

View File

@ -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 */

View File

@ -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. */

View File

@ -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 */

View File

@ -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];

View File

@ -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) {

View File

@ -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,

View File

@ -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

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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;

View File

@ -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;
}
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");
d->damaged = true;
r_d->depths = NULL;
return;
}
if (d->damaged) {
r_d->x = x;
r_d->y = y;
r_d->w = w;
r_d->h = h;
r_d->depths = MEM_mallocN(sizeof(float) * w * h, "View depths Subset");
{
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);
/* Assumed to be this as they are never changed. */
d->depth_range[0] = 0.0;
d->depth_range[1] = 1.0;
d->damaged = false;
}
{
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;
}
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);
}
}
/** \} */
/* -------------------------------------------------------------------- */

View File

@ -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;

View File

@ -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 */

View File

@ -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;

View File

@ -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;
}
}
/** \} */

View File

@ -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;