egl: remove duplicate ARRAY_SIZE() macro declaration
[mesa.git] / progs / demos / cubemap.c
index 1f9f2905759ae1e8ff91d20ed468c86aa615abe7..3e79d6a55890ce513ee6a0425a459c7642b3196c 100644 (file)
@@ -43,6 +43,9 @@
 #include "GL/glut.h"
 #include "readtex.h"
 
+#ifndef GL_TEXTURE_CUBE_MAP_SEAMLESS
+#define GL_TEXTURE_CUBE_MAP_SEAMLESS 0x884F
+#endif
 
 static GLfloat Xrot = 0, Yrot = 0;
 static GLfloat EyeDist = 10;
@@ -53,6 +56,11 @@ static GLint FrameParity = 0;
 static GLenum FilterIndex = 0;
 static GLint ClampIndex = 0;
 static GLboolean supportFBO = GL_FALSE;
+static GLboolean supportSeamless = GL_FALSE;
+static GLboolean seamless = GL_FALSE;
+static GLuint TexObj = 0;
+static GLint T0 = 0;
+static GLint Frames = 0;
 
 
 static struct {
@@ -91,7 +99,9 @@ static struct {
 
 
 
-#define eps1 0.99
+/* The effects of GL_ARB_seamless_cube_map don't show up unless eps1 is 1.0.
+ */
+#define eps1 1.0 /*0.99*/
 #define br   20.0  /* box radius */
 
 static const GLfloat tex_coords[] = {
@@ -231,6 +241,13 @@ static void draw( void )
    glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER,
                    FilterModes[FilterIndex].mag_mode);
 
+   if (supportSeamless) {
+      if (seamless) {
+        glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
+      } else {
+        glDisable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
+      }
+   }
    wrap = ClampModes[ClampIndex].mode;
    glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, wrap);
    glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, wrap);
@@ -268,6 +285,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;
+      }
+   }
 }
 
 
@@ -321,6 +352,11 @@ static void key(unsigned char k, int x, int y)
          mode = !mode;
          set_mode(mode);
          break;
+      case 's':
+        seamless = ! seamless;
+        printf("Seamless cube map filtering is %sabled\n",
+               (seamless) ? "en" : "dis" );
+        break;
       case 'v':
          use_vertex_arrays = ! use_vertex_arrays;
          printf( "Vertex arrays are %sabled\n",
@@ -502,25 +538,32 @@ static void load_envmaps(void)
 static void init( GLboolean useImageFiles )
 {
    /* check for extensions */
-   {
-      char *exten = (char *) glGetString(GL_EXTENSIONS);
-      if (!strstr(exten, "GL_ARB_texture_cube_map")) {
-         printf("Sorry, this demo requires GL_ARB_texture_cube_map\n");
-         exit(0);
-      }
+   if (!GLEW_ARB_texture_cube_map) {
+      printf("Sorry, this demo requires GL_ARB_texture_cube_map\n");
+      exit(0);
+   }
 
-      /* Needed for glGenerateMipmapEXT / auto mipmapping
-       */
-      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);
-      }
+   /* Needed for glGenerateMipmapEXT / auto mipmapping
+    */
+   supportFBO = GLEW_EXT_framebuffer_object;
+
+   if (!supportFBO && !GLEW_SGIS_generate_mipmap) {
+      printf("Sorry, this demo requires GL_EXT_framebuffer_object or "
+            "GL_SGIS_generate_mipmap\n");
+      exit(0);
    }
+
+   /* GLEW doesn't know about this extension yet, so use the old GLUT function
+    * to check for availability.
+    */
+   supportSeamless = glutExtensionSupported("GL_ARB_seamless_cube_map");
+
    printf("GL_RENDERER: %s\n", (char *) glGetString(GL_RENDERER));
 
+
+   glGenTextures(1, &TexObj);
+   glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, TexObj);
+
    if (useImageFiles) {
       load_envmaps();
    }
@@ -570,9 +613,8 @@ static void parse_args(int argc, char *argv[])
 
 int main( int argc, char *argv[] )
 {
-   glutInit(&argc, argv);
-   glutInitWindowPosition(0, 0);
    glutInitWindowSize(600, 500);
+   glutInit(&argc, argv);
    glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
    glutCreateWindow("Texture Cube Mapping");
    glewInit();