[Bf-committers] Code optimisation
Kenneth Styrberg
bf-committers@blender.org
Thu, 22 Apr 2004 23:57:46 +0200
Hi, I did some optimisation in interface_draw.c. I havn't tested how
much it improves performance, at least the code looks a tiny winy bit
cleaner. Maybe all compilers do this optimisation at compile time?
//styken
RCS file: /cvsroot/bf-blender/blender/source/blender/src/interface_draw.c,v
retrieving revision 1.14
diff -u -r1.14 interface_draw.c
--- interface_draw.c 28 Jan 2004 12:16:05 -0000 1.14
+++ interface_draw.c 22 Apr 2004 21:55:45 -0000
@@ -228,7 +228,8 @@
* an alignment group or not. 0 = not middle, 1 = is in the middle.
* Done to allow cleaner drawing
*/
-
+
+ float temp = y2 - (y2 - y1) / 3.0;
/* *** SHADED BUTTON BASE *** */
glShadeModel(GL_SMOOTH);
glBegin(GL_QUADS);
@@ -252,8 +253,8 @@
else M_LIGHT;
}
- glVertex2f(x2,(y2-(y2-y1)/3));
- glVertex2f(x1,(y2-(y2-y1)/3));
+ glVertex2f(x2,temp);
+ glVertex2f(x1,temp);
glEnd();
@@ -268,8 +269,8 @@
else M_LIGHT;
}
- glVertex2f(x1,(y2-(y2-y1)/3));
- glVertex2f(x2,(y2-(y2-y1)/3));
+ glVertex2f(x1, temp);
+ glVertex2f(x2, temp);
glVertex2f(x2,y2);
glVertex2f(x1,y2);
@@ -390,21 +391,23 @@
/* small side double arrow for iconrow */
static void ui_default_iconrow_arrows(float x1, float y1, float x2,
float y2)
{
+ short temp = (short)(y2 - (y2 - y1) / 2.0);
+
glEnable( GL_POLYGON_SMOOTH );
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glShadeModel(GL_FLAT);
glBegin(GL_TRIANGLES);
- glVertex2f((short)x2-2,(short)(y2-(y2-y1)/2)+1);
- glVertex2f((short)x2-6,(short)(y2-(y2-y1)/2)+1);
- glVertex2f((short)x2-4,(short)(y2-(y2-y1)/2)+4);
+ glVertex2f((short)x2-2, temp + 1);
+ glVertex2f((short)x2-6, temp + 1);
+ glVertex2f((short)x2-4, temp + 4);
glEnd();
glBegin(GL_TRIANGLES);
- glVertex2f((short)x2-2,(short)(y2-(y2-y1)/2) -1);
- glVertex2f((short)x2-6,(short)(y2-(y2-y1)/2) -1);
- glVertex2f((short)x2-4,(short)(y2-(y2-y1)/2) -4);
+ glVertex2f((short)x2-2, temp - 1);
+ glVertex2f((short)x2-6, temp - 1);
+ glVertex2f((short)x2-4, temp - 4);
glEnd();
glDisable( GL_BLEND );
@@ -438,6 +441,8 @@
/* left/right arrows for number fields */
static void ui_default_num_arrows(float x1, float y1, float x2, float y2)
{
+ short temp = (short)(y2 - (y2 - y1) / 2.0);
+
glEnable( GL_POLYGON_SMOOTH );
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
@@ -445,18 +450,18 @@
glShadeModel(GL_FLAT);
glBegin(GL_TRIANGLES);
- glVertex2f((short)x1+5,(short)(y2-(y2-y1)/2));
- glVertex2f((short)x1+10,(short)(y2-(y2-y1)/2)+4);
- glVertex2f((short)x1+10,(short)(y2-(y2-y1)/2)-4);
+ glVertex2f((short)x1 + 5, temp);
+ glVertex2f((short)x1 + 10, temp + 4);
+ glVertex2f((short)x1 + 10, temp - 4);
glEnd();
/* right */
glShadeModel(GL_FLAT);
glBegin(GL_TRIANGLES);
- glVertex2f((short)x2-5,(short)(y2-(y2-y1)/2));
- glVertex2f((short)x2-10,(short)(y2-(y2-y1)/2)-4);
- glVertex2f((short)x2-10,(short)(y2-(y2-y1)/2)+4);
+ glVertex2f((short)x2 - 5, temp);
+ glVertex2f((short)x2 - 10, temp - 4);
+ glVertex2f((short)x2 - 10, temp + 4);
glEnd();
glDisable( GL_BLEND );