[Bf-blender-cvs] [cc1af801165] greasepencil-object: GP: Move Control Points data to Runtime

Antonioya noreply at git.blender.org
Tue Dec 11 11:25:44 CET 2018


Commit: cc1af8011655bc732fac550f32aa16f622525f52
Author: Antonioya
Date:   Tue Dec 11 11:25:33 2018 +0100
Branches: greasepencil-object
https://developer.blender.org/rBcc1af8011655bc732fac550f32aa16f622525f52

GP: Move Control Points data to Runtime

As we maybe will use these control points in more operators is not logic keep  them in operator temp data. This makes also possible move drawing to Draw Manager.

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

M	source/blender/editors/gpencil/drawgpencil.c
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_primitive.c
M	source/blender/editors/include/ED_gpencil.h
M	source/blender/makesdna/DNA_gpencil_types.h

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

diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c
index 8bcb8a2b4dd..9d3d5c2bd8a 100644
--- a/source/blender/editors/gpencil/drawgpencil.c
+++ b/source/blender/editors/gpencil/drawgpencil.c
@@ -1441,15 +1441,13 @@ static void gp_primitive_draw_point(const tGPDprimitive *tgpi)
 	//glEnable(GL_BLEND);
 	immBindBuiltinProgram(GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR);
 	GPU_enable_program_point_size();
-	immBegin(GPU_PRIM_POINTS, tgpi->tot_cp_points);
-
-	tGPcontrolpoint *cps = tgpi->cp_points;
-	for (int i = 0; i < tgpi->tot_cp_points; i++) {
-		tGPcontrolpoint *cp = &cps[i];
-		float ink[4];
-		UI_GetThemeColor4fv(cp->color, ink);
-		ink[3] = 0.5f;
-		immAttr4fv(color, ink);
+	immBegin(GPU_PRIM_POINTS, tgpi->gpd->runtime.tot_cp_points);
+
+	bGPDcontrolpoint *cps = tgpi->gpd->runtime.cp_points;
+	for (int i = 0; i < tgpi->gpd->runtime.tot_cp_points; i++) {
+		bGPDcontrolpoint *cp = &cps[i];
+		cp->color[3] = 0.5f;
+		immAttr4fv(color, cp->color);
 		immAttr1f(size, (float)cp->size); 
 		immVertex3fv(pos, &cp->x);
 	}
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 76e33246839..9be570c08b4 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -159,8 +159,6 @@ typedef struct tGPDprimitive {
 	short cyclic;                     /* cyclic option */
 	short flip;                       /* flip option */
 	tGPspoint *points;                /* array of data-points for stroke */
-	tGPcontrolpoint *cp_points;       /* array of control-points for stroke */
-	int tot_cp_points;                /* array of control-points for stroke */
 	bool draw_cp_points;              /* array of control-points for stroke */
 	int point_count;                  /* number of edges allocated */
 	int tot_stored_edges;             /* stored number of polygon edges */
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index ebfe530da8d..229a5eaa0e6 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -288,15 +288,17 @@ static void gp_primitive_set_initdata(bContext *C, tGPDprimitive *tgpi)
 }
 
 /* Helper: set control point */
-static void gp_primitive_set_cp(tGPDprimitive *tgpi, float p[2], int color, int size)
+static void gp_primitive_set_cp(tGPDprimitive *tgpi, float p[2], float color[4], int size)
 {
-	if (tgpi->tot_cp_points < MAX_CP) {
+	bGPDcontrolpoint *cp_points = tgpi->gpd->runtime.cp_points;
+
+	if (tgpi->gpd->runtime.tot_cp_points < MAX_CP) {
 		CLAMP(size, 5, 20);
-		tGPcontrolpoint *cp = &tgpi->cp_points[tgpi->tot_cp_points];
+		bGPDcontrolpoint *cp = &cp_points[tgpi->gpd->runtime.tot_cp_points];
 		copy_v2_v2(&cp->x, p);
-		cp->color = color;
+		copy_v4_v4(cp->color, color);
 		cp->size = size;
-		tgpi->tot_cp_points += 1;
+		tgpi->gpd->runtime.tot_cp_points += 1;
 	}
 }
 
@@ -448,10 +450,12 @@ static void gp_primitive_arc(tGPDprimitive *tgpi, tGPspoint *points2D)
 		p2d->y = (end[1] - cosf(a) * length[1]);
 		a += step;
 	}
-
-	gp_primitive_set_cp(tgpi, tgpi->start, TH_ACTIVE_VERT, 20);
-	gp_primitive_set_cp(tgpi, tgpi->end, TH_ACTIVE_VERT, 20);
-	gp_primitive_set_cp(tgpi, tgpi->origin, TH_REDALERT, 10);
+	float color[4];
+	UI_GetThemeColor4fv(TH_ACTIVE_VERT, color);
+	gp_primitive_set_cp(tgpi, tgpi->start, color, 20);
+	gp_primitive_set_cp(tgpi, tgpi->end, color, 20);
+	UI_GetThemeColor4fv(TH_REDALERT, color);
+	gp_primitive_set_cp(tgpi, tgpi->origin, color, 10);
 }
 
 /* create a bezier */
