[Bf-blender-cvs] [77ac33d] master: cleanup: C99 and vertex array comments

Mike Erwin noreply at git.blender.org
Thu Nov 26 01:53:17 CET 2015


Commit: 77ac33db7b449011e3edaa25a24d0ee193b843c1
Author: Mike Erwin
Date:   Wed Nov 25 19:49:31 2015 -0500
Branches: master
https://developer.blender.org/rB77ac33db7b449011e3edaa25a24d0ee193b843c1

cleanup: C99 and vertex array comments

GPU_buffer no longer has a fallback to client vertex arrays, so remove
comments about it.

Changed a few internal structs/function interfaces to use bool where
appropriate.

Use for-loop scope and flexible declaration placement. PBVH does the
same thing but needs ~150 fewer lines to do it!

The change to BLI_ghashIterator_init is admittedly hackish but makes
GHASH_ITER_INDEX nicer to use.

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

M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/intern/multires.c
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenkernel/intern/pbvh_bmesh.c
M	source/blender/blenlib/BLI_ghash.h
M	source/blender/blenlib/intern/BLI_ghash.c
M	source/blender/gpu/GPU_buffers.h
M	source/blender/gpu/intern/gpu_buffers.c

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

diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 5dc5ebb..5d69cb5 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -98,7 +98,7 @@ void BKE_pbvh_raycast(
         bool original);
 
 bool BKE_pbvh_node_raycast(
-        PBVH *bvh, PBVHNode *node, float (*origco)[3], int use_origco,
+        PBVH *bvh, PBVHNode *node, float (*origco)[3], bool use_origco,
         const float ray_start[3], const float ray_normal[3],
         float *dist);
 
@@ -210,7 +210,7 @@ void BKE_pbvh_bmesh_after_stroke(PBVH *bvh);
 
 void BKE_pbvh_update(PBVH *bvh, int flags, float (*face_nors)[3]);
 void BKE_pbvh_redraw_BB(PBVH *bvh, float bb_min[3], float bb_max[3]);
-void BKE_pbvh_get_grid_updates(PBVH *bvh, int clear, void ***r_gridfaces, int *r_totface);
+void BKE_pbvh_get_grid_updates(PBVH *bvh, bool clear, void ***r_gridfaces, int *r_totface);
 void BKE_pbvh_grids_update(PBVH *bvh, struct CCGElem **grid_elems,
                            void **gridfaces,
                            struct DMFlagMat *flagmats, unsigned int **grid_hidden);
diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c
index 0adc894..fb7463b 100644
--- a/source/blender/blenkernel/intern/multires.c
+++ b/source/blender/blenkernel/intern/multires.c
@@ -1415,7 +1415,7 @@ void multires_stitch_grids(Object *ob)
 		int totface;
 
 		if (ccgdm->pbvh) {
-			BKE_pbvh_get_grid_updates(ccgdm->pbvh, 0, (void ***)&faces, &totface);
+			BKE_pbvh_get_grid_updates(ccgdm->pbvh, false, (void ***)&faces, &totface);
 
 			if (totface) {
 				ccgSubSurf_stitchFaces(ccgdm->ss, 0, faces, totface);
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 311e928..115a415 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -63,7 +63,7 @@
 
 typedef struct PBVHStack {
 	PBVHNode *node;
-	int revisiting;
+	bool revisiting;
 } PBVHStack;
 
 typedef struct PBVHIter {
@@ -87,8 +87,7 @@ void BB_reset(BB *bb)
 /* Expand the bounding box to include a new coordinate */
 void BB_expand(BB *bb, const float co[3])
 {
-	int i;
-	for (i = 0; i < 3; ++i) {
+	for (int i = 0; i < 3; ++i) {
 		bb->bmin[i] = min_ff(bb->bmin[i], co[i]);
 		bb->bmax[i] = max_ff(bb->bmax[i], co[i]);
 	}
@@ -97,8 +96,7 @@ void BB_expand(BB *bb, const float co[3])
 /* Expand the bounding box to include another bounding box */
 void BB_expand_with_bb(BB *bb, BB *bb2)
 {
-	int i;
-	for (i = 0; i < 3; ++i) {
+	for (int i = 0; i < 3; ++i) {
 		bb->bmin[i] = min_ff(bb->bmin[i], bb2->bmin[i]);
 		bb->bmax[i] = max_ff(bb->bmax[i], bb2->bmax[i]);
 	}
@@ -108,9 +106,8 @@ void BB_expand_with_bb(BB *bb, BB *bb2)
 int BB_widest_axis(const BB *bb)
 {
 	float dim[3];
-	int i;
 
-	for (i = 0; i < 3; ++i)
+	for (int i = 0; i < 3; ++i)
 		dim[i] = bb->bmax[i] - bb->bmin[i];
 
 	if (dim[0] > dim[1]) {
@@ -129,8 +126,7 @@ int BB_widest_axis(const BB *bb)
 
 void BBC_update_centroid(BBC *bbc)
 {
-	int i;
-	for (i = 0; i < 3; ++i)
+	for (int i = 0; i < 3; ++i)
 		bbc->bcentroid[i] = (bbc->bmin[i] + bbc->bmax[i]) * 0.5f;
 }
 
@@ -170,13 +166,13 @@ static void update_node_vb(PBVH *bvh, PBVHNode *node)
 //	BB_expand(&node->vb, co);
 //}
 
-static int face_materials_match(const MPoly *f1, const MPoly *f2)
+static bool face_materials_match(const MPoly *f1, const MPoly *f2)
 {
 	return ((f1->flag & ME_SMOOTH) == (f2->flag & ME_SMOOTH) &&
 	        (f1->mat_nr == f2->mat_nr));
 }
 
-static int grid_materials_match(const DMFlagMat *f1, const DMFlagMat *f2)
+static bool grid_materials_match(const DMFlagMat *f1, const DMFlagMat *f2)
 {
 	return ((f1->flag & ME_SMOOTH) == (f2->flag & ME_SMOOTH) &&
 	        (f1->mat_nr == f2->mat_nr));
@@ -279,29 +275,24 @@ static int map_insert_vert(PBVH *bvh, GHash *map,
 /* Find vertices used by the faces in this node and update the draw buffers */
 static void build_mesh_leaf_node(PBVH *bvh, PBVHNode *node)
 {
-	GHashIterator gh_iter;
-	GHash *map;
-	int i, j, totface;
 	bool has_visible = false;
-	int (*face_vert_indices)[4];
-	int *vert_indices;
 
 	node->uniq_verts = node->face_verts = 0;
-	totface = node->totprim;
+	const int totface = node->totprim;
 
 	/* reserve size is rough guess */
-	map = BLI_ghash_int_new_ex("build_mesh_leaf_node gh", 2 * totface);
+	GHash *map = BLI_ghash_int_new_ex("build_mesh_leaf_node gh", 2 * totface);
 
-	face_vert_indices = MEM_callocN(sizeof(int[4]) * totface,
-	                                "bvh node face vert indices");
+	int (*face_vert_indices)[4] = MEM_callocN(sizeof(int[4]) * totface,
+	                                          "bvh node face vert indices");
 
 	node->face_vert_indices = (const int (*)[4])face_vert_indices;
 
-	for (i = 0; i < totface; ++i) {
+	for (int i = 0; i < totface; ++i) {
 		const MLoopTri *lt = &bvh->looptri[node->prim_indices[i]];
 		const int sides = 3;
 
-		for (j = 0; j < sides; ++j) {
+		for (int j = 0; j < sides; ++j) {
 			face_vert_indices[i][j] =
 			        map_insert_vert(bvh, map, &node->face_verts,
 			                        &node->uniq_verts, bvh->mloop[lt->tri[j]].v);
@@ -312,12 +303,12 @@ static void build_mesh_leaf_node(PBVH *bvh, PBVHNode *node)
 		}
 	}
 
-	vert_indices = MEM_callocN(sizeof(int) *
-	                           (node->uniq_verts + node->face_verts),
-	                           "bvh node vert indices");
+	int *vert_indices = MEM_callocN(sizeof(int) * (node->uniq_verts + node->face_verts),
+	                                "bvh node vert indices");
 	node->vert_indices = vert_indices;
 
 	/* Build the vertex list, unique verts first */
+	GHashIterator gh_iter;
 	GHASH_ITER (gh_iter, map) {
 		void *value = BLI_ghashIterator_getValue(&gh_iter);
 		int ndx = GET_INT_FROM_POINTER(value);
@@ -329,10 +320,10 @@ static void build_mesh_leaf_node(PBVH *bvh, PBVHNode *node)
 		        GET_INT_FROM_POINTER(BLI_ghashIterator_getKey(&gh_iter));
 	}
 
-	for (i = 0; i < totface; ++i) {
+	for (int i = 0; i < totface; ++i) {
 		const int sides = 3;
 
-		for (j = 0; j < sides; ++j) {
+		for (int j = 0; j < sides; ++j) {
 			if (face_vert_indices[i][j] < 0)
 				face_vert_indices[i][j] =
 				        -face_vert_indices[i][j] +
@@ -350,10 +341,8 @@ static void build_mesh_leaf_node(PBVH *bvh, PBVHNode *node)
 static void update_vb(PBVH *bvh, PBVHNode *node, BBC *prim_bbc,
                       int offset, int count)
 {
-	int i;
-	
 	BB_reset(&node->vb);
-	for (i = offset + count - 1; i >= offset; --i) {
+	for (int i = offset + count - 1; i >= offset; --i) {
 		BB_expand_with_bb(&node->vb, (BB *)(&prim_bbc[bvh->prim_indices[i]]));
 	}
 	node->orig_vb = node->vb;
@@ -364,19 +353,19 @@ int BKE_pbvh_count_grid_quads(BLI_bitmap **grid_hidden,
                               int *grid_indices, int totgrid,
                               int gridsize)
 {
-	int gridarea = (gridsize - 1) * (gridsize - 1);
-	int i, x, y, totquad;
+	const int gridarea = (gridsize - 1) * (gridsize - 1);
+	int totquad = 0;
 
 	/* grid hidden layer is present, so have to check each grid for
 	 * visibility */
 
-	for (i = 0, totquad = 0; i < totgrid; i++) {
+	for (int i = 0; i < totgrid; i++) {
 		const BLI_bitmap *gh = grid_hidden[grid_indices[i]];
 
 		if (gh) {
 			/* grid hidden are present, have to check each element */
-			for (y = 0; y < gridsize - 1; y++) {
-				for (x = 0; x < gridsize - 1; x++) {
+			for (int y = 0; y < gridsize - 1; y++) {
+				for (int x = 0; x < gridsize - 1; x++) {
 					if (!paint_is_grid_face_hidden(gh, gridsize, x, y))
 						totquad++;
 				}
@@ -418,36 +407,34 @@ static void build_leaf(PBVH *bvh, int node_index, BBC *prim_bbc,
 
 /* Return zero if all primitives in the node can be drawn with the
  * same material (including flat/smooth shading), non-zero otherwise */
-static int leaf_needs_material_split(PBVH *bvh, int offset, int count)
+static bool leaf_needs_material_split(PBVH *bvh, int offset, int count)
 {
-	int i;
-
 	if (count <= 1)
-		return 0;
+		return false;
 
 	if (bvh->looptri) {
 		const MLoopTri *first = &bvh->looptri[bvh->prim_indices[offset]];
 		const MPoly *mp = &bvh->mpoly[first->poly];
 
-		for (i = offset + count - 1; i > offset; --i) {
+		for (int i = offset + count - 1; i > offset; --i) {
 			int prim = bvh->prim_indices[i];
 			const MPoly *mp_other = &bvh->mpoly[bvh->looptri[prim].poly];
 			if (!face_materials_match(mp, mp_other)) {
-				return 1;
+				return true;
 			}
 		}
 	}
 	else {
 		const DMFlagMat *first = &bvh->grid_flag_mats[bvh->prim_indices[offset]];
 
-		for (i = offset + count - 1; i > offset; --i) {
+		for (int i = offset + count - 1; i > offset; --i) {
 			int prim = bvh->prim_indices[i];
 			if (!grid_materials_match(first, &bvh->grid_flag_mats[prim]))
-				return 1;
+				return true;
 		}
 	}
 
-	return 0;
+	return false;
 }
 
 
@@ -465,11 +452,11 @@ static int leaf_needs_material_split(PBVH *bvh, int offset, int count)
 static void build_sub(PBVH *bvh, int node_index, BB *cb, BBC *prim_bbc,
                       int offset, int count)
 {
-	int i, axis, end, below_leaf_limit;
+	int end;
 	BB cb_backing;
 
 	/* Decide whether this is a leaf or not */
-	below_leaf_limit = count <= bvh->leaf_limit;
+	const bool below_leaf_limit = count <= bvh->leaf_limit;
 	if (below_leaf_limit) {
 		if (!leaf_needs_material_split(bvh, offset, count)) {
 			build_leaf(bvh, node_index, prim_bbc, offset, count);
@@ -489,10 +476,10 @@ static void build_sub(PBVH *bvh, int node_index, BB *cb, BBC *prim_bbc,
 		if (!cb) {
 			cb = &cb_backing;
 			BB_reset(cb);
-			for (i = offset + count - 1; i >= offset; --i)
+			for (int i = offset + count - 1; i >= offset; --i)
 				BB_expand(cb, prim_bbc[bvh->prim_indices[i]].bcentroid);
 		}
-		axis = BB_widest_axis(cb);
+		const int axis = BB_widest_axis(cb);
 
 		/* Partition primitives along that axis */
 		end = partition_indices(bvh->prim_indices,
@@ -515,15 +502,13 @@ static void build_sub(PBVH *bvh, int node_index, BB *cb, BBC *prim_bbc,
 
 static void pbvh_build(PBVH *bvh, BB *cb, BBC *prim_bbc, int totprim)
 {
-	int i;
-
 	if (totprim != bvh->totprim) {
 		bvh->totprim = totprim;
 		if (bvh->nodes) MEM_freeN(bvh->nodes);
 		if (bvh->prim_indices) MEM_freeN(bvh->pr

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list