[Bf-blender-cvs] [39e212eb05] blender2.8: OpenGL: further mask_draw tweaks

Mike Erwin noreply at git.blender.org
Fri Feb 17 21:48:41 CET 2017


Commit: 39e212eb05bd2d0a9aeae7820c66834fbb2a393c
Author: Mike Erwin
Date:   Fri Feb 17 15:41:47 2017 -0500
Branches: blender2.8
https://developer.blender.org/rB39e212eb05bd2d0a9aeae7820c66834fbb2a393c

OpenGL: further mask_draw tweaks

- smooth round points
- fewer state changes
- minor cleanup & warning fix

This is a follow-up to rB84141f27a668

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

M	source/blender/editors/mask/mask_draw.c

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

diff --git a/source/blender/editors/mask/mask_draw.c b/source/blender/editors/mask/mask_draw.c
index f2106773be..b20862e763 100644
--- a/source/blender/editors/mask/mask_draw.c
+++ b/source/blender/editors/mask/mask_draw.c
@@ -49,9 +49,11 @@
 #include "ED_clip.h"
 #include "ED_mask.h"  /* own include */
 #include "ED_space_api.h"
+
 #include "BIF_glutil.h"
 
 #include "GPU_immediate.h"
+#include "GPU_draw.h"
 
 #include "UI_resources.h"
 #include "UI_view2d.h"
@@ -100,21 +102,9 @@ static void mask_point_undistort_pos(SpaceClip *sc, float r_co[2], const float c
 	BKE_mask_coord_from_movieclip(sc->clip, &sc->user, r_co, r_co);
 }
 
-static void draw_circle(const float x, const float y,
-                        const float size, const bool fill,
-                        const float scale, const unsigned pos)
-{
-	if (fill) {
-		imm_draw_filled_circle(pos, x, y, 0.7f / scale * size, 8);
-	}
-	else {
-		imm_draw_lined_circle(pos, x, y, 0.7f / scale * size, 8);
-	}
-}
-
 static void draw_single_handle(const MaskLayer *mask_layer, const MaskSplinePoint *point,
                                const eMaskWhichHandle which_handle, const int draw_type,
-                               const float handle_size, const float scale,
+                               const float handle_size,
                                const float point_pos[2], const float handle_pos[2])
 {
 	const BezTriple *bezt = &point->bezt;
@@ -132,7 +122,7 @@ static void draw_single_handle(const MaskLayer *mask_layer, const MaskSplinePoin
 	}
 
 	VertexFormat *format = immVertexFormat();
-	unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
+	unsigned pos = add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT);
 	const unsigned char rgb_gray[4] = {0x60, 0x60, 0x60, 0xff};
 
 	immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
