[Bf-blender-cvs] [f7726a09f01] greasepencil-object: Add a line when edit strokes

Antonio Vazquez noreply at git.blender.org
Thu Aug 3 20:43:11 CEST 2017


Commit: f7726a09f017fe97f16db29bdbe95a3bb2c2ec42
Author: Antonio Vazquez
Date:   Thu Aug 3 14:10:43 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rBf7726a09f017fe97f16db29bdbe95a3bb2c2ec42

Add a line when edit strokes

This thin line helps to determine the stroke shape

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

M	source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M	source/blender/draw/engines/gpencil/gpencil_engine.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h
M	source/blender/draw/engines/gpencil/gpencil_geom.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 856d17f65db..71478b1b947 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -138,6 +138,7 @@ static void gpencil_batch_cache_resize(GpencilBatchCache *cache, int slots)
 	cache->batch_stroke = MEM_recallocN(cache->batch_stroke, sizeof(struct Gwn_Batch) * slots);
 	cache->batch_fill = MEM_recallocN(cache->batch_fill, sizeof(struct Gwn_Batch) * slots);
 	cache->batch_edit = MEM_recallocN(cache->batch_edit, sizeof(struct Gwn_Batch) * slots);
+	cache->batch_edlin = MEM_recallocN(cache->batch_edlin, sizeof(struct Gwn_Batch) * slots);
 }
 
 /* check size and increase if no free slots */
@@ -174,6 +175,7 @@ static void gpencil_batch_cache_init(Object *ob, int cfra)
 	cache->batch_stroke = MEM_callocN(sizeof(struct Gwn_Batch) * cache->cache_size, "Gpencil_Batch_Stroke");
 	cache->batch_fill = MEM_callocN(sizeof(struct Gwn_Batch) * cache->cache_size, "Gpencil_Batch_Fill");
 	cache->batch_edit = MEM_callocN(sizeof(struct Gwn_Batch) * cache->cache_size, "Gpencil_Batch_Edit");
+	cache->batch_edlin = MEM_callocN(sizeof(struct Gwn_Batch) * cache->cache_size, "Gpencil_Batch_Edlin");
 
 	cache->is_editmode = gpd->flag & (GP_DATA_STROKE_EDITMODE | GP_DATA_STROKE_SCULPTMODE | GP_DATA_STROKE_WEIGHTMODE);
 	gpd->flag &= ~GP_DATA_CACHE_IS_DIRTY;
@@ -203,10 +205,12 @@ static void gpencil_batch_cache_clear(GpencilBatchCache *cache, bGPdata *gpd)
 		BATCH_DISCARD_ALL_SAFE(cache->batch_stroke[i]);
 		BATCH_DISCARD_ALL_SAFE(cache->batch_fill[i]);
 		BATCH_DISCARD_ALL_SAFE(cache->batch_edit[i]);
-	}
+		BATCH_DISCARD_ALL_SAFE(cache->batch_edlin[i]);
+		}
 		MEM_SAFE_FREE(cache->batch_stroke);
 		MEM_SAFE_FREE(cache->batch_fill);
 		MEM_SAFE_FREE(cache->batch_edit);
+		MEM_SAFE_FREE(cache->batch_edlin);
 	}
 
 	MEM_SAFE_FREE(cache);
@@ -303,6 +307,15 @@ DRWShadingGroup *DRW_gpencil_shgroup_point_volumetric_create(DRWPass *pass, GPUS
 	return grp;
 }
 
+/* create shading group for edit lines */
+DRWShadingGroup *DRW_gpencil_shgroup_line_create(DRWPass *pass, GPUShader *shader)
+{
+	/* e_data.gpencil_line_sh */
+	DRWShadingGroup *grp = DRW_shgroup_create(shader, pass);
+
+	return grp;
+}
+
 /* create shading group for strokes */
 DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(GPENCIL_e_data *e_data, GPENCIL_Data *vedata, DRWPass *pass, GPUShader *shader, Object *ob,
 	bGPdata *gpd, PaletteColor *palcolor, int id)
