progs/demos: add fps output to cubemap
[mesa.git] / progs / demos / cubemap.c
index 26db42aed5e7fe24d012f53d23dbcf2dd5704c7f..0a3e10dac08b4bf8fac8329c0ad7d6893b18c55a 100644 (file)
@@ -52,6 +52,9 @@ static GLboolean NoClear = GL_FALSE;
 static GLint FrameParity = 0;
 static GLenum FilterIndex = 0;
 static GLint ClampIndex = 0;
+static GLboolean supportFBO = GL_FALSE;
+static GLint T0 = 0;
+static GLint Frames = 0;
 
 
 static struct {
@@ -267,6 +270,20 @@ static void draw( void )
    glPopMatrix();
 
    glutSwapBuffers();
+
+   Frames++;
+
+   {
+      GLint t = glutGet(GLUT_ELAPSED_TIME);
+      if (t - T0 >= 5000) {
+        GLfloat seconds = (t - T0) / 1000.0;
+        GLfloat fps = Frames / seconds;
+        printf("%d frames in %6.3f seconds = %6.3f FPS\n", Frames, seconds, fps);
+        fflush(stdout);
+        T0 = t;
+        Frames = 0;
+      }
+   }
 }
 
 
@@ -403,6 +420,10 @@ static void init_checkers( void )
 
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
 
+   if (!supportFBO)
+      glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
+
+
    /* make colored checkerboard cube faces */
    for (f = 0; f < 6; f++) {
       for (i = 0; i < CUBE_TEX_SIZE; i++) {
@@ -426,7 +447,8 @@ static void init_checkers( void )
                    GL_BGRA, GL_UNSIGNED_BYTE, image);
    }
 
-   glGenerateMipmapEXT(GL_TEXTURE_CUBE_MAP_ARB);
+   if (supportFBO)
+      glGenerateMipmapEXT(GL_TEXTURE_CUBE_MAP_ARB);
 }
 
 
@@ -503,10 +525,13 @@ static void init( GLboolean useImageFiles )
          exit(0);
       }
 
-      /* Needed for glGenerateMipmapEXT
+      /* Needed for glGenerateMipmapEXT / auto mipmapping
        */
-      if (!strstr(exten, "GL_EXT_framebuffer_object")) {
-         printf("Sorry, this demo requires GL_EXT_framebuffer_object\n");
+      if (strstr(exten, "GL_EXT_framebuffer_object")) {
+         supportFBO = GL_TRUE;
+      }
+      else if (!strstr(exten, "GL_SGIS_generate_mipmap")) {
+         printf("Sorry, this demo requires GL_EXT_framebuffer_object or GL_SGIS_generate_mipmap\n");
          exit(0);
       }
    }