[Bf-blender-cvs] [8042d05c5bb] custom-manipulators: Work in progress move from GLU to IMM

Campbell Barton noreply at git.blender.org
Mon Apr 3 14:54:25 CEST 2017


Commit: 8042d05c5bb6654847a5e43693b20b6ff98eb6d6
Author: Campbell Barton
Date:   Mon Apr 3 22:53:27 2017 +1000
Branches: custom-manipulators
https://developer.blender.org/rB8042d05c5bb6654847a5e43693b20b6ff98eb6d6

Work in progress move from GLU to IMM

Drawing rotation widgets now uses IMM, but not arrows
See USE_IMM define.

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

M	source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c
M	source/blender/windowmanager/manipulators/intern/manipulator_library/dial_manipulator.c

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

diff --git a/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c b/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c
index 34fc5772816..f20c3cc2317 100644
--- a/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c
+++ b/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c
@@ -36,9 +36,6 @@
 
 #include "BIF_gl.h"
 
-// IMM-FIXME
-#include <GL/glu.h>
-
 #include "BKE_context.h"
 
 #include "BLI_math.h"
@@ -50,6 +47,7 @@
 #include "ED_screen.h"
 
 #include "GPU_select.h"
+#include "GPU_matrix.h"
 
 #include "MEM_guardedalloc.h"
 
@@ -64,6 +62,11 @@
 #include "manipulator_geometry.h"
 #include "manipulator_library_intern.h"
 
+// #define USE_IMM
+
+#ifndef USE_IMM
+#  include <GL/glu.h>
+#endif
 
 /* to use custom arrows exported to geom_arrow_manipulator.c */
 //#define MANIPULATOR_USE_CUSTOM_ARROWS
@@ -104,8 +107,14 @@ static void manipulator_arrow_get_final_pos(wmManipulator *manipulator, float r_
 	add_v3_v3(r_pos, arrow->manipulator.origin);
 }
 
-static void arrow_draw_geom(const ArrowManipulator *arrow, const bool select)
+static void arrow_draw_geom(const ArrowManipulator *arrow, const bool select, const float color[4])
 {
+
+#ifdef USE_IMM
+#else
+	glColor4fv(color);
+#endif
+
 	if (arrow->style & MANIPULATOR_ARROW_STYLE_CROSS) {
 		glPushAttrib(GL_ENABLE_BIT);
 		glDisable(GL_LIGHTING);
@@ -154,16 +163,26 @@ static void arrow_draw_geom(const ArrowManipulator *arrow, const bool select)
 
 		/* *** draw arrow head *** */
 
+#ifdef USE_IMM
+		gpuPushMatrix();
+#else
 		glPushMatrix();
+#endif
 
 		if (arrow->style & MANIPULATOR_ARROW_STYLE_BOX) {
 			const float size = 0.05f;
 
+#ifdef USE_IMM
+			/* translate to line end with some extra offset so box starts exactly where line ends */
+			gpuTranslate3f(0.0f, 0.0f, arrow->len + size);
+			/* scale down to box size */
+			gpuScale3f(size, size, size);
+#else
 			/* translate to line end with some extra offset so box starts exactly where line ends */
 			glTranslatef(0.0f, 0.0f, arrow->len + size);
 			/* scale down to box size */
 			glScalef(size, size, size);
-
+#endif
 			/* draw cube */
 			wm_manipulator_geometryinfo_draw(&cube_draw_info, select);
 		}
@@ -173,12 +192,18 @@ static void arrow_draw_geom(const ArrowManipulator *arrow, const bool select)
 			const bool use_lighting = select == false && ((U.manipulator_flag & V3D_SHADED_MANIPULATORS) != 0);
 
 			/* translate to line end */
+#ifdef USE_IMM
+			gpuTranslate3f(0.0f, 0.0f, arrow->len);
+#else
 			glTranslatef(0.0f, 0.0f, arrow->len);
-
+#endif
 			if (use_lighting) {
 				glShadeModel(GL_SMOOTH);
 			}
 
+#ifdef USE_IMM
+			// IMM-FIXME
+#else
 			GLUquadricObj *qobj = gluNewQuadric();
 			gluQuadricDrawStyle(qobj, GLU_FILL);
 			gluQuadricOrientation(qobj, GLU_INSIDE);
@@ -186,14 +211,20 @@ static void arrow_draw_geom(const ArrowManipulator *arrow, const bool select)
 			gluQuadricOrientation(qobj, GLU_OUTSIDE);
 			gluCylinder(qobj, width, 0.0, len, 8, 1);
 			gluDeleteQuadric(qobj);
+#endif
 
 			if (use_lighting) {
 				glShadeModel(GL_FLAT);
 			}
 		}
 
+#ifdef USE_IMM
+		gpuPopMatrix();
+#else
 		glPopMatrix();
 #endif
+
+#endif  /* MANIPULATOR_USE_CUSTOM_ARROWS */
 	}
 }
 
