[Bf-blender-cvs] [24ca903f6d8] blender2.8: Draw Manager: draw_cache_imp_displist, always return IndexBuf even when there is no index

Germano noreply at git.blender.org
Tue Dec 19 02:18:11 CET 2017


Commit: 24ca903f6d8f1e87c464b4a50c44c495cda11fec
Author: Germano
Date:   Mon Dec 18 23:17:55 2017 -0200
Branches: blender2.8
https://developer.blender.org/rB24ca903f6d8f1e87c464b4a50c44c495cda11fec

Draw Manager: draw_cache_imp_displist, always return IndexBuf even when there is no index

This prevents possible errors with materials and a crash with low resolution metaball.
Also a small cleanup was done in the code.

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

M	source/blender/draw/intern/draw_cache_impl_curve.c
M	source/blender/draw/intern/draw_cache_impl_displist.c
M	source/blender/draw/intern/draw_cache_impl_metaball.c

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

diff --git a/source/blender/draw/intern/draw_cache_impl_curve.c b/source/blender/draw/intern/draw_cache_impl_curve.c
index 6d98195495f..ff8ffd76ac3 100644
--- a/source/blender/draw/intern/draw_cache_impl_curve.c
+++ b/source/blender/draw/intern/draw_cache_impl_curve.c
@@ -1043,7 +1043,7 @@ Gwn_Batch **DRW_curve_batch_cache_get_surface_shaded(
 
 		for (int i = 0; i < gpumat_array_len; ++i) {
 			cache->surface.shaded_triangles[i] = GWN_batch_create_ex(
-			        GWN_PRIM_TRIS, cache->surface.verts, el[i], el[i] ? GWN_BATCH_OWNS_INDEX : 0);
+			        GWN_PRIM_TRIS, cache->surface.verts, el[i], GWN_BATCH_OWNS_INDEX);
 
 			/* TODO: Add vertbuff for UV */
 		}
diff --git a/source/blender/draw/intern/draw_cache_impl_displist.c b/source/blender/draw/intern/draw_cache_impl_displist.c
index b055a023e79..32c3b3f37fb 100644
--- a/source/blender/draw/intern/draw_cache_impl_displist.c
+++ b/source/blender/draw/intern/draw_cache_impl_displist.c
@@ -128,32 +128,28 @@ Gwn_VertBuf *DRW_displist_vertbuf_calc_pos_with_normals(ListBase *lb)
 		attr_id.nor = GWN_vertformat_attr_add(&format, "nor", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
 	}
 
-	const int vert_len = curve_render_surface_vert_len_get(lb);
 	Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
-	{
-		const int vbo_len_capacity = vert_len;
-		int vbo_len_used = 0;
-		GWN_vertbuf_data_alloc(vbo, vbo_len_capacity);
+	GWN_vertbuf_data_alloc(vbo, curve_render_surface_vert_len_get(lb));
 
-		BKE_displist_normals_add(lb);
+	BKE_displist_normals_add(lb);
 
-		for (const DispList *dl = lb->first; dl; dl = dl->next) {
-			const bool ndata_is_single = dl->type == DL_INDEX3;
-			if (ELEM(dl->type, DL_INDEX3, DL_INDEX4, DL_SURF)) {
-				const float *fp_co = dl->verts;
-				const float *fp_no = dl->nors;
-				const int vbo_end = vbo_len_used + dl_vert_len(dl);
-				while (vbo_len_used < vbo_end) {
-					GWN_vertbuf_attr_set(vbo, attr_id.pos, vbo_len_used, fp_co);
-					if (fp_no) {
-						GWN_vertbuf_attr_set(vbo, attr_id.nor, vbo_len_used, fp_no);
-						if (ndata_is_single == false) {
-							fp_no += 3;
-						}
+	int vbo_len_used = 0;
+	for (const DispList *dl = lb->first; dl; dl = dl->next) {
+		const bool ndata_is_single = dl->type == DL_INDEX3;
+		if (ELEM(dl->type, DL_INDEX3, DL_INDEX4, DL_SURF)) {
+			const float *fp_co = dl->verts;
+			const float *fp_no = dl->nors;
+			const int vbo_end = vbo_len_used + dl_vert_len(dl);
+			while (vbo_len_used < vbo_end) {
+				GWN_vertbuf_attr_set(vbo, attr_id.pos, vbo_len_used, fp_co);
+				if (fp_no) {
+					GWN_vertbuf_attr_set(vbo, attr_id.nor, vbo_len_used, fp_no);
+					if (ndata_is_single == false) {
+						fp_no += 3;
 					}
-					fp_co += 3;
-					vbo_len_used += 1;
 				}
+				fp_co += 3;
+				vbo_len_used += 1;
 			}
 		}
 	}
@@ -164,24 +160,18 @@ Gwn_VertBuf *DRW_displist_vertbuf_calc_pos_with_normals(ListBase *lb)
 Gwn_IndexBuf *DRW_displist_indexbuf_calc_triangles_in_order(ListBase *lb)
 {
 	const int tri_len = curve_render_surface_tri_len_get(lb);
-	if (tri_len == 0) {
-		return NULL;
-	}
-
 	const int vert_len = curve_render_surface_vert_len_get(lb);
 
-	{
-		Gwn_IndexBufBuilder elb;
-		GWN_indexbuf_init(&elb, GWN_PRIM_TRIS, tri_len, vert_len);
-
-		int ofs = 0;
-		for (const DispList *dl = lb->first; dl; dl = dl->next) {
-			displist_indexbufbuilder_set(&elb, dl, ofs);
-			ofs += dl_vert_len(dl);
-		}
+	Gwn_IndexBufBuilder elb;
+	GWN_indexbuf_init(&elb, GWN_PRIM_TRIS, tri_len, vert_len);
 
-		return GWN_indexbuf_build(&elb);
+	int ofs = 0;
+	for (const DispList *dl = lb->first; dl; dl = dl->next) {
+		displist_indexbufbuilder_set(&elb, dl, ofs);
+		ofs += dl_vert_len(dl);
 	}
+
+	return GWN_indexbuf_build(&elb);
 }
 
 Gwn_IndexBuf **DRW_displist_indexbuf_calc_triangles_in_order_split_by_material(ListBase *lb, uint gpumat_array_len)
diff --git a/source/blender/draw/intern/draw_cache_impl_metaball.c b/source/blender/draw/intern/draw_cache_impl_metaball.c
index 9a9bbbd2c0c..f01e7b929f8 100644
--- a/source/blender/draw/intern/draw_cache_impl_metaball.c
+++ b/source/blender/draw/intern/draw_cache_impl_metaball.c
@@ -133,10 +133,9 @@ Gwn_Batch *DRW_metaball_batch_cache_get_triangles_with_normals(Object *ob)
 
 	if (cache->batch == NULL) {
 		ListBase *lb = &ob->curve_cache->disp;
-		Gwn_VertBuf *verts = DRW_displist_vertbuf_calc_pos_with_normals(lb);
 		cache->batch = GWN_batch_create_ex(
 		        GWN_PRIM_TRIS,
-		        verts,
+		        DRW_displist_vertbuf_calc_pos_with_normals(lb),
 		        DRW_displist_indexbuf_calc_triangles_in_order(lb),
 		        GWN_BATCH_OWNS_VBO | GWN_BATCH_OWNS_INDEX);
 	}



More information about the Bf-blender-cvs mailing list