Merge branch 'mesa_7_5_branch'
[mesa.git] / progs / demos / arbocclude.c
index 959e9763b65021611b93b0ebf68b07b72e1711af..9188ad5a5658743c1fb3e3edaaffe0dd004e8f74 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * GL_ARB_occlustion_query demo
+ * GL_ARB_occlusion_query demo
  *
  * Brian Paul
  * 12 June 2003
 #include <stdlib.h>
 #include <string.h>
 #include <math.h>
-#define GL_GLEXT_PROTOTYPES
+#include <GL/glew.h>
 #include <GL/glut.h>
 
+#define TEST_DISPLAY_LISTS 0
 
+static GLboolean Anim = GL_TRUE;
 static GLfloat Xpos = 0;
 static GLuint OccQuery;
-
+static GLint Win = 0;
 
 
 static void
@@ -113,7 +115,15 @@ static void Display( void )
    glScalef(0.3, 0.3, 1.0);
    glRotatef(-90.0 * Xpos, 0, 0, 1);
 
+#if defined(GL_ARB_occlusion_query)
+#if TEST_DISPLAY_LISTS
+   glNewList(10, GL_COMPILE);
+   glBeginQueryARB(GL_SAMPLES_PASSED_ARB, OccQuery);
+   glEndList();
+   glCallList(10);
+#else
    glBeginQueryARB(GL_SAMPLES_PASSED_ARB, OccQuery);
+#endif
 
    glColorMask(0, 0, 0, 0);
    glDepthMask(GL_FALSE);
@@ -125,7 +135,14 @@ static void Display( void )
    glVertex3f(-1,  1, 0);
    glEnd();
 
+#if TEST_DISPLAY_LISTS
+   glNewList(11, GL_COMPILE);
+   glEndQueryARB(GL_SAMPLES_PASSED_ARB);
+   glEndList();
+   glCallList(11);
+#else
    glEndQueryARB(GL_SAMPLES_PASSED_ARB);
+#endif
 
    do {
       /* do useful work here, if any */
@@ -136,6 +153,7 @@ static void Display( void )
    /* turn off occlusion testing */
    glColorMask(1, 1, 1, 1);
    glDepthMask(GL_TRUE);
+#endif /* GL_ARB_occlusion_query */
 
    /* draw the orange rect, so we can see what's going on */
    glColor3f(0.8, 0.5, 0);
@@ -157,6 +175,7 @@ static void Display( void )
    glLoadIdentity();
 
    glColor3f(1, 1, 1);
+#if defined(GL_ARB_occlusion_query)
    sprintf(s, " %4d Fragments Visible", passed);
    glRasterPos3f(-0.50, -0.7, 0);
    PrintString(s);
@@ -164,6 +183,10 @@ static void Display( void )
       glRasterPos3f(-0.25, -0.8, 0);
       PrintString("Fully Occluded");
    }
+#else
+   glRasterPos3f(-0.25, -0.8, 0);
+   PrintString("GL_ARB_occlusion_query not available at compile time");
+#endif /* GL_ARB_occlusion_query */
 
    glutSwapBuffers();
 }
@@ -181,8 +204,16 @@ static void Key( unsigned char key, int x, int y )
    (void) y;
    switch (key) {
       case 27:
+         glutDestroyWindow(Win);
          exit(0);
          break;
+      case ' ':
+         Anim = !Anim;
+         if (Anim)
+            glutIdleFunc(Idle);
+         else
+            glutIdleFunc(NULL);
+         break;
    }
    glutPostRedisplay();
 }
@@ -215,14 +246,21 @@ static void Init( void )
       exit(-1);
    }
 
+#if defined(GL_ARB_occlusion_query)
    glGetQueryivARB(GL_SAMPLES_PASSED_ARB, GL_QUERY_COUNTER_BITS_ARB, &bits);
    if (!bits) {
       printf("Hmmm, GL_QUERY_COUNTER_BITS_ARB is zero!\n");
       exit(-1);
    }
+#endif /* GL_ARB_occlusion_query */
+
+   glGetIntegerv(GL_DEPTH_BITS, &bits);
+   printf("Depthbits: %d\n", bits);
 
+#if defined(GL_ARB_occlusion_query)
    glGenQueriesARB(1, &OccQuery);
-   assert( glIsQueryARB(OccQuery) );
+   assert(OccQuery > 0);
+#endif /* GL_ARB_occlusion_query */
 
    glEnable(GL_DEPTH_TEST);
 }
@@ -234,7 +272,8 @@ int main( int argc, char *argv[] )
    glutInitWindowPosition( 0, 0 );
    glutInitWindowSize( 400, 400 );
    glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
-   glutCreateWindow(argv[0]);
+   Win = glutCreateWindow(argv[0]);
+   glewInit();
    glutReshapeFunc( Reshape );
    glutKeyboardFunc( Key );
    glutSpecialFunc( SpecialKey );