Fix #119397: X-Ray not available in Rendered mode when using Workbench #119769

Closed
Fermin-Lozano wants to merge 3 commits from Fermin-Lozano/blender:fix-#119397 into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
9 changed files with 24 additions and 17 deletions

View File

@ -1033,7 +1033,8 @@ class VIEW3D_HT_header(Header):
sub.popover(panel="VIEW3D_PT_overlay_bones", text="", icon='POSE_HLT')
row = layout.row()
row.active = (object_mode == 'EDIT') or (shading.type in {'WIREFRAME', 'SOLID'})
engine = context.scene.render.engine
row.active = (object_mode == 'EDIT') or (shading.type in {'WIREFRAME', 'SOLID'}) or (engine == 'BLENDER_WORKBENCH')
# While exposing `shading.show_xray(_wireframe)` is correct.
# this hides the key shortcut from users: #70433.
@ -6654,6 +6655,7 @@ class VIEW3D_PT_shading_options(Panel):
if shading.type == 'SOLID':
col.prop(shading, "show_backface_culling")
engine = context.scene.render.engine
row = col.row(align=True)
if shading.type == 'WIREFRAME':
@ -6661,7 +6663,7 @@ class VIEW3D_PT_shading_options(Panel):
sub = row.row()
sub.active = shading.show_xray_wireframe
sub.prop(shading, "xray_alpha_wireframe", text="X-Ray")
elif shading.type == 'SOLID':
elif shading.type == 'SOLID' or engine == 'BLENDER_WORKBENCH':
row.prop(shading, "show_xray", text="")
sub = row.row()
sub.active = shading.show_xray
@ -7139,6 +7141,7 @@ class VIEW3D_PT_overlay_edit_mesh_shading(Panel):
layout = self.layout
view = context.space_data
engine = context.scene.render.engine
shading = view.shading
overlay = view.overlay
tool_settings = context.tool_settings
@ -7163,7 +7166,7 @@ class VIEW3D_PT_overlay_edit_mesh_shading(Panel):
if shading.type == 'WIREFRAME':
xray = shading.show_xray_wireframe and shading.xray_alpha_wireframe < 1.0
elif shading.type == 'SOLID':
elif shading.type == 'SOLID' or engine == 'BLENDER_WORKBENCH':
xray = shading.show_xray and shading.xray_alpha < 1.0
else:
xray = False

View File

@ -114,7 +114,7 @@ static void OVERLAY_engine_init(void *vedata)
pd->wireframe_mode = (v3d->shading.type == OB_WIRE);
pd->clipping_state = RV3D_CLIPPING_ENABLED(v3d, rv3d) ? DRW_STATE_CLIP_PLANES : DRWState(0);
pd->xray_opacity = XRAY_ALPHA(v3d);
pd->xray_enabled = XRAY_ACTIVE(v3d);
pd->xray_enabled = XRAY_ACTIVE(v3d, scene);
pd->xray_enabled_and_not_wire = pd->xray_enabled && v3d->shading.type > OB_WIRE;
pd->clear_in_front = (v3d->shading.type != OB_SOLID);
pd->cfra = DEG_get_ctime(draw_ctx->depsgraph);

View File

@ -40,7 +40,7 @@ void Instance::init()
BKE_scene_uses_blender_workbench(state.scene);
state.is_wireframe_mode = (state.v3d->shading.type == OB_WIRE);
state.hide_overlays = (state.v3d->flag2 & V3D_HIDE_OVERLAYS) != 0;
state.xray_enabled = XRAY_ACTIVE(state.v3d);
state.xray_enabled = XRAY_ACTIVE(state.v3d, state.scene);
state.xray_enabled_and_not_wire = state.xray_enabled && (state.v3d->shading.type > OB_WIRE);
state.xray_opacity = XRAY_ALPHA(state.v3d);
state.cfra = DEG_get_ctime(state.depsgraph);

View File

@ -49,7 +49,7 @@ void SceneState::init(Object *camera_ob /*=nullptr*/)
bool is_render_mode = !v3d || ELEM(v3d->shading.type, OB_RENDER, OB_MATERIAL);
const View3DShading previous_shading = shading;
shading = is_render_mode ? scene->display.shading : v3d->shading;
shading = !v3d ? scene->display.shading : v3d->shading;
cull_state = shading.flag & V3D_SHADING_BACKFACE_CULLING ? DRW_STATE_CULL_BACK :
DRW_STATE_NO_DRAW;

View File

@ -662,7 +662,7 @@ static EditBone *get_nearest_editbonepoint(
use_cycle = !WM_cursor_test_motion_and_update(vc->mval);
}
const bool do_nearest = !(XRAY_ACTIVE(vc->v3d) || use_cycle);
const bool do_nearest = !(XRAY_ACTIVE(vc->v3d, vc->scene) || use_cycle);
/* matching logic from 'mixed_bones_object_selectbuffer' */
int hits = 0;

View File

