[Bf-blender-cvs] [204e067111a] blender2.8: Fix drawing of planar transfrom manipulators, update matrix code

Julian Eisel noreply at git.blender.org
Fri Apr 7 16:04:36 CEST 2017


Commit: 204e067111af9346fccea9981a0a7962ec8ef906
Author: Julian Eisel
Date:   Fri Apr 7 16:02:45 2017 +0200
Branches: blender2.8
https://developer.blender.org/rB204e067111af9346fccea9981a0a7962ec8ef906

Fix drawing of planar transfrom manipulators, update matrix code

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

M	source/blender/windowmanager/manipulators/intern/manipulator_library/arrow2d_manipulator.c
M	source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c
M	source/blender/windowmanager/manipulators/intern/manipulator_library/cage_manipulator.c
M	source/blender/windowmanager/manipulators/intern/manipulator_library/primitive_manipulator.c
M	source/blender/windowmanager/manipulators/intern/wm_manipulator.c
M	source/blender/windowmanager/manipulators/intern/wm_manipulator_intern.h
M	source/blender/windowmanager/manipulators/intern/wm_manipulatormap.c

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

diff --git a/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow2d_manipulator.c b/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow2d_manipulator.c
index 310aec9cbc1..3f7dadbc9c2 100644
--- a/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow2d_manipulator.c
+++ b/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow2d_manipulator.c
@@ -44,6 +44,8 @@
 
 #include "ED_screen.h"
 
+#include "GPU_matrix.h"
+
 #include "MEM_guardedalloc.h"
 
 #include "RNA_access.h"
@@ -73,12 +75,12 @@ static void arrow2d_draw_geom(ArrowManipulator2D *arrow, const float origin[2])
 	const float len = arrow->line_len;
 	const float draw_line_ofs = (arrow->manipulator.line_width * 0.5f) / arrow->manipulator.scale;
 
-	glPushMatrix();
-	glTranslatef(UNPACK2(origin), 0.0f);
-	glScalef(arrow->manipulator.scale, arrow->manipulator.scale, 0.0f);
-	glRotatef(RAD2DEGF(arrow->angle), 0.0f, 0.0f, 1.0f);
+	gpuPushMatrix();
+	gpuTranslate3f(UNPACK2(origin), 0.0f);
+	gpuScale3f(arrow->manipulator.scale, arrow->manipulator.scale, 0.0f);
+	gpuRotate3f(RAD2DEGF(arrow->angle), 0.0f, 0.0f, 1.0f);
 	/* local offset */
-	glTranslatef(arrow->manipulator.offset[0] + draw_line_ofs, arrow->manipulator.offset[1], 0.0f);
+	gpuTranslate3f(arrow->manipulator.offset[0] + draw_line_ofs, arrow->manipulator.offset[1], 0.0f);
 
 	/* TODO get rid of immediate mode */
 	glBegin(GL_LINES);
@@ -91,7 +93,7 @@ static void arrow2d_draw_geom(ArrowManipulator2D *arrow, const float origin[2])
 	glVertex2f(0.0f, len + size * 1.7f);
 	glEnd();
 
