From bd6cc282d28f58766d84d78d4400d3020fe4cb10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Sun, 28 Jun 2020 16:29:27 +0200 Subject: Fix T61573 GPencil: Annotation thickness doesn't work with on OSX This fixes the issue by using the polyline shader but this does not gives the best results. A better way would be to have a dedicated shader for the lines to avoid the line break at every angle change. --- source/blender/editors/gpencil/annotate_draw.c | 39 +++++++++++++++++--------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/gpencil/annotate_draw.c b/source/blender/editors/gpencil/annotate_draw.c index 22df7bbbf31..089f41b4a66 100644 --- a/source/blender/editors/gpencil/annotate_draw.c +++ b/source/blender/editors/gpencil/annotate_draw.c @@ -172,9 +172,14 @@ static void annotation_draw_stroke_buffer(bGPdata *gps, float oldpressure = points[0].pressure; /* draw stroke curve */ - GPU_line_width(max_ff(oldpressure * thickness, 1.0)); + immBindBuiltinProgram(GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR); + + float viewport[4]; + GPU_viewport_size_get_f(viewport); + immUniform2fv("viewportSize", &viewport[2]); + + immUniform1f("lineWidth", max_ff(oldpressure * thickness, 1.0) * U.pixelsize); - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); immUniformColor3fvAlpha(ink, ink[3]); immBeginAtMost(GPU_PRIM_LINE_STRIP, totpoints); @@ -193,7 +198,7 @@ static void annotation_draw_stroke_buffer(bGPdata *gps, immEnd(); draw_points = 0; - GPU_line_width(max_ff(pt->pressure * thickness, 1.0f)); + immUniform1f("lineWidth", max_ff(pt->pressure * thickness, 1.0) * U.pixelsize); immBeginAtMost(GPU_PRIM_LINE_STRIP, totpoints - i + 1); /* need to roll-back one point to ensure that there are no gaps in the stroke */ @@ -327,11 +332,17 @@ static void annotation_draw_stroke_3d( GPUVertFormat *format = immVertexFormat(); uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); - immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); + immBindBuiltinProgram(GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR); + + float viewport[4]; + GPU_viewport_size_get_f(viewport); + immUniform2fv("viewportSize", &viewport[2]); + + immUniform1f("lineWidth", max_ff(curpressure * thickness, 1.0) * U.pixelsize); + immUniformColor3fvAlpha(ink, ink[3]); /* draw stroke curve */ - GPU_line_width(max_ff(curpressure * thickness, 1.0f)); immBeginAtMost(GPU_PRIM_LINE_STRIP, totpoints + cyclic_add); const bGPDspoint *pt = points; for (int i = 0; i < totpoints; i++, pt++) { @@ -351,7 +362,7 @@ static void annotation_draw_stroke_3d( draw_points = 0; curpressure = pt->pressure; - GPU_line_width(max_ff(curpressure * thickness, 1.0f)); + immUniform1f("lineWidth", max_ff(curpressure * thickness, 1.0) * U.pixelsize); immBeginAtMost(GPU_PRIM_LINE_STRIP, totpoints - i + 1 + cyclic_add); /* need to roll-back one point to ensure that there are no gaps in the stroke */ @@ -424,11 +435,15 @@ static void annotation_draw_stroke_2d(const bGPDspoint *points, } else { /* draw stroke curve */ - GPU_line_width(max_ff(oldpressure * thickness, 1.0)); - - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + immBindBuiltinProgram(GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR); immUniformColor3fvAlpha(ink, ink[3]); + float viewport[4]; + GPU_viewport_size_get_f(viewport); + immUniform2fv("viewportSize", &viewport[2]); + + immUniform1f("lineWidth", max_ff(oldpressure * thickness, 1.0) * U.pixelsize); + immBeginAtMost(GPU_PRIM_LINE_STRIP, totpoints); for (int i = 0; i < totpoints; i++) { @@ -448,7 +463,8 @@ static void annotation_draw_stroke_2d(const bGPDspoint *points, immEnd(); draw_points = 0; - GPU_line_width(max_ff(pt->pressure * thickness, 1.0f)); + immUniform1f("lineWidth", max_ff(pt->pressure * thickness, 1.0) * U.pixelsize); + immBeginAtMost(GPU_PRIM_LINE_STRIP, totpoints - i + 1); /* need to roll-back one point to ensure that there are no gaps in the stroke */ @@ -683,9 +699,6 @@ static void annotation_draw_data_layers( continue; } - /* set basic stroke thickness */ - GPU_line_width(lthick); - /* Add layer drawing settings to the set of "draw flags" * NOTE: If the setting doesn't apply, it *must* be cleared, * as dflag's carry over from the previous layer -- cgit v1.2.3