fix the spelling in whole piglit
[piglit.git] / tests / general / attribs.c
blobddb0b060a564701624e57418be38848a8931ab8d
1 /*
2 * Copyright © 2011 Marek Olšák <maraeo@gmail.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
24 /**
25 * Test for immediate-mode style commands like glVertexAttrib, glColor, etc.
26 * with vertex arrays, immediate mode and display lists.
27 * Most of the GL2 and GL3 commands are covered.
29 * glVertex and the commands taking a pointer (e.g. glColor*v) are not
30 * tested here.
33 #include "piglit-util-gl.h"
35 PIGLIT_GL_TEST_CONFIG_BEGIN
37 config.supports_gl_compat_version = 10;
39 config.window_width = 512;
40 config.window_height = 512;
41 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
42 config.khr_no_error_support = PIGLIT_NO_ERRORS;
44 PIGLIT_GL_TEST_CONFIG_END
46 static GLboolean snorm_equation_23;
48 enum {
50 RG,
51 RGB,
52 RGBA
55 enum {
56 FLOAT_TYPE,
57 INT_TYPE,
58 UINT_TYPE
61 enum {
62 VERTEX_ARRAYS,
63 IMMEDIATE_MODE,
64 DISPLAY_LIST,
65 NUM_MODES
68 static const char *mode_to_str[NUM_MODES] = {
69 "vertex arrays",
70 "immediate mode",
71 "display list"
74 static void draw_quad(unsigned mode, float *v,
75 void (*attrib)(float x, float y, float z, float w))
77 static const float verts[] = {
78 0, 0,
79 0, 10,
80 10, 10,
81 10, 0
83 int i;
85 switch (mode) {
86 case VERTEX_ARRAYS:
87 attrib(v[0], v[1], v[2], v[3]);
88 glEnableClientState(GL_VERTEX_ARRAY);
89 glVertexPointer(2, GL_FLOAT, 0, verts);
90 glDrawArrays(GL_QUADS, 0, 4);
91 glDisableClientState(GL_VERTEX_ARRAY);
92 break;
93 case IMMEDIATE_MODE:
94 glBegin(GL_QUADS);
95 for (i = 0; i < 4; i++) {
96 attrib(v[0], v[1], v[2], v[3]);
97 glVertex2fv(&verts[i*2]);
99 glEnd();
100 break;
101 case DISPLAY_LIST:
102 glNewList(1, GL_COMPILE);
103 glBegin(GL_QUADS);
104 for (i = 0; i < 4; i++) {
105 attrib(v[0], v[1], v[2], v[3]);
106 glVertex2fv(&verts[i*2]);
108 glEnd();
109 glEndList();
111 /* Clear to make sure the calls didn't get executed
112 * immediately.
114 glBegin(GL_QUADS);
115 for (i = 0; i < 4; i++) {
116 attrib(0.1, 0.1, 0.1, 0.1);
117 glVertex2fv(&verts[i*2]);
119 glEnd();
121 /* Now call the display list */
122 glCallList(1);
123 break;
124 default:
125 assert(0);
129 static GLboolean test(int x, int y, const char *shaderfunc,
130 unsigned mask, unsigned type, unsigned mode,
131 void (*attrib)(float x, float y, float z, float w),
132 const char *info)
134 static const char *templ = {
135 "%s \n"
136 "#extension GL_ARB_explicit_attrib_location : require \n"
137 "layout(location = 1) in %s attr; \n"
138 "void main() { \n"
139 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; \n"
140 " gl_FrontColor = (%s) * vec4(1.0, 1.0, 1.0, 0.5); \n"
141 "} \n"
143 GLuint prog, vs;
144 GLboolean pass = GL_TRUE;
145 char vstext[1024];
146 int i;
148 float color[3][4] = {
149 {0.2, 0.4, 0.6, 0.8},
150 {0, 1, 0, 1},
151 {0.5, 0.3, 0.9, 0.2}
154 sprintf(vstext, templ,
155 type != FLOAT_TYPE ? "#version 130" : "",
156 type == INT_TYPE ? "ivec4" : type == UINT_TYPE ? "uvec4" : "vec4",
157 shaderfunc);
159 /* Create the shader. */
160 vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vstext);
161 if (!vs)
162 piglit_report_result(PIGLIT_FAIL);
163 prog = piglit_link_simple_program(vs, 0);
164 if (!prog)
165 piglit_report_result(PIGLIT_FAIL);
167 /* Render. */
168 glUseProgram(prog);
169 glLoadIdentity();
170 glTranslatef(x, y, 0);
172 draw_quad(mode, color[0], attrib);
173 glDrawArrays(GL_QUADS, 0, 4);
175 glTranslatef(10, 0, 0);
176 draw_quad(mode, color[1], attrib);
178 glTranslatef(10, 0, 0);
179 draw_quad(mode, color[2], attrib);
181 switch (mask) {
182 case R:
183 for (i = 0; i < 3; i++)
184 color[i][1] = 0;
185 /* fall through */
186 case RG:
187 for (i = 0; i < 3; i++)
188 color[i][2] = 0;
189 /* fall through */
190 case RGB:
191 for (i = 0; i < 3; i++)
192 color[i][3] = 1;
193 /* fall through */
194 case RGBA:
195 break;
196 default:
197 assert(0);
200 if (strstr(info, "GL_INT_2_10_10_10_REV-norm")) {
201 if (snorm_equation_23) {
202 for (i = 0; i < 3; i++) {
203 if (color[i][3] < 1)
204 color[i][3] = 0;
207 else {
208 for (i = 0; i < 3; i++) {
209 if (color[i][3] < 0.333)
210 color[i][3] = 0;
211 else if (color[i][3] < 1)
212 color[i][3] = 0.333;
215 } else if (strstr(info, "GL_INT_2_10_10_10_REV")) {
216 for (i = 0; i < 3; i++) {
217 if (color[i][3] < 1)
218 color[i][3] = 0;
220 } else if (strstr(info, "GL_UNSIGNED_INT_2_10_10_10_REV")) {
221 for (i = 0; i < 3; i++) {
222 if (color[i][3] < 0.333)
223 color[i][3] = 0;
224 else if (color[i][3] < 0.666)
225 color[i][3] = 0.333;
226 else if (color[i][3] < 1)
227 color[i][3] = 0.666;
231 /* We scale alpha in the shader to ensure it's not > 1 when it should be 1. */
232 for (i = 0; i < 3; i++)
233 color[i][3] *= 0.5;
235 /* Probe pixels. */
236 pass = piglit_probe_pixel_rgba(x+5, y+5, color[0]) && pass;
237 pass = piglit_probe_pixel_rgba(x+15, y+5, color[1]) && pass;
238 pass = piglit_probe_pixel_rgba(x+25, y+5, color[2]) && pass;
239 return pass;
242 typedef GLboolean (*test_func)(int x, int y, unsigned mode);
244 #define DEFINE_TEST(func, funcsuffix, params, shaderfunc, mask, type, info) \
245 static void invoke_##func##funcsuffix(float x, float y, float z, float w) \
247 func params; \
250 static GLboolean test_##func##funcsuffix(int x, int y, unsigned mode) \
252 printf("Testing %s, %s\n", #func "(" info ")", mode_to_str[mode]); \
253 return test(x, y, shaderfunc, mask, type, mode, invoke_##func##funcsuffix, info); \
256 #define B(f) ((f) * 0x7F)
257 #define UB(f) ((f) * 0xFF)
258 #define S(f) ((f) * 0x7FFF)
259 #define US(f) ((f) * 0xFFFF)
260 #define I(f) ((double)(f) * 0x7FFFFFFF)
261 #define UI(f) ((double)(f) * 0xFFFFFFFF)
263 /* GL 2.0 */
264 /* XXX This list is incomplete. */
265 DEFINE_TEST(glColor3b,, (B(x), B(y), B(z)), "gl_Color", RGB, FLOAT_TYPE, "")
266 DEFINE_TEST(glColor3d,, (x, y, z), "gl_Color", RGB, FLOAT_TYPE, "")
267 DEFINE_TEST(glColor3f,, (x, y, z), "gl_Color", RGB, FLOAT_TYPE, "")
268 DEFINE_TEST(glColor3i,, (I(x), I(y), I(z)), "gl_Color", RGB, FLOAT_TYPE, "")
269 DEFINE_TEST(glColor3s,, (S(x), S(y), S(z)), "gl_Color", RGB, FLOAT_TYPE, "")
270 DEFINE_TEST(glColor3ub,, (UB(x), UB(y), UB(z)), "gl_Color", RGB, FLOAT_TYPE, "")
271 DEFINE_TEST(glColor3ui,, (UI(x), UI(y), UI(z)), "gl_Color", RGB, FLOAT_TYPE, "")
272 DEFINE_TEST(glColor3us,, (US(x), US(y), US(z)), "gl_Color", RGB, FLOAT_TYPE, "")
273 DEFINE_TEST(glColor4b,, (B(x), B(y), B(z), B(w)), "gl_Color", RGBA, FLOAT_TYPE, "")
274 DEFINE_TEST(glColor4d,, (x, y, z, w), "gl_Color", RGBA, FLOAT_TYPE, "")
275 DEFINE_TEST(glColor4f,, (x, y, z, w), "gl_Color", RGBA, FLOAT_TYPE, "")
276 DEFINE_TEST(glColor4i,, (I(x), I(y), I(z), I(w)), "gl_Color", RGBA, FLOAT_TYPE, "")
277 DEFINE_TEST(glColor4s,, (S(x), S(y), S(z), S(w)), "gl_Color", RGBA, FLOAT_TYPE, "")
278 DEFINE_TEST(glColor4ub,, (UB(x), UB(y), UB(z), UB(w)), "gl_Color", RGBA, FLOAT_TYPE, "")
279 DEFINE_TEST(glColor4ui,, (UI(x), UI(y), UI(z), UI(w)), "gl_Color", RGBA, FLOAT_TYPE, "")
280 DEFINE_TEST(glColor4us,, (US(x), US(y), US(z), US(w)), "gl_Color",RGBA, FLOAT_TYPE, "")
281 DEFINE_TEST(glVertexAttrib1d,, (1, x), "attr", R, FLOAT_TYPE, "")
282 DEFINE_TEST(glVertexAttrib1f,, (1, x), "attr", R, FLOAT_TYPE, "")
283 DEFINE_TEST(glVertexAttrib1s,, (1, S(x)), "attr * vec4(1.0/32768.0, 1.0, 1.0, 1.0)", R, FLOAT_TYPE, "")
284 DEFINE_TEST(glVertexAttrib2d,, (1, x, y), "attr", RG, FLOAT_TYPE, "")
285 DEFINE_TEST(glVertexAttrib2f,, (1, x, y), "attr", RG, FLOAT_TYPE, "")
286 DEFINE_TEST(glVertexAttrib2s,, (1, S(x), S(y)), "attr * vec4(vec2(1.0/32768.0), 1.0, 1.0)", RG, FLOAT_TYPE, "")
287 DEFINE_TEST(glVertexAttrib3d,, (1, x, y, z), "attr", RGB, FLOAT_TYPE, "")
288 DEFINE_TEST(glVertexAttrib3f,, (1, x, y, z), "attr", RGB, FLOAT_TYPE, "")
289 DEFINE_TEST(glVertexAttrib3s,, (1, S(x), S(y), S(z)), "attr * vec4(vec3(1.0/32768.0), 1.0)", RGB, FLOAT_TYPE, "")
290 DEFINE_TEST(glVertexAttrib4Nub,, (1, UB(x), UB(y), UB(z), UB(w)), "attr", RGBA, FLOAT_TYPE, "")
291 DEFINE_TEST(glVertexAttrib4d,, (1, x, y, z, w), "attr", RGBA, FLOAT_TYPE, "")
292 DEFINE_TEST(glVertexAttrib4f,, (1, x, y, z, w), "attr", RGBA, FLOAT_TYPE, "")
293 DEFINE_TEST(glVertexAttrib4s,, (1, S(x), S(y), S(z), S(w)), "attr * vec4(1.0/32768.0)", RGBA, FLOAT_TYPE, "")
295 static test_func tests_GL2[] = {
296 test_glColor3b,
297 test_glColor3d,
298 test_glColor3f,
299 test_glColor3i,
300 test_glColor3s,
301 test_glColor3ub,
302 test_glColor3ui,
303 test_glColor3ui,
304 test_glColor3us,
305 test_glColor4b,
306 test_glColor4d,
307 test_glColor4f,
308 test_glColor4i,
309 test_glColor4s,
310 test_glColor4ub,
311 test_glColor4ui,
312 test_glColor4us,
313 test_glVertexAttrib1d,
314 test_glVertexAttrib1d,
315 test_glVertexAttrib1f,
316 test_glVertexAttrib1s,
317 test_glVertexAttrib2d,
318 test_glVertexAttrib2f,
319 test_glVertexAttrib2s,
320 test_glVertexAttrib3d,
321 test_glVertexAttrib3f,
322 test_glVertexAttrib3s,
323 test_glVertexAttrib4Nub,
324 test_glVertexAttrib4d,
325 test_glVertexAttrib4f,
326 test_glVertexAttrib4s,
329 /* GL 3.0 */
330 DEFINE_TEST(glVertexAttribI1i,, (1, I(x)),
331 "vec4(attr) * vec4(1.0/2147483647.0, 1.0, 1.0, 1.0)", R, INT_TYPE, "")
332 DEFINE_TEST(glVertexAttribI2i,, (1, I(x), I(y)),
333 "vec4(attr) * vec4(vec2(1.0/2147483647.0), 1.0, 1.0)", RG, INT_TYPE, "")
334 DEFINE_TEST(glVertexAttribI3i,, (1, I(x), I(y), I(z)),
335 "vec4(attr) * vec4(vec3(1.0/2147483647.0), 1.0)", RGB, INT_TYPE, "")
336 DEFINE_TEST(glVertexAttribI4i,, (1, I(x), I(y), I(z), I(w)),
337 "vec4(attr) * vec4(1.0/2147483647.0)", RGBA, INT_TYPE, "")
338 DEFINE_TEST(glVertexAttribI1ui,, (1, UI(x)),
339 "vec4(attr) * vec4(1.0/4294967295.0, 1.0, 1.0, 1.0)", R, UINT_TYPE, "")
340 DEFINE_TEST(glVertexAttribI2ui,, (1, UI(x), UI(y)),
341 "vec4(attr) * vec4(vec2(1.0/4294967295.0), 1.0, 1.0)", RG, UINT_TYPE, "")
342 DEFINE_TEST(glVertexAttribI3ui,, (1, UI(x), UI(y), UI(z)),
343 "vec4(attr) * vec4(vec3(1.0/4294967295.0), 1.0)", RGB, UINT_TYPE, "")
344 DEFINE_TEST(glVertexAttribI4ui,, (1, UI(x), UI(y), UI(z), UI(w)),
345 "vec4(attr) * vec4(1.0/4294967295.0)", RGBA, UINT_TYPE, "")
347 static test_func tests_GL3[] = {
348 test_glVertexAttribI1i,
349 test_glVertexAttribI2i,
350 test_glVertexAttribI3i,
351 test_glVertexAttribI4i,
352 test_glVertexAttribI1ui,
353 test_glVertexAttribI2ui,
354 test_glVertexAttribI3ui,
355 test_glVertexAttribI4ui,
358 /* ARB_vertex_type_2_10_10_10_rev */
359 /* Packing functions for a signed normalized 2-bit component.
360 * These are based on equation 2.2 and 2.3 from the opengl specification, see:
361 * http://lists.freedesktop.org/archives/mesa-dev/2013-August/042680.html
363 #define PN2_22(f) ((int)((f) < 0.333 ? 3 /* = -0.333 */ : (f) < 1 ? 0 /* = 0.333 */ : 1))
364 #define PN2_23(f) ((int)((f) < 1 ? 0 : 1))
365 #define PN2(f) (snorm_equation_23 ? PN2_23(f) : PN2_22(f))
366 /* other packing functions */
367 #define P10(f) ((int)((f) * 0x1FF))
368 #define UP10(f) ((int)((f) * 0x3FF))
369 #define P2(f) ((int)(f)) /* unnormalized */
370 #define UP2(f) ((int)((f) * 0x3))
371 #define P1010102(x,y,z,w) (P10(x) | (P10(y) << 10) | (P10(z) << 20) | (P2(w) << 30))
372 #define PN1010102(x,y,z,w) (P10(x) | (P10(y) << 10) | (P10(z) << 20) | (PN2(w) << 30))
373 #define UP1010102(x,y,z,w) (UP10(x) | (UP10(y) << 10) | (UP10(z) << 20) | (UP2(w) << 30))
375 /* GL_INT_2_10_10_10_REV */
376 DEFINE_TEST(glTexCoordP1ui,, (GL_INT_2_10_10_10_REV, P1010102(x,y,z,w)),
377 "gl_MultiTexCoord0 * vec4(1.0/511.0, 1.0, 1.0, 1.0)", R, FLOAT_TYPE, "GL_INT_2_10_10_10_REV")
378 DEFINE_TEST(glTexCoordP2ui,, (GL_INT_2_10_10_10_REV, P1010102(x,y,z,w)),
379 "gl_MultiTexCoord0 * vec4(vec2(1.0/511.0), 1.0, 1.0)", RG, FLOAT_TYPE, "GL_INT_2_10_10_10_REV")
380 DEFINE_TEST(glTexCoordP3ui,, (GL_INT_2_10_10_10_REV, P1010102(x,y,z,w)),
381 "gl_MultiTexCoord0 * vec4(vec3(1.0/511.0), 1.0)", RGB, FLOAT_TYPE, "GL_INT_2_10_10_10_REV")
382 DEFINE_TEST(glTexCoordP4ui,, (GL_INT_2_10_10_10_REV, P1010102(x,y,z,w)),
383 "gl_MultiTexCoord0 * vec4(vec3(1.0/511.0), 1.0)", RGBA, FLOAT_TYPE, "GL_INT_2_10_10_10_REV")
384 DEFINE_TEST(glMultiTexCoordP1ui,, (GL_TEXTURE1, GL_INT_2_10_10_10_REV, P1010102(x,y,z,w)),
385 "gl_MultiTexCoord1 * vec4(1.0/511.0, 1.0, 1.0, 1.0)", R, FLOAT_TYPE, "GL_INT_2_10_10_10_REV")
386 DEFINE_TEST(glMultiTexCoordP2ui,, (GL_TEXTURE1, GL_INT_2_10_10_10_REV, P1010102(x,y,z,w)),
387 "gl_MultiTexCoord1 * vec4(vec2(1.0/511.0), 1.0, 1.0)", RG, FLOAT_TYPE, "GL_INT_2_10_10_10_REV")
388 DEFINE_TEST(glMultiTexCoordP3ui,, (GL_TEXTURE1, GL_INT_2_10_10_10_REV, P1010102(x,y,z,w)),
389 "gl_MultiTexCoord1 * vec4(vec3(1.0/511.0), 1.0)", RGB, FLOAT_TYPE, "GL_INT_2_10_10_10_REV")
390 DEFINE_TEST(glMultiTexCoordP4ui,, (GL_TEXTURE1, GL_INT_2_10_10_10_REV, P1010102(x,y,z,w)),
391 "gl_MultiTexCoord1 * vec4(vec3(1.0/511.0), 1.0)", RGBA, FLOAT_TYPE, "GL_INT_2_10_10_10_REV")
392 DEFINE_TEST(glNormalP3ui,, (GL_INT_2_10_10_10_REV, PN1010102(x,y,z,w)),
393 "vec4(gl_Normal, 1.0)", RGB, FLOAT_TYPE, "GL_INT_2_10_10_10_REV-norm")
394 DEFINE_TEST(glColorP3ui,, (GL_INT_2_10_10_10_REV, PN1010102(x,y,z,w)),
395 "gl_Color", RGB, FLOAT_TYPE, "GL_INT_2_10_10_10_REV-norm")
396 DEFINE_TEST(glColorP4ui,, (GL_INT_2_10_10_10_REV, PN1010102(x,y,z,w)),
397 "gl_Color", RGBA, FLOAT_TYPE, "GL_INT_2_10_10_10_REV-norm")
398 DEFINE_TEST(glSecondaryColorP3ui,, (GL_INT_2_10_10_10_REV, PN1010102(x,y,z,w)),
399 "gl_SecondaryColor", RGB, FLOAT_TYPE, "GL_INT_2_10_10_10_REV-norm")
400 /* GL_INT_2_10_10_10_REV unnormalized */
401 DEFINE_TEST(glVertexAttribP1ui,, (1, GL_INT_2_10_10_10_REV, 0, P1010102(x,y,z,w)),
402 "attr * vec4(1.0/511.0, 1.0, 1.0, 1.0)", R, FLOAT_TYPE, "GL_INT_2_10_10_10_REV")
403 DEFINE_TEST(glVertexAttribP2ui,, (1, GL_INT_2_10_10_10_REV, 0, P1010102(x,y,z,w)),
404 "attr * vec4(vec2(1.0/511.0), 1.0, 1.0)", RG, FLOAT_TYPE, "GL_INT_2_10_10_10_REV")
405 DEFINE_TEST(glVertexAttribP3ui,, (1, GL_INT_2_10_10_10_REV, 0, P1010102(x,y,z,w)),
406 "attr * vec4(vec3(1.0/511.0), 1.0)", RGB, FLOAT_TYPE, "GL_INT_2_10_10_10_REV")
407 DEFINE_TEST(glVertexAttribP4ui,, (1, GL_INT_2_10_10_10_REV, 0, P1010102(x,y,z,w)),
408 "attr * vec4(vec3(1.0/511.0), 1.0)", RGBA, FLOAT_TYPE, "GL_INT_2_10_10_10_REV")
409 /* GL_INT_2_10_10_10_REV normalized */
410 DEFINE_TEST(glVertexAttribP1ui,_norm, (1, GL_INT_2_10_10_10_REV, 1, PN1010102(x,y,z,w)),
411 "attr", R, FLOAT_TYPE, "GL_INT_2_10_10_10_REV-norm")
412 DEFINE_TEST(glVertexAttribP2ui,_norm, (1, GL_INT_2_10_10_10_REV, 1, PN1010102(x,y,z,w)),
413 "attr", RG, FLOAT_TYPE, "GL_INT_2_10_10_10_REV-norm")
414 DEFINE_TEST(glVertexAttribP3ui,_norm, (1, GL_INT_2_10_10_10_REV, 1, PN1010102(x,y,z,w)),
415 "attr", RGB, FLOAT_TYPE, "GL_INT_2_10_10_10_REV-norm")
416 DEFINE_TEST(glVertexAttribP4ui,_norm, (1, GL_INT_2_10_10_10_REV, 1, PN1010102(x,y,z,w)),
417 "attr", RGBA, FLOAT_TYPE, "GL_INT_2_10_10_10_REV-norm")
419 /* GL_UNSIGNED_INT_2_10_10_10_REV */
420 DEFINE_TEST(glTexCoordP1ui,_uint, (GL_UNSIGNED_INT_2_10_10_10_REV, UP1010102(x,y,z,w)),
421 "gl_MultiTexCoord0 * vec4(1.0/1023.0, 1.0, 1.0, 1.0)", R, FLOAT_TYPE, "GL_UNSIGNED_INT_2_10_10_10_REV")
422 DEFINE_TEST(glTexCoordP2ui,_uint, (GL_UNSIGNED_INT_2_10_10_10_REV, UP1010102(x,y,z,w)),
423 "gl_MultiTexCoord0 * vec4(vec2(1.0/1023.0), 1.0, 1.0)", RG, FLOAT_TYPE, "GL_UNSIGNED_INT_2_10_10_10_REV")
424 DEFINE_TEST(glTexCoordP3ui,_uint, (GL_UNSIGNED_INT_2_10_10_10_REV, UP1010102(x,y,z,w)),
425 "gl_MultiTexCoord0 * vec4(vec3(1.0/1023.0), 1.0)", RGB, FLOAT_TYPE, "GL_UNSIGNED_INT_2_10_10_10_REV")
426 DEFINE_TEST(glTexCoordP4ui,_uint, (GL_UNSIGNED_INT_2_10_10_10_REV, UP1010102(x,y,z,w)),
427 "gl_MultiTexCoord0 * vec4(vec3(1.0/1023.0), 1.0/3.0)", RGBA, FLOAT_TYPE, "GL_UNSIGNED_INT_2_10_10_10_REV")
428 DEFINE_TEST(glMultiTexCoordP1ui,_uint, (GL_TEXTURE1, GL_UNSIGNED_INT_2_10_10_10_REV, UP1010102(x,y,z,w)),
429 "gl_MultiTexCoord1 * vec4(1.0/1023.0, 1.0, 1.0, 1.0)", R, FLOAT_TYPE, "GL_UNSIGNED_INT_2_10_10_10_REV")
430 DEFINE_TEST(glMultiTexCoordP2ui,_uint, (GL_TEXTURE1, GL_UNSIGNED_INT_2_10_10_10_REV, UP1010102(x,y,z,w)),
431 "gl_MultiTexCoord1 * vec4(vec2(1.0/1023.0), 1.0, 1.0)", RG, FLOAT_TYPE, "GL_UNSIGNED_INT_2_10_10_10_REV")
432 DEFINE_TEST(glMultiTexCoordP3ui,_uint, (GL_TEXTURE1, GL_UNSIGNED_INT_2_10_10_10_REV, UP1010102(x,y,z,w)),
433 "gl_MultiTexCoord1 * vec4(vec3(1.0/1023.0), 1.0)", RGB, FLOAT_TYPE, "GL_UNSIGNED_INT_2_10_10_10_REV")
434 DEFINE_TEST(glMultiTexCoordP4ui,_uint, (GL_TEXTURE1, GL_UNSIGNED_INT_2_10_10_10_REV, UP1010102(x,y,z,w)),
435 "gl_MultiTexCoord1 * vec4(vec3(1.0/1023.0), 1.0/3.0)", RGBA, FLOAT_TYPE, "GL_UNSIGNED_INT_2_10_10_10_REV")
436 DEFINE_TEST(glNormalP3ui,_uint, (GL_UNSIGNED_INT_2_10_10_10_REV, UP1010102(x,y,z,w)),
437 "vec4(gl_Normal, 1.0)", RGB, FLOAT_TYPE, "GL_UNSIGNED_INT_2_10_10_10_REV-norm")
438 DEFINE_TEST(glColorP3ui,_uint, (GL_UNSIGNED_INT_2_10_10_10_REV, UP1010102(x,y,z,w)),
439 "gl_Color", RGB, FLOAT_TYPE, "GL_UNSIGNED_INT_2_10_10_10_REV-norm")
440 DEFINE_TEST(glColorP4ui,_uint, (GL_UNSIGNED_INT_2_10_10_10_REV, UP1010102(x,y,z,w)),
441 "gl_Color", RGBA, FLOAT_TYPE, "GL_UNSIGNED_INT_2_10_10_10_REV-norm")
442 DEFINE_TEST(glSecondaryColorP3ui,_uint, (GL_UNSIGNED_INT_2_10_10_10_REV, UP1010102(x,y,z,w)),
443 "gl_SecondaryColor", RGB, FLOAT_TYPE, "GL_UNSIGNED_INT_2_10_10_10_REV-norm")
444 /* GL_UNSIGNED_INT_2_10_10_10_REV unnormalized */
445 DEFINE_TEST(glVertexAttribP1ui,_uint, (1, GL_UNSIGNED_INT_2_10_10_10_REV, 0, UP1010102(x,y,z,w)),
446 "attr * vec4(1.0/1023.0, 1.0, 1.0, 1.0)", R, FLOAT_TYPE, "GL_UNSIGNED_INT_2_10_10_10_REV")
447 DEFINE_TEST(glVertexAttribP2ui,_uint, (1, GL_UNSIGNED_INT_2_10_10_10_REV, 0, UP1010102(x,y,z,w)),
448 "attr * vec4(vec2(1.0/1023.0), 1.0, 1.0)", RG, FLOAT_TYPE, "GL_UNSIGNED_INT_2_10_10_10_REV")
449 DEFINE_TEST(glVertexAttribP3ui,_uint, (1, GL_UNSIGNED_INT_2_10_10_10_REV, 0, UP1010102(x,y,z,w)),
450 "attr * vec4(vec3(1.0/1023.0), 1.0)", RGB, FLOAT_TYPE, "GL_UNSIGNED_INT_2_10_10_10_REV")
451 DEFINE_TEST(glVertexAttribP4ui,_uint, (1, GL_UNSIGNED_INT_2_10_10_10_REV, 0, UP1010102(x,y,z,w)),
452 "attr * vec4(vec3(1.0/1023.0), 1.0/3.0)", RGBA, FLOAT_TYPE, "GL_UNSIGNED_INT_2_10_10_10_REV")
453 /* GL_UNSIGNED_INT_2_10_10_10_REV normalized */
454 DEFINE_TEST(glVertexAttribP1ui,_uint_norm, (1, GL_UNSIGNED_INT_2_10_10_10_REV, 1, UP1010102(x,y,z,w)),
455 "attr", R, FLOAT_TYPE, "GL_UNSIGNED_INT_2_10_10_10_REV-norm")
456 DEFINE_TEST(glVertexAttribP2ui,_uint_norm, (1, GL_UNSIGNED_INT_2_10_10_10_REV, 1, UP1010102(x,y,z,w)),
457 "attr", RG, FLOAT_TYPE, "GL_UNSIGNED_INT_2_10_10_10_REV-norm")
458 DEFINE_TEST(glVertexAttribP3ui,_uint_norm, (1, GL_UNSIGNED_INT_2_10_10_10_REV, 1, UP1010102(x,y,z,w)),
459 "attr", RGB, FLOAT_TYPE, "GL_UNSIGNED_INT_2_10_10_10_REV-norm")
460 DEFINE_TEST(glVertexAttribP4ui,_uint_norm, (1, GL_UNSIGNED_INT_2_10_10_10_REV, 1, UP1010102(x,y,z,w)),
461 "attr", RGBA, FLOAT_TYPE, "GL_UNSIGNED_INT_2_10_10_10_REV-norm")
463 static test_func tests_GL_ARB_vertex_type_2_10_10_10_rev[] = {
464 test_glTexCoordP1ui,
465 test_glTexCoordP2ui,
466 test_glTexCoordP3ui,
467 test_glTexCoordP4ui,
468 test_glMultiTexCoordP1ui,
469 test_glMultiTexCoordP2ui,
470 test_glMultiTexCoordP3ui,
471 test_glMultiTexCoordP4ui,
472 test_glNormalP3ui,
473 test_glColorP3ui,
474 test_glColorP4ui,
475 test_glSecondaryColorP3ui,
476 test_glVertexAttribP1ui,
477 test_glVertexAttribP2ui,
478 test_glVertexAttribP3ui,
479 test_glVertexAttribP4ui,
480 test_glVertexAttribP1ui_norm,
481 test_glVertexAttribP2ui_norm,
482 test_glVertexAttribP3ui_norm,
483 test_glVertexAttribP4ui_norm,
484 test_glTexCoordP1ui_uint,
485 test_glTexCoordP2ui_uint,
486 test_glTexCoordP3ui_uint,
487 test_glTexCoordP4ui_uint,
488 test_glMultiTexCoordP1ui_uint,
489 test_glMultiTexCoordP2ui_uint,
490 test_glMultiTexCoordP3ui_uint,
491 test_glMultiTexCoordP4ui_uint,
492 test_glNormalP3ui_uint,
493 test_glColorP3ui_uint,
494 test_glColorP4ui_uint,
495 test_glSecondaryColorP3ui_uint,
496 test_glVertexAttribP1ui_uint,
497 test_glVertexAttribP2ui_uint,
498 test_glVertexAttribP3ui_uint,
499 test_glVertexAttribP4ui_uint,
500 test_glVertexAttribP1ui_uint_norm,
501 test_glVertexAttribP2ui_uint_norm,
502 test_glVertexAttribP3ui_uint_norm,
503 test_glVertexAttribP4ui_uint_norm,
506 #define TESTS(name) #name, tests_##name, ARRAY_SIZE(tests_##name)
508 struct test_set {
509 const char *name;
510 test_func *tests;
511 int num_tests;
512 int gl_version;
513 const char *extension;
514 int alpha_bits;
515 } test_sets[] = {
516 { TESTS(GL2) },
517 { TESTS(GL3), 30 },
518 { TESTS(GL_ARB_vertex_type_2_10_10_10_rev), 0, "GL_ARB_vertex_type_2_10_10_10_rev" },
521 struct test_set *test_set = &test_sets[0];
523 enum piglit_result piglit_display(void)
525 GLboolean pass = GL_TRUE;
526 int i, mode;
527 int x = 0, y = 0;
529 glClear(GL_COLOR_BUFFER_BIT);
530 printf("Testing %s\n", test_set->name);
532 for (mode = 0; mode < NUM_MODES; mode++) {
533 printf("\n");
534 for (i = 0; i < test_set->num_tests; i++) {
535 pass = test_set->tests[i](x, y, mode) && pass;
536 x += 40;
537 if (x+40 > piglit_width) {
538 x = 0;
539 y += 20;
544 if (!piglit_check_gl_error(GL_NO_ERROR))
545 piglit_report_result(PIGLIT_FAIL);
546 piglit_present_results();
548 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
551 void piglit_init(int argc, char **argv)
553 int a,i;
555 piglit_require_gl_version(20);
556 piglit_require_extension("GL_ARB_explicit_attrib_location");
557 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
559 snorm_equation_23 = piglit_get_gl_version() >= 42;
561 glClearColor(0.2, 0.2, 0.2, 1.0);
563 for (a = 1; a < argc; a++) {
564 for (i = 0; i < ARRAY_SIZE(test_sets); i++) {
565 if (strcmp(argv[a], test_sets[i].name) == 0) {
566 if (test_sets[i].gl_version)
567 piglit_require_gl_version(test_sets[i].gl_version);
568 if (test_sets[i].extension)
569 piglit_require_extension(test_sets[i].extension);
571 test_set = &test_sets[i];
572 return;