[Bf-blender-cvs] [c8b7e7973a] blender2.8: OpenGL immediate mode: transform_manipulator.c

Clément Foucault noreply at git.blender.org
Sun Feb 19 13:55:05 CET 2017


Commit: c8b7e7973af3d4675b0076103a727961e8c83ccc
Author: Clément Foucault
Date:   Sun Feb 19 13:59:47 2017 +0100
Branches: blender2.8
https://developer.blender.org/rBc8b7e7973af3d4675b0076103a727961e8c83ccc

OpenGL immediate mode: transform_manipulator.c

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

M	source/blender/editors/transform/transform_manipulator.c

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

diff --git a/source/blender/editors/transform/transform_manipulator.c b/source/blender/editors/transform/transform_manipulator.c
index 33f065b436..9072f96346 100644
--- a/source/blender/editors/transform/transform_manipulator.c
+++ b/source/blender/editors/transform/transform_manipulator.c
@@ -77,6 +77,8 @@
 #include "transform.h"
 
 #include "GPU_select.h"
+#include "GPU_immediate.h"
+#include "GPU_matrix.h"
 
 /* return codes for select, and drawing flags */
 
@@ -706,10 +708,10 @@ static void test_manipulator_axis(const bContext *C)
 
 static float screen_aligned(RegionView3D *rv3d, float mat[4][4])
 {
-	glTranslate3fv(mat[3]);
+	gpuTranslate3fv(mat[3]);
 
 	/* sets view screen aligned */
-	glRotatef(-360.0f * saacos(rv3d->viewquat[0]) / (float)M_PI, rv3d->viewquat[1], rv3d->viewquat[2], rv3d->viewquat[3]);
+	gpuRotate3f(-360.0f * saacos(rv3d->viewquat[0]) / (float)M_PI, rv3d->viewquat[1], rv3d->viewquat[2], rv3d->viewquat[3]);
 
 	return len_v3(mat[0]); /* draw scale */
 }
@@ -722,7 +724,7 @@ static float screen_aligned(RegionView3D *rv3d, float mat[4][4])
  * nsides = amount of points in ring
  * nrigns = amount of rings
  */
