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
This commit is contained in:
parent
da1b002c8d
commit
1425411249
|
@ -1527,9 +1527,6 @@ static void direct_link_area(BlendDataReader *reader, ScrArea *area)
|
|||
|
||||
if (sl->spacetype == SPACE_VIEW3D) {
|
||||
View3D *v3d = (View3D *)sl;
|
||||
|
||||
v3d->flag |= V3D_INVALID_BACKBUF;
|
||||
|
||||
if (v3d->gpd) {
|
||||
BLO_read_data_address(reader, &v3d->gpd);
|
||||
BKE_gpencil_blend_read_data(reader, v3d->gpd);
|
||||
|
|
|
@ -118,8 +118,7 @@ void DRW_draw_select_loop(struct Depsgraph *depsgraph,
|
|||
void DRW_draw_depth_loop(struct Depsgraph *depsgraph,
|
||||
struct ARegion *region,
|
||||
struct View3D *v3d,
|
||||
struct GPUViewport *viewport,
|
||||
bool use_opengl_context);
|
||||
struct GPUViewport *viewport);
|
||||
void DRW_draw_depth_loop_gpencil(struct Depsgraph *depsgraph,
|
||||
struct ARegion *region,
|
||||
struct View3D *v3d,
|
||||
|
|
|
@ -2601,8 +2601,7 @@ static void drw_draw_depth_loop_impl(struct Depsgraph *depsgraph,
|
|||
void DRW_draw_depth_loop(struct Depsgraph *depsgraph,
|
||||
ARegion *region,
|
||||
View3D *v3d,
|
||||
GPUViewport *viewport,
|
||||
bool use_opengl_context)
|
||||
GPUViewport *viewport)
|
||||
{
|
||||
/* Reset before using it. */
|
||||
drw_state_prepare_clean_for_draw(&DST);
|
||||
|
@ -2618,7 +2617,7 @@ void DRW_draw_depth_loop(struct Depsgraph *depsgraph,
|
|||
}
|
||||
}
|
||||
|
||||
drw_draw_depth_loop_impl(depsgraph, region, v3d, viewport, use_opengl_context);
|
||||
drw_draw_depth_loop_impl(depsgraph, region, v3d, viewport, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2634,7 +2633,7 @@ void DRW_draw_depth_loop_gpencil(struct Depsgraph *depsgraph,
|
|||
|
||||
use_drw_engine(&draw_engine_gpencil_type);
|
||||
|
||||
drw_draw_depth_loop_impl(depsgraph, region, v3d, viewport, true);
|
||||
drw_draw_depth_loop_impl(depsgraph, region, v3d, viewport, false);
|
||||
}
|
||||
|
||||
void DRW_draw_select_id(Depsgraph *depsgraph, ARegion *region, View3D *v3d, const rcti *rect)
|
||||
|
@ -2725,7 +2724,6 @@ void DRW_draw_depth_object(
|
|||
{
|
||||
RegionView3D *rv3d = region->regiondata;
|
||||
|
||||
DRW_opengl_context_enable();
|
||||
GPU_matrix_projection_set(rv3d->winmat);
|
||||
GPU_matrix_set(rv3d->viewmat);
|
||||
GPU_matrix_mul(object->obmat);
|
||||
|
@ -2784,7 +2782,6 @@ void DRW_draw_depth_object(
|
|||
GPU_matrix_set(rv3d->viewmat);
|
||||
GPU_depth_test(GPU_DEPTH_NONE);
|
||||
GPU_framebuffer_restore();
|
||||
DRW_opengl_context_disable();
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
|
|
@ -1083,13 +1083,8 @@ 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.region, cdd->vc.v3d, 0);
|
||||
|
||||
if (cdd->vc.rv3d->depths) {
|
||||
cdd->vc.rv3d->depths->damaged = true;
|
||||
}
|
||||
|
||||
ED_view3d_depth_update(cdd->vc.region);
|
||||
ED_view3d_depth_override(
|
||||
cdd->vc.depsgraph, cdd->vc.region, cdd->vc.v3d, NULL, V3D_DEPTH_NO_GPENCIL, true);
|
||||
|
||||
if (cdd->vc.rv3d->depths != NULL) {
|
||||
cdd->project.use_depth = true;
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -144,7 +144,17 @@ bool ED_view3d_camera_to_view_selected(struct Main *bmain,
|
|||
void ED_view3d_lastview_store(struct RegionView3D *rv3d);
|
||||
|
||||
/* Depth buffer */
|
||||
void ED_view3d_depth_update(struct ARegion *region);
|
||||
typedef enum {
|
||||
V3D_DEPTH_NO_GPENCIL = 0,
|
||||
V3D_DEPTH_GPENCIL_ONLY,
|
||||
V3D_DEPTH_OBJECT_ONLY,
|
||||
} eV3DDepthOverrideMode;
|
||||
void ED_view3d_depth_override(struct Depsgraph *depsgraph,
|
||||
struct ARegion *region,
|
||||
struct View3D *v3d,
|
||||
struct Object *obact,
|
||||
eV3DDepthOverrideMode mode,
|
||||
bool update_cache);
|
||||
float ED_view3d_depth_read_cached(const struct ViewContext *vc, const int mval[2]);
|
||||
bool ED_view3d_depth_read_cached_normal(const ViewContext *vc,
|
||||
const int mval[2],
|
||||
|
@ -481,11 +491,6 @@ bool ED_view3d_autodist(struct Depsgraph *depsgraph,
|
|||
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 *depsgraph,
|
||||
struct ARegion *region,
|
||||
struct View3D *v3d,
|
||||
int mode);
|
||||
bool ED_view3d_autodist_simple(struct ARegion *region,
|
||||
const int mval[2],
|
||||
float mouse_worldloc[3],
|
||||
|
|
|
@ -1782,12 +1782,7 @@ static int object_transform_axis_target_invoke(bContext *C, wmOperator *op, cons
|
|||
vc.v3d->flag2 |= V3D_HIDE_OVERLAYS;
|
||||
#endif
|
||||
|
||||
ED_view3d_autodist_init(vc.depsgraph, vc.region, vc.v3d, 0);
|
||||
|
||||
if (vc.rv3d->depths != NULL) {
|
||||
vc.rv3d->depths->damaged = true;
|
||||
}
|
||||
ED_view3d_depth_update(vc.region);
|
||||
ED_view3d_depth_override(vc.depsgraph, vc.region, vc.v3d, NULL, V3D_DEPTH_NO_GPENCIL, true);
|
||||
|
||||
#ifdef USE_RENDER_OVERRIDE
|
||||
vc.v3d->flag2 = flag2_prev;
|
||||
|
|
|
@ -524,15 +524,13 @@ static void PE_set_view3d_data(bContext *C, PEData *data)
|
|||
ED_view3d_viewcontext_init(C, &data->vc, data->depsgraph);
|
||||
|
||||
if (!XRAY_ENABLED(data->vc.v3d)) {
|
||||
if (data->vc.v3d->flag & V3D_INVALID_BACKBUF) {
|
||||
/* needed or else the draw matrix can be incorrect */
|
||||
view3d_operator_needs_opengl(C);
|
||||
|
||||
ED_view3d_backbuf_depth_validate(&data->vc);
|
||||
/* we may need to force an update here by setting the rv3d as dirty
|
||||
* for now it seems ok, but take care!:
|
||||
* rv3d->depths->dirty = 1; */
|
||||
ED_view3d_depth_update(data->vc.region);
|
||||
if (!(data->vc.v3d->runtime.flag & V3D_RUNTIME_DEPTHBUF_OVERRIDDEN)) {
|
||||
ED_view3d_depth_override(data->depsgraph,
|
||||
data->vc.region,
|
||||
data->vc.v3d,
|
||||
data->vc.obact,
|
||||
V3D_DEPTH_OBJECT_ONLY,
|
||||
true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -832,52 +832,6 @@ static void drawrenderborder(ARegion *region, View3D *v3d)
|
|||
immUnbindProgram();
|
||||
}
|
||||
|
||||
void ED_view3d_draw_depth(Depsgraph *depsgraph, ARegion *region, View3D *v3d, bool alphaoverride)
|
||||
{
|
||||
struct bThemeState theme_state;
|
||||
Scene *scene = DEG_get_evaluated_scene(depsgraph);
|
||||
RegionView3D *rv3d = region->regiondata;
|
||||
|
||||
short flag = v3d->flag;
|
||||
float glalphaclip = U.glalphaclip;
|
||||
/* temp set drawtype to solid */
|
||||
/* Setting these temporarily is not nice */
|
||||
v3d->flag &= ~V3D_SELECT_OUTLINE;
|
||||
|
||||
/* not that nice but means we wont zoom into billboards */
|
||||
U.glalphaclip = alphaoverride ? 0.5f : glalphaclip;
|
||||
|
||||
/* Tools may request depth outside of regular drawing code. */
|
||||
UI_Theme_Store(&theme_state);
|
||||
UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW);
|
||||
|
||||
ED_view3d_draw_setup_view(
|
||||
G_MAIN->wm.first, NULL, depsgraph, scene, region, v3d, NULL, NULL, NULL);
|
||||
|
||||
/* get surface depth without bias */
|
||||
rv3d->rflag |= RV3D_ZOFFSET_DISABLED;
|
||||
|
||||
/* Needed in cases the 3D Viewport isn't already setup. */
|
||||
WM_draw_region_viewport_ensure(region, SPACE_VIEW3D);
|
||||
WM_draw_region_viewport_bind(region);
|
||||
|
||||
GPUViewport *viewport = WM_draw_region_get_viewport(region);
|
||||
/* When Blender is starting, a click event can trigger a depth test while the viewport is not
|
||||
* yet available. */
|
||||
if (viewport != NULL) {
|
||||
DRW_draw_depth_loop(depsgraph, region, v3d, viewport, false);
|
||||
}
|
||||
|
||||
WM_draw_region_viewport_unbind(region);
|
||||
|
||||
rv3d->rflag &= ~RV3D_ZOFFSET_DISABLED;
|
||||
|
||||
U.glalphaclip = glalphaclip;
|
||||
v3d->flag = flag;
|
||||
|
||||
UI_Theme_Restore(&theme_state);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
@ -1634,7 +1588,8 @@ void view3d_main_region_draw(const bContext *C, ARegion *region)
|
|||
/* No depth test for drawing action zones afterwards. */
|
||||
GPU_depth_test(GPU_DEPTH_NONE);
|
||||
|
||||
v3d->flag |= V3D_INVALID_BACKBUF;
|
||||
v3d->runtime.flag &= ~V3D_RUNTIME_DEPTHBUF_OVERRIDDEN;
|
||||
/* TODO: Clear cache? */
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
@ -2175,6 +2130,10 @@ static void validate_object_select_id(struct Depsgraph *depsgraph,
|
|||
View3D *v3d,
|
||||
Object *obact)
|
||||
{
|
||||
/* TODO: Use a flag in the selection engine itself. */
|
||||
if (v3d->runtime.flag & V3D_RUNTIME_DEPTHBUF_OVERRIDDEN) {
|
||||
return;
|
||||
}
|
||||
Object *obact_eval = DEG_get_evaluated_object(depsgraph, obact);
|
||||
|
||||
BLI_assert(region->regiontype == RGN_TYPE_WINDOW);
|
||||
|
@ -2193,11 +2152,7 @@ static void validate_object_select_id(struct Depsgraph *depsgraph,
|
|||
/* do nothing */
|
||||
}
|
||||
else {
|
||||
v3d->flag &= ~V3D_INVALID_BACKBUF;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(v3d->flag & V3D_INVALID_BACKBUF)) {
|
||||
v3d->runtime.flag |= V3D_RUNTIME_DEPTHBUF_OVERRIDDEN;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2206,9 +2161,7 @@ static void validate_object_select_id(struct Depsgraph *depsgraph,
|
|||
DRW_select_buffer_context_create(&base, 1, -1);
|
||||
}
|
||||
|
||||
/* TODO: Create a flag in `DRW_manager` because the drawing is no longer
|
||||
* made on the back-buffer in this case. */
|
||||
v3d->flag &= ~V3D_INVALID_BACKBUF;
|
||||
v3d->runtime.flag |= V3D_RUNTIME_DEPTHBUF_OVERRIDDEN;
|
||||
}
|
||||
|
||||
/* TODO: Creating, attaching texture, and destroying a framebuffer is quite slow.
|
||||
|
@ -2235,26 +2188,7 @@ static void view3d_opengl_read_Z_pixels(GPUViewport *viewport, rcti *rect, void
|
|||
|
||||
void ED_view3d_select_id_validate(ViewContext *vc)
|
||||
{
|
||||
/* TODO: Create a flag in `DRW_manager` because the drawing is no longer
|
||||
* made on the back-buffer in this case. */
|
||||
if (vc->v3d->flag & V3D_INVALID_BACKBUF) {
|
||||
validate_object_select_id(vc->depsgraph, vc->view_layer, vc->region, vc->v3d, vc->obact);
|
||||
}
|
||||
}
|
||||
|
||||
void ED_view3d_backbuf_depth_validate(ViewContext *vc)
|
||||
{
|
||||
if (vc->v3d->flag & V3D_INVALID_BACKBUF) {
|
||||
ARegion *region = vc->region;
|
||||
Object *obact_eval = DEG_get_evaluated_object(vc->depsgraph, vc->obact);
|
||||
|
||||
if (obact_eval && ((obact_eval->base_flag & BASE_VISIBLE_DEPSGRAPH) != 0)) {
|
||||
GPUViewport *viewport = WM_draw_region_get_viewport(region);
|
||||
DRW_draw_depth_object(vc->scene, vc->region, vc->v3d, viewport, obact_eval);
|
||||
}
|
||||
|
||||
vc->v3d->flag &= ~V3D_INVALID_BACKBUF;
|
||||
}
|
||||
validate_object_select_id(vc->depsgraph, vc->view_layer, vc->region, vc->v3d, vc->obact);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2326,7 +2260,7 @@ void view3d_update_depths_rect(ARegion *region, ViewDepths *d, rcti *rect)
|
|||
}
|
||||
|
||||
/* Note, with nouveau drivers the glReadPixels() is very slow. T24339. */
|
||||
void ED_view3d_depth_update(ARegion *region)
|
||||
static void view3d_depth_cache_update(ARegion *region)
|
||||
{
|
||||
RegionView3D *rv3d = region->regiondata;
|
||||
|
||||
|
@ -2348,13 +2282,9 @@ void ED_view3d_depth_update(ARegion *region)
|
|||
|
||||
if (d->damaged) {
|
||||
GPUViewport *viewport = WM_draw_region_get_viewport(region);
|
||||
rcti r = {
|
||||
.xmin = 0,
|
||||
.xmax = d->w,
|
||||
.ymin = 0,
|
||||
.ymax = d->h,
|
||||
};
|
||||
view3d_opengl_read_Z_pixels(viewport, &r, d->depths);
|
||||
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;
|
||||
|
@ -2387,19 +2317,81 @@ float view3d_depth_near(ViewDepths *d)
|
|||
return far == far_real ? FLT_MAX : far;
|
||||
}
|
||||
|
||||
void ED_view3d_draw_depth_gpencil(Depsgraph *depsgraph, Scene *scene, ARegion *region, View3D *v3d)
|
||||
/**
|
||||
* Redraw the viewport depth buffer.
|
||||
*
|
||||
* \param mode: V3D_DEPTH_NO_GPENCIL - Redraw viewport without Grease Pencil and Annotations.
|
||||
* V3D_DEPTH_GPENCIL_ONLY - Redraw viewport with Grease Pencil and Annotations only.
|
||||
* V3D_DEPTH_OBJECT_ONLY - Redraw viewport with active object only.
|
||||
* \param update_cache: If true, store the entire depth buffer in #rv3d->depths.
|
||||
*/
|
||||
void ED_view3d_depth_override(Depsgraph *depsgraph,
|
||||
ARegion *region,
|
||||
View3D *v3d,
|
||||
Object *obact,
|
||||
eV3DDepthOverrideMode mode,
|
||||
bool update_cache)
|
||||
{
|
||||
/* Setup view matrix. */
|
||||
ED_view3d_draw_setup_view(NULL, NULL, depsgraph, scene, region, v3d, NULL, NULL, NULL);
|
||||
if (v3d->runtime.flag & V3D_RUNTIME_DEPTHBUF_OVERRIDDEN) {
|
||||
return;
|
||||
}
|
||||
struct bThemeState theme_state;
|
||||
Scene *scene = DEG_get_evaluated_scene(depsgraph);
|
||||
RegionView3D *rv3d = region->regiondata;
|
||||
|
||||
GPU_clear_depth(1.0f);
|
||||
short flag = v3d->flag;
|
||||
/* temp set drawtype to solid */
|
||||
/* Setting these temporarily is not nice */
|
||||
v3d->flag &= ~V3D_SELECT_OUTLINE;
|
||||
|
||||
GPU_depth_test(GPU_DEPTH_LESS_EQUAL);
|
||||
/* Tools may request depth outside of regular drawing code. */
|
||||
UI_Theme_Store(&theme_state);
|
||||
UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW);
|
||||
|
||||
ED_view3d_draw_setup_view(
|
||||
G_MAIN->wm.first, NULL, depsgraph, scene, region, v3d, NULL, NULL, NULL);
|
||||
|
||||
/* get surface depth without bias */
|
||||
rv3d->rflag |= RV3D_ZOFFSET_DISABLED;
|
||||
|
||||
/* Needed in cases the 3D Viewport isn't already setup. */
|
||||
WM_draw_region_viewport_ensure(region, SPACE_VIEW3D);
|
||||
WM_draw_region_viewport_bind(region);
|
||||
|
||||
GPUViewport *viewport = WM_draw_region_get_viewport(region);
|
||||
DRW_draw_depth_loop_gpencil(depsgraph, region, v3d, viewport);
|
||||
/* When Blender is starting, a click event can trigger a depth test while the viewport is not
|
||||
* yet available. */
|
||||
if (viewport != NULL) {
|
||||
switch (mode) {
|
||||
case V3D_DEPTH_NO_GPENCIL:
|
||||
DRW_draw_depth_loop(depsgraph, region, v3d, viewport);
|
||||
break;
|
||||
case V3D_DEPTH_GPENCIL_ONLY:
|
||||
DRW_draw_depth_loop_gpencil(depsgraph, region, v3d, viewport);
|
||||
break;
|
||||
case V3D_DEPTH_OBJECT_ONLY:
|
||||
DRW_draw_depth_object(
|
||||
scene, region, v3d, viewport, DEG_get_evaluated_object(depsgraph, obact));
|
||||
break;
|
||||
}
|
||||
|
||||
GPU_depth_test(GPU_DEPTH_NONE);
|
||||
if (rv3d->depths != NULL) {
|
||||
rv3d->depths->damaged = true;
|
||||
/* TODO: Clear cache? */
|
||||
}
|
||||
if (update_cache) {
|
||||
view3d_depth_cache_update(region);
|
||||
}
|
||||
}
|
||||
|
||||
WM_draw_region_viewport_unbind(region);
|
||||
|
||||
rv3d->rflag &= ~RV3D_ZOFFSET_DISABLED;
|
||||
|
||||
v3d->flag = flag;
|
||||
v3d->runtime.flag |= V3D_RUNTIME_DEPTHBUF_OVERRIDDEN;
|
||||
|
||||
UI_Theme_Restore(&theme_state);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
|
|
@ -3628,9 +3628,8 @@ 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_ensure_evaluated_depsgraph(C), region, v3d, true);
|
||||
|
||||
ED_view3d_depth_override(
|
||||
CTX_data_ensure_evaluated_depsgraph(C), region, v3d, NULL, V3D_DEPTH_NO_GPENCIL, false);
|
||||
{
|
||||
/* avoid allocating the whole depth buffer */
|
||||
ViewDepths depth_temp = {0};
|
||||
|
|
|
@ -122,17 +122,7 @@ void VIEW3D_OT_walk(struct wmOperatorType *ot);
|
|||
void view3d_main_region_draw(const struct bContext *C, struct ARegion *region);
|
||||
void view3d_draw_region_info(const struct bContext *C, struct ARegion *region);
|
||||
|
||||
void ED_view3d_draw_depth(struct Depsgraph *depsgraph,
|
||||
struct ARegion *region,
|
||||
View3D *v3d,
|
||||
bool alphaoverride);
|
||||
|
||||
/* view3d_draw_legacy.c */
|
||||
void ED_view3d_draw_depth_gpencil(struct Depsgraph *depsgraph,
|
||||
Scene *scene,
|
||||
struct ARegion *region,
|
||||
View3D *v3d);
|
||||
|
||||
void ED_view3d_draw_select_loop(struct Depsgraph *depsgraph,
|
||||
ViewContext *vc,
|
||||
Scene *scene,
|
||||
|
|
|
@ -1024,6 +1024,7 @@ static float view_autodist_depth_margin(ARegion *region, const int mval[2], int
|
|||
|
||||
/**
|
||||
* 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.
|
||||
|
@ -1034,7 +1035,7 @@ bool ED_view3d_autodist(Depsgraph *depsgraph,
|
|||
View3D *v3d,
|
||||
const int mval[2],
|
||||
float mouse_worldloc[3],
|
||||
const bool alphaoverride,
|
||||
const bool UNUSED(alphaoverride),
|
||||
const float fallback_depth_pt[3])
|
||||
{
|
||||
float depth_close;
|
||||
|
@ -1042,7 +1043,7 @@ bool ED_view3d_autodist(Depsgraph *depsgraph,
|
|||
bool depth_ok = false;
|
||||
|
||||
/* Get Z Depths, needed for perspective, nice for ortho */
|
||||
ED_view3d_draw_depth(depsgraph, region, v3d, alphaoverride);
|
||||
ED_view3d_depth_override(depsgraph, region, v3d, NULL, V3D_DEPTH_NO_GPENCIL, false);
|
||||
|
||||
/* Attempt with low margin's first */
|
||||
int i = 0;
|
||||
|
@ -1067,22 +1068,7 @@ bool ED_view3d_autodist(Depsgraph *depsgraph,
|
|||
return false;
|
||||
}
|
||||
|
||||
void ED_view3d_autodist_init(Depsgraph *depsgraph, ARegion *region, View3D *v3d, int mode)
|
||||
{
|
||||
/* Get Z Depths, needed for perspective, nice for ortho */
|
||||
switch (mode) {
|
||||
case 0:
|
||||
ED_view3d_draw_depth(depsgraph, region, v3d, true);
|
||||
break;
|
||||
case 1: {
|
||||
Scene *scene = DEG_get_evaluated_scene(depsgraph);
|
||||
ED_view3d_draw_depth_gpencil(depsgraph, scene, region, v3d);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* no 4x4 sampling, run #ED_view3d_autodist_init first */
|
||||
/* no 4x4 sampling, run #ED_view3d_depth_override first */
|
||||
bool ED_view3d_autodist_simple(ARegion *region,
|
||||
const int mval[2],
|
||||
float mouse_worldloc[3],
|
||||
|
|
|
@ -367,7 +367,7 @@ typedef struct View3D {
|
|||
#define V3D_LOCAL_COLLECTIONS (1 << 0)
|
||||
#define V3D_FLAG_UNUSED_1 (1 << 1) /* cleared */
|
||||
#define V3D_HIDE_HELPLINES (1 << 2)
|
||||
#define V3D_INVALID_BACKBUF (1 << 3)
|
||||
#define V3D_FLAG_UNUSED_2 (1 << 3) /* cleared */
|
||||
#define V3D_XR_SESSION_MIRROR (1 << 4)
|
||||
|
||||
#define V3D_FLAG_UNUSED_10 (1 << 10) /* cleared */
|
||||
|
@ -380,6 +380,8 @@ typedef struct View3D {
|
|||
enum {
|
||||
/** The 3D view which the XR session was created in is flagged with this. */
|
||||
V3D_RUNTIME_XR_SESSION_ROOT = (1 << 0),
|
||||
/** Some operators override the depth buffer for dedicated occlusion operations. */
|
||||
V3D_RUNTIME_DEPTHBUF_OVERRIDDEN = (1 << 1),
|
||||
};
|
||||
|
||||
/** #RegionView3D.persp */
|
||||
|
|
|
@ -218,13 +218,6 @@ static bool wm_draw_region_stereo_set(Main *bmain,
|
|||
return false;
|
||||
}
|
||||
|
||||
static void wm_area_mark_invalid_backbuf(ScrArea *area)
|
||||
{
|
||||
if (area->spacetype == SPACE_VIEW3D) {
|
||||
((View3D *)area->spacedata.first)->flag |= V3D_INVALID_BACKBUF;
|
||||
}
|
||||
}
|
||||
|
||||
static void wm_region_test_gizmo_do_draw(bContext *C,
|
||||
ScrArea *area,
|
||||
ARegion *region,
|
||||
|
@ -739,7 +732,6 @@ static void wm_draw_window_offscreen(bContext *C, wmWindow *win, bool stereo)
|
|||
}
|
||||
}
|
||||
|
||||
wm_area_mark_invalid_backbuf(area);
|
||||
CTX_wm_area_set(C, NULL);
|
||||
|
||||
GPU_debug_group_end();
|
||||
|
|
Loading…
Reference in New Issue