[Bf-blender-cvs] [7576ad3d043] transform-manipulators: Merge branch 'blender2.8' into transform-manipulators

Julian Eisel noreply at git.blender.org
Tue Apr 4 21:40:33 CEST 2017


Commit: 7576ad3d043ac5d15e0c5a68e65339904441b5e7
Author: Julian Eisel
Date:   Tue Apr 4 21:39:57 2017 +0200
Branches: transform-manipulators
https://developer.blender.org/rB7576ad3d043ac5d15e0c5a68e65339904441b5e7

Merge branch 'blender2.8' into transform-manipulators

Conflicts:
	intern/gawain/gawain/immediate.h
	intern/gawain/src/immediate.c
	source/blender/editors/physics/physics_ops.c
	source/blender/editors/screen/glutil.c
	source/blender/editors/space_view3d/space_view3d.c
	source/blender/editors/space_view3d/view3d_draw.c
	source/blender/editors/space_view3d/view3d_edit.c
	source/blender/editors/space_view3d/view3d_ops.c
	source/blender/editors/transform/transform_manipulator.c

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



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

diff --cc source/blender/draw/CMakeLists.txt
index d5b54e8a746,cf94fccd4e3..e921a65bfe8
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@@ -40,6 -43,6 +43,7 @@@ set(IN
  	../editors/space_view3d
  	../render/extern/include
  	../render/intern/include
++	../windowmanager
  
  	../../../intern/glew-mx
  	../../../intern/guardedalloc
diff --cc source/blender/draw/intern/draw_view.c
index 00000000000,3ce1d92ed3a..3837a9e8d54
mode 000000,100644..100644
--- a/source/blender/draw/intern/draw_view.c
+++ b/source/blender/draw/intern/draw_view.c
@@@ -1,0 -1,703 +1,707 @@@
+ /*
+  * Copyright 2016, Blender Foundation.
+  *
+  * This program is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU General Public License
+  * as published by the Free Software Foundation; either version 2
+  * of the License, or (at your option) any later version.
+  *
+  * This program is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  * GNU General Public License for more details.
+  *
+  * You should have received a copy of the GNU General Public License
+  * along with this program; if not, write to the Free Software Foundation,
+  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+  *
+  * Contributor(s): Blender Institute
+  *
+  */
+ 
+ /** \file blender/draw/intern/draw_view.c
+  *  \ingroup draw
+  *
+  * Contains dynamic drawing using immediate mode
+  */
+ 
+ #include "DNA_brush_types.h"
+ #include "DNA_screen_types.h"
+ #include "DNA_userdef_types.h"
+ #include "DNA_view3d_types.h"
+ 
+ #include "ED_screen.h"
+ #include "ED_transform.h"
+ #include "ED_view3d.h"
+ 
+ #include "GPU_draw.h"
+ #include "GPU_shader.h"
+ #include "GPU_immediate.h"
+ #include "GPU_matrix.h"
+ 
+ #include "UI_resources.h"
+ 
+ #include "BKE_global.h"
+ #include "BKE_object.h"
+ #include "BKE_paint.h"
+ #include "BKE_unit.h"
+ 
+ #include "DRW_render.h"
+ 
++#include "WM_api.h"
++#include "WM_types.h"
++
+ #include "view3d_intern.h"
+ 
+ #include "draw_view.h"
+ 
+ /* ******************** region info ***************** */
+ 
+ void DRW_draw_region_info(void)
+ {
+ 	const bContext *C = DRW_get_context();
+ 	ARegion *ar = CTX_wm_region(C);
+ 
+ 	DRW_draw_cursor();
+ 	view3d_draw_region_info(C, ar);
+ }
+ 
+ /* ************************* Grid ************************** */
+ 
+ static void gridline_range(double x0, double dx, double max, int *r_first, int *r_count)
+ {
+ 	/* determine range of gridlines that appear in this Area -- similar calc but separate ranges for x & y
+ 	* x0 is gridline 0, the axis in screen space
+ 	* Area covers [0 .. max) pixels */
+ 
+ 	int first = (int)ceil(-x0 / dx);
+ 	int last = (int)floor((max - x0) / dx);
+ 
+ 	if (first <= last) {
+ 		*r_first = first;
+ 		*r_count = last - first + 1;
+ 	}
+ 	else {
+ 		*r_first = 0;
+ 		*r_count = 0;
+ 	}
+ }
+ 
+ static int gridline_count(ARegion *ar, double x0, double y0, double dx)
+ {
+ 	/* x0 & y0 establish the "phase" of the grid within this 2D region
+ 	* dx is the frequency, shared by x & y directions
+ 	* pass in dx of smallest (highest precision) grid we want to draw */
+ 
+ 	int first, x_ct, y_ct;
+ 
+ 	gridline_range(x0, dx, ar->winx, &first, &x_ct);
+ 	gridline_range(y0, dx, ar->winy, &first, &y_ct);
+ 
+ 	int total_ct = x_ct + y_ct;
+ 
+ 	return total_ct;
+ }
+ 
+ static bool drawgrid_draw(ARegion *ar, double x0, double y0, double dx, int skip_mod, unsigned pos, unsigned col, GLubyte col_value[3])
+ {
+ 	/* skip every skip_mod lines relative to each axis; they will be overlaid by another drawgrid_draw
+ 	* always skip exact x0 & y0 axes; they will be drawn later in color
+ 	*
+ 	* set grid color once, just before the first line is drawn
+ 	* it's harmless to set same color for every line, or every vertex
+ 	* but if no lines are drawn, color must not be set! */
+ 
+ 	const float x_max = (float)ar->winx;
+ 	const float y_max = (float)ar->winy;
+ 
+ 	int first, ct;
+ 	int x_ct = 0, y_ct = 0; /* count of lines actually drawn */
+ 	int lines_skipped_for_next_unit = 0;
+ 
+ 	/* draw vertical lines */
+ 	gridline_range(x0, dx, x_max, &first, &ct);
+ 
+ 	for (int i = first; i < first + ct; ++i) {
+ 		if (i == 0)
+ 			continue;
+ 		else if (skip_mod && (i % skip_mod) == 0) {
+ 			++lines_skipped_for_next_unit;
+ 			continue;
+ 		}
+ 
+ 		if (x_ct == 0)
+ 			immAttrib3ub(col, col_value[0], col_value[1], col_value[2]);
+ 
+ 		float x = (float)(x0 + i * dx);
+ 		immVertex2f(pos, x, 0.0f);
+ 		immVertex2f(pos, x, y_max);
+ 		++x_ct;
+ 	}
+ 
+ 	/* draw horizontal lines */
+ 	gridline_range(y0, dx, y_max, &first, &ct);
+ 
+ 	for (int i = first; i < first + ct; ++i) {
+ 		if (i == 0)
+ 			continue;
+ 		else if (skip_mod && (i % skip_mod) == 0) {
+ 			++lines_skipped_for_next_unit;
+ 			continue;
+ 		}
+ 
+ 		if (x_ct + y_ct == 0)
+ 			immAttrib3ub(col, col_value[0], col_value[1], col_value[2]);
+ 
+ 		float y = (float)(y0 + i * dx);
+ 		immVertex2f(pos, 0.0f, y);
+ 		immVertex2f(pos, x_max, y);
+ 		++y_ct;
+ 	}
+ 
+ 	return lines_skipped_for_next_unit > 0;
+ }
+ 
+ #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)
+ {
+ 	RegionView3D *rv3d = ar->regiondata;
+ 
+ 	double fx = rv3d->persmat[3][0];
+ 	double fy = rv3d->persmat[3][1];
+ 	double fw = rv3d->persmat[3][3];
+ 
+ 	const double wx = 0.5 * ar->winx;  /* use double precision to avoid rounding errors */
+ 	const double wy = 0.5 * ar->winy;
+ 
+ 	double x = wx * fx / fw;
+ 	double y = wy * fy / fw;
+ 
+ 	double vec4[4] = { v3d->grid, v3d->grid, 0.0, 1.0 };
+ 	mul_m4_v4d(rv3d->persmat, vec4);
+ 	fx = vec4[0];
+ 	fy = vec4[1];
+ 	fw = vec4[3];
+ 
+ 	double dx = fabs(x - wx * fx / fw);
+ 	if (dx == 0) dx = fabs(y - wy * fy / fw);
+ 
+ 	x += wx;
+ 	y += wy;
+ 
+ 	/* now x, y, and dx have their final values
+ 	* (x,y) is the world origin (0,0,0) mapped to Area-relative screen space
+ 	* dx is the distance in pixels between grid lines -- same for horiz or vert grid lines */
+ 
+ 	glLineWidth(1.0f);
+ 
+ #if 0 /* TODO: write to UI/widget depth buffer, not scene depth */
+ 	glDepthMask(GL_FALSE);  /* disable write in zbuffer */
+ #endif
+ 
+ 	VertexFormat *format = immVertexFormat();
+ 	unsigned int pos = add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT);
+ 	unsigned int color = add_attrib(format, "color", COMP_U8, 3, NORMALIZE_INT_TO_FLOAT);
+ 
+ 	immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+ 
+ 	unsigned char col[3], col2[3];
+ 	UI_GetThemeColor3ubv(TH_GRID, col);
+ 
+ 	if (unit->system) {
+ 		const void *usys;
+ 		int len;
+ 
+ 		bUnit_GetSystem(unit->system, B_UNIT_LENGTH, &usys, &len);
+ 
+ 		bool first = true;
+ 
+ 		if (usys) {
+ 			int i = len;
+ 			while (i--) {
+ 				double scalar = bUnit_GetScaler(usys, i);
+ 
+ 				double dx_scalar = dx * scalar / (double)unit->scale_length;
+ 				if (dx_scalar < (GRID_MIN_PX_D * 2.0)) {
+ 					/* very very small grid items are less useful when dealing with units */
+ 					continue;
+ 				}
+ 
+ 				if (first) {
+ 					first = false;
+ 
+ 					/* Store the smallest drawn grid size units name so users know how big each grid cell is */
+ 					*grid_unit = bUnit_GetNameDisplay(usys, i);
+ 					rv3d->gridview = (float)((scalar * (double)v3d->grid) / (double)unit->scale_length);
+ 
+ 					int gridline_ct = gridline_count(ar, x, y, dx_scalar);
+ 					if (gridline_ct == 0)
+ 						goto drawgrid_cleanup; /* nothing to draw */
+ 
+ 					immBegin(GL_LINES, gridline_ct * 2);
+ 				}
+ 
+ 				float blend_fac = 1.0f - ((GRID_MIN_PX_F * 2.0f) / (float)dx_scalar);
+ 				/* tweak to have the fade a bit nicer */
+ 				blend_fac = (blend_fac * blend_fac) * 2.0f;
+ 				CLAMP(blend_fac, 0.3f, 1.0f);
+ 
+ 				UI_GetThemeColorBlend3ubv(TH_HIGH_GRAD, TH_GRID, blend_fac, col2);
+ 
+ 				const int skip_mod = (i == 0) ? 0 : (int)round(bUnit_GetScaler(usys, i - 1) / scalar);
+ 				if (!drawgrid_draw(ar, x, y, dx_scalar, skip_mod, pos, color, col2))
+ 					break;
+ 			}
+ 		}
+ 	}
+ 	else {
+ 		const double sublines = v3d->gridsubdiv;
+ 		const float  sublines_fl = v3d->gridsubdiv;
+ 
+ 		int grids_to_draw = 2; /* first the faint fine grid, then the bold coarse grid */
+ 
+ 		if (dx < GRID_MIN_PX_D) {
+ 			rv3d->gridview *= sublines_fl;
+ 			dx *= sublines;
+ 			if (dx < GRID_MIN_PX_D) {
+ 				rv3d->gridview *= sublines_fl;
+ 				dx *= sublines;
+ 				if (dx < GRID_MIN_PX_D) {
+ 					rv3d->gridview *= sublines_fl;
+ 					dx *= sublines;
+ 					grids_to_draw = (dx < GRID_MIN_PX_D) ? 0 : 1;
+ 				}
+ 			}
+ 		}
+ 		else {
+ 			if (dx > (GRID_MIN_PX_D * 10.0)) {  /* start blending in */
+ 				rv3d->gridview /= sublines_fl;
+ 				dx /= sublines;
+ 				if (dx > (GRID_MIN_PX_D * 10.0)) {  /* start blending in */
+ 					rv3d->gridview /= sublines_fl;
+ 					dx /= sublines;
+ 					if (dx > (GRID_MIN_PX_D * 10.0)) {
+ 						grids_to_draw = 1;
+ 					}
+ 				}
+ 			}
+ 		}
+ 
+ 		int gridline_ct = gridline_count(ar, x, y, dx);
+ 		if (gridline_ct == 0)
+ 			goto drawgrid_cleanup; /* nothing to draw */
+ 
+ 		immBegin(GL_LINES, gridline_ct * 2);
+ 
+ 		if (grids_to_draw == 2) {
+ 			UI_GetThemeColorBlend3ubv(TH_HIGH_GRAD, TH_GRID, dx / (GRID_MIN_PX_D * 6.0), col2);
+ 			if (drawgrid_draw(ar, x, y, dx, v3d->gridsubdiv, pos, color, col2))
+ 				drawgrid_draw(ar, x, y, dx * sublines, 0, pos, color, col);
+ 		}
+ 		else if (grids_to_draw == 1) {
+ 			drawgrid_draw(ar, x, y, dx, 0, pos, color, col);
+ 		}
+ 	}
+ 
+ 	/* draw visible axes */
+ 	/* horizontal line */
+ 	if (0 <= y && y < ar->winy) {
+ 		UI_make_axis_color(col, col2, ELEM(rv3d->view, RV3D_VIEW_RIGHT, RV3D_VIEW_LEFT) ? 'Y' : 'X');
+ 		immAttrib3ub(color, col2[0], col2[1], col2[2]);
+ 		immVertex2f(pos, 0.0f, y);
+ 		immVertex2f(pos, (float)ar->winx, y);
+ 	}
+ 
+ 	/* vertical line */
+ 	if (0 <= x && x < ar->winx) {
+ 		UI_make_axis_color(col, col2, ELEM(rv3d->view, RV3D_VIEW_TOP, RV3D_VIEW_BOTTOM) ? 'Y' : 'Z');
+ 		immAttrib3ub(color, col2[0], col2[1], col2[2]);
+ 		immVertex2f(pos, x, 0.0f);
+ 		immVertex2f(pos, x, (float)ar->winy);
+ 	}
+ 
+ 	immEnd();
+ 
+ drawgrid_cleanup:
+ 	immUnbindPr

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list