From cd143ca900c44b4904e68f39a95afa4ffce249d0 Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Mon, 7 Jul 2025 16:54:22 +0200 Subject: [PATCH] Fix: Wrong depth status in gizmo selection When selecting gizmos (such as one of the scale handles in the Transform tool), the depth test state does not match what is shown in the viewport. This can lead to unintuitive gizmo selection. The issue is caused by the incorrect assumption that the depth state is already `GPU_DEPTH_NONE` before rendering the gizmos for selection. The solution is to ensure the status before rendering. Pull Request: https://projects.blender.org/blender/blender/pulls/141412 --- .../gizmo/intern/wm_gizmo_map.cc | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.cc b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.cc index 997088ac1ff..80c8ecb9819 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.cc +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.cc @@ -519,9 +519,16 @@ static void gizmo_draw_select_3d_loop(const bContext *C, const int visible_gizmos_len, bool *r_use_select_bias) { + /* WORKAROUND(#132196): `GPU_DEPTH_NONE` leads to issues with Intel GPU drivers on Windows + * where camera gizmos cannot be shifted. `glGetQueryObjectuiv` for `GL_SAMPLES_PASSED` + * seems to return zero in all cases. This might be due to undefined behavior of OpenGL + * when the depth test is disabled and rendering to a depth render target-only framebuffer. + * Using `GPU_DEPTH_ALWAYS` fixes the issue. */ + const bool use_intel_gpu_workaround = true; - /* TODO(@ideasman42): this depends on depth buffer being written to, - * currently broken for the 3D view. */ + /* Set default depth state. */ + GPU_depth_test(use_intel_gpu_workaround ? GPU_DEPTH_ALWAYS : GPU_DEPTH_NONE); + GPU_depth_mask(true); bool is_depth_prev = false; bool is_depth_skip_prev = false; @@ -540,12 +547,7 @@ static void gizmo_draw_select_3d_loop(const bContext *C, GPU_depth_test(GPU_DEPTH_LESS_EQUAL); } else { - /* WORKAROUND(#132196): `GPU_DEPTH_NONE` leads to issues with Intel GPU drivers on Windows - * where camera gizmos cannot be shifted. `glGetQueryObjectuiv` for `GL_SAMPLES_PASSED` - * seems to return zero in all cases. This might be due to undefined behavior of OpenGL - * when the depth test is disabled and rendering to a depth render target-only framebuffer. - * Using `GPU_DEPTH_ALWAYS` fixes the issue. */ - GPU_depth_test(GPU_DEPTH_ALWAYS); + GPU_depth_test(use_intel_gpu_workaround ? GPU_DEPTH_ALWAYS : GPU_DEPTH_NONE); } is_depth_prev = is_depth; } @@ -567,7 +569,9 @@ static void gizmo_draw_select_3d_loop(const bContext *C, gz->type->draw_select(C, gz, select_id << 8); } - if (is_depth_prev) { + /* Reset depth state.*/ + + if (is_depth_prev || use_intel_gpu_workaround) { GPU_depth_test(GPU_DEPTH_NONE); } if (is_depth_skip_prev) {