2 * This program is under the GNU GPL.
3 * Use at your own risk.
5 * written by David Bucciarelli (tech.hmw@plus.it)
13 #include "glut_wrap.h"
20 int (*run
) (int, int);
27 static int frontbuffer
= 1;
29 /***************************************************************************/
34 glMatrixMode(GL_PROJECTION
);
36 gluOrtho2D(-0.5, 639.5, -0.5, 479.5);
37 glMatrixMode(GL_MODELVIEW
);
39 glShadeModel(GL_FLAT
);
40 glDisable(GL_DEPTH_TEST
);
42 glClearColor(0.0, 0.1, 1.0, 0.0);
43 glClear(GL_COLOR_BUFFER_BIT
);
44 glColor3f(1.0, 0.0, 0.0);
48 test01(int size
, int num
)
53 for (y
= 0; y
< num
; y
++)
54 for (x
= 0; x
< 480; x
++)
61 /***************************************************************************/
66 glMatrixMode(GL_PROJECTION
);
68 gluOrtho2D(-0.5, 639.5, -0.5, 479.5);
69 glMatrixMode(GL_MODELVIEW
);
71 glShadeModel(GL_SMOOTH
);
72 glDisable(GL_DEPTH_TEST
);
74 glClearColor(0.0, 0.1, 1.0, 0.0);
75 glClear(GL_COLOR_BUFFER_BIT
);
79 test02(int size
, int num
)
84 for (y
= 0; y
< num
; y
++)
85 for (x
= 0; x
< size
; x
++) {
86 glColor3f(0.0, 1.0, y
/ (float) num
);
87 glVertex2i(0, size
- 1);
88 glColor3f(1.0, 0.0, x
/ (float) size
);
96 /***************************************************************************/
101 glMatrixMode(GL_PROJECTION
);
103 glOrtho(-0.5, 639.5, -0.5, 479.5, 1.0, -1000.0 * 480.0);
104 glMatrixMode(GL_MODELVIEW
);
106 glShadeModel(GL_SMOOTH
);
107 glEnable(GL_DEPTH_TEST
);
109 glClearColor(0.0, 0.1, 1.0, 0.0);
110 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
114 test03(int size
, int num
)
118 glBegin(GL_TRIANGLES
);
119 for (y
= 0; y
< num
; y
++)
120 for (x
= 0; x
< size
; x
+= 5) {
121 z
= num
* size
- (y
* size
+ x
);
122 glColor3f(0.0, 1.0, 0.0);
125 glColor3f(1.0, 0.0, x
/ (float) size
);
126 glVertex3i(size
- 1 - x
, 0, z
);
128 glColor3f(1.0, x
/ (float) size
, 0.0);
129 glVertex3i(x
, size
- 1 - x
, z
);
133 return size
* num
/ 5;
136 /***************************************************************************/
142 GLubyte tex
[128 * 128 * 3];
145 glMatrixMode(GL_PROJECTION
);
147 glOrtho(-0.5, 639.5, -0.5, 479.5, 1.0, -1000.0 * 480.0);
149 glMatrixMode(GL_MODELVIEW
);
151 glShadeModel(GL_SMOOTH
);
152 glEnable(GL_DEPTH_TEST
);
155 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
157 for (y
= 0; y
< 128; y
++)
158 for (x
= 0; x
< 128; x
++) {
159 tex
[(x
+ y
* 128) * 3 + 0] = ((x
% (128 / 4)) < (128 / 8)) ? 255 : 0;
160 tex
[(x
+ y
* 128) * 3 + 1] = ((y
% (128 / 4)) < (128 / 8)) ? 255 : 0;
161 tex
[(x
+ y
* 128) * 3 + 2] = x
;
164 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
165 if ((gluerr
= gluBuild2DMipmaps(GL_TEXTURE_2D
, 3, 128, 128, GL_RGB
,
166 GL_UNSIGNED_BYTE
, (GLvoid
*) (&tex
[0])))) {
167 fprintf(stderr
, "GLULib%s\n", (char *) gluErrorString(gluerr
));
171 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
172 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
174 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
175 GL_LINEAR_MIPMAP_NEAREST
);
176 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
178 glTexEnvf(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
179 glEnable(GL_TEXTURE_2D
);
181 glClearColor(0.0, 0.1, 1.0, 0.0);
182 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
186 test04(int size
, int num
)
190 glBegin(GL_TRIANGLES
);
191 for (y
= 0; y
< num
; y
++)
192 for (x
= 0; x
< size
; x
+= 5) {
193 z
= num
* size
- (y
* size
+ x
);
194 glTexCoord2f(1.0, 1.0);
195 glColor3f(1.0, 0.0, 0.0);
198 glTexCoord2f(0.0, 1.0);
199 glColor3f(0.0, 1.0, 0.0);
200 glVertex3i(size
- 1 - x
, 0, z
);
202 glTexCoord2f(1.0, 0.0);
203 glColor3f(0.0, 0.0, 1.0);
204 glVertex3i(x
, size
- 1 - x
, z
);
208 return num
* size
/ 5;
211 /***************************************************************************/
217 GLubyte tex
[128 * 128 * 3];
220 glMatrixMode(GL_PROJECTION
);
222 glOrtho(-0.5, 639.5, -0.5, 479.5, -1.0, 1.0);
224 glMatrixMode(GL_MODELVIEW
);
226 glShadeModel(GL_SMOOTH
);
227 glEnable(GL_DEPTH_TEST
);
230 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
232 for (y
= 0; y
< 128; y
++)
233 for (x
= 0; x
< 128; x
++) {
234 tex
[(x
+ y
* 128) * 3 + 0] = ((x
% (128 / 4)) < (128 / 8)) ? 255 : 0;
235 tex
[(x
+ y
* 128) * 3 + 1] = ((y
% (128 / 4)) < (128 / 8)) ? 255 : 0;
236 tex
[(x
+ y
* 128) * 3 + 2] = x
;
239 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
240 if ((gluerr
= gluBuild2DMipmaps(GL_TEXTURE_2D
, 3, 128, 128, GL_RGB
,
241 GL_UNSIGNED_BYTE
, (GLvoid
*) (&tex
[0])))) {
242 fprintf(stderr
, "GLULib%s\n", (char *) gluErrorString(gluerr
));
246 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
247 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
249 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
250 GL_LINEAR_MIPMAP_NEAREST
);
251 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
253 glTexEnvf(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
254 glEnable(GL_TEXTURE_2D
);
256 glDepthFunc(GL_ALWAYS
);
258 glClearColor(0.0, 0.1, 1.0, 0.0);
259 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
263 test05(int size
, int num
)
266 float v0
[3], v1
[3], v2
[3], v3
[3];
267 float cv0
[3], cv1
[3], cv2
[3], cv3
[3];
268 float tv0
[3], tv1
[3], tv2
[3], tv3
[3];
270 v0
[0] = 320 - size
/ 2;
271 v0
[1] = 240 - size
/ 2;
273 v1
[0] = 320 + size
/ 2;
274 v1
[1] = 240 - size
/ 2;
276 v2
[0] = 320 - size
/ 2;
277 v2
[1] = 240 + size
/ 2;
279 v3
[0] = 320 + size
/ 2;
280 v3
[1] = 240 + size
/ 2;
307 glBegin(GL_TRIANGLE_STRIP
);
308 for (y
= 0; y
< num
; y
++) {
330 /***************************************************************************/
335 glMatrixMode(GL_PROJECTION
);
337 gluOrtho2D(-0.5, 639.5, -0.5, 479.5);
338 glMatrixMode(GL_MODELVIEW
);
340 glShadeModel(GL_SMOOTH
);
341 glEnable(GL_DEPTH_TEST
);
343 glClearColor(0.0, 0.1, 1.0, 0.0);
344 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
348 test06(int size
, int num
)
352 for (y
= 0; y
< num
; y
++) {
353 glClearColor(y
/ (float) num
, 0.1, 1.0, 0.0);
354 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
360 /***************************************************************************/
362 #define BMARKS_TIME 5.0
366 /* 554 ~= sqrt(640*480) */
368 static benchmark bmarks
[NUM_BMARKS
] = {
369 {"Simple Points", "Pnts", init_test01
, test01
, 0, 0,
370 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
371 {"Smooth Lines", "Lins", init_test02
, test02
, 1, 5,
372 {480, 250, 100, 50, 25, 0, 0, 0, 0, 0}},
373 {"ZSmooth Triangles", "Tris", init_test03
, test03
, 1, 5,
374 {480, 250, 100, 50, 25, 0, 0, 0, 0, 0}},
375 {"ZSmooth Tex Blend Triangles", "Tris", init_test04
, test04
, 1, 5,
376 {480, 250, 100, 50, 25, 0, 0, 0, 0, 0}},
377 {"ZSmooth Tex Blend TMesh Triangles", "Tris", init_test05
, test05
, 2, 8,
378 {400, 250, 100, 50, 25, 10, 5, 2, 0, 0}},
379 {"Color/Depth Buffer Clears", "Clrs", init_test06
, test06
, 3, 0,
380 {554, 0, 0, 0, 0, 0, 0, 0, 0, 0}}
383 /***************************************************************************/
386 dotest0param(benchmark
* bmark
)
388 float stime
, etime
, dtime
, tottime
, maxtime
, mintime
;
389 int num
, numelem
, calibnum
, j
;
391 glPushAttrib(GL_ALL_ATTRIB_BITS
);
394 stime
= glutGet(GLUT_ELAPSED_TIME
);
398 while (dtime
< 2.0) {
401 etime
= glutGet(GLUT_ELAPSED_TIME
);
402 dtime
= (etime
- stime
) / 1000.0;
407 fprintf(stderr
, "Elapsed time for the calibration test (%d): %f\n",
410 num
= (int) ((BMARKS_TIME
/ dtime
) * calibnum
);
415 fprintf(stderr
, "Selected number of benchmark iterations: %d\n", num
);
420 for (tottime
= 0.0, j
= 0; j
< 5; j
++) {
421 glPushAttrib(GL_ALL_ATTRIB_BITS
);
424 stime
= glutGet(GLUT_ELAPSED_TIME
);
425 numelem
= bmark
->run(0, num
);
427 etime
= glutGet(GLUT_ELAPSED_TIME
);
431 dtime
= (etime
- stime
) / 1000.0;
434 fprintf(stderr
, "Elapsed time for run %d: %f\n", j
, dtime
);
442 tottime
-= mintime
+ maxtime
;
444 fprintf(stdout
, "%s\n%f %s/sec", bmark
->name
, numelem
/ (tottime
/ 3.0),
447 if (bmark
->type
== 3)
448 fprintf(stdout
, ", MPixel Fill/sec: %f\n\n",
449 (numelem
* bmark
->size
[0] * (float) bmark
->size
[0]) /
450 (1000000.0 * tottime
/ 3.0));
452 fprintf(stdout
, "\n\n");
455 /***************************************************************************/
458 dotest1param(benchmark
* bmark
)
460 float stime
, etime
, dtime
, tottime
, maxtime
, mintime
;
461 int num
, numelem
, calibnum
, j
, k
;
463 fprintf(stdout
, "%s\n", bmark
->name
);
465 for (j
= 0; j
< bmark
->numsize
; j
++) {
466 fprintf(stderr
, "Current size: %d\n", bmark
->size
[j
]);
468 glPushAttrib(GL_ALL_ATTRIB_BITS
);
471 stime
= glutGet(GLUT_ELAPSED_TIME
);
475 while (dtime
< 2.0) {
476 bmark
->run(bmark
->size
[j
], 1);
478 etime
= glutGet(GLUT_ELAPSED_TIME
);
479 dtime
= (etime
- stime
) / 1000.0;
484 fprintf(stderr
, "Elapsed time for the calibration test (%d): %f\n",
487 num
= (int) ((BMARKS_TIME
/ dtime
) * calibnum
);
492 fprintf(stderr
, "Selected number of benchmark iterations: %d\n", num
);
497 for (numelem
= 1, tottime
= 0.0, k
= 0; k
< 5; k
++) {
498 glPushAttrib(GL_ALL_ATTRIB_BITS
);
501 stime
= glutGet(GLUT_ELAPSED_TIME
);
502 numelem
= bmark
->run(bmark
->size
[j
], num
);
504 etime
= glutGet(GLUT_ELAPSED_TIME
);
508 dtime
= (etime
- stime
) / 1000.0;
511 fprintf(stderr
, "Elapsed time for run %d: %f\n", k
, dtime
);
519 tottime
-= mintime
+ maxtime
;
521 fprintf(stdout
, "SIZE=%03d => %f %s/sec", bmark
->size
[j
],
522 numelem
/ (tottime
/ 3.0), bmark
->unit
);
523 if (bmark
->type
== 2)
524 fprintf(stdout
, ", MPixel Fill/sec: %f\n",
525 (numelem
* bmark
->size
[j
] * bmark
->size
[j
] / 2) /
526 (1000000.0 * tottime
/ 3.0));
528 fprintf(stdout
, "\n");
531 fprintf(stdout
, "\n\n");
534 /***************************************************************************/
542 glDrawBuffer(GL_FRONT
);
544 glDrawBuffer(GL_BACK
);
546 for (i
= 0; i
< NUM_BMARKS
; i
++) {
547 fprintf(stderr
, "Benchmark: %d\n", i
);
549 switch (bmarks
[i
].type
) {
552 dotest0param(&bmarks
[i
]);
556 dotest1param(&bmarks
[i
]);
565 main(int ac
, char **av
)
567 fprintf(stderr
, "GLTest v1.0\nWritten by David Bucciarelli\n");
572 glutInitWindowSize(640, 480);
574 glutInitDisplayMode(GLUT_DOUBLE
| GLUT_RGB
| GLUT_DEPTH
);
575 glutCreateWindow("OpenGL/Mesa Performances");
576 glutDisplayFunc(display
);