3D View: Do not recalculate the depth buffer for 'Auto Depth'

This is a solution to avoid redrawing the depth buffer for each Zoom
with `Auto Depth`.

The solution is to move the `ED_view3d_depth_override` function out of
`ED_view3d_autodist`.

`ED_view3d_depth_override` is now only called for navigation operations
if it does not meet the following condition:

```
    bool has_depth_buffer = !(v3d->flag2 & V3D_HIDE_OVERLAYS) ||
                            ELEM(v3d->shading.type, OB_SOLID, OB_MATERIAL) ||
                            XRAY_FLAG_ENABLED(v3d) ||
                            v3d->shading.type == OB_RENDER &&
                                (strcmp(DEG_get_evaluated_scene(depsgraph)->r.engine,
                                        RE_engine_id_BLENDER_EEVEE) == 0 ||
                                 strcmp(DEG_get_evaluated_scene(depsgraph)->r.engine,
                                        RE_engine_id_BLENDER_WORKBENCH) == 0);
```
This commit is contained in:
Germano Cavalcante
2023-09-28 10:53:30 -03:00
parent df63825cee
commit d33eb78de3
7 changed files with 35 additions and 16 deletions

View File

@@ -849,18 +849,15 @@ void ED_view3d_autodist_last_clear(wmWindow *win);
/**
* Get the world-space 3d location from a screen-space 2d point.
* TODO: Implement #alphaoverride. We don't want to zoom into billboards.
*
* \param mval: Input screen-space pixel location.
* \param mouse_worldloc: Output world-space location.
* \param fallback_depth_pt: Use this points depth when no depth can be found.
*/
bool ED_view3d_autodist(Depsgraph *depsgraph,
ARegion *region,
bool ED_view3d_autodist(ARegion *region,
View3D *v3d,
const int mval[2],
float mouse_worldloc[3],
bool alphaoverride,
const float fallback_depth_pt[3]);
/**

View File

@@ -177,7 +177,9 @@ static void depthdropper_depth_sample_pt(bContext *C,
view3d_operator_needs_opengl(C);
if (ED_view3d_autodist(depsgraph, region, v3d, mval, co, true, nullptr)) {
ED_view3d_depth_override(depsgraph, region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, nullptr);
if (ED_view3d_autodist(region, v3d, mval, co, nullptr)) {
const float mval_center_fl[2] = {float(region->winx) / 2, float(region->winy) / 2};
float co_align[3];

View File

@@ -5831,7 +5831,10 @@ void paint_proj_stroke(const bContext *C,
view3d_operator_needs_opengl(C);
if (!ED_view3d_autodist(depsgraph, region, v3d, mval_i, cursor, false, nullptr)) {
/* Get Z Depths, needed for perspective, nice for ortho */
ED_view3d_depth_override(depsgraph, region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, nullptr);
if (!ED_view3d_autodist(region, v3d, mval_i, cursor, nullptr)) {
return;
}

View File

@@ -854,7 +854,10 @@ void ED_view3d_cursor3d_position(bContext *C,
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
view3d_operator_needs_opengl(C);
if (ED_view3d_autodist(depsgraph, region, v3d, mval, cursor_co, true, nullptr)) {
ED_view3d_depth_override(depsgraph, region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, nullptr);
if (ED_view3d_autodist(region, v3d, mval, cursor_co, nullptr)) {
depth_used = true;
}
}

View File

@@ -31,6 +31,8 @@
#include "DEG_depsgraph_query.hh"
#include "DRW_engine.h"
#include "ED_mesh.hh"
#include "ED_particle.hh"
#include "ED_screen.hh"
@@ -218,11 +220,25 @@ static eViewOpsFlag navigate_pivot_get(bContext *C,
ED_view3d_autodist_last_get(win, r_pivot);
}
else {
/* TODO: Implement 'Alpha Override'. We don't want to zoom into billboards. */
float fallback_depth_pt[3];
negate_v3_v3(fallback_depth_pt, static_cast<RegionView3D *>(region->regiondata)->ofs);
const bool is_set = ED_view3d_autodist(
depsgraph, region, v3d, event->mval, r_pivot, true, fallback_depth_pt);
bool has_depth_buffer = !(v3d->flag2 & V3D_HIDE_OVERLAYS) ||
ELEM(v3d->shading.type, OB_SOLID, OB_MATERIAL) ||
XRAY_FLAG_ENABLED(v3d) ||
v3d->shading.type == OB_RENDER &&
(strcmp(DEG_get_evaluated_scene(depsgraph)->r.engine,
RE_engine_id_BLENDER_EEVEE) == 0 ||
strcmp(DEG_get_evaluated_scene(depsgraph)->r.engine,
RE_engine_id_BLENDER_WORKBENCH) == 0);
if (!has_depth_buffer) {
ED_view3d_depth_override(depsgraph, region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, nullptr);
}
const bool is_set = ED_view3d_autodist(region, v3d, event->mval, r_pivot, fallback_depth_pt);
ED_view3d_autodist_last_set(win, event, r_pivot, is_set);
}

View File

@@ -64,7 +64,10 @@ static int viewcenter_pick_invoke(bContext *C, wmOperator *op, const wmEvent *ev
view3d_operator_needs_opengl(C);
if (ED_view3d_autodist(depsgraph, region, v3d, event->mval, new_ofs, false, nullptr)) {
/* Get Z Depths, needed for perspective, nice for ortho */
ED_view3d_depth_override(depsgraph, region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, nullptr);
if (ED_view3d_autodist(region, v3d, event->mval, new_ofs, nullptr)) {
/* pass */
}
else {

View File

@@ -1106,21 +1106,16 @@ static float view_autodist_depth_margin(ARegion *region, const int mval[2], int
return depth_close;
}
bool ED_view3d_autodist(Depsgraph *depsgraph,
ARegion *region,
bool ED_view3d_autodist(ARegion *region,
View3D *v3d,
const int mval[2],
float mouse_worldloc[3],
const bool /*alphaoverride*/,
const float fallback_depth_pt[3])
{
float depth_close;
int margin_arr[] = {0, 2, 4};
bool depth_ok = false;
/* Get Z Depths, needed for perspective, nice for ortho */
ED_view3d_depth_override(depsgraph, region, v3d, nullptr, V3D_DEPTH_NO_GPENCIL, nullptr);
/* Attempt with low margin's first */
int i = 0;
do {