[Bf-blender-cvs] [a54110751a] blender2.8: OpenGL immediate mode: interface_draw.c (cont)

Clément Foucault noreply at git.blender.org
Tue Feb 7 00:27:42 CET 2017


Commit: a54110751a34c6f9641575258959dbaf6e43f2f3
Author: Clément Foucault
Date:   Mon Feb 6 16:54:26 2017 +0100
Branches: blender2.8
https://developer.blender.org/rBa54110751a34c6f9641575258959dbaf6e43f2f3

OpenGL immediate mode: interface_draw.c (cont)

ui_draw_but_HISTOGRAM
UI_draw_text_underline (untested)

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

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_draw.c
M	source/blender/editors/interface/interface_widgets.c

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

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index a4bd4b8010..286ac6054e 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -318,7 +318,7 @@ void UI_draw_roundbox_gl_mode_3fvAlpha(int mode, float minx, float miny, float m
 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);
+void UI_draw_text_underline(int pos_x, int pos_y, int len, int height, const float color[4]);
 
 void UI_draw_safe_areas(
         unsigned pos, float x1, float x2, float y1, float y2,
diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c
index b3769f537e..60df380923 100644
--- a/source/blender/editors/interface/interface_draw.c
+++ b/source/blender/editors/interface/interface_draw.c
@@ -449,10 +449,18 @@ void UI_draw_roundbox(float minx, float miny, float maxx, float maxy, float rad,
 	ui_draw_anti_roundbox(GL_TRIANGLE_FAN, minx, miny, maxx, maxy, rad, roundboxtype & UI_RB_ALPHA, color);
 }
 
-void UI_draw_text_underline(int pos_x, int pos_y, int len, int height)
+void UI_draw_text_underline(int pos_x, int pos_y, int len, int height, const float color[4])
 {
 	int ofs_y = 4 * U.pixelsize;
-	glRecti(pos_x, pos_y - ofs_y, pos_x + len, pos_y - ofs_y + (height * U.pixelsize));
+
+	VertexFormat *format = immVertexFormat();
+	unsigned pos = add_attrib(format, "pos", GL_INT, 2, CONVERT_INT_TO_FLOAT);
+
+	immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+	immUniformColor4fv(color);
+
+	immRecti(pos, pos_x, pos_y - ofs_y, pos_x + len, pos_y - ofs_y + (height * U.pixelsize));
+	immUnbindProgram();
 }
 
 /* ************** SPECIAL BUTTON DRAWING FUNCTIONS ************* */
@@ -556,45 +564,49 @@ static void draw_scope_end(const rctf *rect, GLint *scissor)
 
 static void histogram_draw_one(
         float r, float g, float b, float alpha,
-        float x, float y, float w, float h, const float *data, int res, const bool is_line)
+        float x, float y, float w, float h, const float *data, int res, const bool is_line,
+        unsigned int pos_attrib)
 {
+	float color[4] = {r, g, b, alpha};
+
 	glEnable(GL_LINE_SMOOTH);
 	glBlendFunc(GL_SRC_ALPHA, GL_ONE);
-	glColor4f(r, g, b, alpha);
+
+	immUniformColor4fv(color);
 
 	if (is_line) {
 		/* curve outline */
 		glLineWidth(1.5);
 
-		glBegin(GL_LINE_STRIP);
+		immBegin(GL_LINE_STRIP, res);
 		for (int i = 0; i < res; i++) {
 			float x2 = x + i * (w / (float)res);
-			glVertex2f(x2, y + (data[i] * h));
+			immVertex2f(pos_attrib, x2, y + (data[i] * h));
 		}
-		glEnd();
+		immEnd();
 	}
 	else {
 		/* under the curve */
-		glBegin(GL_TRIANGLE_STRIP);
-		glVertex2f(x, y);
-		glVertex2f(x, y + (data[0] * h));
+		immBegin(GL_TRIANGLE_STRIP, res*2);
+		immVertex2f(pos_attrib, x, y);
+		immVertex2f(pos_attrib, x, y + (data[0] * h));
 		for (int i = 1; i < res; i++) {
 			float x2 = x + i * (w / (float)res);
-			glVertex2f(x2, y + (data[i] * h));
-			glVertex2f(x2, y);
+			immVertex2f(pos_attrib, x2, y + (data[i] * h));
+			immVertex2f(pos_attrib, x2, y);
 		}
-		glEnd();
+		immEnd();
 
 		/* curve outline */
-		glColor4f(0.f, 0.f, 0.f, 0.25f);
+		immUniformColor4f(0.f, 0.f, 0.f, 0.25f);
 
 		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-		glBegin(GL_LINE_STRIP);
+		immBegin(GL_LINE_STRIP, res);
 		for (int i = 0; i < res; i++) {
 			float x2 = x + i * (w / (float)res);
-			glVertex2f(x2, y + (data[i] * h));
+			immVertex2f(pos_attrib, x2, y + (data[i] * h));
 		}
-		glEnd();
+		immEnd();
 	}
 
 	glDisable(GL_LINE_SMOOTH);
@@ -607,7 +619,7 @@ void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol)
 	Histogram *hist = (Histogram *)but->poin;
 	int res = hist->x_resolution;
 	const bool is_line = (hist->flag & HISTO_FLAG_LINE) != 0;
