[Bf-blender-cvs] [f69678482c8] blender2.8: OpenGL: refactor UI_draw_roundbox functions

Mike Erwin noreply at git.blender.org
Fri Apr 7 01:38:35 CEST 2017


Commit: f69678482c849d873b9686cd6068946205db7c2b
Author: Mike Erwin
Date:   Thu Apr 6 19:15:26 2017 -0400
Branches: blender2.8
https://developer.blender.org/rBf69678482c849d873b9686cd6068946205db7c2b

OpenGL: refactor UI_draw_roundbox functions

Each function takes a bool (filled vs outline) and a color. We already had multiple ways of passing color in; these are still here. Special variant for anti-aliasing.

- took GLenum out of interface
- removed UI_RB_ALPHA flag (only one place really used it)
- use exact vertex count
- removed redundant state changes (BLEND, LINE_SMOOTH)

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

M	source/blender/editors/animation/anim_channels_defines.c
M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_draw.c
M	source/blender/editors/interface/interface_panel.c
M	source/blender/editors/interface/interface_style.c
M	source/blender/editors/interface/interface_widgets.c
M	source/blender/editors/screen/area.c
M	source/blender/editors/space_file/file_draw.c
M	source/blender/editors/space_nla/nla_draw.c
M	source/blender/editors/space_node/drawnode.c
M	source/blender/editors/space_node/node_draw.c
M	source/blender/editors/space_outliner/outliner_draw.c
M	source/blender/editors/space_text/text_draw.c
M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/editors/space_view3d/view3d_ruler.c

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

diff --git a/source/blender/editors/animation/anim_channels_defines.c b/source/blender/editors/animation/anim_channels_defines.c
index c8ece34cb3c..17bca28cba7 100644
--- a/source/blender/editors/animation/anim_channels_defines.c
+++ b/source/blender/editors/animation/anim_channels_defines.c
@@ -123,7 +123,7 @@ static void acf_generic_root_backdrop(bAnimContext *ac, bAnimListElem *ale, floa
 	
 	/* rounded corners on LHS only - top only when expanded, but bottom too when collapsed */
 	UI_draw_roundbox_corner_set((expanded) ? UI_CNR_TOP_LEFT : (UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT));
-	UI_draw_roundbox_gl_mode_3fvAlpha(GL_TRIANGLE_FAN, offset,  yminc, v2d->cur.xmax + EXTRA_SCROLL_PAD, ymaxc, 8, color, 1.0f);
+	UI_draw_roundbox_3fvAlpha(true, offset,  yminc, v2d->cur.xmax + EXTRA_SCROLL_PAD, ymaxc, 8, color, 1.0f);
 }
 
 
@@ -439,7 +439,7 @@ static void acf_summary_backdrop(bAnimContext *ac, bAnimListElem *ale, float ymi
 	 *	- special hack: make the top a bit higher, since we are first... 
 	 */
 	UI_draw_roundbox_corner_set(UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT);
-	UI_draw_roundbox_gl_mode_3fvAlpha(GL_TRIANGLE_FAN, 0,  yminc - 2, v2d->cur.xmax + EXTRA_SCROLL_PAD, ymaxc, 8, color, 1.0f);
+	UI_draw_roundbox_3fvAlpha(true, 0,  yminc - 2, v2d->cur.xmax + EXTRA_SCROLL_PAD, ymaxc, 8, color, 1.0f);
 }
 
 /* name for summary entries */
@@ -828,7 +828,7 @@ static void acf_group_backdrop(bAnimContext *ac, bAnimListElem *ale, float yminc
 	
 	/* rounded corners on LHS only - top only when expanded, but bottom too when collapsed */
 	UI_draw_roundbox_corner_set(expanded ? UI_CNR_TOP_LEFT : (UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT));
-	UI_draw_roundbox_gl_mode_3fvAlpha(GL_TRIANGLE_FAN, offset,  yminc, v2d->cur.xmax + EXTRA_SCROLL_PAD, ymaxc, 8, color, 1.0f);
+	UI_draw_roundbox_3fvAlpha(true, offset,  yminc, v2d->cur.xmax + EXTRA_SCROLL_PAD, ymaxc, 8, color, 1.0f);
 }
 
 /* name for group entries */
@@ -1084,7 +1084,7 @@ static void acf_nla_controls_backdrop(bAnimContext *ac, bAnimListElem *ale, floa
 	
 	/* rounded corners on LHS only - top only when expanded, but bottom too when collapsed */	
 	UI_draw_roundbox_corner_set(expanded ? UI_CNR_TOP_LEFT : (UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT));
-	UI_draw_roundbox_gl_mode_3fvAlpha(GL_TRIANGLE_FAN, offset,  yminc, v2d->cur.xmax + EXTRA_SCROLL_PAD, ymaxc, 5, color, 1.0f);
+	UI_draw_roundbox_3fvAlpha(true, offset,  yminc, v2d->cur.xmax + EXTRA_SCROLL_PAD, ymaxc, 5, color, 1.0f);
 }
 
 /* name for nla controls expander entries */
