[Bf-blender-cvs] [10aee12] vertex_paint_pbvh: WIP incorrect inconvenient code that is supposed to draw PBVH colors.

Antony Riakiotakis noreply at git.blender.org
Fri Jan 2 13:38:18 CET 2015


Commit: 10aee127d4b003c2d910999ed5cb0d699bf4ba7b
Author: Antony Riakiotakis
Date:   Fri Jan 2 13:38:04 2015 +0100
Branches: vertex_paint_pbvh
https://developer.blender.org/rB10aee127d4b003c2d910999ed5cb0d699bf4ba7b

WIP incorrect inconvenient code that is supposed to draw PBVH colors.

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

M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/intern/cdderivedmesh.c
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenkernel/intern/pbvh_intern.h
M	source/blender/blenkernel/intern/subsurf_ccg.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 c8c693f..63d207a 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -62,7 +62,7 @@ typedef void (*BKE_pbvh_HitOccludedCallback)(PBVHNode *node, void *data, float *
 
 PBVH *BKE_pbvh_new(void);
 void BKE_pbvh_build_mesh(PBVH *bvh, struct MFace *faces, struct MVert *verts,
-                         int totface, int totvert, struct CustomData *vdata);
+                         int totface, int totvert, struct CustomData *vdata, struct CustomData *ldata);
 void BKE_pbvh_build_grids(PBVH *bvh, struct CCGElem **grid_elems,
                           struct DMGridAdjacency *gridadj, int totgrid,
                           struct CCGKey *key, void **gridfaces, struct DMFlagMat *flagmats,
@@ -115,7 +115,7 @@ void BKE_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3],
                    int (*setMaterial)(int matnr, void *attribs), bool wireframe);
 
 /* PBVH Access */
-typedef enum {
+typedef enum PBVHType {
 	PBVH_FACES,
 	PBVH_GRIDS,
 	PBVH_BMESH
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index f6df071..feb11e0 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -307,7 +307,7 @@ static PBVH *cdDM_getPBVH(Object *ob, DerivedMesh *dm)
 		BKE_mesh_tessface_ensure(me);
 		
 		BKE_pbvh_build_mesh(cddm->pbvh, me->mface, me->mvert,
-		                    me->totface, me->totvert, &me->vdata);
+		                    me->totface, me->totvert, &me->vdata, &me->ldata);
 
 		if (ss) {
 			pbvh_show_diffuse_color_set(cddm->pbvh, ss->show_diffuse_color);
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index bd95389..75e327c 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -538,7 +538,7 @@ static void pbvh_build(PBVH *bvh, BB *cb, BBC *prim_bbc, int totprim)
 }
 
 /* Do a full rebuild with on Mesh data structure */
-void BKE_pbvh_build_mesh(PBVH *bvh, MFace *faces, MVert *verts, int totface, int totvert, struct CustomData *vdata)
+void BKE_pbvh_build_mesh(PBVH *bvh, MFace *faces, MVert *verts, int totface, int totvert, struct CustomData *vdata, CustomData *ldata)
 {
 	BBC *prim_bbc = NULL;
 	BB cb;
@@ -551,7 +551,11 @@ void BKE_pbvh_build_mesh(PBVH *bvh, MFace *faces, MVert *verts, int totface, int
 	bvh->totvert = totvert;
 	bvh->leaf_limit = LEAF_LIMIT;
 	bvh->vdata = vdata;
-
+	bvh->ldata = ldata;
+	
+	if (bvh->ldata) {
+		bvh->drawtype |= PBVH_DRAW_NO_INDEXED;
+	}
 	BB_reset(&cb);
 
 	/* For each face, store the AABB and the AABB centroid */
@@ -1095,7 +1099,7 @@ static void pbvh_update_draw_buffers(PBVH *bvh, PBVHNode **nodes, int totnode)
 						GPU_build_mesh_pbvh_buffers(node->face_vert_indices,
 					                           bvh->faces, bvh->verts,
 					                           node->prim_indices,
-					                           node->totprim);
+					                           node->totprim, (bvh->drawtype & PBVH_DRAW_NO_INDEXED) != 0);
 					break;
 				case PBVH_BMESH:
 					node->draw_buffers =
@@ -1126,6 +1130,8 @@ static void pbvh_update_draw_buffers(PBVH *bvh, PBVHNode **nodes, int totnode)
 					                        node->face_verts,
 					                        CustomData_get_layer(bvh->vdata,
 					                                             CD_PAINT_MASK),
+					                        CustomData_get_layer(bvh->ldata,
+						                                         CD_MLOOPCOL),
 					                        node->face_vert_indices,
 					                        bvh->show_diffuse_color);
 					break;
diff --git a/source/blender/blenkernel/intern/pbvh_intern.h b/source/blender/blenkernel/intern/pbvh_intern.h
index 6b3ef8e..696d9e8 100644
--- a/source/blender/blenkernel/intern/pbvh_intern.h
+++ b/source/blender/blenkernel/intern/pbvh_intern.h
@@ -116,11 +116,18 @@ typedef enum {
 	PBVH_DYNTOPO_SMOOTH_SHADING = 1
 } PBVHFlags;
 
+/* don't use indexed drawing even if smooth shaded because we need to sample per face face data */
+typedef enum {
+	PBVH_DRAW_NO_INDEXED = 1
+} PBVHDraw;
+
 typedef struct PBVHBMeshLog PBVHBMeshLog;
+typedef enum PBVHType PBVHType;
 
 struct PBVH {
 	PBVHType type;
 	PBVHFlags flags;
+	PBVHDraw drawtype;
 
 	PBVHNode *nodes;
 	int node_mem_count, totnode;
@@ -135,6 +142,7 @@ struct PBVH {
 	MVert *verts;
 	MFace *faces;
 	CustomData *vdata;
+	CustomData *ldata;
 
 	/* Grid Data */
 	CCGKey gridkey;
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index f14b7ee..a964057 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -3389,10 +3389,11 @@ static struct PBVH *ccgDM_getPBVH(Object *ob, DerivedMesh *dm)
 	}
 	else if (ob->type == OB_MESH) {
 		Mesh *me = ob->data;
+		void *ldata = (ob->mode & OB_MODE_VERTEX_PAINT) ? &me->ldata : NULL;
 		ob->paint->pbvh = ccgdm->pbvh = BKE_pbvh_new();
 		BLI_assert(!(me->mface == NULL && me->mpoly != NULL)); /* BMESH ONLY complain if mpoly is valid but not mface */
 		BKE_pbvh_build_mesh(ccgdm->pbvh, me->mface, me->mvert,
-		                    me->totface, me->totvert, &me->vdata);
+		                    me->totface, me->totvert, &me->vdata, ldata);
 	}
 
 	if (ccgdm->pbvh && ob->paint->sculpt)
diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h
index e9b600a..0dc6646 100644
--- a/source/blender/gpu/GPU_buffers.h
+++ b/source/blender/gpu/GPU_buffers.h
@@ -165,7 +165,7 @@ typedef struct GPU_PBVH_Buffers GPU_PBVH_Buffers;
 /* build */
 GPU_PBVH_Buffers *GPU_build_mesh_pbvh_buffers(int (*face_vert_indices)[4],
                                     struct MFace *mface, struct MVert *mvert,
-                                    int *face_indices, int totface);
+                                    int *face_indices, int totface, bool no_indexed);
 
 GPU_PBVH_Buffers *GPU_build_grid_pbvh_buffers(int *grid_indices, int totgrid,
                                     unsigned int **grid_hidden, int gridsize);
