[Bf-blender-cvs] [a61b751972d] HMD_viewport: Avoid view setup function prototypes, move them to top of file

Julian Eisel noreply at git.blender.org
Thu Apr 13 19:48:46 CEST 2017


Commit: a61b751972ddbadef5f35d5be6d04c61f2aa485a
Author: Julian Eisel
Date:   Thu Apr 13 19:47:42 2017 +0200
Branches: HMD_viewport
https://developer.blender.org/rBa61b751972ddbadef5f35d5be6d04c61f2aa485a

Avoid view setup function prototypes, move them to top of file

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

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

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

diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 446cfbed21c..8b083d9885c 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -105,24 +105,6 @@
 #include "view3d_intern.h"  /* own include */
 
 /* prototypes */
-static void view3d_setup_drawing(
-        const wmWindowManager *wm, const wmWindow *win,
-        ARegion *region, View3D *v3d, RegionView3D *rv3d,
-        Scene *scene, bool skip_stereo3d);
-static void view3d_hmd_view_setup(
-        Scene *scene, View3D *v3d, ARegion *region);
-static bool view3d_is_hmd_view_mirror(
-        const wmWindowManager *wm, const View3D *v3d, const RegionView3D *rv3d);
-static void view3d_hmd_view_setup_mirrored(
-        const wmWindowManager *wm, Scene *scene, ARegion *region,
-        const rcti *viewplane_rect);
-static void view3d_hmd_view_setup_interaction(
-        Scene *scene, View3D *v3d, ARegion *region, const rcti *viewplane_rect);
-static void view3d_stereo3d_setup(Scene *scene, View3D *v3d, ARegion *ar);
-static void view3d_stereo3d_setup_offscreen(Scene *scene, View3D *v3d, ARegion *ar,
-                                            float winmat[4][4], const char *viewname);
-static bool view3d_stereo3d_active(const wmWindow *win, Scene *scene, View3D *v3d, RegionView3D *rv3d);
-static void view3d_main_region_setup_view(Scene *scene, View3D *v3d, ARegion *ar, float viewmat[4][4], float winmat[4][4]);
 
 /* handy utility for drawing shapes in the viewport for arbitrary code.
  * could add lines and points too */
@@ -170,3897 +152,3902 @@ void circ(float x, float y, float rad)
 	gluDeleteQuadric(qobj);
 }
 
-
-/* ********* custom clipping *********** */
-
-static void view3d_draw_clipping(RegionView3D *rv3d)
+static bool view3d_is_hmd_view_mirror(const wmWindowManager *wm, const View3D *v3d, const RegionView3D *rv3d)
 {
-	BoundBox *bb = rv3d->clipbb;
-
-	if (bb) {
-		const unsigned int clipping_index[6][4] = {
-			{0, 1, 2, 3},
-			{0, 4, 5, 1},
-			{4, 7, 6, 5},
-			{7, 3, 2, 6},
-			{1, 5, 6, 2},
-			{7, 4, 0, 3}
-		};
-
-		/* fill in zero alpha for rendering & re-projection [#31530] */
-		unsigned char col[4];
-		UI_GetThemeColor4ubv(TH_V3D_CLIPPING_BORDER, col);
-		glColor4ubv(col);
-
-		glEnable(GL_BLEND);
-		glEnableClientState(GL_VERTEX_ARRAY);
-		glVertexPointer(3, GL_FLOAT, 0, bb->vec);
-		glDrawElements(GL_QUADS, sizeof(clipping_index) / sizeof(unsigned int), GL_UNSIGNED_INT, clipping_index);
-		glDisableClientState(GL_VERTEX_ARRAY);
-		glDisable(GL_BLEND);
-	}
+	return wm->hmd_view.hmd_win &&
+	       WM_window_is_running_hmd_view(wm->hmd_view.hmd_win) &&
+	       (v3d->flag3 & V3D_SHOW_HMD_MIRROR) &&
+	       RV3D_IS_LOCKED_SHARED(rv3d);
 }
 
-void ED_view3d_clipping_set(RegionView3D *rv3d)
+static bool view3d_stereo3d_active(const wmWindow *win, Scene *scene, View3D *v3d, RegionView3D *rv3d)
 {
-	double plane[4];
-	const unsigned int tot = (rv3d->viewlock & RV3D_BOXCLIP) ? 4 : 6;
-	unsigned int a;
+	if ((scene->r.scemode & R_MULTIVIEW) == 0)
+		return false;
 
-	for (a = 0; a < tot; a++) {
-		copy_v4db_v4fl(plane, rv3d->clip[a]);
-		glClipPlane(GL_CLIP_PLANE0 + a, plane);
-		glEnable(GL_CLIP_PLANE0 + a);
-	}
-}
+	if (WM_stereo3d_enabled(win, true) == false)
+		return false;
 
