[Bf-blender-cvs] [461387051d0] greasepencil-object: GP: Alloc maximum size

Antonioya noreply at git.blender.org
Mon Nov 19 11:37:41 CET 2018


Commit: 461387051d03eeef63fcfbc64e808601070ebf98
Author: Antonioya
Date:   Mon Nov 19 11:37:30 2018 +0100
Branches: greasepencil-object
https://developer.blender.org/rB461387051d03eeef63fcfbc64e808601070ebf98

GP: Alloc maximum size

The resize of the VBOs is very heavy for the CPU, so now the maximum size is allocated.

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

M	source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M	source/blender/draw/engines/gpencil/gpencil_draw_utils.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h

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

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 ccff826a536..ec690fdd14b 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -106,7 +106,7 @@ void DRW_gpencil_get_point_geom(GpencilBatchCacheElem *be, bGPDstroke *gps, shor
 		be->uvdata_id = GPU_vertformat_attr_add(&be->format, "uvdata", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
 
 		be->vbo = GPU_vertbuf_create_with_format(&be->format);
-		GPU_vertbuf_data_alloc(be->vbo, totvertex);
+		GPU_vertbuf_data_alloc(be->vbo, be->tot_vertex);
 		be->vbo_len = 0;
 	}
 	else {
@@ -153,7 +153,7 @@ void DRW_gpencil_get_stroke_geom(struct GpencilBatchCacheElem *be, bGPDstroke *g
 		be->uvdata_id = GPU_vertformat_attr_add(&be->format, "uvdata", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
 
 		be->vbo = GPU_vertbuf_create_with_format(&be->format);
-		GPU_vertbuf_data_alloc(be->vbo, totvertex);
+		GPU_vertbuf_data_alloc(be->vbo, be->tot_vertex);
 		be->vbo_len = 0;
 	}
 	else {
@@ -226,7 +226,7 @@ void DRW_gpencil_get_fill_geom(struct GpencilBatchCacheElem *be, Object *ob, bGP
 		be->uvdata_id = GPU_vertformat_attr_add(&be->format, "texCoord", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
 
 		be->vbo = GPU_vertbuf_create_with_format(&be->format);
-		GPU_vertbuf_data_alloc(be->vbo, GPENCIL_VBO_BLOCK_SIZE * 64);
+		GPU_vertbuf_data_alloc(be->vbo, be->tot_vertex);
 		be->vbo_len = 0;
 	}
 	else {
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
index d3260c88b83..3de886d3d39 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
@@ -65,6 +65,28 @@
 
 #define GP_SET_SRC_GPS(src_gps) if (src_gps) src_gps = src_gps->next
 
+/* Get number of vertex for using in GPU VBOs */
+void gpencil_calc_vertex(tGPencilObjectCache *cache_ob, GpencilBatchCache *cache, bGPdata *gpd)
+{
+	cache_ob->tot_vertex = 0;
+	cache_ob->tot_triangles = 0;
+
+	for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+		bGPDframe *gpf = gpl->actframe;
+		if ((gpl->flag & GP_LAYER_HIDE) || (gpf == NULL)) {
+			continue;
+		}
+		for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
+			cache_ob->tot_vertex += gps->totpoints + 3;
+			cache_ob->tot_triangles += gps->totpoints - 1;
+		}
+	}
+
+	cache->b_fill.tot_vertex = cache_ob->tot_triangles * 3;
+	cache->b_stroke.tot_vertex = cache_ob->tot_vertex;
+	cache->b_point.tot_vertex = cache_ob->tot_vertex;
+}
+
 /* Helper for doing all the checks on whether a stroke can be drawn */
 static bool gpencil_can_draw_stroke(
         struct MaterialGPencilStyle *gp_style, const bGPDstroke *gps,
@@ -1328,6 +1350,9 @@ void DRW_gpencil_populate_multiedit(
 	/* check if playing animation */
 	bool playing = stl->storage->is_playing;
 
+	/* calc max size of VBOs */
+	gpencil_calc_vertex(cache_ob, cache, gpd);
+
 	/* draw strokes */
 	for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
 		/* don't draw layer if hidden */
@@ -1401,6 +1426,9 @@ void DRW_gpencil_populate_datablock(
 		return;
 	}
 
+	/* calc max size of VBOs */
+	gpencil_calc_vertex(cache_ob, cache, gpd);
+
 	/* init general modifiers data */
 	if (!stl->storage->simplify_modif) {
 		if ((cache->is_dirty) && (ob->greasepencil_modifiers.first)) {
@@ -1480,7 +1508,6 @@ void DRW_gpencil_populate_datablock(
 		gpencil_draw_strokes(
 			cache, e_data, vedata, ts, ob, gpd, gpl, gpf, derived_gpf,
 			opacity, gpl->tintcolor, false, cache_ob);
-
 	}
 
 	/* clear any lattice data */
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 894badd5e95..0fe25ba9f0f 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -42,10 +42,8 @@ struct RenderLayer;
 #define GPENCIL_MAX_SHGROUPS 65536
 #define GPENCIL_GROUPS_BLOCK_SIZE 1024
 
-/* the default size has a big impact in the speed, but use more GPU memory
- * Maybe this could be a parameter
- */
-#define GPENCIL_VBO_BLOCK_SIZE 2048
+/* used to expand VBOs. Size has a big impact in the speed */
+#define GPENCIL_VBO_BLOCK_SIZE 128
 
 #define GPENCIL_COLOR_SOLID   0
 #define GPENCIL_COLOR_TEXTURE 1
@@ -88,6 +86,10 @@ typedef struct tGPencilObjectCache {
 	float obmat[4][4];
 	float zdepth;  /* z-depth value to sort gp object */
 	bool is_dup_ob;  /* flag to tag duplicate objects */
+
+	/* GPU data size */
+	int tot_vertex;
+	int tot_triangles;
 } tGPencilObjectCache;
 
   /* *********** LISTS *********** */
@@ -288,6 +290,9 @@ typedef struct GpencilBatchCacheElem {
 	uint color_id;
 	uint thickness_id;
 	uint uvdata_id;
+
+	/* size for VBO alloc */
+	int tot_vertex;
 } GpencilBatchCacheElem;
 
 typedef struct GpencilBatchGroup {



More information about the Bf-blender-cvs mailing list