progs/tests: compile with SCons and glew
[mesa.git] / progs / tests / packedpixels.c
index 842cf7f34b93822dfb5fa19c8eb197ac21dc08d6..1703b271cb03011f40ff27ce072160cea78e1953 100644 (file)
@@ -8,6 +8,7 @@
 #include <stdlib.h>
 #include <math.h>
 #include <string.h>
+#include <GL/glew.h>
 #include <GL/glut.h>
 
 
@@ -106,6 +107,9 @@ static const struct name_format IntFormats[] = {
 #define NUM_INT_FORMATS (sizeof(IntFormats) / sizeof(IntFormats[0]))
 static GLuint CurFormat = 0;
 
+static GLboolean Test3D = GL_FALSE;
+
+
 
 static void
 PrintString(const char *s)
@@ -167,8 +171,25 @@ MakeTexture(const struct pixel_format *format, GLenum intFormat, GLboolean swap)
    else {
       abort();
    }
-   glTexImage2D(GL_TEXTURE_2D, 0, intFormat, 4, 4, 0,
-                format->format, format->type, texBuffer);
+
+   if (Test3D) {
+      /* 4 x 4 x 4 texture, undefined data */
+      glTexImage3D(GL_TEXTURE_3D, 0, intFormat, 4, 4, 4, 0,
+                   format->format, format->type, NULL);
+      /* fill in Z=1 and Z=2 slices with the real texture data */
+      glTexSubImage3D(GL_TEXTURE_3D, 0,
+                      0, 0, 1,  /* offset */
+                      4, 4, 1,  /* size */
+                      format->format, format->type, texBuffer);
+      glTexSubImage3D(GL_TEXTURE_3D, 0,
+                      0, 0, 2,  /* offset */
+                      4, 4, 1,  /* size */
+                      format->format, format->type, texBuffer);
+   }
+   else {
+      glTexImage2D(GL_TEXTURE_2D, 0, intFormat, 4, 4, 0,
+                   format->format, format->type, texBuffer);
+   }
 
    if (glGetError()) {
       printf("GL Error for %s\n", format->name);
@@ -196,15 +217,21 @@ Draw(void)
 
         MakeTexture(Formats + i, IntFormats[CurFormat].format, swap);
 
-        glEnable(GL_TEXTURE_2D);
+        if (Test3D)
+           glEnable(GL_TEXTURE_3D);
+        else
+           glEnable(GL_TEXTURE_2D);
         glBegin(GL_POLYGON);
-        glTexCoord2f(0, 0);  glVertex2f(0, 0);
-        glTexCoord2f(1, 0);  glVertex2f(w, 0);
-        glTexCoord2f(1, 1);  glVertex2f(w, h);
-        glTexCoord2f(0, 1);  glVertex2f(0, h);
+        glTexCoord3f(0, 0, 0.5);  glVertex2f(0, 0);
+        glTexCoord3f(1, 0, 0.5);  glVertex2f(w, 0);
+        glTexCoord3f(1, 1, 0.5);  glVertex2f(w, h);
+        glTexCoord3f(0, 1, 0.5);  glVertex2f(0, h);
         glEnd();
 
-        glDisable(GL_TEXTURE_2D);
+        if (Test3D)
+           glDisable(GL_TEXTURE_3D);
+        else
+           glDisable(GL_TEXTURE_2D);
         glColor3f(0, 0, 0);
         glRasterPos2i(8, 6);
         PrintString(Formats[i].name);
@@ -230,6 +257,15 @@ Draw(void)
    PrintString(s);
    glPopMatrix();
 
+   glPushMatrix();
+   glTranslatef(2, (i + 2) * (h + 2), 0);
+   glRasterPos2i(8, 6);
+   if (Test3D)
+      PrintString("Target [2/3]: GL_TEXTURE_3D");
+   else
+      PrintString("Target [2/3]: GL_TEXTURE_2D");
+   glPopMatrix();
+
    glutSwapBuffers();
 }
 
@@ -263,6 +299,12 @@ Key(unsigned char key, int x, int y)
          if (CurFormat == NUM_INT_FORMATS)
             CurFormat = 0;
          break;
+      case '2':
+         Test3D = GL_FALSE;
+         break;
+      case '3':
+         Test3D = GL_TRUE;
+         break;
       case 27:
          exit(0);
          break;
@@ -278,6 +320,8 @@ Init(void)
    printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+   glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+   glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
 }
 
@@ -290,6 +334,7 @@ main(int argc, char *argv[])
    glutInitWindowSize(700, 800);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow(argv[0]);
+   glewInit();
    glutReshapeFunc(Reshape);
    glutKeyboardFunc(Key);
    glutDisplayFunc(Draw);