[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29860] branches/soc-2010-nicolasbishop/ source/blender: Some cleanups and optimizations for masks:

Nicholas Bishop nicholasbishop at gmail.com
Fri Jul 2 02:38:04 CEST 2010


Revision: 29860
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29860
Author:   nicholasbishop
Date:     2010-07-02 02:38:04 +0200 (Fri, 02 Jul 2010)

Log Message:
-----------
Some cleanups and optimizations for masks:

* Mesh/grid VBO buffers can now be updated separately for coord/normal data and mask data
* Added a typedef for GPU_Buffers so we don't have the void* cast
* Changed the PBVH update to allow separate updating of mask data
* Fixed a memory leak for the mask_set operator

Modified Paths:
--------------
    branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h
    branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_mask.c
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt.c
    branches/soc-2010-nicolasbishop/source/blender/gpu/gpu_buffers.h
    branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c

Modified: branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h	2010-07-01 23:13:29 UTC (rev 29859)
+++ branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h	2010-07-02 00:38:04 UTC (rev 29860)
@@ -102,12 +102,18 @@
 	PBVH_UpdateNormals = 2,
 	PBVH_UpdateBB = 4,
 	PBVH_UpdateOriginalBB = 8,
-	PBVH_UpdateDrawBuffers = 16,
-	PBVH_UpdateRedraw = 32
+
+	/* Update vertex data (coord + normal */
+	PBVH_UpdateVertBuffers = 16,
+	
+	/* Update color data (used for masks) */
+	PBVH_UpdateColorBuffers = 32,
+
+	PBVH_UpdateRedraw = 64
 } PBVHNodeFlags;
 
 void BLI_pbvh_node_mark_update(PBVHNode *node);
-void BLI_pbvh_node_mark_update_draw_buffers(PBVHNode *node, void *data);
+void BLI_pbvh_node_set_flags(PBVHNode *node, void *data);
 
 void BLI_pbvh_node_get_grids(PBVH *bvh, PBVHNode *node,
 	int **grid_indices, int *totgrid, int *maxgrid, int *gridsize,

Modified: branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c	2010-07-01 23:13:29 UTC (rev 29859)
+++ branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c	2010-07-02 00:38:04 UTC (rev 29860)
@@ -395,7 +395,7 @@
 				  node->uniq_verts,
 				  node->uniq_verts + node->face_verts);
 
-	node->flag |= PBVH_UpdateDrawBuffers;
+	node->flag |= PBVH_UpdateVertBuffers|PBVH_UpdateColorBuffers;
 
 	BLI_ghash_free(map, NULL, NULL);
 }
@@ -406,7 +406,7 @@
 		GPU_build_grid_buffers(bvh->grids, node->prim_indices,
 				node->totprim, bvh->gridsize);
 
