[Bf-blender-cvs] [0013bfdf25a] greasepencil-object: GP: Fix gap drawing Circle, Rectangle and Arc primitives

Antonioya noreply at git.blender.org
Thu Dec 6 17:02:30 CET 2018


Commit: 0013bfdf25a4d0d27216bcc36b07a4b1224b42d6
Author: Antonioya
Date:   Thu Dec 6 17:02:20 2018 +0100
Branches: greasepencil-object
https://developer.blender.org/rB0013bfdf25a4d0d27216bcc36b07a4b1224b42d6

GP: Fix gap drawing Circle, Rectangle and Arc primitives

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

M	source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M	source/blender/editors/gpencil/gpencil_primitive.c

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
index 1afb5daa912..0f9ea009699 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -252,6 +252,9 @@ GPUBatch *DRW_gpencil_get_buffer_stroke_geom(bGPdata *gpd, short thickness)
 
 	tGPspoint *points = gpd->runtime.sbuffer;
 	int totpoints = gpd->runtime.sbuffer_size;
+	/* if cyclic needs more vertex */
+	int cyclic_add = (gpd->runtime.sbuffer_sflag & GP_STROKE_CYCLIC) ? 1 : 0;
+	int totvertex = totpoints + cyclic_add + 2;
 
 	static GPUVertFormat format = { 0 };
 	static uint pos_id, color_id, thickness_id, uvdata_id;
@@ -263,11 +266,11 @@ GPUBatch *DRW_gpencil_get_buffer_stroke_geom(bGPdata *gpd, short thickness)
 	}
 
 	GPUVertBuf *vbo = GPU_vertbuf_create_with_format(&format);
-	GPU_vertbuf_data_alloc(vbo, totpoints + 2);
+	GPU_vertbuf_data_alloc(vbo, totvertex);
 
 	/* draw stroke curve */
 	const tGPspoint *tpt = points;
-	bGPDspoint pt, pt2;
+	bGPDspoint pt, pt2, pt3;
 	int idx = 0;
 
 	/* get origin to reproject point */
@@ -281,19 +284,22 @@ GPUBatch *DRW_gpencil_get_buffer_stroke_geom(bGPdata *gpd, short thickness)
 
 		/* first point for adjacency (not drawn) */
 		if (i == 0) {
-			if (totpoints > 1) {
-				ED_gpencil_tpoint_to_point(ar, origin, &points[1], &pt2);
+			if (gpd->runtime.sbuffer_sflag & GP_STROKE_CYCLIC && totpoints > 2) {
+				ED_gpencil_tpoint_to_point(ar, origin, &points[totpoints - 1], &pt2);
 				gpencil_set_stroke_point(
-				        vbo, &pt2, idx,
-				        pos_id, color_id, thickness_id, uvdata_id, thickness, gpd->runtime.scolor);
+					vbo, &pt2, idx,
+					pos_id, color_id, thickness_id, uvdata_id, thickness, gpd->runtime.scolor);
+				idx++;
 			}
 			else {
+				ED_gpencil_tpoint_to_point(ar, origin, &points[1], &pt2);
 				gpencil_set_stroke_point(
-				        vbo, &pt, idx,
-				        pos_id, color_id, thickness_id, uvdata_id, thickness, gpd->runtime.scolor);
+					vbo, &pt2, idx,
+					pos_id, color_id, thickness_id, uvdata_id, thickness, gpd->runtime.scolor);
+				idx++;
 			}
-			idx++;
 		}
+
 		/* set point */
 		gpencil_set_stroke_point(
 		        vbo, &pt, idx,
@@ -302,16 +308,27 @@ GPUBatch *DRW_gpencil_get_buffer_stroke_geom(bGPdata *gpd, short thickness)
 	}
 
 	/* last adjacency point (not drawn) */
-	if (totpoints > 2) {
-		ED_gpencil_tpoint_to_point(ar, origin, &points[totpoints - 2], &pt2);
+	if (gpd->runtime.sbuffer_sflag & GP_STROKE_CYCLIC && totpoints > 2) {
+		/* draw line to first point to complete the cycle */
+		ED_gpencil_tpoint_to_point(ar, origin, &points[0], &pt2);
 		gpencil_set_stroke_point(
-		        vbo, &pt2, idx,
-		        pos_id, color_id, thickness_id, uvdata_id, thickness, gpd->runtime.scolor);
+			vbo, &pt2, idx,
+			pos_id, color_id, thickness_id, uvdata_id, thickness, gpd->runtime.scolor);
+		idx++;
+		/* now add adjacency point (not drawn) */
+		ED_gpencil_tpoint_to_point(ar, origin, &points[1], &pt3);
+		gpencil_set_stroke_point(
+			vbo, &pt3, idx,
+			pos_id, color_id, thickness_id, uvdata_id, thickness, gpd->runtime.scolor);
+		idx++;
 	}
+	/* last adjacency point (not drawn) */
 	else {
+		ED_gpencil_tpoint_to_point(ar, origin, &points[totpoints - 2], &pt2);
 		gpencil_set_stroke_point(
-		        vbo, &pt, idx,
-		        pos_id, color_id, thickness_id, uvdata_id, thickness, gpd->runtime.scolor);
+			vbo, &pt2, idx,
+			pos_id, color_id, thickness_id, uvdata_id, thickness, gpd->runtime.scolor);
+		idx++;
 	}
 
 	return GPU_batch_create_ex(GPU_PRIM_LINE_STRIP_ADJ, vbo, NULL, GPU_BATCH_OWNS_VBO);
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index 72f4d5bed34..6d0f22a6645 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -111,6 +111,9 @@ static void gp_session_validatebuffer(tGPDprimitive *p)
 	/* reset flags */
 	gpd->runtime.sbuffer_sflag = 0;
 	gpd->runtime.sbuffer_sflag |= GP_STROKE_3DSPACE;
+	if (p->cyclic) {
+		gpd->runtime.sbuffer_sflag |= GP_STROKE_CYCLIC;
+	}
 }
 
 static void gp_init_colors(tGPDprimitive *p)
@@ -432,12 +435,15 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
 	tPGPspoint *points2D = MEM_callocN(sizeof(tPGPspoint) * tgpi->tot_edges, "gp primitive points2D");
 	switch (tgpi->type) {
 		case GP_STROKE_BOX:
+			tgpi->cyclic = true;
 			gp_primitive_rectangle(tgpi, points2D);
 			break;
 		case GP_STROKE_LINE:
+			tgpi->cyclic = false;
 			gp_primitive_line(tgpi, points2D);
 			break;
 		case GP_STROKE_CIRCLE:
+			tgpi->cyclic = true;
 			gp_primitive_circle(tgpi, points2D);
 			break;
 		case GP_STROKE_ARC:
@@ -612,9 +618,6 @@ static void gpencil_primitive_init(bContext *C, wmOperator *op)
 	/* set GP datablock */
 	tgpi->gpd = gpd;
 
-	/* prepare buffer data */
-	gp_session_validatebuffer(tgpi);
-
 	/* getcolor info */
 	tgpi->mat = BKE_gpencil_material_ensure(bmain, tgpi->ob);



More information about the Bf-blender-cvs mailing list