[Bf-blender-cvs] [b1b8ce0bbf4] blender2.8: Getting rid of setlinestyle: GPencil eraser.

Bastien Montagne noreply at git.blender.org
Sat Apr 29 19:31:53 CEST 2017


Commit: b1b8ce0bbf461bea54791d9987f487fe0352bbf7
Author: Bastien Montagne
Date:   Sat Apr 29 16:07:26 2017 +0200
Branches: blender2.8
https://developer.blender.org/rBb1b8ce0bbf461bea54791d9987f487fe0352bbf7

Getting rid of setlinestyle: GPencil eraser.

Note the ugly hack on number of segments for outline dashed circle, to
get an OK-ish rendering of dashes...

===================================================================

M	source/blender/editors/gpencil/gpencil_paint.c

===================================================================

diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 1778d243849..b4092a73df8 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -1850,23 +1850,40 @@ static void gpencil_draw_eraser(bContext *UNUSED(C), int x, int y, void *p_ptr)
 
 	if (p->paintmode == GP_PAINTMODE_ERASER) {
 		VertexFormat *format = immVertexFormat();
-		unsigned int pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT);
+		const uint shdr_pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT);
 		immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
 
 		glEnable(GL_LINE_SMOOTH);
 		glEnable(GL_BLEND);
+		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
 		immUniformColor4ub(255, 100, 100, 20);
-		imm_draw_circle_fill(pos, x, y, p->radius, 40);
+		imm_draw_circle_fill(shdr_pos, x, y, p->radius, 40);
 
-		setlinestyle(6); /* TODO: handle line stipple in shader */
+		immUnbindProgram();
+
+		format = immVertexFormat();
+		const uint shdr_dashed_pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT);
+		const uint shdr_dashed_origin = VertexFormat_add_attrib(format, "line_origin", COMP_F32, 2, KEEP_FLOAT);
+
+		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]);
+
+		immUniform4f("color1", 1.0f, 0.39f, 0.39f, 0.78f);
+		immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f);
+		immUniform1f("dash_width", 12.0f);
+		immUniform1f("dash_width_on", 6.0f);
 
-		immUniformColor4ub(255, 100, 100, 200);
-		imm_draw_circle_wire(pos, x, y, p->radius, 40);
+		imm_draw_circle_wire_dashed(shdr_dashed_pos, shdr_dashed_origin, x, y, p->radius,
+		                            /* XXX Dashed shader gives bad results with sets of small segments currently,
+		                             *     temp hack around the issue. :( */
+		                            max_ii(8, p->radius / 2));  /* was fixed 40 */
 
 		immUnbindProgram();
 
-		setlinestyle(0);
 		glDisable(GL_BLEND);
 		glDisable(GL_LINE_SMOOTH);
 	}




More information about the Bf-blender-cvs mailing list