-	node->flag |= PBVH_UpdateDrawBuffers;
+	node->flag |= PBVH_UpdateVertBuffers|PBVH_UpdateColorBuffers;
 }
 
 /* Recursively build a node in the tree
@@ -974,27 +974,46 @@
 	for(n = 0; n < totnode; n++) {
 		node= nodes[n];
 
-		if(node->flag & PBVH_UpdateDrawBuffers) {
+		if(node->flag & PBVH_UpdateVertBuffers) {
 			if(bvh->grids) {
-				GPU_update_grid_buffers(node->draw_buffers,
-						   bvh->grids,
-						   node->prim_indices,
-						   node->totprim,
-						   bvh->gridsize,
-						   bvh->gridkey,
-						   smooth);
+				GPU_update_grid_vert_buffers(node->draw_buffers,
+							     bvh->grids,
+							     node->prim_indices,
+							     node->totprim,
+							     bvh->gridsize,
+							     bvh->gridkey,
+							     smooth);
 			}
 			else {
-				GPU_update_mesh_buffers(node->draw_buffers,
-						   bvh->verts,
-						   bvh->vdata,
-						   node->vert_indices,
-						   node->uniq_verts +
-						   node->face_verts);
+				GPU_update_mesh_vert_buffers(node->draw_buffers,
+							     bvh->verts,
+							     node->vert_indices,
+							     node->uniq_verts +
+							     node->face_verts);
 			}
 
-			node->flag &= ~PBVH_UpdateDrawBuffers;
+			node->flag &= ~PBVH_UpdateVertBuffers;
 		}
+		
+		if(node->flag & PBVH_UpdateColorBuffers) {
+			if(bvh->grids) {
+				GPU_update_grid_color_buffers(node->draw_buffers,
+							      bvh->grids,
+							      node->prim_indices,
+							      node->totprim,
+							      bvh->gridsize,
+							      bvh->gridkey);
+			}
+			else {
+				GPU_update_mesh_color_buffers(node->draw_buffers,
+							      bvh->vdata,
+							      node->vert_indices,
+							      node->uniq_verts +
+							      node->face_verts);
+			}
+
+			node->flag &= ~PBVH_UpdateColorBuffers;
+		}
 	}
 }
 
@@ -1124,12 +1143,12 @@
 
 void BLI_pbvh_node_mark_update(PBVHNode *node)
 {
-	node->flag |= PBVH_UpdateNormals|PBVH_UpdateBB|PBVH_UpdateOriginalBB|PBVH_UpdateDrawBuffers|PBVH_UpdateRedraw;
+	node->flag |= PBVH_UpdateNormals|PBVH_UpdateBB|PBVH_UpdateOriginalBB|PBVH_UpdateVertBuffers|PBVH_UpdateRedraw;
 }
 
-void BLI_pbvh_node_mark_update_draw_buffers(PBVHNode *node, void *data)
+void BLI_pbvh_node_set_flags(PBVHNode *node, void *data)
 {
-	node->flag |= PBVH_UpdateDrawBuffers|PBVH_UpdateRedraw;
+	node->flag |= GET_INT_FROM_POINTER(data);
 }
 
 void BLI_pbvh_node_get_verts(PBVH *bvh, PBVHNode *node, int **vert_indices, MVert **verts, CustomData **vdata)
@@ -1399,7 +1418,8 @@
 	PBVHNode **nodes;
 	int totnode;
 
-	BLI_pbvh_search_gather(bvh, update_search_cb, SET_INT_IN_POINTER(PBVH_UpdateNormals|PBVH_UpdateDrawBuffers),
+	BLI_pbvh_search_gather(bvh, update_search_cb,
+			       SET_INT_IN_POINTER(PBVH_UpdateNormals|PBVH_UpdateVertBuffers|PBVH_UpdateColorBuffers),
 		&nodes, &totnode);
 
 	pbvh_update_normals(bvh, nodes, totnode, face_nors);

Modified: branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_mask.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_mask.c	2010-07-01 23:13:29 UTC (rev 29859)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_mask.c	2010-07-02 00:38:04 UTC (rev 29860)
@@ -79,12 +79,14 @@
 			}
 			BLI_pbvh_vertex_iter_end;
 
-			BLI_pbvh_node_mark_update(nodes[n]);
+			BLI_pbvh_node_set_flags(nodes[n], SET_INT_IN_POINTER(PBVH_UpdateColorBuffers|PBVH_UpdateRedraw));
 		}
 
+		if(nodes)
+			MEM_freeN(nodes);
+
 		if(mmd)
 			multires_mark_as_modified(ob);
-		BLI_pbvh_update(pbvh, PBVH_UpdateBB|PBVH_UpdateOriginalBB|PBVH_UpdateRedraw, NULL);
 
 		sculpt_undo_push_end(ss);
 
@@ -258,7 +260,7 @@
 
 	if(ob->sculpt->pbvh)
 		BLI_pbvh_search_callback(ob->sculpt->pbvh, NULL, NULL,
-					 BLI_pbvh_node_mark_update_draw_buffers, NULL);
+					 BLI_pbvh_node_set_flags, SET_INT_IN_POINTER(PBVH_UpdateColorBuffers));
 
 	WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);	
 }

Modified: branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt.c	2010-07-01 23:13:29 UTC (rev 29859)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt.c	2010-07-02 00:38:04 UTC (rev 29860)
@@ -1494,7 +1494,7 @@
 		}
 		BLI_pbvh_vertex_iter_end;
 
-		BLI_pbvh_node_mark_update(nodes[n]);
+		BLI_pbvh_node_set_flags(nodes[n], SET_INT_IN_POINTER(PBVH_UpdateColorBuffers|PBVH_UpdateRedraw));
 	}
 }
 

Modified: branches/soc-2010-nicolasbishop/source/blender/gpu/gpu_buffers.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/gpu/gpu_buffers.h	2010-07-01 23:13:29 UTC (rev 29859)
+++ branches/soc-2010-nicolasbishop/source/blender/gpu/gpu_buffers.h	2010-07-02 00:38:04 UTC (rev 29860)
@@ -129,17 +129,26 @@
 void GPU_drawobject_free( struct DerivedMesh *dm );
 
 /* Buffers for non-DerivedMesh drawing */
