[Bf-blender-cvs] [85fa1403f46] blender2.8: OpenGL: Convert drawobject.c (cont)

Clément Foucault noreply at git.blender.org
Thu Mar 9 22:28:27 CET 2017


Commit: 85fa1403f4668d0001f8b722e5f3dde61dfca73c
Author: Clément Foucault
Date:   Thu Mar 9 22:10:18 2017 +0100
Branches: blender2.8
https://developer.blender.org/rB85fa1403f4668d0001f8b722e5f3dde61dfca73c

OpenGL: Convert drawobject.c (cont)

-Softbody matrix
-EditCurve/NURBS

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

M	source/blender/editors/space_view3d/drawobject.c

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

diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index 973055a7d97..1ca11cbb9a8 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -6689,130 +6689,137 @@ static void ob_draw_RE_motion(float com[3], float rotscale[3][3], float itw, flo
 	float tw = itw * drw_size;
 	float th = ith * drw_size;
 
-	glBegin(GL_LINES);
+	VertexFormat *format = immVertexFormat();
+	unsigned int pos = add_attrib(format, "pos", GL_FLOAT, 3, KEEP_FLOAT);
+	unsigned int col = add_attrib(format, "color", GL_UNSIGNED_BYTE, 4, NORMALIZE_INT_TO_FLOAT);
+	immBindBuiltinProgram(GPU_SHADER_3D_FLAT_COLOR);
 
-	glColor4ub(0x7F, 0x00, 0x00, 155);
+	immBegin(GL_LINES, 30);
+
+	immAttrib4ub(col, 0x7F, 0x00, 0x00, 155);
 	root[1] = root[2] = 0.0f;
 	root[0] = -drw_size;
 	mul_m3_v3(tr, root);
 	add_v3_v3(root, com);
-	glVertex3fv(root);
+	immVertex3fv(pos, root);
 	tip[1] = tip[2] = 0.0f;
 	tip[0] = drw_size;
 	mul_m3_v3(tr, tip);
 	add_v3_v3(tip, com);
-	glVertex3fv(tip);
+	immVertex3fv(pos, tip);
 
 	root[1] = 0.0f; root[2] = tw;
 	root[0] = th;
 	mul_m3_v3(tr, root);
 	add_v3_v3(root, com);
-	glVertex3fv(root);
-	glVertex3fv(tip);
+	immVertex3fv(pos, root);
+	immVertex3fv(pos, tip);
 
 	root[1] = 0.0f; root[2] = -tw;
 	root[0] = th;
 	mul_m3_v3(tr, root);
 	add_v3_v3(root, com);
-	glVertex3fv(root);
-	glVertex3fv(tip);
+	immVertex3fv(pos, root);
+	immVertex3fv(pos, tip);
 
 	root[1] = tw; root[2] = 0.0f;
 	root[0] = th;
 	mul_m3_v3(tr, root);
 	add_v3_v3(root, com);
-	glVertex3fv(root);
-	glVertex3fv(tip);
+	immVertex3fv(pos, root);
+	immVertex3fv(pos, tip);
 
 	root[1] = -tw; root[2] = 0.0f;
 	root[0] = th;
 	mul_m3_v3(tr, root);
 	add_v3_v3(root, com);
-	glVertex3fv(root);
-	glVertex3fv(tip);
+	immVertex3fv(pos, root);
+	immVertex3fv(pos, tip);
 
-	glColor4ub(0x00, 0x7F, 0x00, 155);
+	immAttrib4ub(col, 0x00, 0x7F, 0x00, 155);
 
 	root[0] = root[2] = 0.0f;
 	root[1] = -drw_size;
 	mul_m3_v3(tr, root);
 	add_v3_v3(root, com);
-	glVertex3fv(root);
+	immVertex3fv(pos, root);
 	tip[0] = tip[2] = 0.0f;
 	tip[1] = drw_size;
 	mul_m3_v3(tr, tip);
 	add_v3_v3(tip, com);
-	glVertex3fv(tip);
+	immVertex3fv(pos, tip);
 
 	root[0] = 0.0f; root[2] = tw;
 	root[1] = th;
 	mul_m3_v3(tr, root);
 	add_v3_v3(root, com);
-	glVertex3fv(root);
-	glVertex3fv(tip);
+	immVertex3fv(pos, root);
+	immVertex3fv(pos, tip);
 
 	root[0] = 0.0f; root[2] = -tw;
 	root[1] = th;
 	mul_m3_v3(tr, root);
 	add_v3_v3(root, com);
-	glVertex3fv(root);
-	glVertex3fv(tip);
+	immVertex3fv(pos, root);
+	immVertex3fv(pos, tip);
 
 	root[0] = tw; root[2] = 0.0f;
 	root[1] = th;
 	mul_m3_v3(tr, root);
 	add_v3_v3(root, com);
-	glVertex3fv(root);
-	glVertex3fv(tip);
+	immVertex3fv(pos, root);
+	immVertex3fv(pos, tip);
 
 	root[0] = -tw; root[2] = 0.0f;
 	root[1] = th;
 	mul_m3_v3(tr, root);
 	add_v3_v3(root, com);
-	glVertex3fv(root);
-	glVertex3fv(tip);
+	immVertex3fv(pos, root);
+	immVertex3fv(pos, tip);
 
-	glColor4ub(0x00, 0x00, 0x7F, 155);
+	immAttrib4ub(col, 0x00, 0x00, 0x7F, 155);
 	root[0] = root[1] = 0.0f;
 	root[2] = -drw_size;
 	mul_m3_v3(tr, root);
 	add_v3_v3(root, com);
-	glVertex3fv(root);
+	immVertex3fv(pos, root);
 	tip[0] = tip[1] = 0.0f;
 	tip[2] = drw_size;
 	mul_m3_v3(tr, tip);
 	add_v3_v3(tip, com);
-	glVertex3fv(tip);
+	immVertex3fv(pos, tip);
 
 	root[0] = 0.0f; root[1] = tw;
 	root[2] = th;
 	mul_m3_v3(tr, root);
 	add_v3_v3(root, com);
-	glVertex3fv(root);
-	glVertex3fv(tip);
+	immVertex3fv(pos, root);
+	immVertex3fv(pos, tip);
 
 	root[0] = 0.0f; root[1] = -tw;
 	root[2] = th;
 	mul_m3_v3(tr, root);
 	add_v3_v3(root, com);
-	glVertex3fv(root);
-	glVertex3fv(tip);
+	immVertex3fv(pos, root);
+	immVertex3fv(pos, tip);
 
 	root[0] = tw; root[1] = 0.0f;
 	root[2] = th;
 	mul_m3_v3(tr, root);
 	add_v3_v3(root, com);
-	glVertex3fv(root);
-	glVertex3fv(tip);
+	immVertex3fv(pos, root);
+	immVertex3fv(pos, tip);
 
 	root[0] = -tw; root[1] = 0.0f;
 	root[2] = th;
 	mul_m3_v3(tr, root);
 	add_v3_v3(root, com);
-	glVertex3fv(root);
-	glVertex3fv(tip);
+	immVertex3fv(pos, root);
+	immVertex3fv(pos, tip);
+
+	immEnd();
 
-	glEnd();
+	immUnbindProgram();
 }
 
 /* place to add drawers */
