diff options
author | Chris Blackbourn <chrisbblend@gmail.com> | 2022-06-12 08:41:09 +0300 |
---|---|---|
committer | Chris Blackbourn <chrisbblend@gmail.com> | 2022-06-12 08:47:15 +0300 |
commit | cc4d46d91ee1f35455676f4c84ec46502488043a (patch) | |
tree | fdb881a5e798bfc5500eead9dfdbddb91e622f45 /source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c | |
parent | 9d7e73144409c4b65343d00e8db1e030c966b33a (diff) |
Fix unreported: Choose nsegments for 2D rotation gizmo based on screen scale.
This mostly affects large rotation gizmos at high DPI.
Without this patch, they appear as 32-gons instead of circles.
Diffstat (limited to 'source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c')
-rw-r--r-- | source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c index 546157b95c2..11309402220 100644 --- a/source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c +++ b/source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.c @@ -57,8 +57,6 @@ typedef struct ButtonGizmo2D { GPUBatch *shape_batch[2]; } ButtonGizmo2D; -#define CIRCLE_RESOLUTION 32 - /** \} */ /* -------------------------------------------------------------------- */ @@ -68,11 +66,17 @@ typedef struct ButtonGizmo2D { static void button2d_geom_draw_backdrop(const wmGizmo *gz, const float color[4], const float fill_alpha, - const bool select) + const bool select, + const float screen_scale) { float viewport[4]; GPU_viewport_size_get_f(viewport); + const float max_pixel_error = 0.25f; + int nsegments = (int)(ceilf(M_PI / acosf(1.0f - max_pixel_error / screen_scale))); + nsegments = max_ff(nsegments, 8); + nsegments = min_ff(nsegments, 1000); + GPUVertFormat *format = immVertexFormat(); /* NOTE(Metal): Prefer 3D coordinate for 2D rendering when using 3D shader. */ uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); @@ -81,14 +85,14 @@ static void button2d_geom_draw_backdrop(const wmGizmo *gz, if (color[3] == 1.0 && fill_alpha == 1.0 && select == false) { immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); immUniformColor4fv(color); - imm_draw_circle_fill_3d(pos, 0.0f, 0.0f, 1.0f, CIRCLE_RESOLUTION); + imm_draw_circle_fill_3d(pos, 0.0f, 0.0f, 1.0f, nsegments); immUnbindProgram(); immBindBuiltinProgram(GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR); immUniform2fv("viewportSize", &viewport[2]); immUniform1f("lineWidth", gz->line_width * U.pixelsize); immUniformColor4fv(color); - imm_draw_circle_wire_3d(pos, 0.0f, 0.0f, 1.0f, CIRCLE_RESOLUTION); + imm_draw_circle_wire_3d(pos, 0.0f, 0.0f, 1.0f, nsegments); immUnbindProgram(); } else { @@ -97,7 +101,7 @@ static void button2d_geom_draw_backdrop(const wmGizmo *gz, const float fill_color[4] = {UNPACK3(color), fill_alpha * color[3]}; immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); immUniformColor4fv(fill_color); - imm_draw_circle_fill_3d(pos, 0.0f, 0.0f, 1.0f, CIRCLE_RESOLUTION); + imm_draw_circle_fill_3d(pos, 0.0f, 0.0f, 1.0f, nsegments); immUnbindProgram(); } @@ -107,7 +111,7 @@ static void button2d_geom_draw_backdrop(const wmGizmo *gz, immUniform2fv("viewportSize", &viewport[2]); immUniform1f("lineWidth", gz->line_width * U.pixelsize); immUniformColor4fv(color); - imm_draw_circle_wire_3d(pos, 0.0f, 0.0f, 1.0f, CIRCLE_RESOLUTION); + imm_draw_circle_wire_3d(pos, 0.0f, 0.0f, 1.0f, nsegments); immUnbindProgram(); } } @@ -184,9 +188,11 @@ static void button2d_draw_intern(const bContext *C, GPU_matrix_mul(matrix_align); } + const float screen_scale = mat4_to_scale(matrix_final); + if (select) { BLI_assert(is_3d); - button2d_geom_draw_backdrop(gz, color, 1.0, select); + button2d_geom_draw_backdrop(gz, color, 1.0, select, screen_scale); } else { @@ -194,7 +200,7 @@ static void button2d_draw_intern(const bContext *C, if (draw_options & ED_GIZMO_BUTTON_SHOW_BACKDROP) { const float fill_alpha = RNA_float_get(gz->ptr, "backdrop_fill_alpha"); - button2d_geom_draw_backdrop(gz, color, fill_alpha, select); + button2d_geom_draw_backdrop(gz, color, fill_alpha, select, screen_scale); } if (button->shape_batch[0] != NULL) { |