gallium: change remaining util functions to use cso sampler views
[mesa/mesa-lb.git] / progs / tests / texcompsub.c
blob215f5711d9530aee8052f0484b77c9dd16d1aee5
1 /*
2 * Test texture compression.
3 */
6 #include <assert.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <GL/glew.h>
11 #include <GL/glut.h>
13 #include "texcomp_image.h"
15 static int ImgWidth = 512;
16 static int ImgHeight = 512;
17 static GLenum CompFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
18 static GLfloat EyeDist = 5.0;
19 static GLfloat Rot = 0.0;
20 const GLenum Target = GL_TEXTURE_2D;
23 static void
24 CheckError(int line)
26 GLenum err = glGetError();
27 if (err) {
28 printf("GL Error %d at line %d\n", (int) err, line);
32 static void
33 LoadCompressedImage(void)
35 unsigned char ImgDataTemp[ImgSize / 4];
36 unsigned i;
37 const GLenum filter = GL_LINEAR;
38 const int half = ImgSize / 2;
40 glTexImage2D(Target, 0, CompFormat, ImgWidth, ImgHeight, 0,
41 GL_RGB, GL_UNSIGNED_BYTE, NULL);
43 /* bottom half */
44 glCompressedTexSubImage2DARB(Target, 0,
45 0, 0, /* pos */
46 ImgWidth, ImgHeight / 2,
47 CompFormat, ImgSize / 2, ImgData /*+ ImgSize / 2*/);
49 /* top left */
50 for (i = 0; i < ImgHeight / 8; i++) {
51 memcpy(&ImgDataTemp[i * ImgWidth], &ImgData[half + i * 2 * ImgWidth], ImgWidth);
53 glCompressedTexSubImage2DARB(Target, 0,
54 0, ImgHeight / 2, /* pos */
55 ImgWidth / 2, ImgHeight / 2,
56 CompFormat, ImgSize / 4, ImgDataTemp);
58 /* top right */
59 for (i = 0; i < ImgHeight / 8; i++) {
60 memcpy(&ImgDataTemp[i * ImgWidth], &ImgData[half + i * 2 * ImgWidth + ImgWidth], ImgWidth);
62 glCompressedTexSubImage2DARB(Target, 0,
63 ImgWidth / 2, ImgHeight / 2, /* pos */
64 ImgWidth / 2, ImgHeight / 2,
65 CompFormat, ImgSize / 4, ImgDataTemp);
67 glTexParameteri(Target, GL_TEXTURE_MIN_FILTER, filter);
68 glTexParameteri(Target, GL_TEXTURE_MAG_FILTER, filter);
71 static void
72 Init()
74 GLint numFormats, formats[100];
75 GLint p;
77 if (!glutExtensionSupported("GL_ARB_texture_compression")) {
78 printf("Sorry, GL_ARB_texture_compression is required.\n");
79 exit(1);
81 if (!glutExtensionSupported("GL_EXT_texture_compression_s3tc")) {
82 printf("Sorry, GL_EXT_texture_compression_s3tc is required.\n");
83 exit(1);
86 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
87 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
89 glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB, &numFormats);
90 glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS_ARB, formats);
91 printf("%d supported compression formats: ", numFormats);
92 for (p = 0; p < numFormats; p++)
93 printf("0x%x ", formats[p]);
94 printf("\n");
96 glEnable(GL_TEXTURE_2D);
98 LoadCompressedImage();
102 static void
103 Reshape( int width, int height )
105 glViewport( 0, 0, width, height );
106 glMatrixMode( GL_PROJECTION );
107 glLoadIdentity();
108 glFrustum(-1, 1, -1, 1, 4, 100);
109 glMatrixMode( GL_MODELVIEW );
110 glLoadIdentity();
114 static void
115 Key( unsigned char key, int x, int y )
117 (void) x;
118 (void) y;
119 switch (key) {
120 case 'd':
121 EyeDist -= 1.0;
122 if (EyeDist < 4.0)
123 EyeDist = 4.0;
124 break;
125 case 'D':
126 EyeDist += 1.0;
127 break;
128 case 'z':
129 Rot += 5.0;
130 break;
131 case 'Z':
132 Rot -= 5.0;
133 break;
134 case 27:
135 exit(0);
136 break;
138 glutPostRedisplay();
142 static void
143 Draw( void )
145 glClearColor(0.3, 0.3, .8, 0);
146 glClear(GL_COLOR_BUFFER_BIT);
148 CheckError(__LINE__);
149 glPushMatrix();
150 glTranslatef(0, 0, -(EyeDist+0.01));
151 glRotatef(Rot, 0, 0, 1);
152 glBegin(GL_POLYGON);
153 glTexCoord2f(0, 0); glVertex2f(-1, -1);
154 glTexCoord2f(1, 0); glVertex2f( 1, -1);
155 glTexCoord2f(1, 1); glVertex2f( 1, 1);
156 glTexCoord2f(0, 1); glVertex2f(-1, 1);
157 glEnd();
158 glPopMatrix();
160 glutSwapBuffers();
165 main( int argc, char *argv[] )
167 glutInit( &argc, argv );
168 glutInitWindowSize( 600, 600 );
170 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE);
172 glutCreateWindow(argv[0]);
173 glewInit();
175 glutReshapeFunc( Reshape );
176 glutKeyboardFunc( Key );
177 glutDisplayFunc( Draw );
179 Init();
181 glutMainLoop();
182 return 0;