perf/pixel-rate: new pixel throughput microbenchmark
[piglit.git] / tests / spec / glsl-1.50 / execution / get-active-attrib-array.c
blob7a86c6a56e38df76f29a495828755a89a05dd70b
1 /*
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
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.
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 =
40 "#version 150\n"
41 "in int a[1];\n"
42 "in int b[2];\n"
43 "in int c[3];\n"
44 "in int d[4];\n"
45 "in int e[5];\n"
46 "\n"
47 "out vec4 color;\n"
48 "void main()\n"
49 "{\n"
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"
54 "}\n";
56 static const char *fs_source =
57 "#version 150\n"
58 "in vec4 color;\n"
59 "void main()\n"
60 "{\n"
61 " gl_FragColor = color;\n"
62 "}\n";
64 enum piglit_result
65 piglit_display(void)
67 /* UNREACHED */
68 return PIGLIT_FAIL;
72 * Find the given attribute size then, check if the passed expected size
73 * is equal to the actual size.
75 bool
76 getAttribLocTest(GLint program, int active_attribs, int max_name_length,
77 char *attrib_name, int expected_size)
79 bool pass = true;
80 int size = -1;
81 GLenum type = GL_NONE;
82 char *name = malloc(max_name_length);
84 int i;
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) {
90 break;
94 /* Check if no attrib was found */
95 if(i == active_attribs) {
96 pass = false;
97 printf("Attribute '%s' not found\n", attrib_name);
100 /* Check for non-matching sizes */
101 if(size != expected_size) {
102 pass = false;
103 printf("Attribute '%s': size %d; expected %d\n",
104 name, size, expected_size);
107 free(name);
108 return pass;
111 void
112 piglit_init(int argc, char **argv)
114 bool pass = true;
116 GLint prog = 0;
118 GLint active_attribs = 0;
119 GLint max_length = 0;
121 prog = piglit_build_simple_program(vs_source, fs_source);
122 glUseProgram(prog);
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);