Merge branch 'mesa_7_6_branch'
[mesa.git] / progs / demos / clearspd.c
index b2edf3206920a5ca13e8dcc5115b5e854c084c9f..42953f6675e01bd5fa3458f19d5e1515925c6437 100644 (file)
@@ -1,30 +1,9 @@
-/* $Id: clearspd.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
 
 /*
  * Simple GLUT program to measure glClear() and glutSwapBuffers() speed.
  * Brian Paul  February 15, 1997  This file in public domain.
  */
 
-/*
- * $Log: clearspd.c,v $
- * Revision 1.1  1999/08/19 00:55:40  jtg
- * Initial revision
- *
- * Revision 3.3  1999/03/28 18:18:33  brianp
- * minor clean-up
- *
- * Revision 3.2  1999/03/18 08:16:34  joukj
- *
- *     cmpstr needs string.h to included to avoid warnings
- *
- * Revision 3.1  1998/06/29 02:38:30  brianp
- * removed unneeded includes
- *
- * Revision 3.0  1998/02/14 18:42:29  brianp
- * initial rev
- *
- */
-
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -68,6 +47,7 @@ static void Display( void )
          glClear( BufferMask );
          glutSwapBuffers();
       }
+      glFinish();
       t1 = glutGet(GLUT_ELAPSED_TIME) * 0.001;
    }
    else {
@@ -75,10 +55,17 @@ static void Display( void )
       for (i=0;i<Loops;i++) {
          glClear( BufferMask );
       }
+      glFinish();
       t1 = glutGet(GLUT_ELAPSED_TIME) * 0.001;
       glutSwapBuffers();
    }
 
+   /* NOTE: If clearspd doesn't map it's window immediately on
+    * starting, swaps will be istantaneous, so this will send Loops
+    * towards infinity.  When a window is finally mapped, it may be
+    * minutes before the first call to glutSwapBuffers, making it look
+    * like there's a driver bug.
+    */
    if (t1-t0 < MinPeriod) {
       /* Next time do more clears to get longer elapsed time */
       Loops *= 2;
@@ -88,12 +75,12 @@ static void Display( void )
    clearRate = Loops / (t1-t0);
    pixelRate = clearRate * Width * Height;
    if (SwapFlag) {
-      printf("Rate: %d clears+swaps in %gs = %g clears+swaps/s   %d pixels/s\n",
-             Loops, t1-t0, clearRate, (int)pixelRate );
+      printf("Rate: %d clears+swaps in %gs = %g clears+swaps/s   %g pixels/s\n",
+             Loops, t1-t0, clearRate, pixelRate );
    }
    else {
-      printf("Rate: %d clears in %gs = %g clears/s   %d pixels/s\n",
-             Loops, t1-t0, clearRate, (int)pixelRate);
+      printf("Rate: %d clears in %gs = %g clears/s   %g pixels/s\n",
+             Loops, t1-t0, clearRate, pixelRate);
    }
 }
 
@@ -194,6 +181,8 @@ static void Help( const char *program )
 
 int main( int argc, char *argv[] )
 {
+   GLint mode;
+
    printf("For options:  %s -help\n", argv[0]);
 
    Init( argc, argv );
@@ -202,7 +191,15 @@ int main( int argc, char *argv[] )
    glutInitWindowSize( (int) Width, (int) Height );
    glutInitWindowPosition( 0, 0 );
 
-   glutInitDisplayMode( ColorMode | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL | GLUT_ACCUM );
+   mode = ColorMode | GLUT_DOUBLE;
+   if (BufferMask & GL_STENCIL_BUFFER_BIT)
+      mode |= GLUT_STENCIL;
+   if (BufferMask & GL_ACCUM_BUFFER_BIT)
+      mode |= GLUT_ACCUM;
+   if (BufferMask & GL_DEPTH_BUFFER_BIT)
+      mode |= GLUT_DEPTH;
+         
+   glutInitDisplayMode(mode);
 
    glutCreateWindow( argv[0] );