[Bf-blender-cvs] [fe59296] blender2.8: OpenGL: new immediate mode in area.c

Mike Erwin noreply at git.blender.org
Tue Dec 13 20:53:00 CET 2016


Commit: fe5929636182b6721743893c9a2efce1193d335e
Author: Mike Erwin
Date:   Tue Dec 13 14:51:39 2016 -0500
Branches: blender2.8
https://developer.blender.org/rBfe5929636182b6721743893c9a2efce1193d335e

OpenGL: new immediate mode in area.c

D2361 by @punya, part of T49043

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

M	source/blender/editors/screen/area.c

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

diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index 7ad4df6..9a04d5e 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -221,11 +221,23 @@ static void area_draw_azone_fullscreen(short x1, short y1, short x2, short y2, f
 
 		BLI_rcti_init(&click_rect, x, x + icon_size, y, y + icon_size);
 
-		glColor4ub(255, 0, 0, alpha_debug);
-		fdrawbox(click_rect.xmin, click_rect.ymin, click_rect.xmax, click_rect.ymax);
-		glColor4ub(0, 255, 255, alpha_debug);
-		fdrawline(click_rect.xmin, click_rect.ymin, click_rect.xmax, click_rect.ymax);
-		fdrawline(click_rect.xmin, click_rect.ymax, click_rect.xmax, click_rect.ymin);
+		VertexFormat* format = immVertexFormat();
+		unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
+		unsigned color = add_attrib(format, "color", GL_UNSIGNED_BYTE, 4, KEEP_INT);
+
+		immAttrib4ub(color, 255, 0, 0, alpha_debug);
+		immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+		imm_draw_line_box(pos, click_rect.xmin, click_rect.ymin, click_rect.xmax, click_rect.ymax);
+
+		immAttrib4ub(color, 0, 255, 255, alpha_debug);
+		immBegin(GL_LINES, 4);
+		immVertex2f(pos, click_rect.xmin, click_rect.ymin);
+		immVertex2f(pos, click_rect.xmax, click_rect.ymax);
+		immVertex2f(pos, click_rect.xmin, click_rect.ymax);
+		immVertex2f(pos, click_rect.xmax, click_rect.ymin);
+		immEnd();
+
+		immUnbindProgram();
 	}
 }
 
@@ -313,10 +325,17 @@ static void draw_azone_plus(float x1, float y1, float x2, float y2)
 {
 	float width = 0.1f * U.widget_unit;
 	float pad = 0.2f * U.widget_unit;
-	
-	glRectf((x1 + x2 - width) * 0.5f, y1 + pad, (x1 + x2 + width) * 0.5f, y2 - pad);
-	glRectf(x1 + pad, (y1 + y2 - width) * 0.5f, (x1 + x2 - width) * 0.5f, (y1 + y2 + width) * 0.5f);
-	glRectf((x1 + x2 + width) * 0.5f, (y1 + y2 - width) * 0.5f, x2 - pad, (y1 + y2 + width) * 0.5f);
+
+	VertexFormat* format = immVertexFormat();
+	unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
+
+	immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+	immRectf(pos, (x1 + x2 - width) * 0.5f, y1 + pad, (x1 + x2 + width) * 0.5f, y2 - pad);
+	immRectf(pos, x1 + pad, (y1 + y2 - width) * 0.5f, (x1 + x2 - width) * 0.5f, (y1 + y2 + width) * 0.5f);
+	immRectf(pos, (x1 + x2 + width) * 0.5f, (y1 + y2 - width) * 0.5f, x2 - pad, (y1 + y2 + width) * 0.5f);
+
+	immUnbindProgram();
 }
 
 static void region_draw_azone_tab_plus(AZone *az)
@@ -553,9 +572,13 @@ void ED_region_do_draw(bContext *C, ARegion *ar)
 	/* for debugging unneeded area redraws and partial redraw */
 #if 0
 	glEnable(GL_BLEND);
