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
This commit is contained in:
Germano Cavalcante
2025-07-07 16:54:22 +02:00
committed by Germano Cavalcante
parent d4961dac0b
commit cd143ca900

View File

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