diff options
author | Antony Riakiotakis <kalast@gmail.com> | 2014-05-01 00:42:58 +0400 |
---|---|---|
committer | Antony Riakiotakis <kalast@gmail.com> | 2014-05-01 00:43:19 +0400 |
commit | d2a326076342845fc5e0bcfc4ea10b09ce86242e (patch) | |
tree | 70aee396d03fe39c8fc60fc79cdf5246981d5ade | |
parent | d50f8832e39f79a9a2477ddb2e26dd2c801dbc8f (diff) |
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.
-rw-r--r-- | source/blender/blenkernel/intern/pbvh.c | 20 | ||||
-rw-r--r-- | source/blender/gpu/GPU_buffers.h | 4 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_buffers.c | 62 |
3 files changed, 86 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c index 5327f4dc3be..09bf1654e13 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 7ca1c878448..6c7945d69a2 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 df6aa4d868d..9bf63d2fe29 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(); +} |