2 * Copyright © 2012 Intel Corporation
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
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
25 * Check that glGetActiveAttrib returns the correct size values,
26 * for arrays of various sizes.
29 #include "piglit-util-gl.h"
31 PIGLIT_GL_TEST_CONFIG_BEGIN
33 config
.supports_gl_core_version
= 32;
34 config
.supports_gl_compat_version
= 32;
35 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
37 PIGLIT_GL_TEST_CONFIG_END
39 static const char *vs_source
=
50 " color = vec4(a[0] + b[0] + b[1],\n"
51 " c[0] + c[1] + c[2],\n"
52 " d[0] + d[1] + d[2] + d[3],\n"
53 " e[0] + e[1] + e[2] + e[3] + e[4]);\n"
56 static const char *fs_source
=
61 " gl_FragColor = color;\n"
72 * Find the given attribute size then, check if the passed expected size
73 * is equal to the actual size.
76 getAttribLocTest(GLint program
, int active_attribs
, int max_name_length
,
77 char *attrib_name
, int expected_size
)
81 GLenum type
= GL_NONE
;
82 char *name
= malloc(max_name_length
);
85 for(i
= 0; i
< active_attribs
; i
++) {
86 glGetActiveAttrib(program
, i
, max_name_length
,
87 NULL
, &size
, &type
, name
);
89 if(strcmp(attrib_name
, name
) == 0) {
94 /* Check if no attrib was found */
95 if(i
== active_attribs
) {
97 printf("Attribute '%s' not found\n", attrib_name
);
100 /* Check for non-matching sizes */
101 if(size
!= expected_size
) {
103 printf("Attribute '%s': size %d; expected %d\n",
104 name
, size
, expected_size
);
112 piglit_init(int argc
, char **argv
)
118 GLint active_attribs
= 0;
119 GLint max_length
= 0;
121 prog
= piglit_build_simple_program(vs_source
, fs_source
);
124 glGetProgramiv(prog
, GL_ACTIVE_ATTRIBUTES
, &active_attribs
);
125 glGetProgramiv(prog
, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH
, &max_length
);
128 * Check the size of the given attribute with the
129 * corresponding expected array size.
131 pass
= getAttribLocTest(prog
, active_attribs
, max_length
, "a", 1) && pass
;
132 pass
= getAttribLocTest(prog
, active_attribs
, max_length
, "b", 2) && pass
;
133 pass
= getAttribLocTest(prog
, active_attribs
, max_length
, "c", 3) && pass
;
134 pass
= getAttribLocTest(prog
, active_attribs
, max_length
, "d", 4) && pass
;
135 pass
= getAttribLocTest(prog
, active_attribs
, max_length
, "e", 5) && pass
;
137 glDeleteProgram(prog
);
139 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);