Add more structure constructor tests.
[piglit/hramrach.git] / tests / texturing / getteximage-simple.c
blobd22f34cfa19249d7de0cbf87ff5b7d020cac9c85
1 /**
2 * @file getteximage-simple.c
4 * Extremely basic test to check whether image data can be retrieved.
5 *
6 * Note that the texture is used in a full frame of rendering before
7 * the readback, to ensure that buffer manager related code for uploading
8 * texture images is executed before the readback.
10 * This used to crash for R300+bufmgr.
13 #include "piglit-util.h"
15 int piglit_width = 100, piglit_height = 100;
16 int piglit_window_mode = GLUT_RGBA | GLUT_DOUBLE;
17 static GLubyte data[4096]; /* 64*16*4 */
19 static int test_getteximage(void)
21 GLubyte compare[4096];
22 int i;
24 glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, compare);
26 for(i = 0; i < 4096; ++i) {
27 if (data[i] != compare[i]) {
28 printf("GetTexImage() returns incorrect data in byte %i\n", i);
29 printf(" corresponding to (%i,%i) channel %i\n", i / 64, (i / 4) % 16, i % 4);
30 printf(" expected: %i\n", data[i]);
31 printf(" got: %i\n", compare[i]);
32 return 0;
36 return 1;
39 enum piglit_result
40 piglit_display(void)
42 int pass;
44 glClearColor(0.0, 0.0, 0.0, 1.0);
45 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
47 glEnable(GL_TEXTURE_2D);
48 glBegin(GL_QUADS);
49 glTexCoord2f(0, 0);
50 glVertex2f(0, 0);
51 glTexCoord2f(1, 0);
52 glVertex2f(1, 0);
53 glTexCoord2f(1, 1);
54 glVertex2f(1, 1);
55 glTexCoord2f(0, 1);
56 glVertex2f(0, 1);
57 glEnd();
59 glutSwapBuffers();
61 pass = test_getteximage();
63 return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
66 static void Reshape(int width, int height)
68 piglit_width = width;
69 piglit_height = height;
70 glViewport(0, 0, width, height);
71 glMatrixMode(GL_PROJECTION);
72 glLoadIdentity();
73 glOrtho(0.0, 1.0, 0.0, 1.0, -2.0, 6.0);
74 glScalef(1.0, 1.0, -1.0); // flip z-axis
75 glMatrixMode(GL_MODELVIEW);
76 glLoadIdentity();
79 void piglit_init(int argc, char **argv)
81 int i;
83 glutReshapeFunc(Reshape);
85 for(i = 0; i < 4096; ++i)
86 data[i] = rand() & 0xff;
88 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
89 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
90 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
92 Reshape(piglit_width, piglit_height);