@@ -475,12 +479,15 @@ static void gp_primitive_bezier(tGPDprimitive *tgpi, tGPspoint *points2D)
 		interp_v2_v2v2v2v2_cubic(&p2d->x, bcp1, bcp2, bcp3, bcp4, a);
 		a += step;
 	}
-
-	gp_primitive_set_cp(tgpi, tgpi->start, TH_ACTIVE_VERT, 20);
-	gp_primitive_set_cp(tgpi, tgpi->end, TH_ACTIVE_VERT, 20);
-	gp_primitive_set_cp(tgpi, tgpi->origin, TH_REDALERT, 10);
-	gp_primitive_set_cp(tgpi, tgpi->cp1, TH_GP_VERTEX_SELECT, 20);
-	gp_primitive_set_cp(tgpi, tgpi->cp2, TH_GP_VERTEX_SELECT, 20);
+	float color[4];
+	UI_GetThemeColor4fv(TH_ACTIVE_VERT, color);
+	gp_primitive_set_cp(tgpi, tgpi->start, color, 20);
+	gp_primitive_set_cp(tgpi, tgpi->end, color, 20);
+	UI_GetThemeColor4fv(TH_REDALERT, color);
+	gp_primitive_set_cp(tgpi, tgpi->origin, color, 10);
+	UI_GetThemeColor4fv(TH_GP_VERTEX_SELECT, color);
+	gp_primitive_set_cp(tgpi, tgpi->cp1, color, 20);
+	gp_primitive_set_cp(tgpi, tgpi->cp2, color, 20);
 }
 
 /* create a circle */
@@ -504,12 +511,14 @@ static void gp_primitive_circle(tGPDprimitive *tgpi, tGPspoint *points2D)
 		p2d->y = (center[1] + sinf(a) * radius[1]);
 		a += step;
 	}
-
-	gp_primitive_set_cp(tgpi, tgpi->start, TH_ACTIVE_VERT, 20);
-	gp_primitive_set_cp(tgpi, tgpi->end, TH_ACTIVE_VERT, 20);
-	gp_primitive_set_cp(tgpi, tgpi->origin, TH_REDALERT, 10);
-	gp_primitive_set_cp(tgpi, center, TH_REDALERT, 15);
-	gp_primitive_set_cp(tgpi, radius, TH_REDALERT, 15);
+	float color[4];
+	UI_GetThemeColor4fv(TH_ACTIVE_VERT, color);
+	gp_primitive_set_cp(tgpi, tgpi->start, color, 20);
+	gp_primitive_set_cp(tgpi, tgpi->end, color, 20);
+	UI_GetThemeColor4fv(TH_REDALERT, color);
+	gp_primitive_set_cp(tgpi, tgpi->origin, color, 10);
+	gp_primitive_set_cp(tgpi, center, color, 15);
+	gp_primitive_set_cp(tgpi, radius, color, 15);
 
 }
 
@@ -526,7 +535,7 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
 
 	gps->totpoints = (tgpi->tot_edges + tgpi->tot_stored_edges);
 
-	tgpi->tot_cp_points = 0;
+	tgpi->gpd->runtime.tot_cp_points = 0;
 
 	/* compute screen-space coordinates for points */
 	tGPspoint *points2D = tgpi->points;
@@ -695,10 +704,10 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
 	}
 
 	/* store cps and convert coords, this is temporary code */
