ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / glsl-1.20 / getactiveuniform-constant.c
blob4742ae77c2eeebaef2bb21c0802a4c05071f5a55
1 /*
2 * Copyright © 2009 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.
24 /** @file getactiveuniform-constant.c
27 #include "piglit-util-gl.h"
29 PIGLIT_GL_TEST_CONFIG_BEGIN
31 config.supports_gl_compat_version = 10;
33 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
35 PIGLIT_GL_TEST_CONFIG_END
37 static const char vs_code[] =
38 "#version 120\n"
39 "uniform vec4 a;\n"
40 "uniform vec4 b;\n"
41 "uniform vec4 c;\n"
42 "uniform vec4 d;\n"
43 "uniform int i;\n"
44 "const vec4 vv[] =\n"
45 " vec4[](vec4( 1, 2, 3, 4),\n"
46 " vec4( 5, 6, 7, 8),\n"
47 " vec4( 9, 10, 11, 12),\n"
48 " vec4(13, 14, 15, 16));\n"
49 "\n"
50 "void main() {\n"
51 " gl_Position = a + b + c + d + vv[i]\n;"
52 "}\n"
55 static const char fs_code[] =
56 "#version 120\n"
57 "uniform vec4 e;\n"
58 "uniform vec4 f;\n"
59 "uniform vec4 g;\n"
60 "uniform vec4 h;\n"
61 "uniform int j;\n"
62 "\n"
63 "void main() {\n"
64 " const vec4 fv[] =\n"
65 " vec4[](vec4( 1, 2, 3, 4),\n"
66 " vec4( 5, 6, 7, 8),\n"
67 " vec4( 9, 10, 11, 12),\n"
68 " vec4(13, 14, 15, 16));\n"
69 "\n"
70 " gl_FragColor = e + f + g + h + fv[j]\n;"
71 "}\n"
74 static const char *all_uniform_names[] = {
75 "a",
76 "b",
77 "c",
78 "d",
79 "e",
80 "f",
81 "g",
82 "h",
83 "i",
84 "j",
87 static bool uniform_seen[ARRAY_SIZE(all_uniform_names)] = {
88 false,
91 void
92 piglit_init(int argc, char **argv)
94 bool pass = true;
95 GLint prog;
96 GLint vs;
97 GLint fs;
98 GLint num;
99 int i;
101 piglit_require_GLSL_version(120);
103 vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_code);
104 fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_code);
105 prog = piglit_link_simple_program(vs, fs);
107 glGetProgramiv(prog, GL_ACTIVE_UNIFORMS, &num);
108 for (i = 0; i < num; i++) {
109 char name[256];
110 GLsizei length;
111 GLint size;
112 GLenum type;
113 bool found;
114 unsigned j;
116 glGetActiveUniform(prog,
118 sizeof(name),
119 &length,
120 &size,
121 &type,
122 name);
123 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
125 /* Try to find the name in the table of known names.
126 * If the name is not found, fail.
128 found = false;
129 for (j = 0; j < ARRAY_SIZE(all_uniform_names); j++) {
130 if (strcmp(name, all_uniform_names[j]) == 0) {
131 found = true;
132 uniform_seen[j] = true;
133 break;
137 if (!found) {
138 fprintf(stderr,
139 "Uniform name \"%s\" returned by "
140 "glGetActiveUniform, but should not have "
141 "been.\n",
142 name);
143 pass = false;
147 for (i = 0; i < ARRAY_SIZE(uniform_seen); i++) {
148 if (!uniform_seen[i]) {
149 fprintf(stderr,
150 "Uniform name \"%s\" was not returned by "
151 "glGetActiveUniform, but should have "
152 "been.\n",
153 all_uniform_names[i]);
154 pass = false;
158 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
161 enum piglit_result
162 piglit_display(void)
164 /* UNREACHED */
165 return PIGLIT_FAIL;