-	glPopMatrix();
+	gpuPopMatrix();
 }
 
 static void manipulator_arrow2d_draw(const bContext *UNUSED(C), struct wmManipulator *manipulator)
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 8236d9950a2..05fa0d78c4f 100644
--- a/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c
+++ b/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c
@@ -101,9 +101,12 @@ static void manipulator_arrow_get_final_pos(wmManipulator *manipulator, float r_
 
 static void arrow_draw_geom(const ArrowManipulator *arrow, const bool select, const float color[4])
 {
+	unsigned int pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 3, KEEP_FLOAT);
+	bool unbind_shader = true;
+
+	immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+
 	if (arrow->style & MANIPULATOR_ARROW_STYLE_CROSS) {
-		immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
-		unsigned int pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT);
 		immUniformColor4fv(color);
 
 		immBegin(GL_LINES, 4);
@@ -112,8 +115,6 @@ static void arrow_draw_geom(const ArrowManipulator *arrow, const bool select, co
 		immVertex2f(pos, 0.f, -1.0);
 		immVertex2f(pos, 0.f, 1.0);
 		immEnd();
-
-		immUnbindProgram();
 	}
 	else if (arrow->style & MANIPULATOR_ARROW_STYLE_CONE) {
 		const float unitx = arrow->aspect[0];
@@ -125,32 +126,13 @@ static void arrow_draw_geom(const ArrowManipulator *arrow, const bool select, co
 			{-unitx,  unity, 0},
 		};
 
-		unsigned int pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 3, KEEP_FLOAT);
-
-		immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
-		immUniformColor4fv(color);
-
 		glLineWidth(arrow->manipulator.line_width);
-
-		const int vec_size = ARRAY_SIZE(vec);
-		immBegin(PRIM_LINE_STRIP, vec_size);
-		for (int i = 0; i < vec_size; i++) {
-			immVertex3fv(pos, vec[i]);
-		}
-		immEnd();
-
-		glLineWidth(1.0);
-		immUnbindProgram();
-
+		wm_manipulator_vec_draw(color, vec, ARRAY_SIZE(vec), pos, PRIM_LINE_STRIP);
 	}
 	else {
 #ifdef USE_MANIPULATOR_CUSTOM_ARROWS
 		wm_manipulator_geometryinfo_draw(&wm_manipulator_geom_data_arrow, select, color);
 #else
-		unsigned int pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 3, KEEP_FLOAT);
-
-		immBindBuiltinProgram(GPU_SHADER_3D_CLIPPED_UNIFORM_COLOR);
-		immUniformColor4fv(color);
 
 		const float vec[2][3] = {
 			{0.0f, 0.0f, 0.0f},
@@ -158,15 +140,8 @@ static void arrow_draw_geom(const ArrowManipulator *arrow, const bool select, co
 		};
 
 		glLineWidth(arrow->manipulator.line_width);
+		wm_manipulator_vec_draw(color, vec, ARRAY_SIZE(vec), pos, PRIM_LINE_STRIP);
 
-		const int vec_size = ARRAY_SIZE(vec);
-		immBegin(PRIM_LINE_STRIP, vec_size);
-		for (int i = 0; i < vec_size; i++) {
-			immVertex3fv(pos, vec[i]);
-		}
-		immEnd();
-
-		glLineWidth(1.0);
 
 		/* *** draw arrow head *** */
 
@@ -182,6 +157,7 @@ static void arrow_draw_geom(const ArrowManipulator *arrow, const bool select, co
 
 			/* draw cube */
 			immUnbindProgram();
+			unbind_shader = false;
 			wm_manipulator_geometryinfo_draw(&wm_manipulator_geom_data_cube, select, color);
 		}
 		else {
@@ -202,14 +178,15 @@ static void arrow_draw_geom(const ArrowManipulator *arrow, const bool select, co
 			if (use_lighting) {
 				glShadeModel(GL_FLAT);
 			}
-			immUnbindProgram();
 		}
 
 		gpuPopMatrix();
-
-
 #endif  /* USE_MANIPULATOR_CUSTOM_ARROWS */
 	}
+
+	if (unbind_shader) {
+		immUnbindProgram();
+	}
 }
 
 static void arrow_draw_intern(ArrowManipulator *arrow, const bool select, const bool highlight)
diff --git a/source/blender/windowmanager/manipulators/intern/manipulator_library/cage_manipulator.c b/source/blender/windowmanager/manipulators/intern/manipulator_library/cage_manipulator.c
index a22ccfa7c83..c963ede3a42 100644
--- a/source/blender/windowmanager/manipulators/intern/manipulator_library/cage_manipulator.c
+++ b/source/blender/windowmanager/manipulators/intern/manipulator_library/cage_manipulator.c
@@ -45,6 +45,8 @@
 
 #include "ED_screen.h"
 
+#include "GPU_matrix.h"
+
 #include "MEM_guardedalloc.h"
 
 #include "RNA_access.h"
