Add more structure constructor tests.
[piglit/hramrach.git] / tests / texturing / texrect-many.c
blobcda51b51e62c10b4464d579a0e5311171e29dd1d
1 /**
2 * @file texrect-many.c
4 * Tests whether the driver can support a full set of rectangle textures.
6 * (Prompted by a bug in R300 where the driver ran out of indirections).
7 */
9 #include "piglit-util.h"
11 int piglit_width = 16 * 16, piglit_height = 11 * 16;
12 int piglit_window_mode = GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA;
14 static int NumTextures = 16;
15 static GLuint Textures[16];
17 static const GLubyte colors[7][4] = {
18 { 0, 0, 0, 255 },
19 { 255, 0, 0, 255 },
20 { 0, 255, 0, 255 },
21 { 0, 0, 255, 255 },
22 { 128, 0, 0, 128 },
23 { 0, 128, 0, 128 },
24 { 0, 0, 128, 128 }
27 static void ActiveTexture(int i)
29 glActiveTexture(GL_TEXTURE0+i);
30 glClientActiveTexture(GL_TEXTURE0+i);
33 static void DoFrame(void)
35 int i;
37 glClearColor(0.5, 0.5, 0.0, 0.0);
38 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
40 glColor4f(1,1,1,1);
41 glBegin(GL_QUADS);
42 for(i = 0; i < NumTextures; ++i)
43 glMultiTexCoord2f(GL_TEXTURE0+i, 0, 0);
44 glVertex2f(0, 0);
45 for(i = 0; i < NumTextures; ++i)
46 glMultiTexCoord2f(GL_TEXTURE0+i, 16, 0);
47 glVertex2f(1, 0);
48 for(i = 0; i < NumTextures; ++i)
49 glMultiTexCoord2f(GL_TEXTURE0+i, 16, 11);
50 glVertex2f(1, 1);
51 for(i = 0; i < NumTextures; ++i)
52 glMultiTexCoord2f(GL_TEXTURE0+i, 0, 11);
53 glVertex2f(0, 1);
54 glEnd();
56 glutSwapBuffers();
59 static int DoTest(void)
61 GLfloat dmax;
62 int x, y;
64 glReadBuffer(GL_FRONT);
65 dmax = 0;
67 for(x = 0; x < NumTextures; ++x) {
68 for(y = 0; y < 11; ++y) {
69 GLfloat probe[4];
70 GLfloat delta[4];
71 int i;
72 int clr;
74 glReadPixels((2*x+1) * piglit_width / 32,
75 (2*y+1) * piglit_height / 22,
76 1, 1, GL_RGBA, GL_FLOAT, probe);
78 printf(" %i/%i: %f,%f,%f,%f", x, y,
79 probe[0], probe[1], probe[2], probe[3]);
81 clr = (x+y)%7;
82 for(i = 0; i < 4; ++i) {
83 delta[i] = probe[i] - colors[clr][i]/255.0;
85 if (delta[i] > dmax) dmax = delta[i];
86 else if (-delta[i] > dmax) dmax = -delta[i];
89 printf(" Delta: %f,%f,%f,%f\n", delta[0], delta[1], delta[2], delta[3]);
93 printf("Max delta: %f\n", dmax);
95 if (dmax >= 0.02)
96 return 0;
97 else
98 return 1;
102 enum piglit_result
103 piglit_display(void)
105 int pass;
107 DoFrame();
108 pass = DoTest();
110 return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
113 static void Reshape(int width, int height)
115 piglit_width = width;
116 piglit_height = height;
117 glViewport(0, 0, width, height);
118 glMatrixMode(GL_PROJECTION);
119 glLoadIdentity();
120 glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
121 glScalef(1.0, 1.0, -1.0); // flip z-axis
122 glMatrixMode(GL_MODELVIEW);
123 glLoadIdentity();
126 void piglit_init(int argc, char **argv)
128 int i;
129 int maxtextures;
131 if (!GLEW_VERSION_1_3) {
132 printf("Requires OpenGL 1.3\n");
133 piglit_report_result(PIGLIT_SKIP);
136 glutReshapeFunc(Reshape);
138 piglit_require_extension("GL_ARB_texture_rectangle");
140 glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxtextures);
141 if (maxtextures < NumTextures)
142 NumTextures = maxtextures;
144 glGenTextures(NumTextures, Textures);
145 for(i = 0; i < NumTextures; ++i) {
146 GLubyte tex[11*16*4];
147 GLubyte* p;
148 int x, y;
150 ActiveTexture(i);
151 glEnable(GL_TEXTURE_RECTANGLE_ARB);
152 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, Textures[i]);
154 p = tex;
155 for(y = 0; y < 11; ++y) {
156 for(x = 0; x < 16; ++x, p += 4) {
157 if (x != i) {
158 p[0] = p[1] = p[2] = p[3] = 255;
159 } else {
160 int clr = (x+y)%7;
161 p[0] = colors[clr][0];
162 p[1] = colors[clr][1];
163 p[2] = colors[clr][2];
164 p[3] = colors[clr][3];
169 glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, 16, 11, 0,
170 GL_RGBA, GL_UNSIGNED_BYTE, tex);
171 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
172 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
175 Reshape(piglit_width, piglit_height);