[Bf-blender-cvs] [bab586e254f] greasepencil-object: Cleanup: Reduce calls to get GpencilColorData

Antonio Vazquez noreply at git.blender.org
Sun Apr 29 15:37:32 CEST 2018


Commit: bab586e254fe4128992a0586e397165860e95855
Author: Antonio Vazquez
Date:   Sun Apr 29 15:37:24 2018 +0200
Branches: greasepencil-object
https://developer.blender.org/rBbab586e254fe4128992a0586e397165860e95855

Cleanup: Reduce calls to get GpencilColorData

This avoids some duplicate calls.

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

M	source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.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 bd802610718..19ca11721aa 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -383,7 +383,7 @@ static void gpencil_add_stroke_shgroup(GpencilBatchCache *cache, DRWShadingGroup
 	CLAMP_MIN(sthickness, 1);
 	if (cache->is_dirty) {
 		gpencil_batch_cache_check_free_slots(ob);
-		if ((gps->totpoints > 1) && (gpcolor->mode  == GPC_MODE_LINE)) {
+		if ((gps->totpoints > 1) && (gpcolor->mode == GPC_MODE_LINE)) {
 			cache->batch_stroke[cache->cache_idx] = DRW_gpencil_get_stroke_geom(gpf, gps, sthickness, ink);
 		}
 		else {
@@ -456,7 +456,7 @@ static void gpencil_draw_onion_strokes(GpencilBatchCache *cache, GPENCIL_e_data
 
 		int id = stl->storage->shgroup_id;
 		/* check if stroke can be drawn */
-		if (gpencil_can_draw_stroke(ob, gps, true) == false) {
+		if (gpencil_can_draw_stroke(gpcolor, gps, true) == false) {
 			continue;
 		}
 		/* limit the number of shading groups */
@@ -524,8 +524,10 @@ static void gpencil_draw_strokes(GpencilBatchCache *cache, GPENCIL_e_data *e_dat
 	}
 
 	for (gps = derived_gpf->strokes.first; gps; gps = gps->next) {
+		GpencilColorData *gpcolor = BKE_material_gpencil_settings_get(ob, gps->mat_nr + 1);
+
 		/* check if stroke can be drawn */
-		if (gpencil_can_draw_stroke(ob, gps, false) == false) {
+		if (gpencil_can_draw_stroke(gpcolor, gps, false) == false) {
 			continue;
 		}
 		/* limit the number of shading groups */
@@ -533,12 +535,10 @@ static void gpencil_draw_strokes(GpencilBatchCache *cache, GPENCIL_e_data *e_dat
 			continue;
 		}
 
-		GpencilColorData *gpcolor = BKE_material_gpencil_settings_get(ob, gps->mat_nr + 1);
-
 		/* be sure recalc all chache in source stroke to avoid recalculation when frame change 
 		 * and improve fps */
 		if (src_gps) {
-			DRW_gpencil_recalc_geometry_caches(ob, src_gps);
+			DRW_gpencil_recalc_geometry_caches(ob, gpcolor, src_gps);
 		}
 
 		/* if the fill has any value, it's considered a fill and is not drawn if simplify fill is enabled */
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 5e665b95229..24876fda200 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -375,11 +375,11 @@ struct Gwn_Batch *DRW_gpencil_get_buffer_stroke_geom(struct bGPdata *gpd, float
 struct Gwn_Batch *DRW_gpencil_get_buffer_fill_geom(struct bGPdata *gpd);
 struct Gwn_Batch *DRW_gpencil_get_buffer_point_geom(struct bGPdata *gpd, float matrix[4][4], short thickness);
 
-void DRW_gpencil_recalc_geometry_caches(struct Object *ob, struct bGPDstroke *gps);
+void DRW_gpencil_recalc_geometry_caches(struct Object *ob, struct GpencilColorData *gpcolor, struct bGPDstroke *gps);
 
 struct GPUTexture *DRW_gpencil_create_blank_texture(int width, int height);
 
-bool gpencil_can_draw_stroke(struct Object *ob, const struct bGPDstroke *gps, const bool onion);
+bool gpencil_can_draw_stroke(struct GpencilColorData *gpcolor, const struct bGPDstroke *gps, const bool onion);
 
 /* object cache functions */
 struct tGPencilObjectCache *gpencil_object_cache_allocate(struct tGPencilObjectCache *cache, int *gp_cache_size, int *gp_cache_used);
diff --git a/source/blender/draw/engines/gpencil/gpencil_geom.c b/source/blender/draw/engines/gpencil/gpencil_geom.c
index 9ea7660b957..7aa1cba221c 100644
--- a/source/blender/draw/engines/gpencil/gpencil_geom.c
+++ b/source/blender/draw/engines/gpencil/gpencil_geom.c
@@ -387,14 +387,12 @@ Gwn_Batch *DRW_gpencil_get_buffer_fill_geom(bGPdata *gpd)
 
 
 /* Helper for doing all the checks on whether a stroke can be drawn */
-bool gpencil_can_draw_stroke(struct Object *ob, const bGPDstroke *gps, const bool onion)
+bool gpencil_can_draw_stroke(struct GpencilColorData *gpcolor, const bGPDstroke *gps, const bool onion)
 {
 	/* skip stroke if it doesn't have any valid data */
-	if ((gps->points == NULL) || (gps->totpoints < 1))
+	if ((gps->points == NULL) || (gps->totpoints < 1) || (gpcolor == NULL))
 		return false;
 
-	GpencilColorData *gpcolor = BKE_material_gpencil_settings_get(ob, gps->mat_nr + 1);
-
 	/* check if the color is visible */
 	if ((gpcolor == NULL) ||
 	    (gpcolor->flag & GPC_COLOR_HIDE) ||
@@ -574,10 +572,8 @@ static void gpencil_set_fill_point(
 }
 
 /* recalc the internal geometry caches for fill and uvs */
-void DRW_gpencil_recalc_geometry_caches(Object *ob, bGPDstroke *gps) {
+void DRW_gpencil_recalc_geometry_caches(Object *ob, GpencilColorData *gpcolor, bGPDstroke *gps) {
 	if (gps->flag & GP_STROKE_RECALC_CACHES) {
-		GpencilColorData *gpcolor = BKE_material_gpencil_settings_get(ob, gps->mat_nr + 1);
-
 		/* Calculate triangles cache for filling area (must be done only after changes) */
 		if ((gps->tot_triangles == 0) || (gps->triangles == NULL)) {
 			if ((gps->totpoints > 2) &&



More information about the Bf-blender-cvs mailing list