[Bf-blender-cvs] [2724fad582] blender2.8: OpenGL: replace gluProject and gluUnProject, and simplify surrounding code.

Brecht Van Lommel noreply at git.blender.org
Sun Feb 26 00:21:14 CET 2017


Commit: 2724fad582676d2c164b05fe6fccf7a15d88adba
Author: Brecht Van Lommel
Date:   Sat Feb 25 21:58:23 2017 +0100
Branches: blender2.8
https://developer.blender.org/rB2724fad582676d2c164b05fe6fccf7a15d88adba

OpenGL: replace gluProject and gluUnProject, and simplify surrounding code.

Part of T49042.

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

M	source/blender/editors/curve/editcurve_paint.c
M	source/blender/editors/include/BIF_glutil.h
M	source/blender/editors/include/ED_sculpt.h
M	source/blender/editors/include/ED_view3d.h
M	source/blender/editors/mesh/editmesh_knife.c
M	source/blender/editors/physics/particle_edit.c
M	source/blender/editors/screen/glutil.c
M	source/blender/editors/sculpt_paint/paint_hide.c
M	source/blender/editors/sculpt_paint/paint_intern.h
M	source/blender/editors/sculpt_paint/paint_mask.c
M	source/blender/editors/sculpt_paint/paint_utils.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/space_view3d/drawobject.c
M	source/blender/editors/space_view3d/view3d_edit.c
M	source/blender/editors/space_view3d/view3d_project.c
M	source/blender/editors/space_view3d/view3d_select.c
M	source/blender/editors/space_view3d/view3d_view.c
M	source/blender/gpu/GPU_matrix.h
M	source/blender/gpu/intern/gpu_matrix.c

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