-	
+
 	rctf rect = {
 		.xmin = (float)recti->xmin + 1,
 		.xmax = (float)recti->xmax - 1,
@@ -634,34 +646,41 @@ void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol)
 	          (rect.xmax + 1) - (rect.xmin - 1),
 	          (rect.ymax + 1) - (rect.ymin - 1));
 
-	glColor4f(1.f, 1.f, 1.f, 0.08f);
+	VertexFormat *format = immVertexFormat();
+	unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
+
+	immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+	immUniformColor4f(1.f, 1.f, 1.f, 0.08f);
 	/* draw grid lines here */
 	for (int i = 1; i <= HISTOGRAM_TOT_GRID_LINES; i++) {
 		const float fac = (float)i / (float)HISTOGRAM_TOT_GRID_LINES;
 
 		/* so we can tell the 1.0 color point */
 		if (i == HISTOGRAM_TOT_GRID_LINES) {
-			glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
+			immUniformColor4f(1.0f, 1.0f, 1.0f, 0.5f);
 		}
 
-		fdrawline(rect.xmin, rect.ymin + fac * h, rect.xmax, rect.ymin + fac * h);
-		fdrawline(rect.xmin + fac * w, rect.ymin, rect.xmin + fac * w, rect.ymax);
+		imm_draw_line(pos, rect.xmin, rect.ymin + fac * h, rect.xmax, rect.ymin + fac * h);
+		imm_draw_line(pos, rect.xmin + fac * w, rect.ymin, rect.xmin + fac * w, rect.ymax);
 	}
-	
+
 	if (hist->mode == HISTO_MODE_LUMA) {
-		histogram_draw_one(1.0, 1.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_luma, res, is_line);
+		histogram_draw_one(1.0, 1.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_luma, res, is_line, pos);
 	}
 	else if (hist->mode == HISTO_MODE_ALPHA) {
-		histogram_draw_one(1.0, 1.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_a, res, is_line);
+		histogram_draw_one(1.0, 1.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_a, res, is_line, pos);
 	}
 	else {
 		if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_R)
-			histogram_draw_one(1.0, 0.0, 0.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_r, res, is_line);
+			histogram_draw_one(1.0, 0.0, 0.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_r, res, is_line, pos);
 		if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_G)
-			histogram_draw_one(0.0, 1.0, 0.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_g, res, is_line);
+			histogram_draw_one(0.0, 1.0, 0.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_g, res, is_line, pos);
 		if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_B)
-			histogram_draw_one(0.0, 0.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_b, res, is_line);
+			histogram_draw_one(0.0, 0.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_b, res, is_line, pos);
 	}
+
+	immUnbindProgram();
 	
 	/* outline */
 	draw_scope_end(&rect, scissor);
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 3718188fe1..b580d394dd 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -1251,6 +1251,7 @@ static void widget_draw_text_ime_underline(
 	int ofs_x, width;
 	int rect_x = BLI_rcti_size_x(rect);
 	int sel_start = ime_data->sel_start, sel_end = ime_data->sel_end;
+	float fcol[4];
 
 	if (drawstr[0] != 0) {
 		if (but->pos >= but->ofs) {
@@ -1263,8 +1264,8 @@ static void widget_draw_text_ime_underline(
 		width = BLF_width(fstyle->uifont_id, drawstr + but->ofs,
 		                  ime_data->composite_len + but->pos - but->ofs);
 
-		glColor4ubv((unsigned char *)wcol->text);
-		UI_draw_text_underline(rect->xmin + ofs_x, rect->ymin + 6 * U.pixelsize, min_ii(width, rect_x - 2) - ofs_x, 1);
+		rgba_uchar_to_float(fcol, wcol->text);
+		UI_draw_text_underline(rect->xmin + ofs_x, rect->ymin + 6 * U.pixelsize, min_ii(width, rect_x - 2) - ofs_x, 1, fcol);
 
 		/* draw the thick line */
 		if (sel_start != -1 && sel_end != -1) {
@@ -1281,7 +1282,7 @@ static void widget_draw_text_ime_underline(
 			width = BLF_width(fstyle->uifont_id, drawstr + but->ofs,
 			                  sel_end + sel_start - but->ofs);
 
-			UI_draw_text_underline(rect->xmin + ofs_x, rect->ymin + 6 * U.pixelsize, min_ii(width, rect_x - 2) - ofs_x, 2);
+			UI_draw_text_underline(rect->xmin + ofs_x, rect->ymin + 6 * U.pixelsize, min_ii(width, rect_x - 2) - ofs_x, 2, fcol);
 		}
 	}
 }




More information about the Bf-blender-cvs mailing list