@@ -141,7 +131,7 @@ static void draw_single_handle(const MaskLayer *mask_layer, const MaskSplinePoin
 	/* this could be split into its own loop */
 	if (draw_type == MASK_DT_OUTLINE) {
 		glLineWidth(3.0f);
-		immBegin(GL_LINES, 2);
+		immBegin(PRIM_LINES, 2);
 		immVertex2fv(pos, point_pos);
 		immVertex2fv(pos, handle_pos);
 		immEnd();
@@ -161,30 +151,40 @@ static void draw_single_handle(const MaskLayer *mask_layer, const MaskSplinePoin
 	}
 
 	glLineWidth(1.0f);
-	immBegin(GL_LINES, 2);
+	immBegin(PRIM_LINES, 2);
 	immVertex2fv(pos, point_pos);
 	immVertex2fv(pos, handle_pos);
 	immEnd();
+	immUnbindProgram();
 
 	/* draw handle points */
+	immBindBuiltinProgram(GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_SMOOTH);
+	immUniform1f("size", handle_size);
+	immUniform1f("outlineWidth", 1.5f);
+
+	float point_color[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; /* active color by default */
 	if (MASKPOINT_ISSEL_HANDLE(point, which_handle)) {
-		if (point == mask_layer->act_point)
-			immUniformColor3f(1.0f, 1.0f, 1.0f);
-		else
-			immUniformThemeColor(TH_HANDLE_VERTEX_SELECT);
+		if (point != mask_layer->act_point) {
+			UI_GetThemeColor3fv(TH_HANDLE_VERTEX_SELECT, point_color);
+		}
 	}
 	else {
-		immUniformThemeColor(TH_HANDLE_VERTEX);
+		UI_GetThemeColor3fv(TH_HANDLE_VERTEX, point_color);
 	}
 
-	draw_circle(handle_pos[0], handle_pos[1], handle_size, false, scale, pos);
+	immUniform4fv("outlineColor", point_color);
+	immUniformColor3fvAlpha(point_color, 0.25f);
+
+	immBegin(PRIM_POINTS, 1);
+	immVertex2fv(pos, handle_pos);
+	immEnd();
+
 	immUnbindProgram();
 }
 
 /* return non-zero if spline is selected */
 static void draw_spline_points(const bContext *C, MaskLayer *masklay, MaskSpline *spline,
-                               const char draw_flag, const char draw_type,
-                               const float scale)
+                               const char draw_flag, const char draw_type)
 {
 	const bool is_spline_sel = (spline->flag & SELECT) && (masklay->restrictflag & MASK_RESTRICT_SELECT) == 0;
 	const bool is_smooth = (draw_flag & MASK_DRAWFLAG_SMOOTH) != 0;
@@ -205,16 +205,15 @@ static void draw_spline_points(const bContext *C, MaskLayer *masklay, MaskSpline
 		undistort = sc->clip && (sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT);
 
 	/* TODO, add this to sequence editor */
-	int handle_size = UI_GetThemeValuef(TH_HANDLE_VERTEX_SIZE) * U.pixelsize;
-
-	glPointSize(handle_size);
+	float handle_size = 2.0f * UI_GetThemeValuef(TH_HANDLE_VERTEX_SIZE) * U.pixelsize;
 
 	mask_spline_color_get(masklay, spline, is_spline_sel, rgb_spline);
 
 	VertexFormat *format = immVertexFormat();
-	unsigned int pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
+	unsigned int pos = add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT);
 
-	immBindBuiltinProgram(GPU_SHADER_2D_POINT_FIXED_SIZE_UNIFORM_COLOR);
+	immBindBuiltinProgram(GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_SMOOTH);
+	immUniform1f("size", 0.7f * handle_size);
 
 	/* feather points */
 	feather_points = fp = BKE_mask_spline_feather_points(spline, &tot_feather_point);
@@ -249,7 +248,7 @@ static void draw_spline_points(const bContext *C, MaskLayer *masklay, MaskSpline
 				immUniformThemeColor(TH_HANDLE_VERTEX);
 			}
 
-			immBegin(GL_POINTS, 1);
+			immBegin(PRIM_POINTS, 1);
 			immVertex2fv(pos, feather_point);
 			immEnd();
 
@@ -262,8 +261,6 @@ static void draw_spline_points(const bContext *C, MaskLayer *masklay, MaskSpline
 
 	if (is_smooth) {
 		glEnable(GL_LINE_SMOOTH);
-		glEnable(GL_BLEND);
-		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 	}
 
 	/* control points */
@@ -291,7 +288,7 @@ static void draw_spline_points(const bContext *C, MaskLayer *masklay, MaskSpline
 				mask_point_undistort_pos(sc, handle, handle);
 			}
 			draw_single_handle(masklay, point, MASK_WHICH_HANDLE_STICK,
-			                   draw_type, handle_size, scale, vert, handle);
+			                   draw_type, handle_size, vert, handle);
 		}
 		else {
 			float handle_left[2], handle_right[2];
@@ -302,13 +299,13 @@ static void draw_spline_points(const bContext *C, MaskLayer *masklay, MaskSpline
 				mask_point_undistort_pos(sc, handle_left, handle_left);
 			}
 			draw_single_handle(masklay, point, MASK_WHICH_HANDLE_LEFT,
-			                   draw_type, handle_size, scale, vert, handle_left);
+			                   draw_type, handle_size, vert, handle_left);
 			draw_single_handle(masklay, point, MASK_WHICH_HANDLE_RIGHT,
-			                   draw_type, handle_size, scale, vert, handle_right);
+			                   draw_type, handle_size, vert, handle_right);
 		}
 
 		/* bind program in loop so it does not interfere with draw_single_handle */