-void *GPU_build_mesh_buffers(struct GHash *map, struct MVert *mvert,
+typedef struct GPU_Buffers GPU_Buffers;
+
+GPU_Buffers *GPU_build_mesh_buffers(struct GHash *map, struct MVert *mvert,
 			     struct MFace *mface, CustomData *vdata, int *face_indices,
 			     int totface, int *vert_indices, int uniq_verts,
 			     int totvert);
-void GPU_update_mesh_buffers(void *buffers, struct MVert *mvert,
-			     struct CustomData *vdata, int *vert_indices, int totvert);
-void *GPU_build_grid_buffers(struct DMGridData **grids,
+void GPU_update_mesh_vert_buffers(GPU_Buffers *buffers, struct MVert *mvert,
+				  int *vert_indices, int totvert);
+void GPU_update_mesh_color_buffers(GPU_Buffers *buffers,
+				   struct CustomData *vdata,
+				   int *vert_indices, int totvert);
+GPU_Buffers *GPU_build_grid_buffers(struct DMGridData **grids,
 			     int *grid_indices, int totgrid, int gridsize);
-void GPU_update_grid_buffers(void *buffers_v, struct DMGridData **grids,
-			     int *grid_indices, int totgrid, int gridsize,
-			     struct GridKey *gridkey, int smooth);
+void GPU_update_grid_vert_buffers(GPU_Buffers *buffersb, struct DMGridData **grids,
+				  int *grid_indices, int totgrid, int gridsize,
+				  struct GridKey *gridkey, int smooth);
+void GPU_update_grid_color_buffers(GPU_Buffers *buffers,
+				   struct DMGridData **grids,
+				   int *grid_indices, int totgrid,
+				   int gridsize, struct GridKey *gridkey);
 void GPU_draw_buffers(void *buffers);
 void GPU_free_buffers(void *buffers);
 

Modified: branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c	2010-07-01 23:13:29 UTC (rev 29859)
+++ branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c	2010-07-02 00:38:04 UTC (rev 29860)
@@ -400,7 +400,7 @@
 #endif
 } VertexBufferFormat;
 
-typedef struct {
+struct GPU_Buffers {
 	/* opengl buffer handles */
 	GLuint vert_buf, index_buf, color_buf;
 	GLenum index_type;
@@ -419,7 +419,7 @@
 	struct GridKey *gridkey;
 
 	unsigned int tot_tri, tot_quad;
-} GPU_Buffers;
+};
 
 static void delete_buffer(GLuint *buf)
 {
@@ -463,9 +463,7 @@
 	return color_data;
 }
 
-/* For now this looks for just a single mask layer, eventually might include
-   other color layers like vertex colors or weights */
-static void update_mesh_color_buffers(GPU_Buffers *buffers, CustomData *vdata, int *vert_indices, int totvert)
+void GPU_update_mesh_color_buffers(GPU_Buffers *buffers, CustomData *vdata, int *vert_indices, int totvert)
 {
 	unsigned char *color_data;
 	int i, pmask_totlayer;
@@ -491,10 +489,9 @@
 	}
 }
 
-void GPU_update_mesh_buffers(void *buffers_v, MVert *mvert,
-			     CustomData *vdata, int *vert_indices, int totvert)
+void GPU_update_mesh_vert_buffers(GPU_Buffers *buffers, MVert *mvert,
+				  int *vert_indices, int totvert)
 {
-	GPU_Buffers *buffers = buffers_v;
 	VertexBufferFormat *vert_data;
 	int i;
 
@@ -524,19 +521,17 @@
 		else
 			delete_buffer(&buffers->vert_buf);
 
-		update_mesh_color_buffers(buffers, vdata, vert_indices, totvert);
-
 		glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
 	}
 
 	buffers->mvert = mvert;
 }
 
-void *GPU_build_mesh_buffers(GHash *map, MVert *mvert, MFace *mface,
-			     CustomData *vdata,
-			     int *face_indices, int totface,
-			     int *vert_indices, int tot_uniq_verts,
-			     int totvert)
+GPU_Buffers *GPU_build_mesh_buffers(GHash *map, MVert *mvert, MFace *mface,
+				    CustomData *vdata,
+				    int *face_indices, int totface,
+				    int *vert_indices, int tot_uniq_verts,
+				    int totvert)
 {
 	GPU_Buffers *buffers;
 	unsigned short *tri_data;
@@ -596,8 +591,10 @@
 
 	if(buffers->index_buf)

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list