@@ -6821,7 +6828,7 @@ static void drawhandlesN(Nurb *nu, const char sel, const bool hide_handles)
 {
 	if (nu->hide || hide_handles) return;
 
-	if (nu->type == CU_BEZIER) {
+	if (nu->type == CU_BEZIER && nu->pntsu > 0) {
 
 		const float *fp;
 
@@ -6834,9 +6841,14 @@ static void drawhandlesN(Nurb *nu, const char sel, const bool hide_handles)
 			UI_GetThemeColor3ubv(basecol + a, handle_cols[a]);
 		}
 
+		VertexFormat *format = immVertexFormat();
+		unsigned int pos = add_attrib(format, "pos", GL_FLOAT, 3, KEEP_FLOAT);
+		unsigned int col = add_attrib(format, "color", GL_UNSIGNED_BYTE, 3, NORMALIZE_INT_TO_FLOAT);
+		immBindBuiltinProgram(GPU_SHADER_3D_FLAT_COLOR);
+
 		glLineWidth(1.0f);
 
-		glBegin(GL_LINES);
+		immBeginAtMost(GL_LINES, nu->pntsu * 4);
 
 		BezTriple *bezt = nu->bezt;
 		int a = nu->pntsu;
@@ -6845,33 +6857,35 @@ static void drawhandlesN(Nurb *nu, const char sel, const bool hide_handles)
 				if ((bezt->f2 & SELECT) == sel) {
 					fp = bezt->vec[0];
 
-					glColor3ubv(handle_cols[MIN2(bezt->h1, TH_HANDLE_COL_TOT - 1)]);
-					glVertex3fv(fp);
-					glVertex3fv(fp + 3);
+					immAttrib3ubv(col, handle_cols[MIN2(bezt->h1, TH_HANDLE_COL_TOT - 1)]);
+					immVertex3fv(pos, fp);
+					immVertex3fv(pos, fp + 3);
 
-					glColor3ubv(handle_cols[MIN2(bezt->h2, TH_HANDLE_COL_TOT - 1)]);
-					glVertex3fv(fp + 3);
-					glVertex3fv(fp + 6);
+					immAttrib3ubv(col, handle_cols[MIN2(bezt->h2, TH_HANDLE_COL_TOT - 1)]);
+					immVertex3fv(pos, fp + 3);
+					immVertex3fv(pos, fp + 6);
 				}
 				else if ((bezt->f1 & SELECT) == sel) {
 					fp = bezt->vec[0];
 
-					glColor3ubv(handle_cols[MIN2(bezt->h1, TH_HANDLE_COL_TOT - 1)]);
-					glVertex3fv(fp);
-					glVertex3fv(fp + 3);
+					immAttrib3ubv(col, handle_cols[MIN2(bezt->h1, TH_HANDLE_COL_TOT - 1)]);
+					immVertex3fv(pos, fp);
+					immVertex3fv(pos, fp + 3);
 				}
 				else if ((bezt->f3 & SELECT) == sel) {
 					fp = bezt->vec[1];
 
-					glColor3ubv(handle_cols[MIN2(bezt->h2, TH_HANDLE_COL_TOT - 1)]);
-					glVertex3fv(fp);
-					glVertex3fv(fp + 3);
+					immAttrib3ubv(col, handle_cols[MIN2(bezt->h2, TH_HANDLE_COL_TOT - 1)]);
+					immVertex3fv(pos, fp);
+					immVertex3fv(pos, fp + 3);
 				}
 			}
 			bezt++;
 		}
 