-		immBindBuiltinProgram(GPU_SHADER_2D_POINT_FIXED_SIZE_UNIFORM_COLOR);
+		immBindBuiltinProgram(GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_SMOOTH);
 
 		/* draw CV point */
 		if (MASKPOINT_ISSEL_KNOT(point)) {
@@ -320,39 +317,41 @@ static void draw_spline_points(const bContext *C, MaskLayer *masklay, MaskSpline
 		else
 			immUniformThemeColor(TH_HANDLE_VERTEX);
 
-		immBegin(GL_POINTS, 1);
+		immBegin(PRIM_POINTS, 1);
 		immVertex2fv(pos, vert);
 		immEnd();
+
 		immUnbindProgram();
 
 		minmax_v2v2_v2(min, max, vert);
 	}
 
-	immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+	if (is_smooth) {
+		glDisable(GL_LINE_SMOOTH);
+	}
 
 	if (is_spline_sel) {
-		float x = (min[0] + max[0]) / 2.0f;
-		float y = (min[1] + max[1]) / 2.0f;
-		const unsigned char active_spline_color[3] = { 255, 255, 255 };
-		const unsigned char inactive_spline_color[3] = { 255, 255, 0 };
+		float x = (min[0] + max[0]) * 0.5f;
+		float y = (min[1] + max[1]) * 0.5f;
+
+		immBindBuiltinProgram(GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_SMOOTH);
+		immUniform1f("outlineWidth", 1.5f);
 
 		if (masklay->act_spline == spline) {
-			immUniformColor3ubv(active_spline_color);
+			immUniformColor3f(1.0f, 1.0f, 1.0f);
 		}
 		else {
-			immUniformColor3ubv(inactive_spline_color);
+			immUniformColor3f(1.0f, 1.0f, 0.0f);
 		}
 
-		draw_circle(x, y, 6.0f, true, scale, pos);
+		immUniform4f("outlineColor", 0.0f, 0.0f, 0.0f, 1.0f);
+		immUniform1f("size", 12.0f);
 
-		immUniformColor3ub(0, 0, 0);
-		draw_circle(x, y, 6.0f, false, scale, pos);
-	}
-	immUnbindProgram();
+		immBegin(PRIM_POINTS, 1);
+		immVertex2f(pos, x, y);
+		immEnd();
 
-	if (is_smooth) {
-		glDisable(GL_LINE_SMOOTH);
-		glDisable(GL_BLEND);
+		immUnbindProgram();
 	}
 }
 
@@ -379,7 +378,7 @@ static void mask_draw_array(unsigned int pos, PrimitiveType prim_type, const flo
 }
 
 static void mask_draw_curve_type(const bContext *C, MaskSpline *spline, float (*orig_points)[2], int tot_point,
-                                 const bool is_feather, const bool is_smooth, const bool is_active,
+                                 const bool is_feather, const bool is_active,
                                  const unsigned char rgb_spline[4], const char draw_type)
 {
 	const PrimitiveType draw_method = (spline->flag & MASK_SPLINE_CYCLIC) ? PRIM_LINE_LOOP : PRIM_LINE_STRIP;
@@ -443,19 +442,10 @@ static void mask_draw_curve_type(const bContext *C, MaskSpline *spline, float (*
 				rgb_tmp[2] = (unsigned char)(((short)rgb_tmp[2] + (short)rgb_spline[2]) / 2);
 			}
 
-			if (is_smooth == false && is_feather) {
-				glEnable(GL_BLEND);
-				glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-			}
-
 			mask_color_active_tint(rgb_tmp, rgb_tmp, is_active);
 			immUniformColor4ubv(rgb_tmp);
 			mask_draw_array(pos, draw_method, points, tot_point);
 
-			if (is_smooth == false && is_feather) {
-				glDisable(GL_BLEND);
-			}
-
 			immUnbindProgram();
 			break;
 
@@ -517,8 +507,6 @@ static void draw_spline_curve(const bContext *C, MaskLayer *masklay, MaskSpline
 
 	if (is_smooth) {
 		glEnable(GL_LINE_SMOOTH);
-		glEnable(GL_BLEND);
-		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 	}
 
 	feather_points = BKE_mask_spline_feather_differentiated_points_with_resolution(spline, &tot_feather_point, resol, (is_fill != false));
@@ -526,26 +514,24 @@ static void draw_spline_curve(const bContext *C, MaskLayer *masklay, MaskSpline
 	/* draw feather */
 	mask_spline_feather_color_get(masklay, spline, is_spline_sel, rgb_tmp);
 	mask_draw_curve_type(C, spline, feather_points, tot_feather_point,
-	                     true, is_smooth, is_active,
+	                     true, is_active,
 	                     rgb_tmp, draw_type);
 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list