diff --git a/source/blender/editors/curve/editcurve_paint.c b/source/blender/editors/curve/editcurve_paint.c
index 7b93e00b86..c2c85e2017 100644
--- a/source/blender/editors/curve/editcurve_paint.c
+++ b/source/blender/editors/curve/editcurve_paint.c
@@ -92,25 +92,17 @@ static float depth_read_zbuf(const ViewContext *vc, int x, int y)
 }
 
 static bool depth_unproject(
-        const ARegion *ar, const bglMats *mats,
+        const ARegion *ar,
         const int mval[2], const double depth,
         float r_location_world[3])
 {
-	double p[3];
-	if (gluUnProject(
-	        (double)ar->winrct.xmin + mval[0] + 0.5,
-	        (double)ar->winrct.ymin + mval[1] + 0.5,
-	        depth, mats->modelview, mats->projection, (const GLint *)mats->viewport,
-	        &p[0], &p[1], &p[2]))
-	{
-		copy_v3fl_v3db(r_location_world, p);
-		return true;
-	}
-	return false;
+	float centx = (float)mval[0] + 0.5f;
+	float centy = (float)mval[1] + 0.5f;
+	return ED_view3d_unproject(ar, centx, centy, depth, r_location_world);
 }
 
 static bool depth_read_normal(
-        const ViewContext *vc, const bglMats *mats, const int mval[2],
+        const ViewContext *vc, const int mval[2],
         float r_normal[3])
 {
 	/* pixels surrounding */
@@ -126,7 +118,7 @@ static bool depth_read_normal(
 
 			const double depth = (double)depth_read_zbuf(vc, mval_ofs[0], mval_ofs[1]);
 			if ((depth > depths->depth_range[0]) && (depth < depths->depth_range[1])) {
-				if (depth_unproject(ar, mats, mval_ofs, depth, coords[i])) {
+				if (depth_unproject(ar, mval_ofs, depth, coords[i])) {
 					depths_valid[i] = true;
 				}
 			}
@@ -228,7 +220,6 @@ struct CurveDrawData {
 	} prev;
 
 	ViewContext vc;
-	bglMats mats;
 	enum {
 		CURVE_DRAW_IDLE = 0,
 		CURVE_DRAW_PAINTING = 1,
@@ -314,7 +305,7 @@ static bool stroke_elem_project(
 		{
 			const double depth = (double)depth_read_zbuf(&cdd->vc, mval_i[0], mval_i[1]);
 			if ((depth > depths->depth_range[0]) && (depth < depths->depth_range[1])) {
-				if (depth_unproject(ar, &cdd->mats, mval_i, depth, r_location_world)) {
+				if (depth_unproject(ar, mval_i, depth, r_location_world)) {
 					is_location_world_set = true;
 					if (r_normal_world) {
 						zero_v3(r_normal_world);
@@ -323,7 +314,7 @@ static bool stroke_elem_project(
 					if (surface_offset != 0.0f) {
 						const float offset = cdd->project.use_surface_offset_absolute ? 1.0f : radius;
 						float normal[3];
-						if (depth_read_normal(&cdd->vc, &cdd->mats, mval_i, normal)) {
+						if (depth_read_normal(&cdd->vc, mval_i, normal)) {
 							madd_v3_v3fl(r_location_world, normal, offset * surface_offset);
 							if (r_normal_world) {
 								copy_v3_v3(r_normal_world, normal);
@@ -651,7 +642,7 @@ static void curve_draw_event_add_first(wmOperator *op, const wmEvent *event)
 		         CURVE_PAINT_SURFACE_PLANE_NORMAL_VIEW,
 		         CURVE_PAINT_SURFACE_PLANE_NORMAL_SURFACE))
 		{
-			if (depth_read_normal(&cdd->vc, &cdd->mats, event->mval, normal)) {
+			if (depth_read_normal(&cdd->vc, event->mval, normal)) {
 				if (cps->surface_plane == CURVE_PAINT_SURFACE_PLANE_NORMAL_VIEW) {
 					float cross_a[3], cross_b[3];
 					cross_v3_v3v3(cross_a, rv3d->viewinv[2], normal);
@@ -1187,8 +1178,6 @@ static int curve_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 			if ((cps->depth_mode == CURVE_PAINT_PROJECT_SURFACE) &&
 			    (v3d->drawtype > OB_WIRE))
 			{
-				view3d_get_transformation(cdd->vc.ar, cdd->vc.rv3d, NULL, &cdd->mats);
-
 				/* needed or else the draw matrix can be incorrect */
 				view3d_operator_needs_opengl(C);
 
diff --git a/source/blender/editors/include/BIF_glutil.h b/source/blender/editors/include/BIF_glutil.h
index 0b85517f33..a0e47a7a22 100644
--- a/source/blender/editors/include/BIF_glutil.h
+++ b/source/blender/editors/include/BIF_glutil.h
@@ -292,14 +292,6 @@ void setlinestyle(int nr);
 /* own working polygon offset */
 void bglPolygonOffset(float viewdist, float dist);
 
-/* For caching opengl matrices (gluProject/gluUnProject) */
-typedef struct bglMats {
-	double modelview[16];
-	double projection[16];
-	int viewport[4];
-} bglMats;
-void bgl_get_mats(bglMats *mats);
-
 /* **** Color management helper functions for GLSL display/transform ***** */
 
 /* Draw imbuf on a screen, preferably using GLSL display transform */
diff --git a/source/blender/editors/include/ED_sculpt.h b/source/blender/editors/include/ED_sculpt.h
index 6daaac5bb4..a81d63d9f2 100644
--- a/source/blender/editors/include/ED_sculpt.h
+++ b/source/blender/editors/include/ED_sculpt.h
@@ -39,8 +39,7 @@ struct rcti;
 
 /* sculpt.c */
 void ED_operatortypes_sculpt(void);
-void ED_sculpt_redraw_planes_get(float planes[4][4], struct ARegion *ar,
-                                 struct RegionView3D *rv3d, struct Object *ob);
+void ED_sculpt_redraw_planes_get(float planes[4][4], struct ARegion *ar, struct Object *ob);
 int  ED_sculpt_mask_box_select(struct bContext *C, struct ViewContext *vc, const struct rcti *rect, bool select, bool extend);
 
 #endif /* __ED_SCULPT_H__ */
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index cc83b97fc0..4863604bf6 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -56,7 +56,6 @@ struct ViewContext;
 struct bContext;
 struct bPoseChannel;
 struct bScreen;
-struct bglMats;
 struct rctf;
 struct rcti;
 struct wmOperator;
@@ -233,7 +232,9 @@ bool ED_view3d_win_to_segment(const struct ARegion *ar, struct View3D *v3d, cons
                               float r_ray_start[3], float r_ray_end[3], const bool do_clip);
 void ED_view3d_ob_project_mat_get(const struct RegionView3D *v3d, struct Object *ob, float pmat[4][4]);
 void ED_view3d_ob_project_mat_get_from_obmat(const struct RegionView3D *rv3d, float obmat[4][4], float pmat[4][4]);
-void ED_view3d_unproject(struct bglMats *mats, float out[3], const float x, const float y, const float z);
+
+void ED_view3d_project(const struct ARegion *ar, const float world[3], float region[3]);
+bool ED_view3d_unproject(const struct ARegion *ar, float regionx, float regiony, float regionz, float world[3]);
 
 /* end */
 
@@ -262,7 +263,8 @@ bool ED_view3d_calc_render_border(struct Scene *scene, struct View3D *v3d,
                                   struct ARegion *ar, struct rcti *rect);
 
 void ED_view3d_clipping_calc_from_boundbox(float clip[6][4], const struct BoundBox *clipbb, const bool is_flip);
-void ED_view3d_clipping_calc(struct BoundBox *bb, float planes[4][4], struct bglMats *mats, const struct rcti *rect);
+void ED_view3d_clipping_calc(struct BoundBox *bb, float planes[4][4],
+        const struct ARegion *ar, const struct Object *ob, const struct rcti *rect);
 void ED_view3d_clipping_local(struct RegionView3D *rv3d, float mat[4][4]);
 bool ED_view3d_clipping_test(const struct RegionView3D *rv3d, const float co[3], const bool is_local);
 void ED_view3d_clipping_set(struct RegionView3D *rv3d);
@@ -312,7 +314,6 @@ void view3d_set_viewcontext(struct bContext *C, struct ViewContext *vc);
 void view3d_operator_needs_opengl(const struct bContext *C);
 void view3d_region_operator_needs_opengl(struct wmWindow *win, struct ARegion *ar);
 void view3d_opengl_read_pixels(struct ARegion *ar, int x, int y, int w, int h, int format, int type, void *data);
-void view3d_get_transformation(const struct ARegion *ar, struct RegionView3D *rv3d, struct Object *ob, struct bglMats *mats);
 
 /* XXX should move to BLI_math */
 bool edge_inside_circle(const float cent[2], float radius, const float screen_co_a[2], const float screen_co_b[2]);
diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c
index 2250aaab31..f320943d68 100644
--- a/source/blender/editors/mesh/editmesh_knife.c
+++ b/source/blender/editors/mesh/editmesh_knife.c
@@ -1418,7 +1418,7 @@ static bool bm_ray_cast_cb_elem_not_in_face_check(BMFace *f, void *user_data)
  * intersecting faces matching this face (or connected when an vert/edge) will be ignored.
  */
 static bool point_is_visible(
-        KnifeTool_OpData *kcd, const float p[3], const float s[2], bglMats *mats,
+        KnifeTool_OpData *kcd, const float p[3], const float s[2],
         BMElem *ele_test)
 {
 	BMFace *f_hit;
@@ -1436,7 +1436,7 @@ static bool point_is_visible(
 		float view[3], p_ofs[3];
 
 		/* TODO: I think there's a simpler way to get the required raycast ray */
-		ED_view3d_unproject(mats, view, s[0], s[1], 0.0f);
+		ED_view3d_unproject(kcd->vc.ar, s[0], s[1], 0.0f, view);
 
 		mul_m4_v3(kcd->ob->imat, view);
 
@@ -1509,7 +1509,6 @@ static void set_linehit_depth(KnifeTool_OpData *kcd, KnifeLineHit *lh)
 /* Finds visible (or all, if cutting through) edges that intersects the current screen drag line */
 static void knife_find_line_hits(KnifeTool_OpData *kcd)
 {
-	bglMats mats;
 	SmallHash faces, kfes, kfvs;
 	float v1[3], v2[3], v3[3], v4[3], s1[2], s2[2];
 	BVHTree *planetree, *tree;
@@ -1539,8 +1538,6 @@ static void knife_find_line_hits(KnifeTool_OpData *kcd)
 	const bool use_hit_prev = true;
 	const bool use_hit_curr = (kcd->is_drag_hold == false);
 
-	bgl_get_mats(&mats);
-
 	if (kcd->linehits) {
 		MEM_freeN(kcd->linehits);
 		kcd->linehits = NULL;
@@ -1669,7 +1666,7 @@ static void knife_find_line_hits(KnifeTool_OpData *kcd)
 		knife_project_v2(kcd, v->cageco, s);
 		d = dist_squared_to_line_segment_v2(s, s1, s2);
 		if ((d <= vert_tol_sq) &&
-		    (point_is_visible(kcd, v->cageco, s, &mats, bm_elem_from_knife_vert(v, &kfe_hit))))
+		    (point_is_visible(kcd, v->cageco, s, bm_elem_from_knife_vert(v, &kfe_hit))))
 		{
 			memset(&hit, 0, sizeof(hit));
 			hit.v = v;
@@ -1732,7 +1729,7 @@ static void knife_find_line_hits(KnifeTool_OpData *kcd)
 				 * Need to find 3d intersection of ray through sint */
 				knife_input_ray_segment(kcd, sint, 1.0f, r1, r2);
 				isect_kind = isect_line_line_v3(kfe->v1->cageco, kfe->v2->cageco, r1, r2, p_cage, p_cage_tmp);
-				if (isect_kind >= 1 && point_is_visible(kcd, p_cage, sint, &mats, bm_elem_from_knife_edge(kfe))) {
+				if (isect_kind >= 1 && point_is_visible(kcd, p_cage, sint, bm_elem_from_knife_edge(kfe))) {
 					memset(&hit, 0, sizeof(hit));
 					if (kcd->snap_midpo

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list