@@ -220,16 +251,29 @@ static void arrow_draw_intern(ArrowManipulator *arrow, const bool select, const
 	copy_v3_v3(mat[3], final_pos);
 	mul_mat3_m4_fl(mat, arrow->manipulator.scale);
 
+#ifdef USE_IMM
+	gpuPushMatrix();
+	gpuMultMatrix3D(mat);
+#else
 	glPushMatrix();
 	glMultMatrixf(mat);
+#endif
 
-	glColor4fv(col);
-	glEnable(GL_BLEND);
+#ifdef USE_IMM
+	gpuTranslate3fv(arrow->manipulator.offset);
+#else
 	glTranslatef(UNPACK3(arrow->manipulator.offset));
-	arrow_draw_geom(arrow, select);
+#endif
+
+	glEnable(GL_BLEND);
+	arrow_draw_geom(arrow, select, col);
 	glDisable(GL_BLEND);
 
+#ifdef USE_IMM
+	gpuPopMatrix();
+#else
 	glPopMatrix();
+#endif
 
 	if (arrow->manipulator.interaction_data) {
 		ManipulatorInteraction *inter = arrow->manipulator.interaction_data;
@@ -238,16 +282,25 @@ static void arrow_draw_intern(ArrowManipulator *arrow, const bool select, const
 		copy_v3_v3(mat[3], inter->init_origin);
 		mul_mat3_m4_fl(mat, inter->init_scale);
 
+#ifdef USE_IMM
+		gpuPushMatrix();
+		gpuMultMatrix3D(mat);
+		gpuTranslate3fv(arrow->manipulator.offset);
+#else
 		glPushMatrix();
 		glMultMatrixf(mat);
+		glTranslatef(UNPACK3(arrow->manipulator.offset));
+#endif
 
 		glEnable(GL_BLEND);
-		glColor4f(0.5f, 0.5f, 0.5f, 0.5f);
-		glTranslatef(UNPACK3(arrow->manipulator.offset));
-		arrow_draw_geom(arrow, select);
+		arrow_draw_geom(arrow, select, (const float [4]){0.5f, 0.5f, 0.5f, 0.5f});
 		glDisable(GL_BLEND);
 
+#ifdef USE_IMM
+		gpuPopMatrix();
+#else
 		glPopMatrix();
+#endif
 	}
 }
 
diff --git a/source/blender/windowmanager/manipulators/intern/manipulator_library/dial_manipulator.c b/source/blender/windowmanager/manipulators/intern/manipulator_library/dial_manipulator.c
index ada1d022910..2d26bda7a0a 100644
--- a/source/blender/windowmanager/manipulators/intern/manipulator_library/dial_manipulator.c
+++ b/source/blender/windowmanager/manipulators/intern/manipulator_library/dial_manipulator.c
@@ -35,9 +35,7 @@
  */
 
 #include "BIF_gl.h"
-
-// IMM-FIXME
-#include <GL/glu.h>
+#include "BIF_glutil.h"
 
 #include "BKE_context.h"
 
@@ -50,6 +48,10 @@
 
 #include "GPU_select.h"
 
+#include "GPU_matrix.h"
+
+#include "GPU_immediate.h"
+
 #include "MEM_guardedalloc.h"
 
 #include "WM_api.h"
@@ -63,6 +65,11 @@
 #include "manipulator_geometry.h"
 #include "manipulator_library_intern.h"
 
+#define USE_IMM
+
+#ifndef USE_IMM
+#include <GL/glu.h>
+#endif
 
 /* to use custom dials exported to geom_dial_manipulator.c */
 //#define MANIPULATOR_USE_CUSTOM_DIAS
@@ -100,13 +107,36 @@ static void dial_geom_draw(const DialManipulator *dial, const float col[4], cons
 	const bool filled = (dial->style == MANIPULATOR_DIAL_STYLE_RING_FILLED);
 
 	glLineWidth(dial->manipulator.line_width);
-	glColor4fv(col);
 
-	GLUquadricObj *qobj = gluNewQuadric();
-	gluQuadricDrawStyle(qobj, filled ? GLU_FILL : GLU_SILHOUETTE);
-	/* inner at 0.0 with silhouette drawing confuses OGL selection, so draw it at width */
-	gluDisk(qobj, filled ? 0.0 : DIAL_WIDTH, DIAL_WIDTH, DIAL_RESOLUTION, 1);
-	gluDeleteQuadric(qobj);
+#ifdef USE_IMM
+	{
+		VertexFormat *format = immVertexFormat();
+		unsigned int pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
+
+		immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+
+		immUniformColor4fv(col);
+
+		if (filled) {
+			imm_draw_filled_circle(pos, 0, 0, 1.0, DIAL_RESOLUTION);
+		}
+		else {
+			imm_draw_lined_circle(pos, 0, 0, 1.0, DIAL_RESOLUTION);
+		}
+
+		immUnbindProgram();
+	}
+#else
+	{
+		glColor4fv(col);
+
+		GLUquadricObj *qobj = gluNewQuadric();
+		gluQuadricDrawStyle(qobj, filled ? GLU_FILL : GLU_SILHOUETTE);
+		/* inner at 0.0 with silhouette drawing confuses OGL selection, so draw it at width */
+		gluDisk(qobj, filled ? 0.0 : DIAL_WIDTH, DIAL_WIDTH, DIAL_RESOLUTION, 1);
+		gluDeleteQuadric(qobj);
+	}
+#endif
 
 	UNUSED_VARS(select);
 #endif
@@ -115,10 +145,30 @@ static void dial_geom_draw(const DialManipulator *dial, const float col[4], cons
 /**
  * Draws a line from (0, 0, 0) to \a co_outer, at \a angle.
  */
-static void dial_ghostarc_draw_helpline(const float angle, const float co_outer[3])
+static void dial_ghostarc_draw_helpline(const float angle, const float co_outer[3], const float col[4])
 {
 	glLineWidth(1.0f);
 
+#ifdef USE_IMM
+	gpuPushMatrix();
+	gpuRotate3f(RAD2DEGF(angle), 0.0f, 0.0f, -1.0f);
+
+	unsigned int pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 3, KEEP_FLOAT);
+
+	immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+
+	immUniformColor4fv(col);
+
+	immBegin(PRIM_LINE_STRIP, 2);
+	immVertex3f(pos, 0.0f, 0.0f, 0.0f);
+	immVertex3fv(pos, co_outer);
+	immEnd();
+
+	immUnbindProgram();
+
+	gpuPopMatrix();
+#else
+	glColor4fv(col);
 	glPushMatrix();
 	glRotatef(RAD2DEGF(angle), 0.0f, 0.0f, -1.0f);
 //	glScalef(0.0f, DIAL_WIDTH - dial->manipulator.line_width * 0.5f / U.widget_scale, 0.0f);
@@ -127,16 +177,29 @@ static void dial_ghostarc_draw_helpline(const float angle, const float co_outer[
 	glVertex3fv(co_outer);
 	glEnd();
 	glPopMatrix();
+#endif
 }
 
-static void dial_ghostarc_draw(const DialManipulator *dial, const float angle_ofs, const float angle_delta)
+static void dial_ghostarc_draw(
+        const DialManipulator *dial, const float angle_ofs, const float angle_delta, const float color[4])
 {
-	GLUquadricObj *qobj = gluNewQuadric();
 	const float width_inner = DIAL_WIDTH - dial->manipulator.line_width * 0.5f / U.manipulator_scale;
 
+#ifdef USE_IMM
+	VertexFormat *format = immVertexFormat();
+	unsigned int pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
+	immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+	immUniformColor4fv(color);
+	imm_draw_filled_circle_partial(
+	        pos, 0, 0, 0.0, width_inner, DIAL_RESOLUTION, RAD2DEGF(angle_ofs), RAD2DEGF(angle_delta));
+	immUnbindProgram();
+#else
+	GLUquadricObj *qobj = gluNewQuadric();
+	glColor4fv(color);
 	gluQuadricDrawStyle(qobj, GLU_FILL);
 	gluPartialDisk(qobj, 0.0, width_inner, DIAL_RESOLUTION, 1, RAD2DEGF(angle_ofs), RAD2DEGF(angle_delta));
 	gluDeleteQuadric(qobj);
+#endif
 }
 
 static void dial_ghostarc_get_angles(
@@ -206,9 +269,15 @@ static void dial_draw_intern(const bContext *C, DialManipulator *dial, const boo
 	copy_v3_v3(mat[3], dial->manipulator.origin);
 	mul_mat3_m4_fl(mat, dial->manipulator.scale);
 
+#ifdef USE_IMM
+	gpuPushMatrix();
+	gpuMultMatrix3D(mat);
+	gpuTranslate3fv(dial->manipulator.offset);
+#else
 	glPushMatrix();
 	glMultMatrixf(mat);
 	glTranslatef(UNPACK3(dial->manipulator.offset));
+#endif
 
 	/* draw rotation indicator arc first */
 	if ((dial->manipulator.flag & WM_MANIPULATOR_DRAW_VALUE) && (dial->manipulator.state & WM_MANIPULATOR_ACTIVE)) {
@@ -218,18 +287,20 @@ static void dial_draw_intern(const bContext *C, DialManipulator *dial, const boo
 
 		dial_ghostarc_get_angles(dial, win->eventstate, CTX_wm_region(C), mat, co_outer, &angle_ofs, &angle_delta);
 		/* draw! */
-		glColor4f(0.8f, 0.8f, 0.8f, 0.4f);
-		dial_ghostarc_draw(dial, angle_ofs, an

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list