132001f49Smrg/*
232001f49Smrg * This program is under the GNU GPL.
332001f49Smrg * Use at your own risk.
432001f49Smrg *
532001f49Smrg * written by David Bucciarelli (tech.hmw@plus.it)
632001f49Smrg *            Humanware s.r.l.
732001f49Smrg */
832001f49Smrg
932001f49Smrg#include <stdlib.h>
1032001f49Smrg#include <stdio.h>
1132001f49Smrg#include <string.h>
1232001f49Smrg#include <math.h>
1332001f49Smrg#include "glut_wrap.h"
1432001f49Smrg
1532001f49Smrgtypedef struct
1632001f49Smrg{
1732001f49Smrg   char *name;
1832001f49Smrg   char *unit;
1932001f49Smrg   void (*init) (void);
2032001f49Smrg   int (*run) (int, int);
2132001f49Smrg   int type;
2232001f49Smrg   int numsize;
2332001f49Smrg   int size[10];
2432001f49Smrg}
2532001f49Smrgbenchmark;
2632001f49Smrg
2732001f49Smrgstatic int frontbuffer = 1;
2832001f49Smrg
2932001f49Smrg/***************************************************************************/
3032001f49Smrg
3132001f49Smrgstatic void
3232001f49Smrginit_test01(void)
3332001f49Smrg{
3432001f49Smrg   glMatrixMode(GL_PROJECTION);
3532001f49Smrg   glLoadIdentity();
3632001f49Smrg   gluOrtho2D(-0.5, 639.5, -0.5, 479.5);
3732001f49Smrg   glMatrixMode(GL_MODELVIEW);
3832001f49Smrg
3932001f49Smrg   glShadeModel(GL_FLAT);
4032001f49Smrg   glDisable(GL_DEPTH_TEST);
4132001f49Smrg
4232001f49Smrg   glClearColor(0.0, 0.1, 1.0, 0.0);
4332001f49Smrg   glClear(GL_COLOR_BUFFER_BIT);
4432001f49Smrg   glColor3f(1.0, 0.0, 0.0);
4532001f49Smrg}
4632001f49Smrg
4732001f49Smrgstatic int
4832001f49Smrgtest01(int size, int num)
4932001f49Smrg{
5032001f49Smrg   int x, y;
5132001f49Smrg
5232001f49Smrg   glBegin(GL_POINTS);
5332001f49Smrg   for (y = 0; y < num; y++)
5432001f49Smrg      for (x = 0; x < 480; x++)
5532001f49Smrg	 glVertex2i(x, x);
5632001f49Smrg   glEnd();
5732001f49Smrg
5832001f49Smrg   return 480 * num;
5932001f49Smrg}
6032001f49Smrg
6132001f49Smrg/***************************************************************************/
6232001f49Smrg
6332001f49Smrgstatic void
6432001f49Smrginit_test02(void)
6532001f49Smrg{
6632001f49Smrg   glMatrixMode(GL_PROJECTION);
6732001f49Smrg   glLoadIdentity();
6832001f49Smrg   gluOrtho2D(-0.5, 639.5, -0.5, 479.5);
6932001f49Smrg   glMatrixMode(GL_MODELVIEW);
7032001f49Smrg
7132001f49Smrg   glShadeModel(GL_SMOOTH);
7232001f49Smrg   glDisable(GL_DEPTH_TEST);
7332001f49Smrg
7432001f49Smrg   glClearColor(0.0, 0.1, 1.0, 0.0);
7532001f49Smrg   glClear(GL_COLOR_BUFFER_BIT);
7632001f49Smrg}
7732001f49Smrg
7832001f49Smrgstatic int
7932001f49Smrgtest02(int size, int num)
8032001f49Smrg{
8132001f49Smrg   int x, y;
8232001f49Smrg
8332001f49Smrg   glBegin(GL_LINES);
8432001f49Smrg   for (y = 0; y < num; y++)
8532001f49Smrg      for (x = 0; x < size; x++) {
8632001f49Smrg	 glColor3f(0.0, 1.0, y / (float) num);
8732001f49Smrg	 glVertex2i(0, size - 1);
8832001f49Smrg	 glColor3f(1.0, 0.0, x / (float) size);
8932001f49Smrg	 glVertex2i(x, x);
9032001f49Smrg      }
9132001f49Smrg   glEnd();
9232001f49Smrg
9332001f49Smrg   return num * size;
9432001f49Smrg}
9532001f49Smrg
9632001f49Smrg/***************************************************************************/
9732001f49Smrg
9832001f49Smrgstatic void
9932001f49Smrginit_test03(void)
10032001f49Smrg{
10132001f49Smrg   glMatrixMode(GL_PROJECTION);
10232001f49Smrg   glLoadIdentity();
10332001f49Smrg   glOrtho(-0.5, 639.5, -0.5, 479.5, 1.0, -1000.0 * 480.0);
10432001f49Smrg   glMatrixMode(GL_MODELVIEW);
10532001f49Smrg
10632001f49Smrg   glShadeModel(GL_SMOOTH);
10732001f49Smrg   glEnable(GL_DEPTH_TEST);
10832001f49Smrg
10932001f49Smrg   glClearColor(0.0, 0.1, 1.0, 0.0);
11032001f49Smrg   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
11132001f49Smrg}
11232001f49Smrg
11332001f49Smrgstatic int
11432001f49Smrgtest03(int size, int num)
11532001f49Smrg{
11632001f49Smrg   int x, y, z;
11732001f49Smrg
11832001f49Smrg   glBegin(GL_TRIANGLES);
11932001f49Smrg   for (y = 0; y < num; y++)
12032001f49Smrg      for (x = 0; x < size; x += 5) {
12132001f49Smrg	 z = num * size - (y * size + x);
12232001f49Smrg	 glColor3f(0.0, 1.0, 0.0);
12332001f49Smrg	 glVertex3i(0, x, z);
12432001f49Smrg
12532001f49Smrg	 glColor3f(1.0, 0.0, x / (float) size);
12632001f49Smrg	 glVertex3i(size - 1 - x, 0, z);
12732001f49Smrg
12832001f49Smrg	 glColor3f(1.0, x / (float) size, 0.0);
12932001f49Smrg	 glVertex3i(x, size - 1 - x, z);
13032001f49Smrg      }
13132001f49Smrg   glEnd();
13232001f49Smrg
13332001f49Smrg   return size * num / 5;
13432001f49Smrg}
13532001f49Smrg
13632001f49Smrg/***************************************************************************/
13732001f49Smrg
13832001f49Smrgstatic void
13932001f49Smrginit_test04(void)
14032001f49Smrg{
14132001f49Smrg   int x, y;
14232001f49Smrg   GLubyte tex[128 * 128 * 3];
14332001f49Smrg   GLenum gluerr;
14432001f49Smrg
14532001f49Smrg   glMatrixMode(GL_PROJECTION);
14632001f49Smrg   glLoadIdentity();
14732001f49Smrg   glOrtho(-0.5, 639.5, -0.5, 479.5, 1.0, -1000.0 * 480.0);
14832001f49Smrg
14932001f49Smrg   glMatrixMode(GL_MODELVIEW);
15032001f49Smrg
15132001f49Smrg   glShadeModel(GL_SMOOTH);
15232001f49Smrg   glEnable(GL_DEPTH_TEST);
15332001f49Smrg
15432001f49Smrg   glEnable(GL_BLEND);
15532001f49Smrg   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
15632001f49Smrg
15732001f49Smrg   for (y = 0; y < 128; y++)
15832001f49Smrg      for (x = 0; x < 128; x++) {
15932001f49Smrg	 tex[(x + y * 128) * 3 + 0] = ((x % (128 / 4)) < (128 / 8)) ? 255 : 0;
16032001f49Smrg	 tex[(x + y * 128) * 3 + 1] = ((y % (128 / 4)) < (128 / 8)) ? 255 : 0;
16132001f49Smrg	 tex[(x + y * 128) * 3 + 2] = x;
16232001f49Smrg      }
16332001f49Smrg
16432001f49Smrg   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
16532001f49Smrg   if ((gluerr = gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 128, 128, GL_RGB,
16632001f49Smrg				   GL_UNSIGNED_BYTE, (GLvoid *) (&tex[0])))) {
16732001f49Smrg      fprintf(stderr, "GLULib%s\n", (char *) gluErrorString(gluerr));
16832001f49Smrg      exit(-1);
16932001f49Smrg   }
17032001f49Smrg
17132001f49Smrg   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
17232001f49Smrg   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
17332001f49Smrg
17432001f49Smrg   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
17532001f49Smrg		   GL_LINEAR_MIPMAP_NEAREST);
17632001f49Smrg   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
17732001f49Smrg
17832001f49Smrg   glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
17932001f49Smrg   glEnable(GL_TEXTURE_2D);
18032001f49Smrg
18132001f49Smrg   glClearColor(0.0, 0.1, 1.0, 0.0);
18232001f49Smrg   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
18332001f49Smrg}
18432001f49Smrg
18532001f49Smrgstatic int
18632001f49Smrgtest04(int size, int num)
18732001f49Smrg{
18832001f49Smrg   int x, y, z;
18932001f49Smrg
19032001f49Smrg   glBegin(GL_TRIANGLES);
19132001f49Smrg   for (y = 0; y < num; y++)
19232001f49Smrg      for (x = 0; x < size; x += 5) {
19332001f49Smrg	 z = num * size - (y * size + x);
19432001f49Smrg	 glTexCoord2f(1.0, 1.0);
19532001f49Smrg	 glColor3f(1.0, 0.0, 0.0);
19632001f49Smrg	 glVertex3i(0, x, z);
19732001f49Smrg
19832001f49Smrg	 glTexCoord2f(0.0, 1.0);
19932001f49Smrg	 glColor3f(0.0, 1.0, 0.0);
20032001f49Smrg	 glVertex3i(size - 1 - x, 0, z);
20132001f49Smrg
20232001f49Smrg	 glTexCoord2f(1.0, 0.0);
20332001f49Smrg	 glColor3f(0.0, 0.0, 1.0);
20432001f49Smrg	 glVertex3i(x, size - 1 - x, z);
20532001f49Smrg      }
20632001f49Smrg   glEnd();
20732001f49Smrg
20832001f49Smrg   return num * size / 5;
20932001f49Smrg}
21032001f49Smrg
21132001f49Smrg/***************************************************************************/
21232001f49Smrg
21332001f49Smrgstatic void
21432001f49Smrginit_test05(void)
21532001f49Smrg{
21632001f49Smrg   int x, y;
21732001f49Smrg   GLubyte tex[128 * 128 * 3];
21832001f49Smrg   GLenum gluerr;
21932001f49Smrg
22032001f49Smrg   glMatrixMode(GL_PROJECTION);
22132001f49Smrg   glLoadIdentity();
22232001f49Smrg   glOrtho(-0.5, 639.5, -0.5, 479.5, -1.0, 1.0);
22332001f49Smrg
22432001f49Smrg   glMatrixMode(GL_MODELVIEW);
22532001f49Smrg
22632001f49Smrg   glShadeModel(GL_SMOOTH);
22732001f49Smrg   glEnable(GL_DEPTH_TEST);
22832001f49Smrg
22932001f49Smrg   glEnable(GL_BLEND);
23032001f49Smrg   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
23132001f49Smrg
23232001f49Smrg   for (y = 0; y < 128; y++)
23332001f49Smrg      for (x = 0; x < 128; x++) {
23432001f49Smrg	 tex[(x + y * 128) * 3 + 0] = ((x % (128 / 4)) < (128 / 8)) ? 255 : 0;
23532001f49Smrg	 tex[(x + y * 128) * 3 + 1] = ((y % (128 / 4)) < (128 / 8)) ? 255 : 0;
23632001f49Smrg	 tex[(x + y * 128) * 3 + 2] = x;
23732001f49Smrg      }
23832001f49Smrg
23932001f49Smrg   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
24032001f49Smrg   if ((gluerr = gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 128, 128, GL_RGB,
24132001f49Smrg				   GL_UNSIGNED_BYTE, (GLvoid *) (&tex[0])))) {
24232001f49Smrg      fprintf(stderr, "GLULib%s\n", (char *) gluErrorString(gluerr));
24332001f49Smrg      exit(-1);
24432001f49Smrg   }
24532001f49Smrg
24632001f49Smrg   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
24732001f49Smrg   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
24832001f49Smrg
24932001f49Smrg   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
25032001f49Smrg		   GL_LINEAR_MIPMAP_NEAREST);
25132001f49Smrg   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
25232001f49Smrg
25332001f49Smrg   glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
25432001f49Smrg   glEnable(GL_TEXTURE_2D);
25532001f49Smrg
25632001f49Smrg   glDepthFunc(GL_ALWAYS);
25732001f49Smrg
25832001f49Smrg   glClearColor(0.0, 0.1, 1.0, 0.0);
25932001f49Smrg   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
26032001f49Smrg}
26132001f49Smrg
26232001f49Smrgstatic int
26332001f49Smrgtest05(int size, int num)
26432001f49Smrg{
26532001f49Smrg   int y;
26632001f49Smrg   float v0[3], v1[3], v2[3], v3[3];
26732001f49Smrg   float cv0[3], cv1[3], cv2[3], cv3[3];
26832001f49Smrg   float tv0[3], tv1[3], tv2[3], tv3[3];
26932001f49Smrg
27032001f49Smrg   v0[0] = 320 - size / 2;
27132001f49Smrg   v0[1] = 240 - size / 2;
27232001f49Smrg   v0[2] = 0.0;
27332001f49Smrg   v1[0] = 320 + size / 2;
27432001f49Smrg   v1[1] = 240 - size / 2;
27532001f49Smrg   v1[2] = 0.0;
27632001f49Smrg   v2[0] = 320 - size / 2;
27732001f49Smrg   v2[1] = 240 + size / 2;
27832001f49Smrg   v2[2] = 0.0;
27932001f49Smrg   v3[0] = 320 + size / 2;
28032001f49Smrg   v3[1] = 240 + size / 2;
28132001f49Smrg   v3[2] = 0.0;
28232001f49Smrg   cv0[0] = 1.0;
28332001f49Smrg   cv0[1] = 0.0;
28432001f49Smrg   cv0[2] = 0.0;
28532001f49Smrg   cv1[0] = 1.0;
28632001f49Smrg   cv1[1] = 1.0;
28732001f49Smrg   cv1[2] = 0.0;
28832001f49Smrg   cv2[0] = 1.0;
28932001f49Smrg   cv2[1] = 0.0;
29032001f49Smrg   cv2[2] = 1.0;
29132001f49Smrg   cv3[0] = 1.0;
29232001f49Smrg   cv3[1] = 1.0;
29332001f49Smrg   cv3[2] = 1.0;
29432001f49Smrg   tv0[0] = 0.0;
29532001f49Smrg   tv0[1] = 0.0;
29632001f49Smrg   tv0[2] = 0.0;
29732001f49Smrg   tv1[0] = 1.0;
29832001f49Smrg   tv1[1] = 0.0;
29932001f49Smrg   tv1[2] = 0.0;
30032001f49Smrg   tv2[0] = 0.0;
30132001f49Smrg   tv2[1] = 1.0;
30232001f49Smrg   tv2[2] = 0.0;
30332001f49Smrg   tv3[0] = 1.0;
30432001f49Smrg   tv3[1] = 1.0;
30532001f49Smrg   tv3[2] = 0.0;
30632001f49Smrg
30732001f49Smrg   glBegin(GL_TRIANGLE_STRIP);
30832001f49Smrg   for (y = 0; y < num; y++) {
30932001f49Smrg      glColor3fv(cv0);
31032001f49Smrg      glTexCoord2fv(tv0);
31132001f49Smrg      glVertex3fv(v0);
31232001f49Smrg
31332001f49Smrg      glColor3fv(cv1);
31432001f49Smrg      glTexCoord2fv(tv1);
31532001f49Smrg      glVertex3fv(v1);
31632001f49Smrg
31732001f49Smrg      glColor3fv(cv2);
31832001f49Smrg      glTexCoord2fv(tv2);
31932001f49Smrg      glVertex3fv(v2);
32032001f49Smrg
32132001f49Smrg      glColor3fv(cv3);
32232001f49Smrg      glTexCoord2fv(tv3);
32332001f49Smrg      glVertex3fv(v3);
32432001f49Smrg   }
32532001f49Smrg   glEnd();
32632001f49Smrg
32732001f49Smrg   return 4 * num - 2;
32832001f49Smrg}
32932001f49Smrg
33032001f49Smrg/***************************************************************************/
33132001f49Smrg
33232001f49Smrgstatic void
33332001f49Smrginit_test06(void)
33432001f49Smrg{
33532001f49Smrg   glMatrixMode(GL_PROJECTION);
33632001f49Smrg   glLoadIdentity();
33732001f49Smrg   gluOrtho2D(-0.5, 639.5, -0.5, 479.5);
33832001f49Smrg   glMatrixMode(GL_MODELVIEW);
33932001f49Smrg
34032001f49Smrg   glShadeModel(GL_SMOOTH);
34132001f49Smrg   glEnable(GL_DEPTH_TEST);
34232001f49Smrg
34332001f49Smrg   glClearColor(0.0, 0.1, 1.0, 0.0);
34432001f49Smrg   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
34532001f49Smrg}
34632001f49Smrg
34732001f49Smrgstatic int
34832001f49Smrgtest06(int size, int num)
34932001f49Smrg{
35032001f49Smrg   int y;
35132001f49Smrg
35232001f49Smrg   for (y = 0; y < num; y++) {
35332001f49Smrg      glClearColor(y / (float) num, 0.1, 1.0, 0.0);
35432001f49Smrg      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
35532001f49Smrg   }
35632001f49Smrg
35732001f49Smrg   return num;
35832001f49Smrg}
35932001f49Smrg
36032001f49Smrg/***************************************************************************/
36132001f49Smrg
36232001f49Smrg#define BMARKS_TIME 5.0
36332001f49Smrg
36432001f49Smrg#define NUM_BMARKS 6
36532001f49Smrg
36632001f49Smrg/* 554 ~= sqrt(640*480) */
36732001f49Smrg
36832001f49Smrgstatic benchmark bmarks[NUM_BMARKS] = {
36932001f49Smrg   {"Simple Points", "Pnts", init_test01, test01, 0, 0,
37032001f49Smrg    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
37132001f49Smrg   {"Smooth Lines", "Lins", init_test02, test02, 1, 5,
37232001f49Smrg    {480, 250, 100, 50, 25, 0, 0, 0, 0, 0}},
37332001f49Smrg   {"ZSmooth Triangles", "Tris", init_test03, test03, 1, 5,
37432001f49Smrg    {480, 250, 100, 50, 25, 0, 0, 0, 0, 0}},
37532001f49Smrg   {"ZSmooth Tex Blend Triangles", "Tris", init_test04, test04, 1, 5,
37632001f49Smrg    {480, 250, 100, 50, 25, 0, 0, 0, 0, 0}},
37732001f49Smrg   {"ZSmooth Tex Blend TMesh Triangles", "Tris", init_test05, test05, 2, 8,
37832001f49Smrg    {400, 250, 100, 50, 25, 10, 5, 2, 0, 0}},
37932001f49Smrg   {"Color/Depth Buffer Clears", "Clrs", init_test06, test06, 3, 0,
38032001f49Smrg    {554, 0, 0, 0, 0, 0, 0, 0, 0, 0}}
38132001f49Smrg};
38232001f49Smrg
38332001f49Smrg/***************************************************************************/
38432001f49Smrg
38532001f49Smrgstatic void
38632001f49Smrgdotest0param(benchmark * bmark)
38732001f49Smrg{
38832001f49Smrg   float stime, etime, dtime, tottime, maxtime, mintime;
38932001f49Smrg   int num, numelem, calibnum, j;
39032001f49Smrg
39132001f49Smrg   glPushAttrib(GL_ALL_ATTRIB_BITS);
39232001f49Smrg   bmark->init();
39332001f49Smrg
39432001f49Smrg   stime = glutGet(GLUT_ELAPSED_TIME);
39532001f49Smrg
39632001f49Smrg   dtime = 0.0;
39732001f49Smrg   calibnum = 0;
39832001f49Smrg   while (dtime < 2.0) {
39932001f49Smrg      bmark->run(0, 1);
40032001f49Smrg      glFinish();
40132001f49Smrg      etime = glutGet(GLUT_ELAPSED_TIME);
40232001f49Smrg      dtime = (etime - stime) / 1000.0;
40332001f49Smrg      calibnum++;
40432001f49Smrg   }
40532001f49Smrg   glPopAttrib();
40632001f49Smrg
40732001f49Smrg   fprintf(stderr, "Elapsed time for the calibration test (%d): %f\n",
40832001f49Smrg	   calibnum, dtime);
40932001f49Smrg
41032001f49Smrg   num = (int) ((BMARKS_TIME / dtime) * calibnum);
41132001f49Smrg
41232001f49Smrg   if (num < 1)
41332001f49Smrg      num = 1;
41432001f49Smrg
41532001f49Smrg   fprintf(stderr, "Selected number of benchmark iterations: %d\n", num);
41632001f49Smrg
41732001f49Smrg   mintime = HUGE_VAL;
41832001f49Smrg   maxtime = -HUGE_VAL;
41932001f49Smrg
42032001f49Smrg   for (tottime = 0.0, j = 0; j < 5; j++) {
42132001f49Smrg      glPushAttrib(GL_ALL_ATTRIB_BITS);
42232001f49Smrg      bmark->init();
42332001f49Smrg
42432001f49Smrg      stime = glutGet(GLUT_ELAPSED_TIME);
42532001f49Smrg      numelem = bmark->run(0, num);
42632001f49Smrg      glFinish();
42732001f49Smrg      etime = glutGet(GLUT_ELAPSED_TIME);
42832001f49Smrg
42932001f49Smrg      glPopAttrib();
43032001f49Smrg
43132001f49Smrg      dtime = (etime - stime) / 1000.0;
43232001f49Smrg      tottime += dtime;
43332001f49Smrg
43432001f49Smrg      fprintf(stderr, "Elapsed time for run %d: %f\n", j, dtime);
43532001f49Smrg
43632001f49Smrg      if (dtime < mintime)
43732001f49Smrg	 mintime = dtime;
43832001f49Smrg      if (dtime > maxtime)
43932001f49Smrg	 maxtime = dtime;
44032001f49Smrg   }
44132001f49Smrg
44232001f49Smrg   tottime -= mintime + maxtime;
44332001f49Smrg
44432001f49Smrg   fprintf(stdout, "%s\n%f %s/sec", bmark->name, numelem / (tottime / 3.0),
44532001f49Smrg	   bmark->unit);
44632001f49Smrg
44732001f49Smrg   if (bmark->type == 3)
44832001f49Smrg      fprintf(stdout, ", MPixel Fill/sec: %f\n\n",
44932001f49Smrg	      (numelem * bmark->size[0] * (float) bmark->size[0]) /
45032001f49Smrg	      (1000000.0 * tottime / 3.0));
45132001f49Smrg   else
45232001f49Smrg      fprintf(stdout, "\n\n");
45332001f49Smrg}
45432001f49Smrg
45532001f49Smrg/***************************************************************************/
45632001f49Smrg
45732001f49Smrgstatic void
45832001f49Smrgdotest1param(benchmark * bmark)
45932001f49Smrg{
46032001f49Smrg   float stime, etime, dtime, tottime, maxtime, mintime;
46132001f49Smrg   int num, numelem, calibnum, j, k;
46232001f49Smrg
46332001f49Smrg   fprintf(stdout, "%s\n", bmark->name);
46432001f49Smrg
46532001f49Smrg   for (j = 0; j < bmark->numsize; j++) {
46632001f49Smrg      fprintf(stderr, "Current size: %d\n", bmark->size[j]);
46732001f49Smrg
46832001f49Smrg      glPushAttrib(GL_ALL_ATTRIB_BITS);
46932001f49Smrg      bmark->init();
47032001f49Smrg
47132001f49Smrg      stime = glutGet(GLUT_ELAPSED_TIME);
47232001f49Smrg
47332001f49Smrg      dtime = 0.0;
47432001f49Smrg      calibnum = 0;
47532001f49Smrg      while (dtime < 2.0) {
47632001f49Smrg	 bmark->run(bmark->size[j], 1);
47732001f49Smrg	 glFinish();
47832001f49Smrg	 etime = glutGet(GLUT_ELAPSED_TIME);
47932001f49Smrg	 dtime = (etime - stime) / 1000.0;
48032001f49Smrg	 calibnum++;
48132001f49Smrg      }
48232001f49Smrg      glPopAttrib();
48332001f49Smrg
48432001f49Smrg      fprintf(stderr, "Elapsed time for the calibration test (%d): %f\n",
48532001f49Smrg	      calibnum, dtime);
48632001f49Smrg
48732001f49Smrg      num = (int) ((BMARKS_TIME / dtime) * calibnum);
48832001f49Smrg
48932001f49Smrg      if (num < 1)
49032001f49Smrg	 num = 1;
49132001f49Smrg
49232001f49Smrg      fprintf(stderr, "Selected number of benchmark iterations: %d\n", num);
49332001f49Smrg
49432001f49Smrg      mintime = HUGE_VAL;
49532001f49Smrg      maxtime = -HUGE_VAL;
49632001f49Smrg
49732001f49Smrg      for (numelem = 1, tottime = 0.0, k = 0; k < 5; k++) {
49832001f49Smrg	 glPushAttrib(GL_ALL_ATTRIB_BITS);
49932001f49Smrg	 bmark->init();
50032001f49Smrg
50132001f49Smrg	 stime = glutGet(GLUT_ELAPSED_TIME);
50232001f49Smrg	 numelem = bmark->run(bmark->size[j], num);
50332001f49Smrg	 glFinish();
50432001f49Smrg	 etime = glutGet(GLUT_ELAPSED_TIME);
50532001f49Smrg
50632001f49Smrg	 glPopAttrib();
50732001f49Smrg
50832001f49Smrg	 dtime = (etime - stime) / 1000.0;
50932001f49Smrg	 tottime += dtime;
51032001f49Smrg
51132001f49Smrg	 fprintf(stderr, "Elapsed time for run %d: %f\n", k, dtime);
51232001f49Smrg
51332001f49Smrg	 if (dtime < mintime)
51432001f49Smrg	    mintime = dtime;
51532001f49Smrg	 if (dtime > maxtime)
51632001f49Smrg	    maxtime = dtime;
51732001f49Smrg      }
51832001f49Smrg
51932001f49Smrg      tottime -= mintime + maxtime;
52032001f49Smrg
52132001f49Smrg      fprintf(stdout, "SIZE=%03d => %f %s/sec", bmark->size[j],
52232001f49Smrg	      numelem / (tottime / 3.0), bmark->unit);
52332001f49Smrg      if (bmark->type == 2)
52432001f49Smrg	 fprintf(stdout, ", MPixel Fill/sec: %f\n",
52532001f49Smrg		 (numelem * bmark->size[j] * bmark->size[j] / 2) /
52632001f49Smrg		 (1000000.0 * tottime / 3.0));
52732001f49Smrg      else
52832001f49Smrg	 fprintf(stdout, "\n");
52932001f49Smrg   }
53032001f49Smrg
53132001f49Smrg   fprintf(stdout, "\n\n");
53232001f49Smrg}
53332001f49Smrg
53432001f49Smrg/***************************************************************************/
53532001f49Smrg
53632001f49Smrgstatic void
53732001f49Smrgdisplay(void)
53832001f49Smrg{
53932001f49Smrg   int i;
54032001f49Smrg
54132001f49Smrg   if (frontbuffer)
54232001f49Smrg      glDrawBuffer(GL_FRONT);
54332001f49Smrg   else
54432001f49Smrg      glDrawBuffer(GL_BACK);
54532001f49Smrg
54632001f49Smrg   for (i = 0; i < NUM_BMARKS; i++) {
54732001f49Smrg      fprintf(stderr, "Benchmark: %d\n", i);
54832001f49Smrg
54932001f49Smrg      switch (bmarks[i].type) {
55032001f49Smrg      case 0:
55132001f49Smrg      case 3:
55232001f49Smrg	 dotest0param(&bmarks[i]);
55332001f49Smrg	 break;
55432001f49Smrg      case 1:
55532001f49Smrg      case 2:
55632001f49Smrg	 dotest1param(&bmarks[i]);
55732001f49Smrg	 break;
55832001f49Smrg      }
55932001f49Smrg   }
56032001f49Smrg
56132001f49Smrg   exit(0);
56232001f49Smrg}
56332001f49Smrg
56432001f49Smrgint
56532001f49Smrgmain(int ac, char **av)
56632001f49Smrg{
56732001f49Smrg   fprintf(stderr, "GLTest v1.0\nWritten by David Bucciarelli\n");
56832001f49Smrg
56932001f49Smrg   if (ac == 2)
57032001f49Smrg      frontbuffer = 0;
57132001f49Smrg
57232001f49Smrg   glutInitWindowSize(640, 480);
57332001f49Smrg   glutInit(&ac, av);
57432001f49Smrg   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
57532001f49Smrg   glutCreateWindow("OpenGL/Mesa Performances");
57632001f49Smrg   glutDisplayFunc(display);
57732001f49Smrg   glutMainLoop();
57832001f49Smrg
57932001f49Smrg   return 0;
58032001f49Smrg}
581