[Bf-blender-cvs] [1fc1fd8] blender2.8: OpenGL: draw area resize handle with new immediate mode

Mike Erwin noreply at git.blender.org
Tue Aug 23 05:40:03 CEST 2016


Commit: 1fc1fd837209d31608dbb89ff90ddb31ed89107c
Author: Mike Erwin
Date:   Mon Aug 22 23:39:42 2016 -0400
Branches: blender2.8
https://developer.blender.org/rB1fc1fd837209d31608dbb89ff90ddb31ed89107c

OpenGL: draw area resize handle with new immediate mode

The little grabby handle in the corner of an area. Now uses 1 draw call
instead of 6.

Also one version of the (+) icon to show a hidden region. Why do we
have multiple versions of this?

Fixed a harmless signed/unsigned error.

Fixed a GL state error that prematurely disabled blending.

Added imm_draw_filled_circle function, which can be used for drawing
other widgets.

Work toward T49042 and T49043

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

M	source/blender/editors/include/BIF_glutil.h
M	source/blender/editors/screen/area.c
M	source/blender/editors/screen/glutil.c

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

diff --git a/source/blender/editors/include/BIF_glutil.h b/source/blender/editors/include/BIF_glutil.h
index 40d4639..a5a1200 100644
--- a/source/blender/editors/include/BIF_glutil.h
+++ b/source/blender/editors/include/BIF_glutil.h
@@ -81,10 +81,8 @@ void glutil_draw_lined_arc(float start, float angle, float radius, int nsegments
 void glutil_draw_filled_arc(float start, float angle, float radius, int nsegments);
 
 /**
- * Draw a circle outline with the given \a radius,
- * starting at angle \a start and arcing through
- * \a angle. The circle is centered at \a x, \a y
- * and drawn in the XY plane.
+ * Draw a circle outline with the given \a radius.
+ * The circle is centered at \a x, \a y and drawn in the XY plane.
  *
  * \param pos The vertex attribute number for position.
  * \param x Horizontal center.
@@ -95,6 +93,18 @@ void glutil_draw_filled_arc(float start, float angle, float radius, int nsegment
 void imm_draw_lined_circle(unsigned pos, float x, float y, float radius, int nsegments);
 
 /**
+ * Draw a filled circle with the given \a radius.
+ * The circle is centered at \a x, \a y and drawn in the XY plane.
+ *
+ * \param pos The vertex attribute number for position.
+ * \param x Horizontal center.
+ * \param y Vertical center.
+ * \param radius The circle's radius.
+ * \param nsegments The number of segments to use in drawing (more = smoother).
+ */
+void imm_draw_filled_circle(unsigned pos, float x, float y, float radius, int nsegments);
+
+/**
  * Returns a float value as obtained by glGetFloatv.
  * The param must cause only one value to be gotten from GL.
  */
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index 8d058ed..0924f02 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -57,6 +57,9 @@
 #include "ED_screen_types.h"
 #include "ED_space_api.h"
 
+#include "GPU_shader.h"
+#include "GPU_immediate.h"
+
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 #include "BLF_api.h"
@@ -206,7 +209,7 @@ static void area_draw_azone_fullscreen(short x1, short y1, short x2, short y2, f
 	if (G.debug_value == 1) {
 		rcti click_rect;
 		float icon_size = UI_DPI_ICON_SIZE + 7 * UI_DPI_FAC;
-		char alpha_debug = 255 * alpha;
+		unsigned char alpha_debug = 255 * alpha;
 
 		BLI_rcti_init(&click_rect, x, x + icon_size, y, y + icon_size);
 
@@ -229,59 +232,73 @@ static void area_draw_azone(short x1, short y1, short x2, short y2)
 	dx = copysign(ceilf(0.3f * abs(dx)), dx);
 	dy = copysign(ceilf(0.3f * abs(dy)), dy);
 
-	glEnable(GL_BLEND);
 	glEnable(GL_LINE_SMOOTH);
+
+	VertexFormat* format = immVertexFormat();
+	unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
+	unsigned col = add_attrib(format, "color", GL_UNSIGNED_BYTE, 4, NORMALIZE_INT_TO_FLOAT);
+
+	immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+	immBegin(GL_LINES, 12);
+
+	immAttrib4ub(col, 255, 255, 255, 180);
+	immVertex2f(pos, x1, y2);
+	immVertex2f(pos, x2, y1);
+
+	immAttrib4ub(col, 255, 255, 255, 130);
+	immVertex2f(pos, x1, y2 - dy);
+	immVertex2f(pos, x2 - dx, y1);
+
+	immAttrib4ub(col, 255, 255, 255, 80);
+	immVertex2f(pos, x1, y2 - 2 * dy);
+	immVertex2f(pos, x2 - 2 * dx, y1);
 	
-	glColor4ub(255, 255, 255, 180);
-	fdrawline(x1, y2, x2, y1);
-	glColor4ub(255, 255, 255, 130);
-	fdrawline(x1, y2 - dy, x2 - dx, y1);
-	glColor4ub(255, 255, 255, 80);
-	fdrawline(x1, y2 - 2 * dy, x2 - 2 * dx, y1);
-	
-	glColor4ub(0, 0, 0, 210);
-	fdrawline(x1, y2 + 1, x2 + 1, y1);
-	glColor4ub(0, 0, 0, 180);
-	fdrawline(x1, y2 - dy + 1, x2 - dx + 1, y1);
-	glColor4ub(0, 0, 0, 150);
-	fdrawline(x1, y2 - 2 * dy + 1, x2 - 2 * dx + 1, y1);
+	immAttrib4ub(col, 0, 0, 0, 210);
+	immVertex2f(pos, x1, y2 + 1);
+	immVertex2f(pos, x2 + 1, y1);
+
+	immAttrib4ub(col, 0, 0, 0, 180);
+	immVertex2f(pos, x1, y2 - dy + 1);
+	immVertex2f(pos, x2 - dx + 1, y1);
+
+	immAttrib4ub(col, 0, 0, 0, 150);
+	immVertex2f(pos, x1, y2 - 2 * dy + 1);
+	immVertex2f(pos, x2 - 2 * dx + 1, y1);
+
+	immEnd();
+	immUnbindProgram();
 
 	glDisable(GL_LINE_SMOOTH);
-	glDisable(GL_BLEND);
 }
 
 static void region_draw_azone_icon(AZone *az)
 {
-	GLUquadricObj *qobj = NULL; 
-	short midx = az->x1 + (az->x2 - az->x1) / 2;
-	short midy = az->y1 + (az->y2 - az->y1) / 2;
-		
-	qobj = gluNewQuadric();
-	
-	glPushMatrix();
-	glTranslatef(midx, midy, 0.0);
-	
-	/* outlined circle */
-	glEnable(GL_LINE_SMOOTH);
+	float midx = az->x1 + (az->x2 - az->x1) * 0.5f;
+	float midy = az->y1 + (az->y2 - az->y1) * 0.5f;
 
-	glColor4f(1.f, 1.f, 1.f, 0.8f);
+	VertexFormat* format = immVertexFormat();
+	unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
 
-	gluQuadricDrawStyle(qobj, GLU_FILL); 
-	gluDisk(qobj, 0.0,  4.25f, 16, 1);
+	immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
 
-	glColor4f(0.2f, 0.2f, 0.2f, 0.9f);
-	
-	gluQuadricDrawStyle(qobj, GLU_SILHOUETTE); 
-	gluDisk(qobj, 0.0,  4.25f, 16, 1);
-	
+	/* outlined circle */
+	immUniform4f("color", 1.0f, 1.0f, 1.0f, 0.8f);
+	imm_draw_filled_circle(pos, midx, midy, 4.25f, 12);
+	/* TODO(merwin): replace this --^ with one round point once shader is ready */
+	glEnable(GL_LINE_SMOOTH);
+	immUniform4f("color", 0.2f, 0.2f, 0.2f, 0.9f);
+	imm_draw_lined_circle(pos, midx, midy, 4.25f, 12);
 	glDisable(GL_LINE_SMOOTH);
-	
-	glPopMatrix();
-	gluDeleteQuadric(qobj);
-	
+
 	/* + */
-	sdrawline(midx, midy - 2, midx, midy + 3);
-	sdrawline(midx - 2, midy, midx + 3, midy);
+	immBegin(GL_LINES, 4);
+	immVertex2f(pos, midx, midy - 2);
+	immVertex2f(pos, midx, midy + 3);
+	immVertex2f(pos, midx - 2, midy);
+	immVertex2f(pos, midx + 3, midy);
+	immEnd();
+
+	immUnbindProgram();
 }
 
 static void draw_azone_plus(float x1, float y1, float x2, float y2)
diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c
index 3ed89ed..3e42587 100644
--- a/source/blender/editors/screen/glutil.c
+++ b/source/blender/editors/screen/glutil.c
@@ -182,9 +182,9 @@ void glutil_draw_lined_arc(float start, float angle, float radius, int nsegments
 	glEnd();
 }
 
-void imm_draw_lined_circle(unsigned pos, float x, float y, float rad, int nsegments)
+static void imm_draw_circle(GLenum prim_type, unsigned pos, float x, float y, float rad, int nsegments)
 {
-	immBegin(GL_LINE_LOOP, nsegments);
+	immBegin(prim_type, nsegments);
 	for (int i = 0; i < nsegments; ++i) {
 		float angle = 2 * M_PI * ((float)i / (float)nsegments);
 		immVertex2f(pos, x + rad * cosf(angle),
@@ -193,6 +193,16 @@ void imm_draw_lined_circle(unsigned pos, float x, float y, float rad, int nsegme
 	immEnd();
 }
 
+void imm_draw_lined_circle(unsigned pos, float x, float y, float rad, int nsegments)
+{
+	imm_draw_circle(GL_LINE_LOOP, pos, x, y, rad, nsegments);
+}
+
+void imm_draw_filled_circle(unsigned pos, float x, float y, float rad, int nsegments)
+{
+	imm_draw_circle(GL_TRIANGLE_FAN, pos, x, y, rad, nsegments);
+}
+
 float glaGetOneFloat(int param)
 {
 	GLfloat v;




More information about the Bf-blender-cvs mailing list