[Bf-blender-cvs] [0fc4cf7637] blender2.8: OpenGL: draw navmesh with new imm mode

Mike Erwin noreply at git.blender.org
Thu Mar 16 05:06:13 CET 2017


Commit: 0fc4cf7637e8663aab695b2c33a6695f0604334f
Author: Mike Erwin
Date:   Thu Mar 16 00:05:05 2017 -0400
Branches: blender2.8
https://developer.blender.org/rB0fc4cf7637e8663aab695b2c33a6695f0604334f

OpenGL: draw navmesh with new imm mode

This is an old stash. Part of DerivedMesh so the whole thing might be removed soon.

part of T49043

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

M	source/blender/blenkernel/intern/DerivedMesh.c

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

diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 39f1db0b88..9022faba18 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -76,8 +76,8 @@ static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm);
 #include "BLI_sys_types.h" /* for intptr_t support */
 
 #include "GPU_buffers.h"
-#include "GPU_glew.h"
 #include "GPU_shader.h"
+#include "GPU_immediate.h"
 
 #ifdef WITH_OPENSUBDIV
 #  include "BKE_depsgraph.h"
@@ -3937,7 +3937,6 @@ BLI_INLINE void navmesh_intToCol(int i, float col[3])
 
 static void navmesh_drawColored(DerivedMesh *dm)
 {
-	int a, glmode;
 	MVert *mvert = (MVert *)CustomData_get_layer(&dm->vertData, CD_MVERT);
 	MFace *mface = (MFace *)CustomData_get_layer(&dm->faceData, CD_MFACE);
 	int *polygonIdx = (int *)CustomData_get_layer(&dm->polyData, CD_RECAST);
@@ -3952,34 +3951,42 @@ static void navmesh_drawColored(DerivedMesh *dm)
 	dm->drawEdges(dm, 0, 1);
 #endif
 
-	/* if (GPU_buffer_legacy(dm) ) */ /* TODO - VBO draw code, not high priority - campbell */
-	{
-		DEBUG_VBO("Using legacy code. drawNavMeshColored\n");
-		glBegin(glmode = GL_QUADS);
-		for (a = 0; a < dm->numTessFaceData; a++, mface++) {
-			int new_glmode = mface->v4 ? GL_QUADS : GL_TRIANGLES;
-			int pi = polygonIdx[a];
-			if (pi <= 0) {
-				zero_v3(col);
-			}
-			else {
-				navmesh_intToCol(pi, col);
-			}
+	VertexFormat *format = immVertexFormat();
+	unsigned pos = add_attrib(format, "pos", COMP_F32, 3, KEEP_FLOAT);
+	unsigned color = add_attrib(format, "color", COMP_F32, 3, KEEP_FLOAT);
 
-			if (new_glmode != glmode) {
-				glEnd();
-				glBegin(glmode = new_glmode);
-			}
-			glColor3fv(col);
-			glVertex3fv(mvert[mface->v1].co);
-			glVertex3fv(mvert[mface->v2].co);
-			glVertex3fv(mvert[mface->v3].co);
-			if (mface->v4) {
-				glVertex3fv(mvert[mface->v4].co);
-			}
+	immBindBuiltinProgram(GPU_SHADER_3D_FLAT_COLOR);
+
+	/* Note: batch drawing API would let us share vertices */
+	immBeginAtMost(PRIM_TRIANGLES, dm->numTessFaceData * 6);
+	for (int a = 0; a < dm->numTessFaceData; a++, mface++) {
+		int pi = polygonIdx[a];
+		if (pi <= 0) {
+			zero_v3(col);
+		}
+		else {
+			navmesh_intToCol(pi, col);
+		}
+
+		immSkipAttrib(color);
+		immVertex3fv(pos, mvert[mface->v1].co);
+		immSkipAttrib(color);
+		immVertex3fv(pos, mvert[mface->v2].co);
+		immAttrib3fv(color, col);
+		immVertex3fv(pos, mvert[mface->v3].co);
+
+		if (mface->v4) {
+			/* this tess face is a quad, so draw the other triangle */
+			immSkipAttrib(color);
+			immVertex3fv(pos, mvert[mface->v1].co);
+			immSkipAttrib(color);
+			immVertex3fv(pos, mvert[mface->v3].co);
+			immAttrib3fv(color, col);
+			immVertex3fv(pos, mvert[mface->v4].co);
 		}
-		glEnd();
 	}
+	immEnd();
+	immUnbindProgram();
 }
 
 static void navmesh_DM_drawFacesTex(




More information about the Bf-blender-cvs mailing list