-/* use these to temp disable/enable clipping when 'rv3d->rflag & RV3D_CLIPPING' is set */
-void ED_view3d_clipping_disable(void)
-{
-	unsigned int a;
+	if ((v3d->camera == NULL) || (v3d->camera->type != OB_CAMERA) || rv3d->persp != RV3D_CAMOB)
+		return false;
 
-	for (a = 0; a < 6; a++) {
-		glDisable(GL_CLIP_PLANE0 + a);
-	}
-}
-void ED_view3d_clipping_enable(void)
-{
-	unsigned int a;
+	if (scene->r.views_format & SCE_VIEWS_FORMAT_MULTIVIEW) {
+		if (v3d->stereo3d_camera == STEREO_MONO_ID)
+			return false;
 
-	for (a = 0; a < 6; a++) {
-		glEnable(GL_CLIP_PLANE0 + a);
+		return BKE_scene_multiview_is_stereo3d(&scene->r);
 	}
-}
-
-static bool view3d_clipping_test(const float co[3], const float clip[6][4])
-{
-	if (plane_point_side_v3(clip[0], co) > 0.0f)
-		if (plane_point_side_v3(clip[1], co) > 0.0f)
-			if (plane_point_side_v3(clip[2], co) > 0.0f)
-				if (plane_point_side_v3(clip[3], co) > 0.0f)
-					return false;
 
 	return true;
 }
 
-/* for 'local' ED_view3d_clipping_local must run first
- * then all comparisons can be done in localspace */
-bool ED_view3d_clipping_test(const RegionView3D *rv3d, const float co[3], const bool is_local)
+
+/* ********* View Setup (Matrices) *********** */
+
+/**
+ * \note keep this synced with #ED_view3d_mats_rv3d_backup/#ED_view3d_mats_rv3d_restore
+ */
+void ED_view3d_update_viewmat(Scene *scene, View3D *v3d, ARegion *ar, float viewmat[4][4], float winmat[4][4])
 {
-	return view3d_clipping_test(co, is_local ? rv3d->clip_local : rv3d->clip);
-}
+	RegionView3D *rv3d = ar->regiondata;
 
-/* ********* end custom clipping *********** */
+	/* setup window matrices */
+	if (winmat)
+		copy_m4_m4(rv3d->winmat, winmat);
+	else
+		view3d_winmatrix_set(ar, v3d, NULL);
 
+	/* setup view matrix */
+	if (viewmat)
+		copy_m4_m4(rv3d->viewmat, viewmat);
+	else
+		view3d_viewmatrix_set(scene, v3d, rv3d);  /* note: calls BKE_object_where_is_calc for camera... */
 
-static void drawgrid_draw(ARegion *ar, double wx, double wy, double x, double y, double dx)
-{	
-	double verts[2][2];
+	/* update utility matrices */
+	mul_m4_m4m4(rv3d->persmat, rv3d->winmat, rv3d->viewmat);
+	invert_m4_m4(rv3d->persinv, rv3d->persmat);
+	invert_m4_m4(rv3d->viewinv, rv3d->viewmat);
+	
+	/* calculate GLSL view dependent values */
 
-	x += (wx);
-	y += (wy);
+	/* store window coordinates scaling/offset */
+	if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
+		rctf cameraborder;
+		ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &cameraborder, false);
+		rv3d->viewcamtexcofac[0] = (float)ar->winx / BLI_rctf_size_x(&cameraborder);
+		rv3d->viewcamtexcofac[1] = (float)ar->winy / BLI_rctf_size_y(&cameraborder);
+		
+		rv3d->viewcamtexcofac[2] = -rv3d->viewcamtexcofac[0] * cameraborder.xmin / (float)ar->winx;
+		rv3d->viewcamtexcofac[3] = -rv3d->viewcamtexcofac[1] * cameraborder.ymin / (float)ar->winy;
+	}
+	else {
+		rv3d->viewcamtexcofac[0] = rv3d->viewcamtexcofac[1] = 1.0f;
+		rv3d->viewcamtexcofac[2] = rv3d->viewcamtexcofac[3] = 0.0f;
+	}
 