@@ -560,6 +573,17 @@ static void gpencil_add_editpoints_shgroup(GPENCIL_StorageList *stl, GpencilBatc
 		Object *obact = draw_ctx->obact;
 		bool is_weight_paint = (gpd) && (gpd->flag & GP_DATA_STROKE_WEIGHTMODE);
 
+		/* line of the original stroke */
+		if (cache->is_dirty) {
+			gpencil_batch_cache_check_free_slots(ob, gpd);
+			cache->batch_edlin[cache->cache_idx] = DRW_gpencil_get_edlin_geom(gps, ts->gp_sculpt.alpha, gpd->flag);
+		}
+		if (cache->batch_edlin[cache->cache_idx]) {
+			if ((obact) && (obact == ob)) {
+				DRW_shgroup_call_add(stl->g_data->shgrps_edit_line, cache->batch_edlin[cache->cache_idx], gpf->viewmatrix);
+			}
+		}
+		/* edit points */
 		if ((gps->flag & GP_STROKE_SELECT) || (is_weight_paint)) {
 			if ((gpl->flag & GP_LAYER_UNLOCK_COLOR) || ((gps->palcolor->flag & PC_COLOR_LOCKED) == 0)) {
 				if (cache->is_dirty) {
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index ddd4e5488cd..7557d5da1dd 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -94,6 +94,11 @@ static void GPENCIL_engine_init(void *vedata)
 		e_data.gpencil_volumetric_sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR);
 	}
 
+	/* used for edit lines for edit modes */
+	if (!e_data.gpencil_line_sh) {
+		e_data.gpencil_line_sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_FLAT_COLOR);
+	}
+
 	/* used to filling during drawing */
 	if (!e_data.gpencil_drawing_fill_sh) {
 		e_data.gpencil_drawing_fill_sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_SMOOTH_COLOR);
@@ -164,6 +169,7 @@ static void GPENCIL_cache_init(void *vedata)
 		/* edit pass */
 		psl->edit_pass = DRW_pass_create("Gpencil Edit Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND);
 		stl->g_data->shgrps_edit_volumetric = DRW_gpencil_shgroup_edit_volumetric_create(psl->edit_pass, e_data.gpencil_volumetric_sh);
+		stl->g_data->shgrps_edit_line = DRW_gpencil_shgroup_edit_volumetric_create(psl->edit_pass, e_data.gpencil_line_sh);
 		/* drawing buffer pass */
 		const DRWContextState *draw_ctx = DRW_context_state_get();
 		Palette *palette = BKE_palette_get_active_from_context(draw_ctx->evil_C);
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 59e85903140..ff09c6edcff 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -107,6 +107,7 @@ typedef struct GPENCIL_Data {
 /* *********** STATIC *********** */
 typedef struct g_data {
 	struct DRWShadingGroup *shgrps_edit_volumetric;
+	struct DRWShadingGroup *shgrps_edit_line;
 	struct DRWShadingGroup *shgrps_drawing_stroke;
 	struct DRWShadingGroup *shgrps_drawing_fill;
 
@@ -124,6 +125,7 @@ typedef struct GPENCIL_e_data {
 	struct GPUShader *gpencil_stroke_sh;
 	struct GPUShader *gpencil_point_sh;
 	struct GPUShader *gpencil_volumetric_sh;
+	struct GPUShader *gpencil_line_sh;
 	struct GPUShader *gpencil_drawing_fill_sh;
 	struct GPUShader *gpencil_fullscreen_sh;
 	/* temp depth texture */
@@ -142,6 +144,7 @@ typedef struct GpencilBatchCache {
 	Gwn_Batch **batch_stroke;
 	Gwn_Batch **batch_fill;
 	Gwn_Batch **batch_edit;
+	Gwn_Batch **batch_edlin;
 
 	/* settings to determine if cache is invalid */
 	bool is_dirty;
@@ -158,6 +161,7 @@ struct DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(struct GPENCIL_e_data
 struct DRWShadingGroup *DRW_gpencil_shgroup_point_create(struct GPENCIL_e_data *e_data, struct GPENCIL_Data *vedata, struct DRWPass *pass, struct GPUShader *shader, struct Object *ob,
 	                                                     struct bGPdata *gpd, struct PaletteColor *palcolor, int id);
 struct DRWShadingGroup *DRW_gpencil_shgroup_point_volumetric_create(struct DRWPass *pass, struct GPUShader *shader);
+struct DRWShadingGroup *DRW_gpencil_shgroup_line_create(struct DRWPass *pass, struct GPUShader *shader);
 struct DRWShadingGroup *DRW_gpencil_shgroup_edit_volumetric_create(struct DRWPass *pass, struct GPUShader *shader);
 struct DRWShadingGroup *DRW_gpencil_shgroup_drawing_fill_create(struct DRWPass *pass, struct GPUShader *shader);
 
@@ -168,6 +172,7 @@ struct Gwn_Batch *DRW_gpencil_get_point_geom(struct bGPDstroke *gps, short thick
 struct Gwn_Batch *DRW_gpencil_get_stroke_geom(struct bGPDframe *gpf, struct bGPDstroke *gps, short thickness, const float ink[4]);
 struct Gwn_Batch *DRW_gpencil_get_fill_geom(struct bGPDstroke *gps, const float color[4]);
 struct Gwn_Batch *DRW_gpencil_get_edit_geom(struct bGPDstroke *gps, float alpha, short dflag);
+struct Gwn_Batch *DRW_gpencil_get_edlin_geom(struct bGPDstroke *gps, float alpha, short dflag);
 struct Gwn_Batch *DRW_gpencil_get_buffer_stroke_geom(struct bGPdata *gpd, float matrix[4][4], short thickness);
 struct Gwn_Batch *DRW_gpencil_get_buffer_fill_geom(const struct tGPspoint *points, int totpoints, float ink[4]);
 struct Gwn_Batch *DRW_gpencil_get_buffer_point_geom(struct bGPdata *gpd, float matrix[4][4], short thickness);
diff --git a/source/blender/draw/engines/gpencil/gpencil_geom.c b/source/blender/draw/engines/gpencil/gpencil_geom.c
index 1150bf49790..66c469ee2ad 100644
--- a/source/blender/draw/engines/gpencil/gpencil_geom.c
+++ b/source/blender/draw/engines/gpencil/gpencil_geom.c
@@ -705,3 +705,86 @@ Gwn_Batch *DRW_gpencil_get_edit_geom(bGPDstroke *gps, float alpha, short dflag)
 
 	return GWN_batch_create(GWN_PRIM_POINTS, vbo, NULL);
 }
+
+/* Draw lines for strokes being edited */
+Gwn_Batch *DRW_gpencil_get_edlin_geom(bGPDstroke *gps, float alpha, short dflag)
+{
+	const DRWContextState *draw_ctx = DRW_context_state_get();
+	Scene *scene = draw_ctx->scene;
+	Object *ob = draw_ctx->obact;
+	bGPdata *gpd = ob->gpd;
+	ToolSettings *ts = scene->toolsettings;
+	bool is_weight_paint = (gpd) && (gpd->flag & GP_DATA_STROKE_WEIGHTMODE);
+
+	int vgindex = ob->actdef - 1;
+	if (!BLI_findlink(&ob->defbase, vgindex)) {
+		vgindex = -1;
+	}
+
+	/* Get size of verts:
+	* - The selected state needs to be larger than the unselected state so that
+	*   they stand out more.
+	* - We use the theme setting for size of the unselected verts
+	*/
+	float bsize = UI_GetThemeValuef(TH_GP_VERTEX_SIZE);
+	float vsize;
+	if ((int)bsize > 8) {
+		vsize = 10.0f;
+		bsize = 8.0f;
+	}
+	else {
+		vsize = bsize + 2;
+	}
+
+	/* for now, we assume that the base color of the points is not too close to the real color */
+	/* set color using palette */
+	PaletteColor *palcolor = gps->palcolor;
+
+	float selectColor[4];
+	UI_GetThemeColor3fv(TH_GP_VERTEX_SELECT, selectColor);
+	selectColor[3] = alpha;
+	float linecolor[4];
+	ARRAY_SET_ITEMS(linecolor, 0.5f, 0.5f, 0.5f, 0.5f);
+
+
+	static Gwn_VertFormat format = { 0 };
+	static unsigned int pos_id, color_id, size_id;
+	if (format.attrib_ct == 0) {
+		pos_id = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+		color_id = GWN_vertformat_attr_add(&format, "color", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
+	}
+
+	Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+	GWN_vertbuf_data_alloc(vbo, gps->totpoints);
+
+	/* Draw all the stroke lines (selected or not) */
+	bGPDspoint *pt = gps->points;
+	int idx = 0;
+	float fcolor[4];
+	float fsize = 0;
+	for (int i = 0; i < gps->totpoints; i++, pt++) {
+		/* weight paint */
+		if (is_weight_paint) {
+			float weight = BKE_gpencil_vgroup_use_index(pt, vgindex);
+			CLAMP(weight, 0.0f, 1.0f);
+			float hue = 2.0f * (1.0f - weight) / 3.0f;
+			hsv_to_rgb(hue, 1.0f, 1.0f, &selectColor[0], &selectColor[1], &selectColor[2]);
+			selectColor[3] = 1.0

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list