-static void partial_doughnut(float radring, float radhole, int start, int end, int nsides, int nrings)
+static void partial_doughnut(unsigned int pos, float radring, float radhole, int start, int end, int nsides, int nrings)
 {
 	float theta, phi, theta1;
 	float cos_theta, sin_theta;
@@ -745,7 +747,7 @@ static void partial_doughnut(float radring, float radhole, int start, int end, i
 		sin_theta1 = sinf(theta1);
 
 		if (do_caps && i == start) {  // cap
-			glBegin(GL_POLYGON);
+			immBegin(GL_TRIANGLE_FAN, nsides+1);
 			phi = 0.0;
 			for (j = nsides; j >= 0; j--) {
 				float cos_phi, sin_phi, dist;
@@ -755,12 +757,12 @@ static void partial_doughnut(float radring, float radhole, int start, int end, i
 				sin_phi = sinf(phi);
 				dist = radhole + radring * cos_phi;
 
-				glVertex3f(cos_theta1 * dist, -sin_theta1 * dist,  radring * sin_phi);
+				immVertex3f(pos, cos_theta1 * dist, -sin_theta1 * dist,  radring * sin_phi);
 			}
-			glEnd();
+			immEnd();
 		}
 		if (i >= start && i <= end) {
-			glBegin(GL_QUAD_STRIP);
+			immBegin(GL_TRIANGLE_STRIP, (nsides+1) * 2);
 			phi = 0.0;
 			for (j = nsides; j >= 0; j--) {
 				float cos_phi, sin_phi, dist;
@@ -770,14 +772,14 @@ static void partial_doughnut(float radring, float radhole, int start, int end, i
 				sin_phi = sinf(phi);
 				dist = radhole + radring * cos_phi;
 
-				glVertex3f(cos_theta1 * dist, -sin_theta1 * dist, radring * sin_phi);
-				glVertex3f(cos_theta * dist, -sin_theta * dist,  radring * sin_phi);
+				immVertex3f(pos, cos_theta1 * dist, -sin_theta1 * dist, radring * sin_phi);
+				immVertex3f(pos, cos_theta * dist, -sin_theta * dist,  radring * sin_phi);
 			}
-			glEnd();
+			immEnd();
 		}
 
 		if (do_caps && i == end) {    // cap
-			glBegin(GL_POLYGON);
+			immBegin(GL_TRIANGLE_FAN, nsides+1);
 			phi = 0.0;
 			for (j = nsides; j >= 0; j--) {
 				float cos_phi, sin_phi, dist;
@@ -787,9 +789,9 @@ static void partial_doughnut(float radring, float radhole, int start, int end, i
 				sin_phi = sinf(phi);
 				dist = radhole + radring * cos_phi;
 
-				glVertex3f(cos_theta * dist, -sin_theta * dist,  radring * sin_phi);
+				immVertex3f(pos, cos_theta * dist, -sin_theta * dist,  radring * sin_phi);
 			}
-			glEnd();
+			immEnd();
 		}
 
 
@@ -858,7 +860,7 @@ static void manipulator_setcolor(View3D *v3d, char axis, int colcode, unsigned c
 		}
 	}
 
-	glColor4ubv(col);
+	immUniformColor4ubv(col);
 }
 
 static void manipulator_axis_order(RegionView3D *rv3d, int r_axis_order[3])
@@ -878,7 +880,7 @@ static void manipulator_axis_order(RegionView3D *rv3d, int r_axis_order[3])
 /* viewmatrix should have been set OK, also no shademode! */
 static void draw_manipulator_axes_single(View3D *v3d, RegionView3D *rv3d, int colcode,
                                          int flagx, int flagy, int flagz, int axis,
-                                         const bool is_picksel)
+                                         const bool is_picksel, unsigned int pos)
 {
 	switch (axis) {
 		case 0:
@@ -891,10 +893,10 @@ static void draw_manipulator_axes_single(View3D *v3d, RegionView3D *rv3d, int co
 				else {
 					manipulator_setcolor(v3d, 'X', colcode, axisBlendAngle(rv3d->tw_idot[0]));
 				}
-				glBegin(GL_LINES);
-				glVertex3f(0.2f, 0.0f, 0.0f);
-				glVertex3f(1.0f, 0.0f, 0.0f);
-				glEnd();
+				immBegin(GL_LINES, 2);
+				immVertex3f(pos, 0.2f, 0.0f, 0.0f);
+				immVertex3f(pos, 1.0f, 0.0f, 0.0f);
+				immEnd();
 			}
 			break;
 		case 1:
@@ -906,10 +908,10 @@ static void draw_manipulator_axes_single(View3D *v3d, RegionView3D *rv3d, int co
 				else {
 					manipulator_setcolor(v3d, 'Y', colcode, axisBlendAngle(rv3d->tw_idot[1]));
 				}
-				glBegin(GL_LINES);
-				glVertex3f(0.0f, 0.2f, 0.0f);
-				glVertex3f(0.0f, 1.0f, 0.0f);
-				glEnd();
+				immBegin(GL_LINES, 2);
+				immVertex3f(pos, 0.0f, 0.2f, 0.0f);
+				immVertex3f(pos, 0.0f, 1.0f, 0.0f);
+				immEnd();
 			}
 			break;
 		case 2:
@@ -921,21 +923,21 @@ static void draw_manipulator_axes_single(View3D *v3d, RegionView3D *rv3d, int co
 				else {
 					manipulator_setcolor(v3d, 'Z', colcode, axisBlendAngle(rv3d->tw_idot[2]));
 				}
-				glBegin(GL_LINES);
-				glVertex3f(0.0f, 0.0f, 0.2f);
-				glVertex3f(0.0f, 0.0f, 1.0f);
-				glEnd();
+				immBegin(GL_LINES, 2);
+				immVertex3f(pos, 0.0f, 0.0f, 0.2f);
+				immVertex3f(pos, 0.0f, 0.0f, 1.0f);
+				immEnd();
 			}
 			break;
 	}
 }
 static void draw_manipulator_axes(View3D *v3d, RegionView3D *rv3d, int colcode,
                                   int flagx, int flagy, int flagz,
-                                  const int axis_order[3], const bool is_picksel)
+                                  const int axis_order[3], const bool is_picksel, unsigned int pos)
 {
 	int i;
 	for (i = 0; i < 3; i++) {
-		draw_manipulator_axes_single(v3d, rv3d, colcode, flagx, flagy, flagz, axis_order[i], is_picksel);
+		draw_manipulator_axes_single(v3d, rv3d, colcode, flagx, flagy, flagz, axis_order[i], is_picksel, pos);
 	}
 }
 
@@ -945,8 +947,8 @@ static void preOrthoFront(const bool ortho, float twmat[4][4], int axis)
 		float omat[4][4];
 		copy_m4_m4(omat, twmat);
 		orthogonalize_m4(omat, axis);
-		glPushMatrix();
-		glMultMatrixf(omat);
+		gpuPushMatrix();
+		gpuMultMatrix3D(omat);
 		glFrontFace(is_negative_m4(omat) ? GL_CW : GL_CCW);
 	}
 }
@@ -954,7 +956,7 @@ static void preOrthoFront(const bool ortho, float twmat[4][4], int axis)
 static void postOrtho(const bool ortho)
 {
 	if (ortho == false) {
-		glPopMatrix();
+		gpuPopMatrix();
 	}
 }
 
