2 * @file getteximage-simple.c
4 * Extremely basic test to check whether image data can be retrieved.
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];
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
]);
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
);
61 pass
= test_getteximage();
63 return pass
? PIGLIT_SUCCESS
: PIGLIT_FAILURE
;
66 static void Reshape(int width
, int height
)
69 piglit_height
= height
;
70 glViewport(0, 0, width
, height
);
71 glMatrixMode(GL_PROJECTION
);
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
);
79 void piglit_init(int argc
, char **argv
)
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
);