@@ -175,7 +175,7 @@ GPU_PBVH_Buffers *GPU_build_bmesh_pbvh_buffers(int smooth_shading);
 /* update */
 
 void GPU_update_mesh_pbvh_buffers(GPU_PBVH_Buffers *buffers, MVert *mvert,
-							 int *vert_indices, int totvert, const float *vmask,
+							 int *vert_indices, int totvert, const float *vmask, const int *lcol,
 							 int (*face_vert_indices)[4], bool show_diffuse_color);
 
 void GPU_update_bmesh_pbvh_buffers(GPU_PBVH_Buffers *buffers,
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index f0ef55a..f3e223e 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -1573,7 +1573,7 @@ static void gpu_color_from_mask_quad_set(const CCGKey *key,
 }
 
 void GPU_update_mesh_pbvh_buffers(GPU_PBVH_Buffers *buffers, MVert *mvert,
-                             int *vert_indices, int totvert, const float *vmask,
+                             int *vert_indices, int totvert, const float *vmask, const int *lcol,
                              int (*face_vert_indices)[4], bool show_diffuse_color)
 {
 	VertexBufferFormat *vert_data;
@@ -1623,7 +1623,11 @@ void GPU_update_mesh_pbvh_buffers(GPU_PBVH_Buffers *buffers, MVert *mvert,
 					VertexBufferFormat *out = vert_data + face_vert_indices[face][index]; \
 					if (vmask) \
 						gpu_color_from_mask_copy(vmask[vertex], diffuse_color, out->color); \
-					else \
+					else if (lcol) { \
+						char *lc = (char *)(lcol + vertex); \
+						copy_v3_v3_char((char *)out->color, lc); \
+						printf("updating vcol\n"); \
+					} else \
 						rgb_float_to_uchar(out->color, diffuse_color); \
 				} (void)0
 
@@ -1688,9 +1692,13 @@ void GPU_update_mesh_pbvh_buffers(GPU_PBVH_Buffers *buffers, MVert *mvert,
 
 							if (vmask)
 								gpu_color_from_mask_copy(fmask, diffuse_color, out->color);
-							else
+							if (lcol) {
+								char *lc = (char *)(lcol + fv[vi[j][k]]);
+								copy_v3_v3_char((char *)out->color, lc);
+								printf("updating vcol\n");
+							} else
 								rgb_float_to_uchar(out->color, diffuse_color);
-
+							
 							vert_data++;
 						}
 					}
@@ -1713,7 +1721,7 @@ void GPU_update_mesh_pbvh_buffers(GPU_PBVH_Buffers *buffers, MVert *mvert,
 GPU_PBVH_Buffers *GPU_build_mesh_pbvh_buffers(int (*face_vert_indices)[4],
                                     MFace *mface, MVert *mvert,
                                     int *face_indices,
-                                    int totface)
+                                    int totface, bool no_indexed)
 {
 	GPU_PBVH_Buffers *buffers;
 	unsigned short *tri_data;
@@ -1721,7 +1729,7 @@ GPU_PBVH_Buffers *GPU_build_mesh_pbvh_buffers(int (*face_vert_indices)[4],
 
 	buffers = MEM_callocN(sizeof(GPU_PBVH_Buffers), "GPU_Buffers");
 	buffers->index_type = GL_UNSIGNED_SHORT;
-	buffers->smooth = mface[face_indices[0]].flag & ME_SMOOTH;
+	buffers->smooth = (mface[face_indices[0]].flag & ME_SMOOTH) && !no_indexed;
 
 	buffers->show_diffuse_color = false;
 	buffers->use_matcaps = false;




More information about the Bf-blender-cvs mailing list