[Bf-blender-cvs] [d2a3260] master: Add PBVH debug display, where we can see the PBVH node bounding boxes.

Antony Riakiotakis noreply at git.blender.org
Wed Apr 30 22:43:34 CEST 2014


Commit: d2a326076342845fc5e0bcfc4ea10b09ce86242e
Author: Antony Riakiotakis
Date:   Wed Apr 30 23:42:58 2014 +0300
https://developer.blender.org/rBd2a326076342845fc5e0bcfc4ea10b09ce86242e

Add PBVH debug display, where we can see the PBVH node bounding boxes.

To enable enter debug value 14.
Leaf nodes are green while container nodes are red.

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

M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/gpu/GPU_buffers.h
M	source/blender/gpu/intern/gpu_buffers.c

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

diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 5327f4d..09bf165 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -34,6 +34,7 @@
 #include "BKE_pbvh.h"
 #include "BKE_ccg.h"
 #include "BKE_DerivedMesh.h"
+#include "BKE_global.h"
 #include "BKE_mesh.h" /* for BKE_mesh_calc_normals */
 #include "BKE_paint.h"
 
@@ -1088,6 +1089,22 @@ static void pbvh_update_draw_buffers(PBVH *bvh, PBVHNode **nodes, int totnode)
 	}
 }
 
+static void pbvh_draw_BB(PBVH *bvh)
+{
+	PBVHNode *node;
+	int a;
+
+	GPU_init_draw_pbvh_BB();
+
+	for (a = 0; a < bvh->totnode; a++) {
+		node = &bvh->nodes[a];
+
+		GPU_draw_pbvh_BB(node->vb.bmin, node->vb.bmax, ((node->flag & PBVH_Leaf) != 0));
+	}
+
+	GPU_end_draw_pbvh_BB();
+}
+
 static int pbvh_flush_bb(PBVH *bvh, PBVHNode *node, int flag)
 {
 	int update = 0;
@@ -1691,6 +1708,9 @@ void BKE_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3],
 	else {
 		BKE_pbvh_search_callback(bvh, NULL, NULL, BKE_pbvh_node_draw, &draw_data);
 	}
+
+	if (G.debug_value == 14)
+		pbvh_draw_BB(bvh);
 }
 
 void BKE_pbvh_grids_update(PBVH *bvh, CCGElem **grids, DMGridAdjacency *gridadj, void **gridfaces,
diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h
index 7ca1c87..6c7945d 100644
--- a/source/blender/gpu/GPU_buffers.h
+++ b/source/blender/gpu/GPU_buffers.h
@@ -194,6 +194,10 @@ void GPU_update_grid_pbvh_buffers(GPU_PBVH_Buffers *buffers, struct CCGElem **gr
 void GPU_draw_pbvh_buffers(GPU_PBVH_Buffers *buffers, DMSetMaterial setMaterial,
                            bool wireframe);
 
+void GPU_draw_pbvh_BB(float min[3], float max[3], bool leaf);
+void GPU_end_draw_pbvh_BB(void);
+void GPU_init_draw_pbvh_BB(void);
+
 bool GPU_pbvh_buffers_diffuse_changed(GPU_PBVH_Buffers *buffers, struct GSet *bm_faces, bool show_diffuse_color);
 
 void GPU_free_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 df6aa4d..9bf63d2 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -2657,3 +2657,65 @@ void GPU_free_pbvh_buffers(GPU_PBVH_Buffers *buffers)
 		MEM_freeN(buffers);
 	}
 }
+
+
+/* debug function, draws the pbvh BB */
+void GPU_draw_pbvh_BB(float min[3], float max[3], bool leaf)
+{
+	float quads[4][4][3] = {
+	    {
+	        {min[0], min[1], min[2]},
+	        {max[0], min[1], min[2]},
+	        {max[0], min[1], max[2]},
+	        {min[0], min[1], max[2]}
+	    },
+
+	    {
+	        {min[0], min[1], min[2]},
+	        {min[0], max[1], min[2]},
+	        {min[0], max[1], max[2]},
+	        {min[0], min[1], max[2]}
+	    },
+
+	    {
+	        {max[0], max[1], min[2]},
+	        {max[0], min[1], min[2]},
+	        {max[0], min[1], max[2]},
+	        {max[0], max[1], max[2]}
+	    },
+
+	    {
+	        {max[0], max[1], min[2]},
+	        {min[0], max[1], min[2]},
+	        {min[0], max[1], max[2]},
+	        {max[0], max[1], max[2]}
+	    },
+	};
+
+	if (leaf)
+		glColor4f(0.0, 1.0, 0.0, 0.5);
+	else
+		glColor4f(1.0, 0.0, 0.0, 0.5);
+
+	glVertexPointer(3, GL_FLOAT, 0, &quads[0][0][0]);
+	glDrawArrays(GL_QUADS, 0, 16);
+}
+
+void GPU_init_draw_pbvh_BB(void)
+{
+	glPushAttrib(GL_ENABLE_BIT);
+	glDisable(GL_CULL_FACE);
+	glEnableClientState(GL_VERTEX_ARRAY);
+	glDisableClientState(GL_COLOR_ARRAY);
+	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+	glDisable(GL_LIGHTING);
+	glDisable(GL_COLOR_MATERIAL);
+	glEnable(GL_BLEND);
+	glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
+}
+
+void GPU_end_draw_pbvh_BB(void)
+{
+	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+	glPopAttrib();
+}




More information about the Bf-blender-cvs mailing list