From ce4663403b80f99ebaa263145aa591fdce95e96f Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Sat, 7 Oct 2023 09:09:33 -0400 Subject: [PATCH] Cleanup: Return early to reduce indentation for 3D cursor drawing --- source/blender/draw/intern/draw_view_c.cc | 124 +++++++++++----------- 1 file changed, 62 insertions(+), 62 deletions(-) diff --git a/source/blender/draw/intern/draw_view_c.cc b/source/blender/draw/intern/draw_view_c.cc index 10ba660eca2..d35b48cf8ac 100644 --- a/source/blender/draw/intern/draw_view_c.cc +++ b/source/blender/draw/intern/draw_view_c.cc @@ -97,51 +97,53 @@ void DRW_draw_cursor() ARegion *region = draw_ctx->region; Scene *scene = draw_ctx->scene; ViewLayer *view_layer = draw_ctx->view_layer; + if (!is_cursor_visible(draw_ctx, scene, view_layer)) { + return; + } GPU_color_mask(true, true, true, true); GPU_depth_mask(false); GPU_depth_test(GPU_DEPTH_NONE); - if (is_cursor_visible(draw_ctx, scene, view_layer)) { - int co[2]; + /* Get cursor data into quaternion form */ + const View3DCursor *cursor = &scene->cursor; - /* Get cursor data into quaternion form */ - const View3DCursor *cursor = &scene->cursor; + int co[2]; + if (!ED_view3d_project_int_global( + region, cursor->location, co, V3D_PROJ_TEST_NOP | V3D_PROJ_TEST_CLIP_NEAR) == + V3D_PROJ_RET_OK) + { + return; + } - if (ED_view3d_project_int_global( - region, cursor->location, co, V3D_PROJ_TEST_NOP | V3D_PROJ_TEST_CLIP_NEAR) == - V3D_PROJ_RET_OK) - { - RegionView3D *rv3d = static_cast(region->regiondata); + RegionView3D *rv3d = static_cast(region->regiondata); - float cursor_quat[4]; - BKE_scene_cursor_rot_to_quat(cursor, cursor_quat); + float cursor_quat[4]; + BKE_scene_cursor_rot_to_quat(cursor, cursor_quat); - /* Draw nice Anti Aliased cursor. */ - GPU_line_width(1.0f); - GPU_blend(GPU_BLEND_ALPHA); - GPU_line_smooth(true); + /* Draw nice Anti Aliased cursor. */ + GPU_line_width(1.0f); + GPU_blend(GPU_BLEND_ALPHA); + GPU_line_smooth(true); - float eps = 1e-5f; - rv3d->viewquat[0] = -rv3d->viewquat[0]; - bool is_aligned = compare_v4v4(cursor_quat, rv3d->viewquat, eps); - if (is_aligned == false) { - float tquat[4]; - rotation_between_quats_to_quat(tquat, rv3d->viewquat, cursor_quat); - is_aligned = tquat[0] - eps < -1.0f; - } - rv3d->viewquat[0] = -rv3d->viewquat[0]; + float eps = 1e-5f; + rv3d->viewquat[0] = -rv3d->viewquat[0]; + bool is_aligned = compare_v4v4(cursor_quat, rv3d->viewquat, eps); + if (is_aligned == false) { + float tquat[4]; + rotation_between_quats_to_quat(tquat, rv3d->viewquat, cursor_quat); + is_aligned = tquat[0] - eps < -1.0f; + } + rv3d->viewquat[0] = -rv3d->viewquat[0]; - /* Draw lines */ - if (is_aligned == false) { - uint pos = GPU_vertformat_attr_add( - immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); - immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); - immUniformThemeColor3(TH_VIEW_OVERLAY); - immBegin(GPU_PRIM_LINES, 12); + /* Draw lines */ + if (is_aligned == false) { + uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); + immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); + immUniformThemeColor3(TH_VIEW_OVERLAY); + immBegin(GPU_PRIM_LINES, 12); - const float scale = ED_view3d_pixel_size_no_ui_scale(rv3d, cursor->location) * - U.widget_unit; + const float scale = ED_view3d_pixel_size_no_ui_scale(rv3d, cursor->location) * U.widget_unit; #define CURSOR_VERT(axis_vec, axis, fac) \ immVertex3f(pos, \ @@ -156,40 +158,38 @@ void DRW_draw_cursor() } \ ((void)0) - for (int axis = 0; axis < 3; axis++) { - float axis_vec[3] = {0}; - axis_vec[axis] = scale; - mul_qt_v3(cursor_quat, axis_vec); - CURSOR_EDGE(axis_vec, axis, +); - CURSOR_EDGE(axis_vec, axis, -); - } + for (int axis = 0; axis < 3; axis++) { + float axis_vec[3] = {0}; + axis_vec[axis] = scale; + mul_qt_v3(cursor_quat, axis_vec); + CURSOR_EDGE(axis_vec, axis, +); + CURSOR_EDGE(axis_vec, axis, -); + } #undef CURSOR_VERT #undef CURSOR_EDGE - immEnd(); - immUnbindProgram(); - } - - float original_proj[4][4]; - GPU_matrix_projection_get(original_proj); - GPU_matrix_push(); - ED_region_pixelspace(region); - GPU_matrix_translate_2f(co[0] + 0.5f, co[1] + 0.5f); - GPU_matrix_scale_2f(U.widget_unit, U.widget_unit); - - GPUBatch *cursor_batch = DRW_cache_cursor_get(is_aligned); - GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_FLAT_COLOR); - GPU_batch_set_shader(cursor_batch, shader); - - GPU_batch_draw(cursor_batch); - - GPU_blend(GPU_BLEND_NONE); - GPU_line_smooth(false); - GPU_matrix_pop(); - GPU_matrix_projection_set(original_proj); - } + immEnd(); + immUnbindProgram(); } + + float original_proj[4][4]; + GPU_matrix_projection_get(original_proj); + GPU_matrix_push(); + ED_region_pixelspace(region); + GPU_matrix_translate_2f(co[0] + 0.5f, co[1] + 0.5f); + GPU_matrix_scale_2f(U.widget_unit, U.widget_unit); + + GPUBatch *cursor_batch = DRW_cache_cursor_get(is_aligned); + GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_FLAT_COLOR); + GPU_batch_set_shader(cursor_batch, shader); + + GPU_batch_draw(cursor_batch); + + GPU_blend(GPU_BLEND_NONE); + GPU_line_smooth(false); + GPU_matrix_pop(); + GPU_matrix_projection_set(original_proj); } /* -------------------------------------------------------------------- */