-	glColor4f(drand48(), drand48(), drand48(), 0.1f);
-	glRectf(ar->drawrct.xmin - ar->winrct.xmin, ar->drawrct.ymin - ar->winrct.ymin,
+	VertexFormat* format = immVertexFormat();
+	unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
+	immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+	immUniformColor4f(drand48(), drand48(), drand48(), 0.1f);
+	immRectf(pos, ar->drawrct.xmin - ar->winrct.xmin, ar->drawrct.ymin - ar->winrct.ymin,
 	        ar->drawrct.xmax - ar->winrct.xmin, ar->drawrct.ymax - ar->winrct.ymin);
+	immUnbindProgram();
 	glDisable(GL_BLEND);
 #endif
 
@@ -1993,8 +2016,12 @@ void ED_region_panels(const bContext *C, ARegion *ar, const char *context, int c
 		/* view should be in pixelspace */
 		UI_view2d_view_restore(C);
 		glEnable(GL_BLEND);
-		UI_ThemeColor4((ar->type->regionid == RGN_TYPE_PREVIEW) ? TH_PREVIEW_BACK : TH_BACK);
-		glRecti(0, 0, BLI_rcti_size_x(&ar->winrct), BLI_rcti_size_y(&ar->winrct) + 1);
+		VertexFormat* format = immVertexFormat();
+		unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
+		immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+		immUniformThemeColor((ar->type->regionid == RGN_TYPE_PREVIEW) ? TH_PREVIEW_BACK : TH_BACK);
+		immRecti(pos, 0, 0, BLI_rcti_size_x(&ar->winrct), BLI_rcti_size_y(&ar->winrct) + 1);
+		immUnbindProgram();
 		glDisable(GL_BLEND);
 	}
 	else {
@@ -2123,8 +2150,12 @@ void ED_region_info_draw(ARegion *ar, const char *text, float fill_color[4], con
 
 	glEnable(GL_BLEND);
 	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-	glColor4fv(fill_color);
-	glRecti(rect.xmin, rect.ymin, rect.xmax + 1, rect.ymax + 1);
+	VertexFormat* format = immVertexFormat();
+	unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
+	immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+	immUniformColor4fv(fill_color);
+	immRecti(pos, rect.xmin, rect.ymin, rect.xmax + 1, rect.ymax + 1);
+	immUnbindProgram();
 	glDisable(GL_BLEND);
 
 	/* text */
@@ -2323,12 +2354,15 @@ void ED_region_image_metadata_draw(int x, int y, ImBuf *ibuf, const rctf *frame,
 	box_y = metadata_box_height_get(ibuf, blf_mono_font, true);
 
 	if (box_y) {
-		UI_ThemeColor(TH_METADATA_BG);
-
 		/* set up rect */
 		BLI_rctf_init(&rect, frame->xmin, frame->xmax, frame->ymax, frame->ymax + box_y);
 		/* draw top box */
-		glRectf(rect.xmin, rect.ymin, rect.xmax, rect.ymax);
+		VertexFormat* format = immVertexFormat();
+		unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
+		immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+		immUniformThemeColor(TH_METADATA_BG);
+		immRectf(pos, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
+		immUnbindProgram();
 
 		BLF_clipping(blf_mono_font, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
 		BLF_enable(blf_mono_font, BLF_CLIPPING);
@@ -2345,12 +2379,15 @@ void ED_region_image_metadata_draw(int x, int y, ImBuf *ibuf, const rctf *frame,
 	box_y = metadata_box_height_get(ibuf, blf_mono_font, false);
 
 	if (box_y) {
-		UI_ThemeColor(TH_METADATA_BG);
-
 		/* set up box rect */
 		BLI_rctf_init(&rect, frame->xmin, frame->xmax, frame->ymin - box_y, frame->ymin);
 		/* draw top box */
-		glRectf(rect.xmin, rect.ymin, rect.xmax, rect.ymax);
+		VertexFormat* format = immVertexFormat();
+		unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
+		immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+		immUniformThemeColor(TH_METADATA_BG);
+		immRectf(pos, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
+		immUnbindProgram();
 
 		BLF_clipping(blf_mono_font, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
 		BLF_enable(blf_mono_font, BLF_CLIPPING);
@@ -2482,8 +2519,13 @@ void ED_region_visible_rect(ARegion *ar, rcti *rect)
 
 void ED_region_cache_draw_background(const ARegion *ar)
 {
-	glColor4ub(128, 128, 255, 64);
-	glRecti(0, 0, ar->winx, 8 * UI_DPI_FAC);
+	VertexFormat* format = immVertexFormat();
+	unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
+
+	immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+	immUniformColor4ub(128, 128, 255, 64);
+	immRecti(pos, 0, 0, ar->winx, 8 * UI_DPI_FAC);
+	immUnbindProgram();
 }
 
 void ED_region_cache_draw_curfra_label(const int framenr, const float x, const float y)




More information about the Bf-blender-cvs mailing list