-		glEnd();
+		immEnd();
+
+		immUnbindProgram();
 
 #undef TH_HANDLE_COL_TOT
 
@@ -6882,30 +6896,30 @@ static void drawhandlesN_active(Nurb *nu)
 {
 	if (nu->hide) return;
 
-	UI_ThemeColor(TH_ACTIVE_SPLINE);
-	glLineWidth(2.0f);
-
-	glBegin(GL_LINES);
+	if (nu->type == CU_BEZIER && nu->pntsu > 0) {
+		unsigned int pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 3, KEEP_FLOAT);
+		immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+		immUniformThemeColor(TH_ACTIVE_SPLINE);
+		glLineWidth(2.0f);
 
-	if (nu->type == CU_BEZIER) {
+		immBeginAtMost(GL_LINES, nu->pntsu * 4);
 		BezTriple *bezt = nu->bezt;
 		int a = nu->pntsu;
 		while (a--) {
 			if (bezt->hide == 0) {
 				const float *fp = bezt->vec[0];
 
-				glVertex3fv(fp);
-				glVertex3fv(fp + 3);
+				immVertex3fv(pos, fp);
+				immVertex3fv(pos, fp + 3);
 
-				glVertex3fv(fp + 3);
-				glVertex3fv(fp + 6);
+				immVertex3fv(pos, fp + 3);
+				immVertex3fv(pos, fp + 6);
 			}
 			bezt++;
 		}
+		immEnd();
+		immUnbindProgram();
 	}
-	glEnd();
-
-	glColor3ub(0, 0, 0);
 }
 
 static void drawvertsN(const Nurb *nurb, const bool hide_handles, const void *vert)