@@ -983,10 +985,18 @@ static void draw_manipulator_rotate(
 	glDisable(GL_DEPTH_TEST);
 	unit_m4(unitmat);
 
+
 	/* prepare for screen aligned draw */
 	size = len_v3(rv3d->twmat[0]);
-	glPushMatrix();
-	glTranslate3fv(rv3d->twmat[3]);
+	gpuMatrixBegin3D_legacy();
+	gpuPushMatrix();
+	gpuTranslate3fv(rv3d->twmat[3]);
+
+
+	const unsigned pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 3, KEEP_FLOAT);
+
+	immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+
 
 	if (arcs) {
 		/* clipplane makes nice handles, calc here because of multmatrix but with translate! */
@@ -995,29 +1005,29 @@ static void draw_manipulator_rotate(
 		glClipPlane(GL_CLIP_PLANE0, plane);
 	}
 	/* sets view screen aligned */
-	glRotatef(-360.0f * saacos(rv3d->viewquat[0]) / (float)M_PI, rv3d->viewquat[1], rv3d->viewquat[2], rv3d->viewquat[3]);
+	gpuRotate3f(-360.0f * saacos(rv3d->viewquat[0]) / (float)M_PI, rv3d->viewquat[1], rv3d->viewquat[2], rv3d->viewquat[3]);
 
 	/* Screen aligned help circle */
 	if (arcs) {
 		if (is_picksel == false) {
-			UI_ThemeColorShade(TH_BACK, -30);
-			drawcircball(GL_LINE_LOOP, unitmat[3], size, unitmat);
+			immUniformThemeColorShade(TH_BACK, -30);
+			imm_drawcircball(unitmat[3], size, unitmat, pos);
 		}
 	}
 
 	/* Screen aligned trackball rot circle */
 	if (drawflags & MAN_ROT_T) {
 		if (is_picksel) GPU_select_load_id(MAN_ROT_T);
-		else UI_ThemeColor(TH_TRANSFORM);
+		else immUniformThemeColor(TH_TRANSFORM);
 
-		drawcircball(GL_LINE_LOOP, unitmat[3], 0.2f * size, unitmat);
+		imm_drawcircball(unitmat[3], 0.2f * size, unitmat, pos);
 	}
 
 	/* Screen aligned view rot circle */
 	if (drawflags & MAN_ROT_V) {
 		if (is_picksel) GPU_select_load_id(MAN_ROT_V);
-		else UI_ThemeColor(TH_TRANSFORM);
-		drawcircball(GL_LINE_LOOP, unitmat[3], 1.2f * size, unitmat);
+		else immUniformThemeColor(TH_TRANSFORM);
+		imm_drawcircball(unitmat[3], 1.2f * size, unitmat, pos);
 
 		if (is_moving) {
 			float vec[3];
@@ -1025,14 +1035,15 @@ static void draw_manipulator_rotate(
 			vec[1] = 0; // XXX (float)(t->mouse.imval[1] - t->center2d[1]);
 			vec[2] = 0.0f;
 			normalize_v3_length(vec, 1.2f * size);
-			glBegin(GL_LINES);
-			glVertex3f(0.0f, 0.0f, 0.0f);
-			glVertex3fv(vec);
-			glEnd();
+			immBegin(GL_LINES, 2);
+			immVertex3f(pos, 0.0f, 0.0f, 0.0f);
+			immVertex3fv(pos,vec);
+			immEnd();
 		}
 	}
-	glPopMatrix();
+	gpuPopMatrix();
 
+	gpuPushMatrix();
 
 	ortho = is_orthogonal_m4(rv3d->twmat);
 	
@@ -1041,14 +1052,14 @@ static void draw_manipulator_rotate(
 		copy_m4_m4(matt, rv3d->twmat); // to copy the parts outside of [3][3]
 		// XXX mul_m4_m3m4(matt, t->mat, rv3d->twmat);
 		if (ortho) {
-			glMultMatrixf(matt);
+			gpuMultMatrix3D(matt);
 			glFrontFace(is_negative_m4(matt) ? GL_CW : GL_CCW);
 		}
 	}
 	else {
 		if (ortho) {
 			glFrontFace(is_negative_m4(rv3d->twmat) ? GL_CW : GL_CCW);
-			glMultMatrixf(rv3d->twmat);
+			gpuMultMatrix3D(rv3d->twmat);
 		}
 	}
 
@@ -1060,28 +1071,28 @@ static void draw_manipulator_rotate(
 				if ((drawflags & MAN_ROT_X) || (is_moving && (drawflags & MAN_ROT_Z))) {
 					preOrthoFront(ortho, rv3d->twmat, 2);
 					manipulator_setcolor(v3d, 'X', colcode, 255);
-					glBegin(GL_LINES);
-					glVertex3f(0.2f, 0.0f, 0.0f);
-					glVertex3f(1.0f, 0.0f, 0.0f);
-					glEnd();
+					immBegin(GL_LINES, 2);
+					immVertex3f(pos, 0.2f, 0.0f, 0.0f);
+					immVertex3f(pos, 1.0f, 0.0f, 0.0f);
+					immEnd();
 					postOrtho(ortho);
 				}
 				if ((drawflags & MAN_ROT_Y) || (is_moving && (drawflags & MAN_ROT_X))) {
 					preOrthoFront(ortho, rv3d->twmat, 0);
 					manipu

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list