[Bf-blender-cvs] [daeebc1] cycles-ptex-06: A few code cleanups in debug code

Nicholas Bishop noreply at git.blender.org
Thu Jan 15 20:13:05 CET 2015


Commit: daeebc1670bc41b66e9a00764da7cb4b5390643d
Author: Nicholas Bishop
Date:   Thu Jan 8 11:45:00 2015 +0100
Branches: cycles-ptex-06
https://developer.blender.org/rBdaeebc1670bc41b66e9a00764da7cb4b5390643d

A few code cleanups in debug code

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

M	source/blender/editors/space_view3d/drawobject.c

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

diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index 2afca0e..26fb15b 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -43,6 +43,7 @@
 #include "DNA_world_types.h"
 #include "DNA_object_types.h"
 
+#include "BLI_array.h"
 #include "BLI_listbase.h"
 #include "BLI_link_utils.h"
 #include "BLI_string.h"
@@ -3678,6 +3679,9 @@ static void dm_draw_vert_order(RegionView3D *rv3d, DerivedMesh *dm)
 		float pos[3], col[4];
 	} VertCol;
 
+	VertCol *vert_col = NULL;
+	BLI_array_staticdeclare(vert_col, BM_DEFAULT_NGON_STACK_SIZE);
+
 	const float alpha = 0.5;
 	const float start_col[4] = {1, 0, 0, alpha};
 	const float rest_col[4] =  {0, 1, 0, alpha};
@@ -3685,7 +3689,9 @@ static void dm_draw_vert_order(RegionView3D *rv3d, DerivedMesh *dm)
 	const MVert *verts = dm->getVertArray(dm);
 	const MPoly *polys = dm->getPolyArray(dm);
 	const MLoop *loops = dm->getLoopArray(dm);
-	int a, b;
+
+	const int num_poly = dm->getNumPolys(dm);
+	int cur_poly;
 
 	glEnableClientState(GL_VERTEX_ARRAY);
 	glEnableClientState(GL_COLOR_ARRAY);
@@ -3695,35 +3701,40 @@ static void dm_draw_vert_order(RegionView3D *rv3d, DerivedMesh *dm)
 	glDisable(GL_LIGHTING);
 	glEnable(GL_BLEND);
 
-	for (a = 0; a < dm->getNumPolys(dm); a++) {
-		const MPoly *p = &polys[a];
-		VertCol *points = MEM_callocN(sizeof(VertCol) * p->totloop, "points");
+	for (cur_poly = 0; cur_poly < num_poly; cur_poly++) {
+		const MPoly *p = &polys[cur_poly];
+		int cur_loop;
 
 		float avg[3] = {0, 0, 0};
-		for (b = 0; b < p->totloop; b++) {
-			const MLoop *l = &loops[p->loopstart + b];
+		for (cur_loop = 0; cur_loop < p->totloop; cur_loop++) {
+			const MLoop *l = &loops[p->loopstart + cur_loop];
 			const MVert *v = &verts[l->v];
-			copy_v3_v3(points[b].pos, v->co);
+			const bool first_line = cur_loop <= 1;
+			VertCol *cur_vert_col = BLI_array_append_ret(vert_col);
+
+			copy_v3_v3(cur_vert_col->pos, v->co);
 			add_v3_v3(avg, v->co);
 
 			/* First line gets a different color to indicate which
 			 * loop the polygon starts at */
-			copy_v4_v4(points[b].col, (b <= 1) ? start_col : rest_col);
+			copy_v4_v4(cur_vert_col->col, first_line ? start_col : rest_col);
 		}
 
 		/* Move points in towards center a bit */
 		mul_v3_fl(avg, 1.0f / p->totloop);
-		for (b = 0; b < p->totloop; b++) {
-			interp_v3_v3v3(points[b].pos, points[b].pos, avg, 0.3);
+		for (cur_loop = 0; cur_loop < p->totloop; cur_loop++) {
+			VertCol *cur_vert_col = &vert_col[cur_loop];
+			interp_v3_v3v3(cur_vert_col->pos, cur_vert_col->pos, avg, 0.3);
 		}
 
-		glVertexPointer(3, GL_FLOAT, sizeof(VertCol), points);
-		glColorPointer(4, GL_FLOAT, sizeof(VertCol), &points[0].col);
+		glVertexPointer(3, GL_FLOAT, sizeof(VertCol), &vert_col->pos);
+		glColorPointer(4, GL_FLOAT, sizeof(VertCol), &vert_col->col);
 		glDrawArrays(GL_LINE_STRIP, 0, p->totloop);
-
-		MEM_freeN(points);
+		BLI_array_empty(vert_col);
 	}
 
+	BLI_array_free(vert_col);
+
 	/* Reset all GL state */
 	ED_view3d_polygon_offset(rv3d, 0.0);
 	glDisableClientState(GL_VERTEX_ARRAY);




More information about the Bf-blender-cvs mailing list