-	/* set fixed 'Y' */
-	verts[0][1] = 0.0f;
-	verts[1][1] = (double)ar->winy;
+	/**
+	 * Calculate pixel-size factor once, is used for lamps and object centers.
+	 * Used by #ED_view3d_pixel_size and typically not accessed directly.
+	 *
+	 * \note #BKE_camera_params_compute_viewplane' also calculates a pixel-size value,
+	 * passed to #RE_SetPixelSize, in ortho mode this is compatible with this value,
+	 * but in perspective mode its offset by the near-clip.
+	 *
+	 * 'RegionView3D.pixsize' is used for viewport drawing, not rendering.
+	 */
+	{
+		/* note:  '1.0f / len_v3(v1)'  replaced  'len_v3(rv3d->viewmat[0])'
+		 * because of float point precision problems at large values [#23908] */
+		float v1[3], v2[3];
+		float len_px, len_sc;
 
-	/* iter over 'X' */
-	verts[0][0] = verts[1][0] = x - dx * floor(x / dx);
-	glEnableClientState(GL_VERTEX_ARRAY);
-	glVertexPointer(2, GL_DOUBLE, 0, verts);
+		v1[0] = rv3d->persmat[0][0];
+		v1[1] = rv3d->persmat[1][0];
+		v1[2] = rv3d->persmat[2][0];
 
-	while (verts[0][0] < ar->winx) {
-		glDrawArrays(GL_LINES, 0, 2);
-		verts[0][0] = verts[1][0] = verts[0][0] + dx;
-	}
+		v2[0] = rv3d->persmat[0][1];
+		v2[1] = rv3d->persmat[1][1];
+		v2[2] = rv3d->persmat[2][1];
 
-	/* set fixed 'X' */
-	verts[0][0] = 0.0f;
-	verts[1][0] = (double)ar->winx;
+		len_px = 2.0f / sqrtf(min_ff(len_squared_v3(v1), len_squared_v3(v2)));
+		len_sc = (float)MAX2(ar->winx, ar->winy);
 
-	/* iter over 'Y' */
-	verts[0][1] = verts[1][1] = y - dx * floor(y / dx);
-	while (verts[0][1] < ar->winy) {
-		glDrawArrays(GL_LINES, 0, 2);
-		verts[0][1] = verts[1][1] = verts[0][1] + dx;
+		rv3d->pixsize = len_px / len_sc;
 	}
-
-	glDisableClientState(GL_VERTEX_ARRAY);
 }
 
-#define GRID_MIN_PX_D   6.0
-#define GRID_MIN_PX_F 6.0f
-
-static void drawgrid(UnitSettings *unit, ARegion *ar, View3D *v3d, const char **grid_unit)
+static void view3d_main_region_setup_view(
+        Scene *scene, View3D *v3d, ARegion *ar,
+        float viewmat[4][4], float winmat[4][4])
 {
-	/* extern short bgpicmode; */
 	RegionView3D *rv3d = ar->regiondata;
-	double wx, wy, x, y, fw, fx, fy, dx;
-	double vec4[4];
-	unsigned char col[3], col2[3];
 
-	fx = rv3d->persmat[3][0];
-	fy = rv3d->persmat[3][1];
-	fw = rv3d->persmat[3][3];
+	ED_view3d_update_viewmat(scene, v3d, ar, viewmat, winmat);
 
-	wx = (ar->winx / 2.0); /* because of rounding errors, grid at wrong location */
-	wy = (ar->winy / 2.0);
+	/* set for opengl */
+	glMatrixMode(GL_PROJECTION);
+	glLoadMatrixf(rv3d->winmat);
+	glMatrixMode(GL_MODELVIEW);
+	glLoadMatrixf(rv3d->viewmat);
+}
 
-	x = (wx) * fx / fw;
-	y = (wy) * fy / fw;
+/**
+ * Store values from #RegionView3D, set when drawing.
+ * This is needed when we draw with to a viewport using a different matrix (offscreen drawing for example).
+ *
+ * Values set by #ED_view3d_update_viewmat should be handled here.
+ */
+struct RV3DMatrixStore {
+	float winmat[4][4];
+	float viewmat[4][4];
+	float viewinv[4][4];
+	float persmat[4][4];
+	float persinv[4][4];
+	float viewcamtexcofac[4];
+	float pixsize;
+};
 
-	vec4[0] = vec4[1] = v3d->grid;
+struct RV3DMatrixStore *ED_view3d_mats_rv3d_backup(struct RegionView3D *rv3d)
+{
+	struct RV3DMatrixStore *rv3dmat = MEM_mallocN(sizeof(*rv3dmat), __func__);
+	copy_m4_m4(rv3dmat->winmat, rv3d->winmat);
+	copy_m4_m4(rv3dmat->viewmat, rv3d->viewmat);
+	copy_m4_m4(rv3dmat->persmat, rv3d->persmat);
+	copy_m4_m4(rv3dmat->persinv, rv3d->persinv);
+	copy_m4_m4(rv3dmat->viewinv, rv3d->viewinv);
+	copy_v4_v4(rv3dmat->viewcamtexcofac, rv3d->viewcamtexcofac);
+	rv3dmat->pixsize = rv3d->pixsize;
+	return (void *)rv3dmat;
+}
 
-	vec4[2] = 0.0;
-	vec4[3] = 1.0;
-	mul_m4_v4d(rv3d->persmat, vec4);
-	fx = vec4[0];
-	fy = vec4[1];
-	fw = vec4[3];
+void ED_view3d_mats_rv3d_restore(struct RegionView3D *rv3d, struct RV3DMatrixStore *rv3dmat)
+{
+	copy_m4_m4(rv3d->winmat, rv3dmat->winmat);
+	copy_m4_m4(rv3d->viewmat, rv3dma

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list