@@ -3438,7 +3438,7 @@ static void acf_nlaaction_backdrop(bAnimContext *ac, bAnimListElem *ale, float y
 	/* draw slightly shifted up vertically to look like it has more separation from other channels,
 	 * but we then need to slightly shorten it so that it doesn't look like it overlaps
 	 */
-	UI_draw_roundbox_gl_mode(GL_TRIANGLE_FAN, offset,  yminc + NLACHANNEL_SKIP, (float)v2d->cur.xmax, ymaxc + NLACHANNEL_SKIP - 1, 8, color);
+	UI_draw_roundbox_4fv(true, offset,  yminc + NLACHANNEL_SKIP, (float)v2d->cur.xmax, ymaxc + NLACHANNEL_SKIP - 1, 8, color);
 }
 
 /* name for nla action entries */
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 358df02ea9d..c0b457be918 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -309,16 +309,19 @@ typedef enum {
  * Functions to draw various shapes, taking theme settings into account.
  * Used for code that draws its own UI style elements. */
 
-void UI_draw_roundbox(float minx, float miny, float maxx, float maxy, float rad, const float color[4]);
 void UI_draw_roundbox_corner_set(int type);
+void UI_draw_roundbox_aa(bool filled, float minx, float miny, float maxx, float maxy, float rad, const float color[4]);
+void UI_draw_roundbox_4fv(bool filled, float minx, float miny, float maxx, float maxy, float rad, const float col[4]);
+void UI_draw_roundbox_3ubAlpha(bool filled, float minx, float miny, float maxx, float maxy, float rad, const unsigned char col[3], unsigned char alpha);
+void UI_draw_roundbox_3fvAlpha(bool filled, float minx, float miny, float maxx, float maxy, float rad, const float col[3], float alpha);
+void UI_draw_roundbox_shade_x(bool filled, float minx, float miny, float maxx, float maxy, float rad, float shadetop, float shadedown, const float col[4]);
+
+#if 0 /* unused */
 int  UI_draw_roundbox_corner_get(void);
-void UI_draw_roundbox_unfilled(float minx, float miny, float maxx, float maxy, float rad, const float color[4]);
+void UI_draw_roundbox_shade_y(bool filled, float minx, float miny, float maxx, float maxy, float rad, float shadeleft, float shaderight, const float col[4]);
+#endif
+
 void UI_draw_box_shadow(unsigned char alpha, float minx, float miny, float maxx, float maxy);
-void UI_draw_roundbox_gl_mode_3ubAlpha(int mode, float minx, float miny, float maxx, float maxy, float rad, unsigned char col[3], unsigned char alpha);
-void UI_draw_roundbox_gl_mode_3fvAlpha(int mode, float minx, float miny, float maxx, float maxy, float rad, float col[3], float alpha);
-void UI_draw_roundbox_gl_mode(int mode, float minx, float miny, float maxx, float maxy, float rad, float col[4]);
-void UI_draw_roundbox_shade_x(int mode, float minx, float miny, float maxx, float maxy, float rad, float shadetop, float shadedown, const float col[4]);
-void UI_draw_roundbox_shade_y(int mode, float minx, float miny, float maxx, float maxy, float rad, float shadeleft, float shaderight, const float col[4]);
 void UI_draw_text_underline(int pos_x, int pos_y, int len, int height, const float color[4]);
 
 void UI_draw_safe_areas(
@@ -855,9 +858,6 @@ enum {
 	UI_CNR_ALL          = (UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT)
 };
 
-/* not apart of the corner flags but mixed in some functions  */
-#define UI_RB_ALPHA (UI_CNR_ALL + 1)
-
 uiLayout *UI_block_layout(uiBlock *block, int dir, int type, int x, int y, int size, int em, int padding, struct uiStyle *style);
 void UI_block_layout_set_current(uiBlock *block, uiLayout *layout);
 void UI_block_layout_resolve(uiBlock *block, int *x, int *y);
diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c
index 4f056589867..89d9fe992ba 100644
--- a/source/blender/editors/interface/interface_draw.c
+++ b/source/blender/editors/interface/interface_draw.c
@@ -72,35 +72,36 @@ void UI_draw_roundbox_corner_set(int type)
 	 * if this is undone, it's not that big a deal, only makes curves edges
 	 * square for the  */
 	roundboxtype = type;
-	
 }
 
+#if 0 /* unused */
 int UI_draw_roundbox_corner_get(void)
 {
 	return roundboxtype;
 }
+#endif
 
-void UI_draw_roundbox_gl_mode_3ubAlpha(int mode, float minx, float miny, float maxx, float maxy, float rad, unsigned char col[3], unsigned char alpha)
+void UI_draw_roundbox_3ubAlpha(bool filled, float minx, float miny, float maxx, float maxy, float rad, const unsigned char col[3], unsigned char alpha)
 {
 	float colv[4];
 	colv[0] = ((float)col[0]) / 255;
 	colv[1] = ((float)col[1]) / 255;
 	colv[2] = ((float)col[2]) / 255;
 	colv[3] = ((float)alpha) / 255;
-	UI_draw_roundbox_gl_mode(mode, minx, miny, maxx, maxy, rad, colv);
+	UI_draw_roundbox_4fv(filled, minx, miny, maxx, maxy, rad, colv);
 }
 
-void UI_draw_roundbox_gl_mode_3fvAlpha(int mode, float minx, float miny, float maxx, float maxy, float rad, float col[3], float alpha)
+void UI_draw_roundbox_3fvAlpha(bool filled, float minx, float miny, float maxx, float maxy, float rad, const float col[3], float alpha)
 {
 	float colv[4];
 	colv[0] = col[0];
 	colv[1] = col[1];
 	colv[2] = col[2];
 	colv[3] = alpha;
-	UI_draw_roundbox_gl_mode(mode, minx, miny, maxx, maxy, rad, colv);
+	UI_draw_roundbox_4fv(filled, minx, miny, maxx, maxy, rad, colv);
 }
 
-void UI_draw_roundbox_gl_mode(int mode, float minx, float miny, float maxx, float maxy, float rad, float col[4])
+void UI_draw_roundbox_4fv(bool filled, float minx, float miny, float maxx, float maxy, float rad, const float col[4])
 {
 	float vec[7][2] = {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, {0.707, 0.293},
 	                   {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}};
@@ -114,12 +115,16 @@ void UI_draw_roundbox_gl_mode(int mode, float minx, float miny, float maxx, floa
 		mul_v2_fl(vec[a], rad);
 	}
 
-	BLI_assert(mode != GL_POLYGON);
+	unsigned int vert_ct = 0;
+	vert_ct += (roundboxtype & UI_CNR_BOTTOM_RIGHT) ? 9 : 1;
+	vert_ct += (roundboxtype & UI_CNR_TOP_RIGHT) ? 9 : 1;
+	vert_ct += (roundboxtype & UI_CNR_TOP_LEFT) ? 9 : 1;
+	vert_ct += (roundboxtype & UI_CNR_BOTTOM_LEFT) ? 9 : 1;
 
 	immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
 	immUniformColor4fv(col);
 
-	immBeginAtMost(mode, 36);
+	immBegin(filled ? PRIM_TRIANGLE_FAN : PRIM_LINE_LOOP, vert_ct);
 	/* start with corner right-bottom */
 	if (roundboxtype & UI_CNR_BOTTOM_RIGHT) {
 		immVertex2f(pos, maxx - rad, miny);
@@ -186,7 +191,7 @@ static void round_box_shade_col(unsigned attrib, const float col1[3], float cons
 /* linear horizontal shade within button or in outline */
 /* view2d scrollers use it */
 void UI_draw_roundbox_shade_x(
-        int mode, float minx, float miny, float maxx, float maxy,
+        bool filled, float minx, float miny, float maxx, float maxy,
         float rad, float shadetop, float shadedown, const float col[4])
 {
 	float vec[7][2] = {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, {0.707, 0.293},
@@ -208,8 +213,6 @@ void UI_draw_roundbox_shade_x(
 		mul_v2_fl(vec[a], rad);
 	}
 
-	BLI_assert(mode != GL_POLYGON);
-
 	/* 'shade' defines strength of shading */
 	coltop[0]  = min_ff(1.0f, col[0] + shadetop);
 	coltop[1]  = min_ff(1.0f, col[1] + shadetop);
@@ -223,7 +226,7 @@ void UI_draw_roundbox_shade_x(
 	vert_count += (roundboxtype & UI_CNR_TOP_LEFT) ? 9 : 1;
 	vert_count += (roundboxtype & UI_CNR_BOTTOM_LEFT) ? 9 : 1;
 
-	immBegin(mode, vert_count);
+	immBegin(filled ? PRIM_TRIANGLE_FAN : PRIM_LINE_LOOP, vert_count);
 
 	/* start with corner right-bottom */
 	if (roundboxtype & UI_CNR_BOTTOM_RIGHT) {
@@ -304,10 +307,11 @@ void UI_draw_roundbox_shade_x(
 	immUnbindProgram();
 }
 
+#if 0 /* unused */
 /* linear vertical shade within button or in outline */
 /* view2d scrol

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list