@ -1247,14 +1247,15 @@ void ED_view3d_shade_update(Main *bmain, View3D *v3d, ScrArea *area);
#define SHADING_XRAY_FLAG_ENABLED(shading) (((shading).flag & SHADING_XRAY_FLAG(shading)) != 0)
#define SHADING_XRAY_ENABLED(shading) \
(SHADING_XRAY_FLAG_ENABLED(shading) && (SHADING_XRAY_ALPHA(shading) < 1.0f))
#define SHADING_XRAY_ACTIVE(shading) \
(SHADING_XRAY_ENABLED(shading) && ((shading).type < OB_MATERIAL))
#define SHADING_XRAY_ACTIVE(shading, scene) \
(SHADING_XRAY_ENABLED(shading) && \
((shading).type < OB_MATERIAL || STREQ(scene->r.engine, RE_engine_id_BLENDER_WORKBENCH)))
#define XRAY_ALPHA(v3d) SHADING_XRAY_ALPHA((v3d)->shading)
#define XRAY_FLAG(v3d) SHADING_XRAY_FLAG((v3d)->shading)
#define XRAY_FLAG_ENABLED(v3d) SHADING_XRAY_FLAG_ENABLED((v3d)->shading)
#define XRAY_ENABLED(v3d) SHADING_XRAY_ENABLED((v3d)->shading)
#define XRAY_ACTIVE(v3d) SHADING_XRAY_ACTIVE((v3d)->shading)
#define XRAY_ACTIVE(v3d, scene) SHADING_XRAY_ACTIVE((v3d)->shading, scene)
#define OVERLAY_RETOPOLOGY_ENABLED(overlay) \
(((overlay).edit_flag & V3D_OVERLAY_EDIT_RETOPOLOGY) != 0)

View File

@ -28,6 +28,7 @@
#include "BKE_report.hh"
#include "BKE_scene.hh"
#include "BKE_screen.hh"
#include "RE_engine.h"
#include "DEG_depsgraph_query.hh"
@ -1198,6 +1199,7 @@ static int toggle_xray_exec(bContext *C, wmOperator *op)
View3D *v3d = CTX_wm_view3d(C);
ScrArea *area = CTX_wm_area(C);
Object *obact = CTX_data_active_object(C);
RenderEngineType *engine_type = CTX_data_engine_type(C);
if (obact && ((obact->mode & OB_MODE_POSE) ||
((obact->mode & OB_MODE_WEIGHT_PAINT) && BKE_object_pose_armature_get(obact))))
@ -1206,7 +1208,8 @@ static int toggle_xray_exec(bContext *C, wmOperator *op)
}
else {
const bool xray_active = ((obact && (obact->mode & OB_MODE_EDIT)) ||
ELEM(v3d->shading.type, OB_WIRE, OB_SOLID));
ELEM(v3d->shading.type, OB_WIRE, OB_SOLID) ||
STREQ(engine_type->idname, "BLENDER_WORKBENCH"));
if (v3d->shading.type == OB_WIRE) {
v3d->shading.flag ^= V3D_SHADING_XRAY_WIREFRAME;

View File

@ -2190,12 +2190,12 @@ static int mixed_bones_object_selectbuffer_extended(const ViewContext *vc,
if (use_cycle) {
/* Update the coordinates (even if the return value isn't used). */
const bool has_motion = WM_cursor_test_motion_and_update(mval);
if (!XRAY_ACTIVE(v3d)) {
if (!XRAY_ACTIVE(v3d, vc->scene)) {
do_nearest = has_motion;
}
}
else {
if (!XRAY_ACTIVE(v3d)) {
if (!XRAY_ACTIVE(v3d, vc->scene)) {
do_nearest = true;
}
}
@ -2432,7 +2432,7 @@ static Base *ed_view3d_give_base_under_cursor_ex(bContext *C,
const ViewContext vc = ED_view3d_viewcontext_init(C, depsgraph);
const bool do_nearest = !XRAY_ACTIVE(vc.v3d);
const bool do_nearest = !XRAY_ACTIVE(vc.v3d, vc.scene);
const bool do_material_slot_selection = r_material_slot != nullptr;
const int hits = mixed_bones_object_selectbuffer(
&vc, &buffer, mval, VIEW3D_SELECT_FILTER_NOP, do_nearest, false, do_material_slot_selection);

View File

@ -676,12 +676,12 @@ int view3d_opengl_select_ex(const ViewContext *vc,
ED_view3d_draw_setup_view(
wm, vc->win, depsgraph, scene, region, v3d, vc->rv3d->viewmat, nullptr, &rect);
if (!XRAY_ACTIVE(v3d)) {
if (!XRAY_ACTIVE(v3d, scene)) {
GPU_depth_test(GPU_DEPTH_LESS_EQUAL);
}
/* If in X-ray mode, we select the wires in priority. */
if (XRAY_ACTIVE(v3d) && use_nearest) {
if (XRAY_ACTIVE(v3d, scene) && use_nearest) {
/* We need to call "GPU_select_*" API's inside DRW_draw_select_loop
* because the OpenGL context created & destroyed inside this function. */
DrawSelectLoopUserData drw_select_loop_user_data = {};
@ -741,7 +741,7 @@ int view3d_opengl_select_ex(const ViewContext *vc,
ED_view3d_draw_setup_view(
wm, vc->win, depsgraph, scene, region, v3d, vc->rv3d->viewmat, nullptr, nullptr);
if (!XRAY_ACTIVE(v3d)) {
if (!XRAY_ACTIVE(v3d, scene)) {
GPU_depth_test(GPU_DEPTH_NONE);
}