From e63ec3fd16be1162f1a5982bf804bc24bddbb0e8 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Sun, 13 Feb 2022 13:49:45 +0000 Subject: [PATCH] backend: gl: fix corner being drawn with wrong color The outer pixels of the corner are drawn with antialiasing, but it color used for antialiasing is wrong. The estimated border color is used when there is actually no border. Related: #770 Signed-off-by: Yuxuan Shui --- src/backend/gl/gl_common.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/backend/gl/gl_common.c b/src/backend/gl/gl_common.c index ad15cad..dda99f8 100644 --- a/src/backend/gl/gl_common.c +++ b/src/backend/gl/gl_common.c @@ -1561,12 +1561,17 @@ const char *win_shader_glsl = GLSL(330, if (brightness > max_brightness) c.rgb = c.rgb * (max_brightness / brightness); + // Rim color is the color of the outer rim of the window, if there is no + // border, it's the color of the window itself, otherwise it's the border. + // Using mix() to avoid a branch here. + vec4 rim_color = mix(c, border_color, clamp(border_width, 0.0f, 1.0f)); + vec2 outer_size = vec2(textureSize(tex, 0)); vec2 inner_size = outer_size - vec2(corner_radius) * 2.0f; float rect_distance = rectangle_sdf(texcoord - outer_size / 2.0f, inner_size / 2.0f) - corner_radius; if (rect_distance > 0.0f) { - c = (1.0f - clamp(rect_distance, 0.0f, 1.0f)) * border_color; + c = (1.0f - clamp(rect_distance, 0.0f, 1.0f)) * rim_color; } else { float factor = clamp(rect_distance + border_width, 0.0f, 1.0f); c = (1.0f - factor) * c + factor * border_color;