[Bf-blender-cvs] [c2baf3e486] blender2.8: OpenGL: draw PBVH bounding box with new imm mode

Mike Erwin noreply at git.blender.org
Fri Mar 3 03:51:00 CET 2017


Commit: c2baf3e486021c048c87eea66e3183966ff86d2f
Author: Mike Erwin
Date:   Thu Mar 2 21:40:13 2017 -0500
Branches: blender2.8
https://developer.blender.org/rBc2baf3e486021c048c87eea66e3183966ff86d2f

OpenGL: draw PBVH bounding box with new imm mode

It wasn't using old immediate mode, but was using
- client vertex arrays (obsolete)
- quads (obsolete)
- state attrib stack (obsolete)
- polygon mode (still allowed, but gross)

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

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 4fe4d6e75a..549d8798cd 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -40,6 +40,7 @@
 #include "BKE_paint.h"
 
 #include "GPU_buffers.h"
+#include "GPU_immediate.h"
 
 #include "bmesh.h"
 
@@ -1156,15 +1157,16 @@ static void pbvh_update_draw_buffers(PBVH *bvh, PBVHNode **nodes, int totnode)
 
 static void pbvh_draw_BB(PBVH *bvh)
 {
-	GPU_init_draw_pbvh_BB();
+	unsigned int pos = add_attrib(immVertexFormat(), "pos", COMP_F32, 3, KEEP_FLOAT);
+	immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
 
 	for (int a = 0; a < bvh->totnode; a++) {
 		PBVHNode *node = &bvh->nodes[a];
 
-		GPU_draw_pbvh_BB(node->vb.bmin, node->vb.bmax, ((node->flag & PBVH_Leaf) != 0));
+		GPU_draw_pbvh_BB(node->vb.bmin, node->vb.bmax, ((node->flag & PBVH_Leaf) != 0), pos);
 	}
 
-	GPU_end_draw_pbvh_BB();
+	immUnbindProgram();
 }
 
 static int pbvh_flush_bb(PBVH *bvh, PBVHNode *node, int flag)
diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h
index b693d473bd..958d5aed4a 100644
--- a/source/blender/gpu/GPU_buffers.h
+++ b/source/blender/gpu/GPU_buffers.h
@@ -258,10 +258,8 @@ 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, bool fast);
 
-/* debug PBVH draw*/
-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);
+/* debug PBVH draw */
+void GPU_draw_pbvh_BB(float min[3], float max[3], bool leaf, unsigned int pos);
 
 bool GPU_pbvh_buffers_diffuse_changed(GPU_PBVH_Buffers *buffers, struct GSet *bm_faces, bool show_diffuse_color);
 
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index 370841327a..6492cf9092 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -56,6 +56,7 @@
 #include "GPU_buffers.h"
 #include "GPU_draw.h"
 #include "GPU_basic_shader.h"
+#include "GPU_immediate.h"
 
 #include "bmesh.h"
 
@@ -2033,59 +2034,57 @@ void GPU_free_pbvh_buffer_multires(GridCommonGPUBuffer **grid_common_gpu_buffer)
 }
 
 /* debug function, draws the pbvh BB */
-void GPU_draw_pbvh_BB(float min[3], float max[3], bool leaf)
+void GPU_draw_pbvh_BB(float min[3], float max[3], bool leaf, unsigned int pos)
 {
-	const 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);
+		immUniformColor4f(0.0, 1.0, 0.0, 0.5);
 	else
-		glColor4f(1.0, 0.0, 0.0, 0.5);
+		immUniformColor4f(1.0, 0.0, 0.0, 0.5);
 
-	glVertexPointer(3, GL_FLOAT, 0, &quads[0][0][0]);
-	glDrawArrays(GL_QUADS, 0, 16);
-}
+	/* TODO(merwin): revisit this after we have mutable VertexBuffers
+	 * could keep a static batch & index buffer, change the VBO contents per draw
+	 */
 
-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);
-	glEnable(GL_BLEND);
-}
+	immBegin(PRIM_LINES, 24);
 
-void GPU_end_draw_pbvh_BB(void)
-{
-	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-	glPopAttrib();
+	/* top */
+	immVertex3f(pos, min[0], min[1], max[2]);
+	immVertex3f(pos, min[0], max[1], max[2]);
+
+	immVertex3f(pos, min[0], max[1], max[2]);
+	immVertex3f(pos, max[0], max[1], max[2]);
+
+	immVertex3f(pos, max[0], max[1], max[2]);
+	immVertex3f(pos, max[0], min[1], max[2]);
+
+	immVertex3f(pos, max[0], min[1], max[2]);
+	immVertex3f(pos, min[0], min[1], max[2]);
+
+	/* bottom */
+	immVertex3f(pos, min[0], min[1], min[2]);
+	immVertex3f(pos, min[0], max[1], min[2]);
+
+	immVertex3f(pos, min[0], max[1], min[2]);
+	immVertex3f(pos, max[0], max[1], min[2]);
+
+	immVertex3f(pos, max[0], max[1], min[2]);
+	immVertex3f(pos, max[0], min[1], min[2]);
+
+	immVertex3f(pos, max[0], min[1], min[2]);
+	immVertex3f(pos, min[0], min[1], min[2]);
+
+	/* sides */
+	immVertex3f(pos, min[0], min[1], min[2]);
+	immVertex3f(pos, min[0], min[1], max[2]);
+
+	immVertex3f(pos, min[0], max[1], min[2]);
+	immVertex3f(pos, min[0], max[1], max[2]);
+
+	immVertex3f(pos, max[0], max[1], min[2]);
+	immVertex3f(pos, max[0], max[1], max[2]);
+
+	immVertex3f(pos, max[0], min[1], min[2]);
+	immVertex3f(pos, max[0], min[1], max[2]);
+
+	immEnd();
 }




More information about the Bf-blender-cvs mailing list