No longer alias generic vertex attribs with conventional attribs for GL_ARB_vertex_pr...
[mesa.git] / progs / tests / ext422square.c
index d1c168773091f0adefc2f28398763c7153a17707..6533514d697a045af088c3aca2063957e792145f 100644 (file)
@@ -24,6 +24,7 @@ static GLfloat Xrot = 0, Yrot = 0, Zrot = 0;
 static GLint ImgWidth, ImgHeight;
 static GLushort *ImageYUV = NULL;
 static const GLuint yuvObj = 100;
+static const GLuint rgbObj = 101;
 
 static void Init( int argc, char *argv[] );
 
@@ -59,11 +60,12 @@ static void Display( void )
    glBindTexture(GL_TEXTURE_2D, yuvObj);
 
    glPushMatrix();
-      glEnable(GL_FRAGMENT_PROGRAM_ARB);
+      glEnable(GL_FRAGMENT_PROGRAM_ARB); 
       glTranslatef( -1.1, 0.0, -15.0 );
       glRotatef(Xrot, 1.0, 0.0, 0.0);
       glRotatef(Yrot, 0.0, 1.0, 0.0);
       glRotatef(Zrot, 0.0, 0.0, 1.0);
+      glBindTexture(GL_TEXTURE_2D, yuvObj);
       DrawObject();
    glPopMatrix();
 
@@ -73,6 +75,7 @@ static void Display( void )
       glRotatef(Xrot, 1.0, 0.0, 0.0);
       glRotatef(Yrot, 0.0, 1.0, 0.0);
       glRotatef(Zrot, 0.0, 0.0, 1.0);
+      glBindTexture(GL_TEXTURE_2D, rgbObj);
       DrawObject();
    glPopMatrix();
 
@@ -136,6 +139,12 @@ static void SpecialKey( int key, int x, int y )
 static void Init( int argc, char *argv[] )
 {
    const char *file;
+   const GLfloat yuvtorgb[16] = {
+      1.164,   1.164,    1.164,      0,
+      0,       -.391,    2.018,      0,
+      1.596,   -.813,    0.0,        0,
+      (-.0625*1.164 + -.5*1.596),     (-.0625*1.164 + -.5*-.813 + -.5*-.391),     (-.0625*1.164 + -.5*2.018),      1  
+   };
 
    if (!glutExtensionSupported("GL_ARB_fragment_program")) {
       printf("Error: GL_ARB_fragment_program not supported!\n");
@@ -204,6 +213,30 @@ static void Init( int argc, char *argv[] )
 
    }
 
+   /* Now the same, but use a color matrix to do the conversion at
+    * upload time:
+    */
+   glBindTexture(GL_TEXTURE_2D, rgbObj);
+   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+   glMatrixMode( GL_COLOR_MATRIX );
+   glLoadMatrixf( yuvtorgb );
+   
+   glTexImage2D(GL_TEXTURE_2D, 0,
+                GL_RGB,
+               ImgWidth, ImgHeight, 0,
+                GL_422_EXT,
+               GL_UNSIGNED_BYTE, ImageYUV);
+
+   glLoadIdentity();
+   glMatrixMode( GL_MODELVIEW );
+
+   glEnable(GL_TEXTURE_2D);
+
+   glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+
+
    glShadeModel(GL_FLAT);
    glClearColor(0.3, 0.3, 0.4, 1.0);
 }