@@ -7000,63 +7014,78 @@ static void drawvertsN(const Nurb *nurb, const bool hide_handles, const void *ve
 
 static void editnurb_draw_active_poly(Nurb *nu)
 {
-	UI_ThemeColor(TH_ACTIVE_SPLINE);
+	VertexFormat *format = immVertexFormat();
+	unsigned pos = add_attrib(format, "pos", GL_FLOAT, 3, KEEP_FLOAT);
+	immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+	immUniformThemeColor(TH_ACTIVE_SPLINE);
+
 	glLineWidth(2.0f);
 
 	BPoint *bp = nu->bp;
 	for (int b = 0; b < nu->pntsv; b++) {
-		if (nu->flagu & 1) glBegin(GL_LINE_LOOP);
-		else glBegin(GL_LINE_STRIP);
+		if (nu->pntsu >= 2) {
+			if (nu->flagu & 1) immBegin(GL_LINE_LOOP, nu->pntsu);
+			else immBegin(GL_LINE_STRIP, nu->pntsu);
 
-		for (int a = 0; a < nu->pntsu; a++, bp++) {
-			glVertex3fv(bp->vec);
-		}
+			for (int a = 0; a < nu->pntsu; a++, bp++) {
+				immVertex3fv(pos, bp->vec);
+			}
 
-		glEnd();
+			immEnd();
+		}
 	}
 
-	glColor3ub(0, 0, 0);
+	immUnbindProgram();
 }
 
 static void editnurb_draw_active_nurbs(Nurb *nu)
 {
-	UI_ThemeColor(TH_ACTIVE_SPLINE);
-	glLineWidth(2.0f);
-
-	glBegin(GL_LINES);
-	BPoint *bp = nu->bp;
-	for (int b = 0; b < nu->pntsv; b++) {
-		BPoint *bp1 = bp;
-		bp++;
+	if (nu->pntsv > 0) {
+		VertexFormat *format = immVertexFormat();
+		unsigned pos = add_attrib(format, "pos", GL_FLOAT, 3, KEEP_FLOAT);
+		immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+		immUniformThemeColor(TH_ACTIVE_SPLINE);
 
-		for (int a = nu->pntsu - 1; a > 0; a--, bp++) {
-			if (bp->hide == 0 && bp1->hide == 0) {
-				glVertex3fv(bp->vec);
-				glVertex3fv(bp1->vec);
+		glLineWidth(2.0f);
+		// just quick guesstimate of how many verts to draw
+		int count = (nu->pntsu - 1) * nu->pntsv * 2;
+		if (nu->pntsv > 1) count += (nu->pntsv - 1) * nu->pntsu * 2;
+		if (count < 2) return;
+
+		immBeginAtMost(GL_LINES, count);
+		BPoint *bp = nu->bp;
+		for (int b = 0; b < nu->pntsv; b++) {
+			BPoint *bp1 = bp;
+			bp++;
+
+			for (int a = nu->pntsu - 1; a > 0; a--, bp++) {
+				if (bp->hide == 0 && bp1->hide == 0) {
+					immVertex3fv(pos, bp->vec);
+					immVertex3fv(pos, bp1->vec);
+				}
+				bp1 = bp;
 			}
-			bp1 = bp;
 		}
-	}
-
-	if (nu->pntsv > 1) {    /* surface */
 
-		int ofs = nu->pntsu;
-		for (int b = 0; b < nu->pntsu; b++) {
-			BPoint *bp1 = nu->bp + b;
-			bp = bp1 + ofs;
-			for (int a = nu->pntsv - 1; a > 0; a--, bp += ofs) {
-				if (bp->hide == 0 && bp1->hide == 0) {
-					glVertex3fv(bp->vec);
-					glVertex3fv(bp1->vec);
+		if (nu->pntsv > 1) {    /* surface */
+			int ofs = nu->pntsu;
+			for (int b = 0; b < nu->pntsu; b++) {
+				BPoint *bp1 = nu->bp + b;
+				bp = bp1 + ofs;
+				for (int a = nu->pntsv - 1; a > 0; a--,

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list