From 4b682fa3e7a1df187fda355ecff3aa8cad8d4029 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Wed, 26 Apr 2017 21:22:05 +0200 Subject: [PATCH] Getting rid of setlinestyle: Paint 'line' strokes. --- .../editors/sculpt_paint/paint_stroke.c | 42 +++++++------------ 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index d882baf6251..b6c4febe607 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -168,39 +168,32 @@ static void paint_draw_line_cursor(bContext *C, int x, int y, void *customdata) PaintStroke *stroke = customdata; glEnable(GL_LINE_SMOOTH); - glEnable(GL_BLEND); - setlinestyle(3); - glLineWidth(3.0f); + VertexFormat *format = immVertexFormat(); + unsigned int pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT); + unsigned int line_origin = VertexFormat_add_attrib(format, "line_origin", COMP_F32, 2, KEEP_FLOAT); - unsigned int pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT); - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - - immUniformColor4ub(0, 0, 0, paint->paint_cursor_col[3]); - - immBegin(PRIM_LINES, 2); - - if (stroke->constrain_line) { - immVertex2f(pos, stroke->last_mouse_position[0], stroke->last_mouse_position[1]); - immVertex2f(pos, stroke->constrained_pos[0], stroke->constrained_pos[1]); - } - else { - immVertex2f(pos, stroke->last_mouse_position[0], stroke->last_mouse_position[1]); - immVertex2f(pos, x, y); - } - - immEnd(); - - glLineWidth(1.0f); - immUniformColor4ub(255, 255, 255, paint->paint_cursor_col[3]); + immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR); + + float viewport_size[4]; + glGetFloatv(GL_VIEWPORT, viewport_size); + immUniform2f("viewport_size", viewport_size[2], viewport_size[3]); + + const float alpha = (float)paint->paint_cursor_col[3] / 255.0f; + immUniform4f("color1", 0.0f, 0.0f, 0.0f, alpha); + immUniform4f("color2", 1.0f, 1.0f, 1.0f, alpha); + immUniform1f("dash_width", 6.0f); + immUniform1f("dash_width_on", 3.0f); immBegin(PRIM_LINES, 2); if (stroke->constrain_line) { + immAttrib2f(line_origin, stroke->last_mouse_position[0], stroke->last_mouse_position[1]); immVertex2f(pos, stroke->last_mouse_position[0], stroke->last_mouse_position[1]); immVertex2f(pos, stroke->constrained_pos[0], stroke->constrained_pos[1]); } else { + immAttrib2f(line_origin, stroke->last_mouse_position[0], stroke->last_mouse_position[1]); immVertex2f(pos, stroke->last_mouse_position[0], stroke->last_mouse_position[1]); immVertex2f(pos, x, y); } @@ -209,9 +202,6 @@ static void paint_draw_line_cursor(bContext *C, int x, int y, void *customdata) immUnbindProgram(); - setlinestyle(0); - - glDisable(GL_BLEND); glDisable(GL_LINE_SMOOTH); }