[Bf-blender-cvs] [0dd766b0438] blender2.8: DWM: Share VBO positions & normals for mesh cache

Campbell Barton noreply at git.blender.org
Mon May 8 09:53:42 CEST 2017


Commit: 0dd766b0438c08b56186893b6c7de1aacfda26a5
Author: Campbell Barton
Date:   Mon May 8 16:25:29 2017 +1000
Branches: blender2.8
https://developer.blender.org/rB0dd766b0438c08b56186893b6c7de1aacfda26a5

DWM: Share VBO positions & normals for mesh cache

Select, weight & color cache included redundant position and normals.

Use multiple VBO's per batch for more efficient storage.

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

M	source/blender/draw/intern/draw_cache_impl_mesh.c

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

diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c
index 3cde00e14d1..a9d54da9d08 100644
--- a/source/blender/draw/intern/draw_cache_impl_mesh.c
+++ b/source/blender/draw/intern/draw_cache_impl_mesh.c
@@ -1196,10 +1196,9 @@ static bool mesh_render_data_looptri_cos_nors_smooth_get(
 	return true;
 }
 
-static bool mesh_render_data_looptri_cos_weights_get(
-        MeshRenderData *rdata, const int tri_idx,
-        float *(*r_vert_cos)[3], float *(*r_vert_weights)[3],
-        short **r_tri_nor, short *(*r_vert_nors)[3], bool *r_is_smooth, int defgroup)
+static bool mesh_render_data_looptri_weights_get(
+        MeshRenderData *rdata, const int tri_idx, int defgroup,
+        float *(*r_vert_weights)[3])
 {
 	BLI_assert(
 	        rdata->types &
@@ -1211,58 +1210,31 @@ static bool mesh_render_data_looptri_cos_weights_get(
 		if (BM_elem_flag_test(bm_looptri[0]->f, BM_ELEM_HIDDEN)) {
 			return false;
 		}
-
-		mesh_render_data_ensure_poly_normals_short(rdata);
-		mesh_render_data_ensure_vert_normals_short(rdata);
 		mesh_render_data_ensure_vert_weight_color(rdata, defgroup);
 
-		short (*pnors_short)[3] = rdata->poly_normals_short;
-		short (*vnors_short)[3] = rdata->vert_normals_short;
 		float (*vweight)[3] = rdata->vert_weight_color;
 
-		(*r_vert_cos)[0] = bm_looptri[0]->v->co;
-		(*r_vert_cos)[1] = bm_looptri[1]->v->co;
-		(*r_vert_cos)[2] = bm_looptri[2]->v->co;
 		(*r_vert_weights)[0] = vweight[BM_elem_index_get(bm_looptri[0]->v)];
 		(*r_vert_weights)[1] = vweight[BM_elem_index_get(bm_looptri[1]->v)];
 		(*r_vert_weights)[2] = vweight[BM_elem_index_get(bm_looptri[2]->v)];
-		*r_tri_nor = pnors_short[BM_elem_index_get(bm_looptri[0]->f)];
-		(*r_vert_nors)[0] = vnors_short[BM_elem_index_get(bm_looptri[0]->v)];
-		(*r_vert_nors)[1] = vnors_short[BM_elem_index_get(bm_looptri[1]->v)];
-		(*r_vert_nors)[2] = vnors_short[BM_elem_index_get(bm_looptri[2]->v)];
-
-		*r_is_smooth = BM_elem_flag_test_bool(bm_looptri[0]->f, BM_ELEM_SMOOTH);
 	}
 	else {
 		const MLoopTri *mlt = &rdata->mlooptri[tri_idx];
 
-		mesh_render_data_ensure_poly_normals_short(rdata);
 		mesh_render_data_ensure_vert_weight_color(rdata, defgroup);
 
-		short (*pnors_short)[3] = rdata->poly_normals_short;
 		float (*vweight)[3] = rdata->vert_weight_color;
-
-		(*r_vert_cos)[0] = rdata->mvert[rdata->mloop[mlt->tri[0]].v].co;
-		(*r_vert_cos)[1] = rdata->mvert[rdata->mloop[mlt->tri[1]].v].co;
-		(*r_vert_cos)[2] = rdata->mvert[rdata->mloop[mlt->tri[2]].v].co;
 		(*r_vert_weights)[0] = vweight[rdata->mloop[mlt->tri[0]].v];
 		(*r_vert_weights)[1] = vweight[rdata->mloop[mlt->tri[1]].v];
 		(*r_vert_weights)[2] = vweight[rdata->mloop[mlt->tri[2]].v];
-		*r_tri_nor = pnors_short[mlt->poly];
-		(*r_vert_nors)[0] = rdata->mvert[rdata->mloop[mlt->tri[0]].v].no;
-		(*r_vert_nors)[1] = rdata->mvert[rdata->mloop[mlt->tri[1]].v].no;
-		(*r_vert_nors)[2] = rdata->mvert[rdata->mloop[mlt->tri[2]].v].no;
-
-		*r_is_smooth = (rdata->mpoly[mlt->poly].flag & ME_SMOOTH) != 0;
 	}
 
 	return true;
 }
 
-static bool mesh_render_data_looptri_cos_vert_colors_get(
+static bool mesh_render_data_looptri_vert_colors_get(
         MeshRenderData *rdata, const int tri_idx,
-        float *(*r_vert_cos)[3], char *(*r_vert_colors)[3],
-        short **r_tri_nor, short *(*r_vert_nors)[3], bool *r_is_smooth)
+        char *(*r_vert_colors)[3])
 {
 	BLI_assert(
 	        rdata->types &
@@ -1271,25 +1243,13 @@ static bool mesh_render_data_looptri_cos_vert_colors_get(
 	if (rdata->edit_bmesh) {
 		const BMLoop **bm_looptri = (const BMLoop **)rdata->edit_bmesh->looptris[tri_idx];
 
-		mesh_render_data_ensure_poly_normals_short(rdata);
 		mesh_render_data_ensure_vert_color(rdata);
 
-		short (*pnors_short)[3] = rdata->poly_normals_short;
-		short (*vnors_short)[3] = rdata->vert_normals_short;
 		char (*vcol)[3] = rdata->vert_color;
 
-		(*r_vert_cos)[0] = bm_looptri[0]->v->co;
-		(*r_vert_cos)[1] = bm_looptri[1]->v->co;
-		(*r_vert_cos)[2] = bm_looptri[2]->v->co;
 		(*r_vert_colors)[0] = vcol[BM_elem_index_get(bm_looptri[0]->v)];
 		(*r_vert_colors)[1] = vcol[BM_elem_index_get(bm_looptri[1]->v)];
 		(*r_vert_colors)[2] = vcol[BM_elem_index_get(bm_looptri[2]->v)];
-		*r_tri_nor = pnors_short[BM_elem_index_get(bm_looptri[0]->f)];
-		(*r_vert_nors)[0] = vnors_short[BM_elem_index_get(bm_looptri[0]->v)];
-		(*r_vert_nors)[1] = vnors_short[BM_elem_index_get(bm_looptri[1]->v)];
-		(*r_vert_nors)[2] = vnors_short[BM_elem_index_get(bm_looptri[2]->v)];
-
-		*r_is_smooth = BM_elem_flag_test_bool(bm_looptri[0]->f, BM_ELEM_SMOOTH);
 	}
 	else {
 		const MLoopTri *mlt = &rdata->mlooptri[tri_idx];
@@ -1297,30 +1257,19 @@ static bool mesh_render_data_looptri_cos_vert_colors_get(
 		mesh_render_data_ensure_poly_normals_short(rdata);
 		mesh_render_data_ensure_vert_color(rdata);
 
-		short (*pnors_short)[3] = rdata->poly_normals_short;
 		char (*vcol)[3] = rdata->vert_color;
 
-		(*r_vert_cos)[0] = rdata->mvert[rdata->mloop[mlt->tri[0]].v].co;
-		(*r_vert_cos)[1] = rdata->mvert[rdata->mloop[mlt->tri[1]].v].co;
-		(*r_vert_cos)[2] = rdata->mvert[rdata->mloop[mlt->tri[2]].v].co;
 		(*r_vert_colors)[0] = vcol[mlt->tri[0]];
 		(*r_vert_colors)[1] = vcol[mlt->tri[1]];
 		(*r_vert_colors)[2] = vcol[mlt->tri[2]];
-		*r_tri_nor = pnors_short[mlt->poly];
-		(*r_vert_nors)[0] = rdata->mvert[rdata->mloop[mlt->tri[0]].v].no;
-		(*r_vert_nors)[1] = rdata->mvert[rdata->mloop[mlt->tri[1]].v].no;
-		(*r_vert_nors)[2] = rdata->mvert[rdata->mloop[mlt->tri[2]].v].no;
-
-		*r_is_smooth = (rdata->mpoly[mlt->poly].flag & ME_SMOOTH) != 0;
 	}
 
 	return true;
 }
 
-static bool mesh_render_data_looptri_cos_select_id_get(
+static bool mesh_render_data_looptri_select_id_get(
         MeshRenderData *rdata, const int tri_idx, const bool use_hide,
-        float *(*r_vert_cos)[3],
-        short **r_tri_nor, int *r_select_id)
+        int *r_select_id)
 {
 	BLI_assert(
 	        rdata->types &
@@ -1334,16 +1283,6 @@ static bool mesh_render_data_looptri_cos_select_id_get(
 			return false;
 		}
 
-		mesh_render_data_ensure_poly_normals_short(rdata);
-
-		short (*pnors_short)[3] = rdata->poly_normals_short;
-
-
-		(*r_vert_cos)[0] = bm_looptri[0]->v->co;
-		(*r_vert_cos)[1] = bm_looptri[1]->v->co;
-		(*r_vert_cos)[2] = bm_looptri[2]->v->co;
-		*r_tri_nor = pnors_short[poly_index];
-
 		GPU_select_index_get(poly_index + 1, r_select_id);
 	}
 	else {
@@ -1353,16 +1292,6 @@ static bool mesh_render_data_looptri_cos_select_id_get(
 		if (use_hide && (rdata->mpoly[poly_index].flag & ME_HIDE)) {
 			return false;
 		}
-
-		mesh_render_data_ensure_poly_normals_short(rdata);
-
-		short (*pnors_short)[3] = rdata->poly_normals_short;
-
-		(*r_vert_cos)[0] = rdata->mvert[rdata->mloop[mlt->tri[0]].v].co;
-		(*r_vert_cos)[1] = rdata->mvert[rdata->mloop[mlt->tri[1]].v].co;
-		(*r_vert_cos)[2] = rdata->mvert[rdata->mloop[mlt->tri[2]].v].co;
-		*r_tri_nor = pnors_short[poly_index];
-
 		GPU_select_index_get(poly_index + 1, r_select_id);
 	}
 
@@ -1658,12 +1587,12 @@ typedef struct MeshBatchCache {
 	Batch *all_triangles;
 
 	VertexBuffer *pos_with_normals;
-	VertexBuffer *pos_with_weights;
-	VertexBuffer *pos_with_vert_colors;
+	VertexBuffer *tri_aligned_weights;
+	VertexBuffer *tri_aligned_vert_colors;
+	VertexBuffer *tri_aligned_select_id;
 	VertexBuffer *edge_pos_with_sel;
 	VertexBuffer *tri_pos_with_sel;
 	VertexBuffer *pos_with_sel;
-	VertexBuffer *pos_with_sel_id;
 	Batch *triangles_with_normals;
 	Batch *triangles_with_weights;
 	Batch *triangles_with_vert_colors;
@@ -1830,9 +1759,11 @@ static void mesh_batch_cache_clear(Mesh *me)
 	BATCH_DISCARD_SAFE(cache->triangles_with_normals);
 	BATCH_DISCARD_SAFE(cache->points_with_normals);
 	VERTEXBUFFER_DISCARD_SAFE(cache->pos_with_normals);
-	BATCH_DISCARD_ALL_SAFE(cache->triangles_with_weights);
-	BATCH_DISCARD_ALL_SAFE(cache->triangles_with_vert_colors);
-	VERTEXBUFFER_DISCARD_SAFE(cache->pos_with_sel_id);
+	VERTEXBUFFER_DISCARD_SAFE(cache->tri_aligned_vert_colors);
+	VERTEXBUFFER_DISCARD_SAFE(cache->tri_aligned_weights);
+	BATCH_DISCARD_SAFE(cache->triangles_with_weights);
+	BATCH_DISCARD_SAFE(cache->triangles_with_vert_colors);
+	VERTEXBUFFER_DISCARD_SAFE(cache->tri_aligned_select_id);
 	BATCH_DISCARD_SAFE(cache->triangles_with_select_id);
 
 	BATCH_DISCARD_ALL_SAFE(cache->fancy_edges);
@@ -2085,195 +2016,142 @@ static VertexBuffer *mesh_batch_cache_get_tri_pos_and_normals(
 	return cache->pos_with_normals;
 }
 
-static VertexBuffer *mesh_batch_cache_get_tri_pos_normals_and_weights(
+static VertexBuffer *mesh_batch_cache_get_tri_weights(
         MeshRenderData *rdata, MeshBatchCache *cache, int defgroup)
 {
 	BLI_assert(
 	        rdata->types &
 	        (MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI | MR_DATATYPE_LOOP | MR_DATATYPE_POLY | MR_DATATYPE_DVERT));
 
-	if (cache->pos_with_weights == NULL) {
-		unsigned int vidx = 0, cidx = 0, nidx = 0;
+	if (cache->tri_aligned_weights == NULL) {
+		unsigned int cidx = 0;
 
 		static VertexFormat format = { 0 };
-		static unsigned int pos_id, col_id, nor_id;
+		static unsigned int col_id;
 		if (format.attrib_ct == 0) {
 			/* initialize vertex format */
-			pos_id = VertexFormat_add_attrib(&format, "pos", COMP_F32, 3, KEEP_FLOAT);
-			nor_id = VertexFormat_add_attrib(&format, "nor", COMP_I16, 3, NORMALIZE_INT_TO_FLOAT);
 			col_id = VertexFormat_add_attrib(&format, "color", COMP_F32, 3, KEEP_FLOAT);
 		}
 
 		const int tri_len = mesh_render_data_looptri_len_get(rdata);
 
-		VertexBuffer *vbo = cache->pos_with_weights = VertexBuffer_create_with_format(&format);
+		VertexBuffer *vbo = cache->tri_aligned_weights = VertexBuffer_create_with_format(&format);
 
 		const int vbo_len_capacity = tri_len * 3;
 		int vbo_len_used = 0;
 		VertexBuffer_allocate_data(vbo, vbo_len_capacity);
 
 		for (int i = 0; i < tri_len; i++) {
-			float *tri_vert_cos[3], *tri_vert_weights[3];
-			short *tri_nor, *tri_vert_nors[3];
-			bool is_smooth;
+			float *tri_vert_weights[3];
 
-			if (mesh_render_data_looptri_cos_weights_get(
-			        rdata, i, &tri_vert_cos, &tri_vert_weights, &tri_nor, &tri_vert_nors, &is_smooth, defgroup))
+			if (mesh_render_data_looptri_weights_get(
+			        rdata, i, defgroup, &tri_vert_weights))
 			{
 				VertexB

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list