@@ -187,13 +189,13 @@ static void manipulator_rect_transform_draw(const bContext *UNUSED(C), wmManipul
 	r.xmax = half_w;
 	r.ymax = half_h;
 
-	glPushMatrix();
-	glTranslatef(manipulator->origin[0] + manipulator->offset[0],
+	gpuPushMatrix();
+	gpuTranslate3f(manipulator->origin[0] + manipulator->offset[0],
 	        manipulator->origin[1] + manipulator->offset[1], 0.0f);
 	if (cage->style & MANIPULATOR_RECT_TRANSFORM_STYLE_SCALE_UNIFORM)
-		glScalef(cage->scale[0], cage->scale[0], 1.0);
+		gpuScale3f(cage->scale[0], cage->scale[0], 1.0);
 	else
-		glScalef(cage->scale[0], cage->scale[1], 1.0);
+		gpuScale3f(cage->scale[0], cage->scale[1], 1.0);
 
 	if (w > h)
 		aspx = h / w;
@@ -218,7 +220,7 @@ static void manipulator_rect_transform_draw(const bContext *UNUSED(C), wmManipul
 	                                w, h, cage->manipulator.line_width);
 
 	glLineWidth(1.0);
-	glPopMatrix();
+	gpuPopMatrix();
 }
 
 static int manipulator_rect_transform_get_cursor(wmManipulator *manipulator)
diff --git a/source/blender/windowmanager/manipulators/intern/manipulator_library/primitive_manipulator.c b/source/blender/windowmanager/manipulators/intern/manipulator_library/primitive_manipulator.c
index 5a0700359d8..7dd5d199e62 100644
--- a/source/blender/windowmanager/manipulators/intern/manipulator_library/primitive_manipulator.c
+++ b/source/blender/windowmanager/manipulators/intern/manipulator_library/primitive_manipulator.c
@@ -38,6 +38,8 @@
 #include "DNA_view3d_types.h"
 #include "DNA_manipulator_types.h"
 
+#include "GPU_immediate.h"
+#include "GPU_matrix.h"
 #include "GPU_select.h"
 
 #include "MEM_guardedalloc.h"
@@ -83,19 +85,17 @@ static void manipulator_primitive_draw_geom(
 {
 	float (*verts)[3];
 	float vert_count;
+	unsigned int pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 3, KEEP_FLOAT);
 
 	if (style == MANIPULATOR_PRIMITIVE_STYLE_PLANE) {
 		verts = verts_plane;
 		vert_count = ARRAY_SIZE(verts_plane);
 	}
 
-	glEnableClientState(GL_VERTEX_ARRAY);
-	glVertexPointer(3, GL_FLOAT, 0, verts);
-	glColor4fv(col_inner);
-	glDrawArrays(GL_QUADS, 0, vert_count);
-	glColor4fv(col_outer);
-	glDrawArrays(GL_LINE_LOOP, 0, vert_count);
-	glDisableClientState(GL_VERTEX_ARRAY);
+	immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+	wm_manipulator_vec_draw(col_inner, verts, vert_count, pos, PRIM_QUADS);
+	wm_manipulator_vec_draw(col_outer, verts, vert_count, pos, PRIM_LINE_LOOP);
+	immUnbindProgram();
 }
 
 static void manipulator_primitive_draw_intern(
@@ -120,19 +120,19 @@ static void manipulator_primitive_draw_intern(
 	copy_v3_v3(mat[3], prim->manipulator.origin);
 	mul_mat3_m4_fl(mat, prim->manipulator.scale);
 
-	glPushMatrix();
-	glMultMatrixf(mat);
+	gpuPushMatrix();
+	gpuMultMatrix3D(mat);
 
 	manipulator_color_get(&prim->manipulator, highlight, col_outer);
 	copy_v4_v4(col_inner, col_outer);
 	col_inner[3] *= 0.5f;
 
 	glEnable(GL_BLEND);
-	glTranslatef(UNPACK3(prim->manipulator.offset));
+	gpuTranslate3fv(prim->manipulator.offset);
 	manipulator_primitive_draw_geom(col_inner, col_outer, prim->style);
 	glDisable(GL_BLEND);
 
-	glPopMatrix();
+	gpuPopMatrix();
 
 	if (prim->manipulator.interaction_data) {
 		ManipulatorInteraction *inter = prim->manipulator.interaction_data;
@@ -145,15 +145,15 @@ static void manipulator_primitive_draw_intern(
 		copy_v3_v3(mat[3], inter->init_origin);
 		mul_mat3_m4_fl(mat, inter->init_scale);
 
-		glPushMatrix();
-		glMultMatrixf(mat);
+		gpuPushMatrix();
+		gpuMultMatrix3D(mat);
 
 		glEnable(GL_BLEND);
-		glTranslatef(UNPACK3(prim->manipulator.offset));
+		gpuTranslate3f(UNPACK3(prim->manipulator.offset));
 		manipulator_primitive_draw_geom(col_inner, col_outer, prim->style);
 		glDisable(GL_BLEND);
 
-		glPopMatrix();
+		gpuPopMatrix();
 	}
 }
 
diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulator.c b/source/blender/windowmanager/manipulators/intern/wm_manipulator.c
index 1917c473d94..b11fad46286 100644
--- a/source/blender/windowmanager/manipulators/intern/wm_manipulator.c
+++ b/source/blender/windowmanager/manipulators/intern/wm_manipulator.c
@@ -41,6 +41,7 @@
 
 #include "GPU_batch.h"
 #include "GPU_glew.h"
+#include "GPU_immediate.h"
 
 #include "MEM_guardedalloc.h"
 
@@ -112,6 +113,18 @@ void wm_manipulator_geometryinfo_draw(const ManipulatorGeomInfo *info, const boo
 	Batch_discard_all(b

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list