-	if (tgpi->tot_cp_points > 0) {
-		tGPcontrolpoint *cps = tgpi->cp_points;
-		for (int i = 0; i < tgpi->tot_cp_points; i++) {
-			tGPcontrolpoint *cp = &cps[i];
+	if (tgpi->gpd->runtime.tot_cp_points > 0) {
+		bGPDcontrolpoint *cps = tgpi->gpd->runtime.cp_points;
+		for (int i = 0; i < tgpi->gpd->runtime.tot_cp_points; i++) {
+			bGPDcontrolpoint *cp = &cps[i];
 			gp_stroke_convertcoords_tpoint(tgpi->scene, tgpi->ar, tgpi->ob, tgpi->gpl, (tGPspoint *)cp, NULL, &cp->x);
 		}
 		tgpi->draw_cp_points = true;
@@ -782,7 +791,8 @@ static void gpencil_primitive_exit(bContext *C, wmOperator *op)
 		ED_workspace_status_text(C, NULL);
 
 		MEM_SAFE_FREE(tgpi->points);
-		MEM_SAFE_FREE(tgpi->cp_points);
+		tgpi->gpd->runtime.tot_cp_points = 0;
+		MEM_SAFE_FREE(tgpi->gpd->runtime.cp_points);
 		/* finally, free memory used by temp data */
 		BKE_gpencil_free_strokes(tgpi->gpf);
 		MEM_SAFE_FREE(tgpi->gpf);
@@ -822,8 +832,6 @@ static void gpencil_primitive_init(bContext *C, wmOperator *op)
 	op->customdata = tgpi;
 
 	tgpi->points = MEM_callocN(sizeof(tGPspoint), "gp primitive points2D");
-	tgpi->cp_points = MEM_callocN(sizeof(tGPcontrolpoint) * MAX_CP, "gp primitive cpoint");
-	tgpi->tot_cp_points = 0;
 
 	/* set current scene and window info */
 	tgpi->bmain = CTX_data_main(C);
@@ -842,6 +850,10 @@ static void gpencil_primitive_init(bContext *C, wmOperator *op)
 	/* set GP datablock */
 	tgpi->gpd = gpd;
 
+	/* control points */
+	tgpi->gpd->runtime.cp_points = MEM_callocN(sizeof(bGPDcontrolpoint) * MAX_CP, "gp primitive cpoint");
+	tgpi->gpd->runtime.tot_cp_points = 0;
+
 	/* getcolor info */
 	tgpi->mat = BKE_gpencil_material_ensure(bmain, tgpi->ob);
 
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index 376a3bd01ee..767d5646ecd 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -81,13 +81,6 @@ typedef struct tGPspoint {
 	float uv_rot;           /* uv rotation for dor mode */
 } tGPspoint;
 
-/* Temporary 'Control Point' data for curves */
-typedef struct tGPcontrolpoint {
-	float x, y, z;          /* x and y coordinates of control point */
-	int color;              /* theme color */
-	int size;               /* radius */
-} tGPcontrolpoint;
-
 /* used to sort by zdepth gpencil objects in viewport */
 /* TODO: this could be a system parameter in userprefs screen */
 #define GP_CACHE_BLOCK_SIZE 16
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index 43ce3649db3..934ef4a4829 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -48,6 +48,13 @@ struct MDeformVert;
 /* ***************************************** */
 /* GP Stroke Points */
 
+/* 'Control Point' data for primitives and curves */
+typedef struct bGPDcontrolpoint {
+	float x, y, z;          /* x and y coordinates of control point */
+	float color[4];         /* point color */
+	int size;               /* radius */
+} bGPDcontrolpoint;
+
 /* Grease-Pencil Annotations - 'Stroke Point'
  * -> Coordinates may either be 2d or 3d depending on settings at the time
  * -> Coordinates of point on stroke, in proportions of window size
@@ -345,6 +352,10 @@ typedef struct bGPdata_Runtime {
 	short sbuffer_size;			/* number of elements currently in cache */
 	short sbuffer_sflag;		/* flags for stroke that cache represents */
 	char pad_[6];
+
+	int tot_cp_points;                 /* number of control-points for stroke */
+	char pad1_[4];
+	bGPDcontrolpoint *cp_points;       /* array of control-points for stroke */
 } bGPdata_Runtime;
 
 /* grid configuration */



More information about the Bf-blender-cvs mailing list